I need a way to fake reflection in C++ code that makes as few
assumptions about the data types involved as possible. I suspect
there is no good answer for what I need to do, but I'll present the
case anyway.
We have a class that normally registers with another service, which
then executes callbacks in our class. Since that other service isn't
going to be available for testing for a while, we're simulating it
with a simple script-based driver. The callbacks look something like:
class MyListener : public baseListener
{
public:
onSubscribe (const MyQueryType& query);
onUnsubscribe (const MyQueryType& query);
onChanged(const MyQueryType& oldQuery, const myQueryType&
newQuery);
// etc., etc., etc.
};
There are potentially going to be many different types of listeners,
each taking a different query object type.
The format of the script is:
subscribe <MyQueryType>{p arm1 = value1; parm2 = value2; parmN =
valueN;}
unsubscribe <MyQueryType>{p arm1 = value1; parm2 = value2; parmN =
valueN;}
subscribe <MyQueryType>{p arm1 = value1;}
As you can see, some parameters for the query type may be left
unspecified.
Now, here's my problem: I need to take a text description of an object
and translate that into a real object, setting its parameters. IOW,
at runtime I need to go from a string of text that says:
subscribe <MyQueryType>{p arm1 = value1; parm2 = value2; parmN =
valueN;}
to executing the equivalent of the following code:
MyQueryType newQuery;
newQuery.parm1 = value1;
newQuery.parm2 = value2;
newQuery.parmN = valueN;
m_listener.Subs cribe(newQuery) ;
but doing so in a way that isn't hard-coded, or that relies on an
implementation for every possible query type.
I need some way to fake reflection, where I could maybe do something
like
genericQueryObj ect = CreateObject(ty peName);
genericQueryObj ect.Set(paramNa me, paramValue);
... // repeat for each parameter
m_listener.Subs cribe(genericQu eryObject.GetQu ery());
without having to write a specific implementation for every possible
query type class. IOW, I don't want to have to do this:
void MyQueryTypeHand ler::Set(string paramName, string value)
{
if (paramName == "lat")
lat = convertToFloat( value);
else if (paramName == "lon")
lon = convertToFloat( value);
...
}
for each query type, especially since I don't know what query types
are going to be generated in the future.
Just being able to refer to members by name would be a *huge* help,
but I suspect there's no good answer for what I need to do, and that I
am going to have to some variation of the Set function above, but if
anyone has any pointers, I'd be glad to hear them. 1 1719 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Fakhar |
last post by:
Hi All,
How can I check fake requests on my webpage. I am asking for email address
as input and I wounder if anyone write a program to send fake requests and
my system will be busy to respond those requests.
Specifically, I want to check if more than 10 requests from same IP in last
One minute then my Website should not respond to that IP.
Take care
|
by: Alex |
last post by:
Hello people,
The following is not a troll but a serious request.
I found myself in a position where I have to present a Pro/Con list to management and architects in our company with regard to developing new products (specifically - desktop products) in C#/.NET instead of the usual C++/COM that we do.
Since I am not an experienced .NET developer by any definition, I don't have a good grip on the "Pro" part.
The argument that I hear...
|
by: Sol Linderstein |
last post by:
Hi,
I'm writing a CGI application and here's what I'm stuck with. There
are some text boxes in an html form that I want to validate. The
validation needs to happen on the server side because the data to
validate against is inside a mysql database residing on the server. I
want to present the user with a popup only if the validation fails.
Ideally the user doesn't even know the validation is happening unless
it fails. He just moves from...
|
by: Jason Coyne Gaijin42 |
last post by:
I have seen several people looking for a way to access the Columns
collection when using the AutoGenerate = true option. Some
people have gotten so far as to find the private autoGenColumnsArray
that has the information, but we as developers have no way to access
this information.
I have come up with a solution for the problem, (as I am sure many
others have) using reflection. Here is some sample code that will
print out the auto...
|
by: Mark |
last post by:
Am I out of my mind if I use Reflection everytime someone logs into our site
to get and track the current Major/Minor/Build/Revision version that the
person is viewing our site through? This information would then be logged
to a database along with some other information about the user.
Thanks in advance.
Mark
| |
by: Sky Sigal |
last post by:
I coming unglued... really need some help. 3 days chasing my tail all over
MSDN's documentation ...and I'm getting nowhere.
I have a problem with TypeConverters and
storage of expandableobjects to attributes in tags (think Style tag -> Style
object).
The problem that I am chasing is:
Html side:
|
by: Shawn Hogan |
last post by:
Hi everyone,
I've been trying to execute a control's private event code via reflection
from another class with the goal of potentially doing some unit testing. The
examples below are trying to execute button2's click event.
This works great when i know the name of the method that i want to invoke. I
do so by doing this:
Dim AssemblyPointer As Reflection.Assembly
|
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= |
last post by:
I get the above error in some of the ASP.NET web applications on a
server, and I need some help figuring out how to deal with it.
This is a rather long post, and I hope I have enough details that
someone who bothers to read all of it have some pointers.
Note, I have posted the stack trace and the code exhibiting the problem
further down so if you want to start by reading that, search for +++
Also note that I am unable to reproduce...
|
by: Cralis |
last post by:
Hi guys,
Someone once said, 'You can do that with reflection'. I can't recall
what it was I was trying to do at the time, but then he said, 'Any
developer knows what reflection is...'. I kept quiet and smiled.
What is reflection!?
I have been reading it up, and all I can work out is that it has
something to do with Late Binding, and the use of GetType and Type.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |