From: Hicham Mouline on 21 Jun 2010 08:40 Hello, I have a base class with a number of pure virtual functions. I will have to write a large number of derived classes and I wish to generate the derived class definitions programmatically as containing the list of all pure virtual functions present in the base class. class Base { public: <function decl 1> <pure virtual function decl 2> ... <function decl n> private: ... }; I'd like to generate the following header file content programmatically: class Derived1 : public Base { private: <list of pure virtual functions from Base> }; The implementation file Derived1.cpp would also be generated programmatically as it only varies slightly for each new derived class. How would one proceed? I think there are many options, such as run a script (shell, perl or any other external executable) and try to parse the class. I understand a C++ parser is notoriously difficult to write. Is there an easier way? perhaps with boost? Regards, -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Nick Hounsome on 22 Jun 2010 08:29 On 22 June, 00:40, "Hicham Mouline" <hic...(a)mouline.org> wrote: > Hello, > > I have a base class with a number of pure virtual functions. > I will have to write a large number of derived classes and I wish to > generate the derived class definitions programmatically as containing the > list of all pure virtual functions present in the base class. > > class Base { > public: > <function decl 1> > <pure virtual function decl 2> > ... > <function decl n> > private: > ... > > }; > > I'd like to generate the following header file content programmatically: > > class Derived1 : public Base { > private: > <list of pure virtual functions from Base> > > }; > > The implementation file Derived1.cpp would also be generated > programmatically as it only > varies slightly for each new derived class. > > How would one proceed? > > I think there are many options, such as run a script (shell, perl or any > other external executable) and try to parse the class. I understand a C++ > parser is notoriously difficult to write. > > Is there an easier way? perhaps with boost? Generate Base from the the script as well as the derived classes. NB you can generate a class (IBase perhaps) containing only the pure virtual functions and have your actual Base (with it's concrete functions) derive from that. If the differences are realy very small perhaps they can be more easily expressed in data instead? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Jeremy on 22 Jun 2010 09:07 On Jun 21, 6:40 pm, "Hicham Mouline" <hic...(a)mouline.org> wrote: > Hello, > > I have a base class with a number of pure virtual functions. > I will have to write a large number of derived classes and I wish to > generate the derived class definitions programmatically as containing the > list of all pure virtual functions present in the base class. > > class Base { > public: > <function decl 1> > <pure virtual function decl 2> > ... > <function decl n> > private: > ... > > }; > > I'd like to generate the following header file content programmatically: > > class Derived1 : public Base { > private: > <list of pure virtual functions from Base> > > }; > > The implementation file Derived1.cpp would also be generated > programmatically as it only > varies slightly for each new derived class. > > How would one proceed? > > I think there are many options, such as run a script (shell, perl or any > other external executable) and try to parse the class. I understand a C++ > parser is notoriously difficult to write. > > Is there an easier way? perhaps with boost? > > Regards, { quoted clc++ banner removed; please, do it yourself. really. -mod } Get a free copy of StarUml or some similiar UML software. Model your system, and then let the tool auto-generate all the interface and implementation files. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Jorgen Grahn on 22 Jun 2010 09:12 On Mon, 2010-06-21, Hicham Mouline wrote: > Hello, > > I have a base class with a number of pure virtual functions. > I will have to write a large number of derived classes and I wish to > generate the derived class definitions programmatically as containing the > list of all pure virtual functions present in the base class. > > class Base { > public: > <function decl 1> > <pure virtual function decl 2> > ... > <function decl n> > private: > ... > }; > > I'd like to generate the following header file content programmatically: > > class Derived1 : public Base { > private: > <list of pure virtual functions from Base> > }; > > The implementation file Derived1.cpp would also be generated > programmatically as it only > varies slightly for each new derived class. > > How would one proceed? > > I think there are many options, such as run a script (shell, perl or any > other external executable) and try to parse the class. I understand a C++ > parser is notoriously difficult to write. > > Is there an easier way? perhaps with boost? Since you (according to what you write above) know what Base looks like already, the easiest way is surely to embed that knowledge into the script, too. (Or spend fifteen minutes with a text editor and search-and-replace, since I guess this happens exactly once per project using Base.) /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: Comparing Multiple Strings More Efficiently Next: future of the C++ |