473,803 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with automatic code generation

heard that we can do automatic code generation using macros, but not
sure how can I pursue this. Here is my problem.

In my env, I have class A,B and C. All of them has constructors, and
few common methods, like reset, and execute.

now my env(main) class actually is where I am creating this objects.
in .h
A myA;
B myB;
C myC;

and later I am calling methods in my .C file
myA.reset();
myB.reset();
myC.reset();
myA.execute();
.....
myC.execute();

now let say if I add Class D, I have to modify my env.h and env.C. And
I am trying to prevent that.
one way i was thinking of doing this, is to write macros:
so I can do:
REGISTER_OBJECT ("A","myA");
REGISTER_RESET( "A","myA",reset );
REGISTER_EXECUT E("A", "myA", execute)
.............

May be using macros might be one way to do this. I am really confuse
how I can I write this macros. Please guide me.

Thank you,

Jan 31 '07 #1
6 1956
JoshforRefugee <an*****@yahoo. comwrote:
heard that we can do automatic code generation using macros, but not
sure how can I pursue this. Here is my problem.

In my env, I have class A,B and C. All of them has constructors, and
few common methods, like reset, and execute.
Don't bother with macros for things that can be done with simple
OO techniques. Your classes should probably derive from a base
class that declares the common methods as virtuals.
Jan 31 '07 #2
problem is I own env class, and my group owns other classes. and I
don't want to be bother by creating class and registering its
function, every time someone adds new class or wants to create new
object for same class.

how can I do this?

Jan 31 '07 #3
JoshforRefugee wrote:
>
how can I do this?
What do you want - new names for single class? Or what?

--
Maksim A Polyanin
Jan 31 '07 #4
just an interface for users so that they can register their classes
with my "main/env" class.

What I am doing, is collecting all classes out there, written by users
and constructing objects for them, and calling their methods (reset,
run). Users derived their class from base object class. Right now,
when someone adds new class, I have to open up "main/env" class and
create object for new class, and call common methods (reset, run) for
that new object.

My goal is to not manually touch "main/evn" class, everytime someone
creates new class. Let have some hooks that users can use so that they
can create these class and reset/run methods will be call for
them.

Jan 31 '07 #5
On Jan 31, 7:16 pm, "JoshforRefugee " <anki...@yahoo. comwrote:
just an interface for users so that they can register their classes
with my "main/env" class.

What I am doing, is collecting all classes out there, written by users
and constructing objects for them, and calling their methods (reset,
run). Users derived their class from base object class. Right now,
when someone adds new class, I have to open up "main/env" class and
create object for new class, and call common methods (reset, run) for
that new object.

My goal is to not manually touch "main/evn" class, everytime someone
creates new class. Let have some hooks that users can use so that they
can create these class and reset/run methods will be call for
them.
Can't you do something like this:

class env {
std::vector<Bas e*classes;
public:
void register(Base& b) {
classes.push_ba ck(&b);
}
void resetAll() {
for (size_t i = 0; i < classes.size(); ++i)
classes[i]->reset();
}
};

I kind of assume here that you'll only have one instance of env (a
singleton comes to mind) but even if you don't you might be able to
use this approach. The idea is that the new classes registers
themselves with your env instance either when constructed or soon
after.

--
Erik Wikström

Feb 1 '07 #6
that is good help. Thank you Erik.
that will take care of registering functions for new classes.
How about creating object for this class. Can I automate that?

so now in my top class, where I am doing

class top {
env myEnv;
A myA;
B myB;
C myC; //can I automate this creating
public:
void run() {
myEnv.resetAll( );
myEnv.execute() ;
}

};

something like this in my classes will be very useful:

DECLARE (A, "myA");
DECLARE (A, "myAA");
class A {
.......

}

DECLARE(B, "myB");
class B {
....
}

so basically user has control how many objects to create.
Feb 1 '07 #7

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

Similar topics

0
2446
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in UML, and using automatic code generation to make Python APIs, XML I/O etc. (more below). We can be found at http://www.ccpn.ac.uk/index.html As a general point, automtic code generation would seem like a good idea in special cases where:
5
3537
by: ArShAm | last post by:
Hi there Please help me to optimize this code for speed I added /O2 to compiler settings I added /Oe to compiler settings for accepting register type request , but it seems that is not allowed and if I remove register type for "l" , time of generating codes doesn't change the original code makes some files , but I removed that section to make it simple for you to read please help me to optimize it for faster running
15
7912
by: Kannan Goundan | last post by:
Maintaining a C++ header file can be painful. I want a way to automatically generate header files from the implementation file. Does anybody know of a program that does this? If not, I'd like to try writing one. The input file would consist of function definitions and class definitions (with all methods defined inline). The program would extract all the signatures and place them in a header file. I can see some small problems...
2
1717
by: Paul M | last post by:
Hi there, can anyone help me with this one.... i have a page which is in normal english format, but when i wanna change it to Russian format text, i set the Culture code, but it still remains the same. Does this mean that every bit of text i need to convert every label on my screens in order for them to show or is there an easier way to this? thanks for anybody's help.
4
2534
by: Petterson Mikael | last post by:
Hi, Anyone out there that knows of a automatic test generation tool for cpp? Another requirement is that the test results should be presented in xml. All hints appreciated. cheers, //mikael
6
3555
by: Bill foust | last post by:
I'm running into a situation there I think an operator overload would solve the issue, but I'm unable to make it work for some reason. If anyone can help here I would appreciate it. I have a base class that is common to many other classes. public class Base .... end class I have 2 seperate classes that inherit from base
1
2518
by: woessner | last post by:
I have a lot of classes which derive from a common base class. I want to be able to clone objects of these types so I have given the base class a pure virtual clone method. The derived classes all have complete copy constructors so the cloning process will consiste of "return new Derived(*this);". Here's the setup: struct Base { virtual Base* Clone() const = 0; };
0
312
by: JoshforRefugee | last post by:
heard that we can do automatic code generation using macros, but not sure how can I pursue this. Here is my problem. In my env, I have class A,B and C. All of them has constructors, and few common methods, like reset, and execute. now my env(main) class actually is where I am creating this objects. in .h A myA; B myB;
25
2675
by: sidd | last post by:
In the following code: int i = 5; ---it goes to .data segment int j; ---it goes to bss segment int main() { int c; int i = 5; ---stack
34
3696
by: =?ISO-8859-1?Q?Marcel_M=FCller?= | last post by:
Hi, is there a way to avoid the automatic copy constructor generation. I do not want the object to be non-copyable. I simply do not want that copying is done by the default copy constructor. But there is a constructor that accepts the base class. This one should be used for copying. In fact i have a set of classes with a common abstract base. The implementations do not have own data members. They only implement
0
9699
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, 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...
0
10542
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, 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...
0
10068
tracyyun
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...
0
6840
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();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
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...

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.