LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-06-2007, 01:06 PM   #1
crash_override_me
Member
 
Registered: Aug 2005
Location: India, New Delhi
Distribution: Debian Etch, Ubuntu
Posts: 342

Rep: Reputation: 30
Exclamation Reflection in C++


hi..

has anybody used reflection in C++, like there is reflection in Java.
i have to build a Testing tool to test a class.. so i need the run time info. about the various variables, methods of a class.

i have got one reflection library at sf.net called "cppreflect"
can anyone help me on this..??
 
Old 03-06-2007, 01:47 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
AFAIK, there is no reflection in C++. You don't really need it anyways, with real templates instead of "Generics". If you haven't already, you should check out boost.
 
Old 03-07-2007, 03:36 AM   #3
crash_override_me
Member
 
Registered: Aug 2005
Location: India, New Delhi
Distribution: Debian Etch, Ubuntu
Posts: 342

Original Poster
Rep: Reputation: 30
i need to build a data flow testing tool..
that is a class is input into the tool, the tool generates different sequences of methods of the class.
& finally shortlists the feasible sequences out of these...!

each method is embedded with 3 things
1. Pre-Condition: that must be tue bfore the method executes
2. Post-Condition: that must be tue after the method execution is over
3. Invariant: condition true for the entire class

the class is emedded with these conditions & input to the tool for its data flow testing: (flow of data from one method to another)..

does the boost library provide a mechanism which can help me??

or if u have some suggestion regarding other ways of doing this,,
please share them..!
 
Old 03-07-2007, 09:29 AM   #4
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
So, you want make an automatic unit testing data generator? How are you embedding the constraints into the code? As marked asserts?

I believe the best way to do this (in C++) is to essentially "compile" your sources. You can use lex and yacc to do this, or use Boost.Spirit for parsing.
 
Old 03-07-2007, 10:31 AM   #5
crash_override_me
Member
 
Registered: Aug 2005
Location: India, New Delhi
Distribution: Debian Etch, Ubuntu
Posts: 342

Original Poster
Rep: Reputation: 30
actually i need to build a tool that takes class with embedded constraints as input & generates the possible sequences of methods.

the constraints are put inside the methods... by the creater of the class, like for Class 'Stack'==>

class Stack
{
Stack()
{
-1<top<=stack_size; // invariant
}

push()
{
(!stack_full) // pre-cond.
{ }

(!stack_empty) // post-cond.
}

pop()
{
(!stack_empty) // pre-cond.
{ }

(!stack_full) // post-cond.
}
}

the class is embedded with constraints;
the diff sequences cud be:

1. Stack(),push(),pop(),push(),push()
2. Stack(),push(),pop(),pop() ---> not feasible // 2 pops consecutively

now can u guess wat i am trying to do...?

Can this be done by just using Files...?
 
Old 03-07-2007, 12:47 PM   #6
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Right, you're trying to make a unit test generator. Right there, it's more or less legal C++, but you're throwing away the condtion results. Best practice to make sure that you are actually assert()ing them, see http://en.wikipedia.org/wiki/Assertion_(computing).

Anyway, my original suggestion still applies (to write a "compiler"), and good luck with your project!

Last edited by tuxdev; 03-07-2007 at 12:48 PM.
 
Old 03-07-2007, 02:09 PM   #7
crash_override_me
Member
 
Registered: Aug 2005
Location: India, New Delhi
Distribution: Debian Etch, Ubuntu
Posts: 342

Original Poster
Rep: Reputation: 30
Quote:
the class is embedded with constraints;
the diff sequences cud be:

1. Stack(),push(),pop(),push(),push()
2. Stack(),push(),pop(),pop() ---> not feasible // 2 pops consecutively
one thing that i forgot to tell you was:
for 2 methods in the sequence, the post-cond. of 1st shud satisfy the pre-cond. of 2nd method.

i.e:
for:
Stack()-->push()-->pop()

1. post-cond. of Stack() satisfies pre-cond. of push()
2. post-cond. of push() satisfies pre-cond. of pop()

do u think, this requires reflection..??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reflection x & redhat binary_0011 Linux - General 0 07-06-2006 04:34 AM
Reflection without RandR? thepr0fess0r Linux - General 3 04-12-2005 07:35 AM
Reflection X KoR Linux - General 1 10-03-2003 06:32 PM
reflection 8 on RedHat 7.3 drick Linux - Software 0 07-28-2002 07:27 PM
Reflection X saal Linux - General 2 11-19-2001 06:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration