473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need some way to fake reflection in C++ code

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>{parm1 = value1; parm2 = value2; parmN =
valueN;}
unsubscribe <MyQueryType>{parm1 = value1; parm2 = value2; parmN =
valueN;}
subscribe <MyQueryType>{parm1 = 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>{parm1 = 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.Subscribe(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

genericQueryObject = CreateObject(typeName);
genericQueryObject.Set(paramName, paramValue);
... // repeat for each parameter
m_listener.Subscribe(genericQueryObject.GetQuery() );

without having to write a specific implementation for every possible
query type class. IOW, I don't want to have to do this:

void MyQueryTypeHandler::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.

Aug 23 '07 #1
1 1685
This: http://lcgapp.cern.ch/project/archit...ctionPaper.pdf

may or may not help you.
Aug 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
55
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...
3
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...
2
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...
2
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...
3
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...
0
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...
1
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.