![]() |
KaliVeda
Toolkit for HIC analysis
|
Factory class for generating skeleton files for new classes.
It can generate basic '.h' and '.cpp' files for
There are two ways to use KVClassFactory in order to generate code:
For example, let us suppose that we want to add the following public method to our class:
This can be done as follows:
The addition of a new method may mean that it is necessary to add an '#include' directive to either the header or the implementation file of the new class. For example, in this case, the use of 'cout', 'endl' etc. may require to add an '#include <iostream>' to the '.cpp' file of the new class. This can be done as follows:
For another example of this kind of approach, see the method KVParticleCondition::Optimize.
Definition at line 86 of file KVClassFactory.h.
#include <KVClassFactory.h>

Classes | |
| class | KVClassConstructor |
| Constructor for a class generated with KVClassFactory. More... | |
| class | KVClassDestructor |
| Destructor for a class generated with KVClassFactory. More... | |
| class | KVClassMember |
| Member variable in a class generated with KVClassFactory. More... | |
| class | KVClassMethod |
| Method in a class generated with KVClassFactory. More... | |
Public Member Functions | |
| KVClassFactory () | |
| Default ctor. More... | |
| KVClassFactory (const Char_t *classname, const Char_t *classdesc, const Char_t *base_class="", Bool_t withTemplate=kFALSE, const Char_t *templateFile="") | |
| KVClassFactory (const KVClassFactory &) | |
| ctor par copie More... | |
| void | AddAllBaseConstructors () |
| KVClassConstructor * | AddConstructor (const Char_t *argument_type="", const Char_t *argument_name="", const Char_t *default_value="", const Char_t *access="public") |
| void | AddDefaultConstructor () |
| void | AddDestructor (const TString &access="public") |
| void | AddGetSetMethods (const KVNameValueList &) |
| For each named parameter in the list, we add protected member variables with the name and type of the parameter. More... | |
| void | AddHeaderIncludeFile (const Char_t *filename) |
| void | AddImplIncludeFile (const Char_t *filename) |
| KVClassMember * | AddMember (const Char_t *name, const Char_t *type, const Char_t *comment, const Char_t *access="protected") |
| KVClassMethod * | AddMethod (const Char_t *name, const Char_t *return_type, const Char_t *access="public", Bool_t isVirtual=kFALSE, Bool_t isConst=kFALSE) |
| void | AddMethod (const KVClassMethod &kvcm) |
| void | AddMethodArgument (const Char_t *method_name, const Char_t *argument_type, const Char_t *argument_name="", const Char_t *default_value="") |
| void | AddMethodBody (const Char_t *method_name, const KVString &body) |
| void | AddMethodComment (const Char_t *method_name, const KVString &comment) |
| Set the comments for method 'method_name' added to the class using AddMethod. More... | |
| void | Copy (TObject &obj) const override |
| Copy the state of this KVClassFactory to the one referenced by 'obj'. More... | |
| void | GenerateCode () |
| Generate header and implementation file for currently-defined class. More... | |
| const Char_t * | GetBaseClass () const |
| const Char_t * | GetClassDesc () const |
| const Char_t * | GetClassName () const |
| KVClassConstructor * | GetDefaultCtor () const |
| KVClassDestructor * | GetDestructor () const |
| const Char_t * | GetHeaderFileName () const |
| const Char_t * | GetImpFileName () const |
| const KVList * | GetListOfMembers () const |
| const KVList * | GetListOfMethods () const |
| KVClassMethod * | GetMethod (const Char_t *name) const |
| Int_t | GetNumberOfMemberVariables () const |
| const Char_t * | GetOutputPath () const |
| const Char_t * | GetTemplateBase () const |
| Bool_t | HasVirtualMethods () const |
| void | InlineAllConstructors (bool yes=true) |
| void | InlineAllMethods (bool yes=true) |
| Bool_t | IsBaseClassTObject () const |
| void | Print (Option_t *opt="") const override |
| Print infos on object. More... | |
| void | SetBaseClass (const Char_t *b) |
| void | SetClassDesc (const Char_t *d) |
| void | SetClassName (const Char_t *n) |
| void | SetInheritAllConstructors (Bool_t yes=kTRUE) |
| void | SetOutputPath (const KVString &p) |
| void | SetTemplate (Bool_t temp, const Char_t *temp_file) |
| Bool_t | WithMultipleBaseClasses () const |
| Bool_t | WithTemplate () const |
Public Member Functions inherited from TObject | |
| TObject () | |
| TObject (const TObject &object) | |
| virtual | ~TObject () |
| void | AbstractMethod (const char *method) const |
| virtual void | AppendPad (Option_t *option="") |
| virtual void | Browse (TBrowser *b) |
| ULong_t | CheckedHash () |
| virtual const char * | ClassName () const |
| virtual void | Clear (Option_t *="") |
| virtual TObject * | Clone (const char *newname="") const |
| virtual Int_t | Compare (const TObject *obj) const |
| virtual void | Delete (Option_t *option="") |
| virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
| virtual void | Draw (Option_t *option="") |
| virtual void | DrawClass () const |
| virtual TObject * | DrawClone (Option_t *option="") const |
| virtual void | Dump () const |
| virtual void | Error (const char *method, const char *msgfmt,...) const |
| virtual void | Execute (const char *method, const char *params, Int_t *error=nullptr) |
| virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr) |
| virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
| virtual void | Fatal (const char *method, const char *msgfmt,...) const |
| virtual TObject * | FindObject (const char *name) const |
| virtual TObject * | FindObject (const TObject *obj) const |
| virtual Option_t * | GetDrawOption () const |
| virtual const char * | GetIconName () const |
| virtual const char * | GetName () const |
| virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
| virtual Option_t * | GetOption () const |
| virtual const char * | GetTitle () const |
| virtual UInt_t | GetUniqueID () const |
| virtual Bool_t | HandleTimer (TTimer *timer) |
| virtual ULong_t | Hash () const |
| Bool_t | HasInconsistentHash () const |
| virtual void | Info (const char *method, const char *msgfmt,...) const |
| virtual Bool_t | InheritsFrom (const char *classname) const |
| virtual Bool_t | InheritsFrom (const TClass *cl) const |
| virtual void | Inspect () const |
| void | InvertBit (UInt_t f) |
| virtual TClass * | IsA () const |
| Bool_t | IsDestructed () const |
| virtual Bool_t | IsEqual (const TObject *obj) const |
| virtual Bool_t | IsFolder () const |
| R__ALWAYS_INLINE Bool_t | IsOnHeap () const |
| virtual Bool_t | IsSortable () const |
| R__ALWAYS_INLINE Bool_t | IsZombie () const |
| virtual void | ls (Option_t *option="") const |
| void | MayNotUse (const char *method) const |
| virtual Bool_t | Notify () |
| void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
| void | operator delete (void *ptr) |
| void | operator delete (void *ptr, void *vp) |
| void | operator delete[] (void *ptr) |
| void | operator delete[] (void *ptr, void *vp) |
| void * | operator new (size_t sz) |
| void * | operator new (size_t sz, void *vp) |
| void * | operator new[] (size_t sz) |
| void * | operator new[] (size_t sz, void *vp) |
| TObject & | operator= (const TObject &rhs) |
| virtual void | Paint (Option_t *option="") |
| virtual void | Pop () |
| virtual Int_t | Read (const char *name) |
| virtual void | RecursiveRemove (TObject *obj) |
| void | ResetBit (UInt_t f) |
| virtual void | SaveAs (const char *filename="", Option_t *option="") const |
| virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
| void | SetBit (UInt_t f) |
| void | SetBit (UInt_t f, Bool_t set) |
| virtual void | SetDrawOption (Option_t *option="") |
| virtual void | SetUniqueID (UInt_t uid) |
| virtual void | Streamer (TBuffer &) |
| void | StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b) |
| virtual void | SysError (const char *method, const char *msgfmt,...) const |
| R__ALWAYS_INLINE Bool_t | TestBit (UInt_t f) const |
| Int_t | TestBits (UInt_t f) const |
| virtual void | UseCurrentStyle () |
| virtual void | Warning (const char *method, const char *msgfmt,...) const |
| virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) |
| virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const |
Static Public Member Functions | |
| static void | MakeClass (const Char_t *classname, const Char_t *classdesc, const Char_t *base_class="", Bool_t withTemplate=kFALSE, const Char_t *templateFile="") |
Static Public Member Functions inherited from TObject | |
| static TClass * | Class () |
| static const char * | Class_Name () |
| static constexpr Version_t | Class_Version () |
| static const char * | DeclFileName () |
| static Longptr_t | GetDtorOnly () |
| static Bool_t | GetObjectStat () |
| static void | SetDtorOnly (void *obj) |
| static void | SetObjectStat (Bool_t stat) |
Additional Inherited Members | |
Public Types inherited from TObject | |
| enum | EDeprecatedStatusBits |
| enum | EStatusBits |
Public Attributes inherited from TObject | |
| kBitMask | |
| kCanDelete | |
| kCannotPick | |
| kHasUUID | |
| kInconsistent | |
| kInvalidObject | |
| kIsOnHeap | |
| kIsReferenced | |
| kMustCleanup | |
| kNoContextMenu | |
| kNotDeleted | |
| kObjInCanvas | |
| kOverwrite | |
| kSingleKey | |
| kWriteDelete | |
| kZombie | |
Protected Member Functions inherited from TObject | |
| virtual void | DoError (int level, const char *location, const char *fmt, va_list va) const |
| void | MakeZombie () |
Protected Attributes inherited from TObject | |
| kOnlyPrepStep | |
| KVClassFactory::KVClassFactory | ( | ) |
Default ctor.
Definition at line 42 of file KVClassFactory.cpp.
| KVClassFactory::KVClassFactory | ( | const Char_t * | classname, |
| const Char_t * | classdesc, | ||
| const Char_t * | base_class = "", |
||
| Bool_t | withTemplate = kFALSE, |
||
| const Char_t * | templateFile = "" |
||
| ) |
Create a new class with the following characteristics:
classname = name of new class classdesc = short (one line) description of class base_class = name of base class(es)* (if creating a derived class) withTemplate = kTRUE if template files for the '.h' and '.cpp' are to be used templateFile = base name of template files
*(if the class has several base classes, give a comma-separated list)
Only classname and classdesc have to be given. By default we create a new base class without use of template files.
If withTemplate=kTRUE, the base name for the template files must be given. We check that the template files exist. If they do not, an error message is printed and this object will be made a zombie (test IsZombie() after constructor). The template for the class structure is defined in a '.h' and a '.cpp' file, as follows:
if templateFile="" (default), we expect base_class!="", and template files with names base_classTemplate.h and base_classTemplate.cpp must be present in either $TEMPLATEDIR, $HOME or $PWD directories. the dummy classname "base_classTemplate" will be replaced everywhere by 'classname'
if templateFile="/absolute/path/classTemplate" we use classTemplate.h & classTemplate.cpp in the given directory. the dummy classname "classTemplate" will be replaced everywhere by 'classname'
if templateFile="classTemplate" we look for classTemplate.h & classTemplate.cpp in $TEMPLATEDIR, $HOME or $PWD directories. the dummy classname "classTemplate" will be replaced everywhere by 'classname'
Definition at line 81 of file KVClassFactory.cpp.
| KVClassFactory::KVClassFactory | ( | const KVClassFactory & | obj | ) |
ctor par copie
Definition at line 216 of file KVClassFactory.cpp.
| void KVClassFactory::AddAllBaseConstructors | ( | ) |
Add constructors with the same signature as all base class constructors (apart from the default ctor or any copy constructors, which are a special case) If this class has its own member variables, we add them to the argument list of each base class constructor.
Definition at line 2030 of file KVClassFactory.cpp.
| KVClassFactory::KVClassConstructor * KVClassFactory::AddConstructor | ( | const Char_t * | argument_type = "", |
| const Char_t * | argument_name = "", |
||
| const Char_t * | default_value = "", |
||
| const Char_t * | access = "public" |
||
| ) |
Add a constructor with or without arguments to the class. If no arguments are given, adds a default constructor (no arguments).
Optional argument 'access' determines access type (public, protected or private) [default: "public"]
If more than one argument is needed, user should keep the returned pointer to the new object and use KVClassMethod::AddArgument() in order to add further arguments.
In order to define the implementation of the ctor method, user should keep the returned pointer to the new object and use KVClassMethod::SetMethodBody(KVString&).
Definition at line 1225 of file KVClassFactory.cpp.
| void KVClassFactory::AddDefaultConstructor | ( | ) |
Definition at line 719 of file KVClassFactory.cpp.
If this is a base class with virtual methods, it must have a virtual destructor
Otherwise, there is no need to add one
Definition at line 2072 of file KVClassFactory.cpp.
| void KVClassFactory::AddGetSetMethods | ( | const KVNameValueList & | nvl | ) |
For each named parameter in the list, we add protected member variables with the name and type of the parameter.
Definition at line 1386 of file KVClassFactory.cpp.
Add a file which will appear in the 'includes' list of the '.h' file i.e. we will add a line #include "filename" to the .h file
Definition at line 1330 of file KVClassFactory.cpp.
Add a file which will appear in the 'includes' list of the '.cpp' file i.e. we will add a line #include "filename" to the .cpp file
Definition at line 1348 of file KVClassFactory.cpp.
| KVClassFactory::KVClassMember * KVClassFactory::AddMember | ( | const Char_t * | name, |
| const Char_t * | type, | ||
| const Char_t * | comment, | ||
| const Char_t * | access = "protected" |
||
| ) |
Add a member variable to the class, with name 'f[name]' according to ROOT convention. The access type is by default "protected", in accordance with OO-encapsulation.
Definition at line 779 of file KVClassFactory.cpp.
| KVClassFactory::KVClassMethod * KVClassFactory::AddMethod | ( | const Char_t * | name, |
| const Char_t * | return_type, | ||
| const Char_t * | access = "public", |
||
| Bool_t | isVirtual = kFALSE, |
||
| Bool_t | isConst = kFALSE |
||
| ) |
Add a method to the class. User must give return type and name of method. Optional arguments determine access type (public, protected or private) and if the method is 'virtual' and/or 'const'
If another method with the same name already exists, user should keep the returned pointer to the new KVClassMethod object and use KVClassMethod::AddArgument(), KVClassMethod::SetMethodBody() in order to define arguments, method body, etc. instead of using the AddMethodArgument, AddMethodBody methods
Definition at line 1186 of file KVClassFactory.cpp.
| void KVClassFactory::AddMethod | ( | const KVClassMethod & | kvcm | ) |
A new KVClassMethod object will be created and added to the class, copying the informations held in kvcm
Definition at line 1163 of file KVClassFactory.cpp.
| void KVClassFactory::AddMethodArgument | ( | const Char_t * | method_name, |
| const Char_t * | argument_type, | ||
| const Char_t * | argument_name = "", |
||
| const Char_t * | default_value = "" |
||
| ) |
Add an argument to the method 'method_name' added to the class using AddMethod. User must give type of argument. Optional argument argument_name gives name of argument (will be used in implementation declaration). Optional argument default_value gives default value.
Definition at line 1265 of file KVClassFactory.cpp.
Set the body of the code for method 'method_name' added to the class using AddMethod. N.B. does not work for implementing constructors, see AddConstructor
Definition at line 1289 of file KVClassFactory.cpp.
Set the comments for method 'method_name' added to the class using AddMethod.
Definition at line 1308 of file KVClassFactory.cpp.
Copy the state of this KVClassFactory to the one referenced by 'obj'.
Reimplemented from TObject.
Definition at line 189 of file KVClassFactory.cpp.
| void KVClassFactory::GenerateCode | ( | ) |
Generate header and implementation file for currently-defined class.
Definition at line 732 of file KVClassFactory.cpp.
|
inline |
Definition at line 542 of file KVClassFactory.h.
|
inline |
Definition at line 528 of file KVClassFactory.h.
|
inline |
Definition at line 502 of file KVClassFactory.h.
|
inline |
Definition at line 493 of file KVClassFactory.h.
|
inline |
Definition at line 497 of file KVClassFactory.h.
|
inline |
Return name of header source file If path has been set with SetOutputPath() this is the full path to the file
Definition at line 510 of file KVClassFactory.h.
|
inline |
Return name of implemntation source file If path has been set with SetOutputPath() this is the full path to the file
Definition at line 517 of file KVClassFactory.h.
|
inline |
Definition at line 485 of file KVClassFactory.h.
|
inline |
Definition at line 481 of file KVClassFactory.h.
|
inline |
Definition at line 489 of file KVClassFactory.h.
|
inline |
Definition at line 563 of file KVClassFactory.h.
|
inline |
Return output directory for generated source files Default [=""] is current working directory
Definition at line 582 of file KVClassFactory.h.
|
inline |
Definition at line 559 of file KVClassFactory.h.
|
inline |
Definition at line 595 of file KVClassFactory.h.
| void KVClassFactory::InlineAllConstructors | ( | bool | yes = true | ) |
| yes | =true: Write implementation of all constructors & the destructor in the header file of the class. |
Definition at line 1432 of file KVClassFactory.cpp.
| void KVClassFactory::InlineAllMethods | ( | bool | yes = true | ) |
| yes | =true: Write implementation of all non-ctor/non-dtor methods in the header file of the class |
Definition at line 1415 of file KVClassFactory.cpp.
|
inline |
Definition at line 554 of file KVClassFactory.h.
|
static |
Static method for generating skeleton header and implementation files for a new class.
Give a name for the class and a short description, used for HTML doc.
The optional string 'base_class' gives the name(s) of the parent class(es)*, in case of inheritance; if not given, the new class will be a base class. *(in case of several base classes, give a comma-separated list)
if withTemplate=kTRUE, we use a template for the class structure, defined in a '.h' and a '.cpp' file, as follows:
Example of use:
will generate the following MyClass.h and MyClass.cpp files:
Definition at line 631 of file KVClassFactory.cpp.
Print infos on object.
Reimplemented from TObject.
Definition at line 1365 of file KVClassFactory.cpp.
Definition at line 532 of file KVClassFactory.h.
Definition at line 524 of file KVClassFactory.h.
Definition at line 506 of file KVClassFactory.h.
Call with kFALSE to prevent class inheriting all constructors from base class
Definition at line 589 of file KVClassFactory.h.
Set output directory for generated source files Default is current working directory
Definition at line 575 of file KVClassFactory.h.
If the class uses template files (temp=kTRUE), 'templateFile' is the base name used to find these files. The template for the class structure is defined in a '.h' and a '.cpp' file, as follows:
if templateFile="" (default), we expect a base class to have been given, and template files with names base_classTemplate.h and base_classTemplate.cpp must be present in either $TEMPLATEDIR, $HOME or $PWD directories. the dummy classname "base_classTemplate" will be replaced everywhere by 'classname'
if templateFile="/absolute/path/classTemplate" we use classTemplate.h & classTemplate.cpp in the given directory. the dummy classname "classTemplate" will be replaced everywhere by 'classname'
if templateFile="classTemplate" we look for classTemplate.h & classTemplate.cpp in $TEMPLATEDIR, $HOME or $PWD directories. the dummy classname "classTemplate" will be replaced everywhere by 'classname'
Definition at line 151 of file KVClassFactory.cpp.
|
inline |
Definition at line 546 of file KVClassFactory.h.
|
inline |
Definition at line 550 of file KVClassFactory.h.