KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVClassFactory.h
1/*
2$Id: KVClassFactory.h,v 1.13 2009/01/21 08:04:20 franklan Exp $
3$Revision: 1.13 $
4$Date: 2009/01/21 08:04:20 $
5*/
6
7#ifndef __KVCLASSFACTORY_H
8#define __KVCLASSFACTORY_H
9
10#include "Riostream.h"
11#include "TDatime.h"
12#include "TClass.h"
13#include "KVString.h"
14#include "KVNameValueList.h"
15#include "KVList.h"
16#include "KVBase.h"
17
18
86class KVClassFactory : public TObject {
87
88private:
89
111
112protected:
113
114 void WritePreProc(std::ofstream&);
115 void WriteWhoWhen(std::ofstream&);
116 void SetWhoWhen();
117 void WriteClassDec(std::ofstream&);
118 void WriteClassHeader();
119 void WriteClassImp();
122 Bool_t CheckTemplateFiles(const Char_t* base_class,
123 const Char_t* templateFile);
124
125
128 void AddCopyConstructor();
129
132public:
133
139 class KVClassMember : public KVBase {
140
141 protected:
142 KVString fComment;//informative comment for member variable, like this one :)
143 KVString fRealName;//the name of the member without the leading 'f'
144
145 public:
147 {
148 SetAccess();
149 }
150 KVClassMember(const Char_t*, const Char_t*, const Char_t*, const Char_t* = "protected");
152 ROOT_COPY_ASSIGN_OP(KVClassMember)
153 virtual ~KVClassMember() {}
154 void Copy(TObject& obj) const;
155
156 void Print(Option_t* = "") const;
157
158 virtual void WriteDeclaration(KVString&);
159
161 void SetAccess(const Char_t* acc = "public")
162 {
163 SetLabel(acc);
164 }
165
167 const Char_t* GetAccess() const
168 {
169 return GetLabel();
170 }
172 {
174 return !strcmp(GetAccess(), "public");
175 }
177 {
179 return !strcmp(GetAccess(), "protected");
180 }
182 {
184 return !strcmp(GetAccess(), "private");
185 }
186
188 void SetComment(const Char_t* c)
189 {
190 fComment = c;
191 }
192
194 const Char_t* GetComment() const
195 {
196 return fComment;
197 }
198
200 const Char_t* GetRealName() const
201 {
202 return fRealName;
203 }
204
205 ClassDef(KVClassMember, 1) //KVClassFactory helper class - description of class member variable
206 };
207
209
217
218 protected:
219 virtual void write_method_body(KVString& decl);
220 KVNameValueList fFields;//fields of method declaration
221 Bool_t fVirtual;//kTRUE if method is 'virtual'
222 Bool_t fConst;//kTRUE if method is 'const'
223 int fNargs;//counts arguments
224 Bool_t fInline;//kTRUE if method body is to be written in header file
225
226 public:
227
229 {
230 return fNargs;
231 }
233 {
234 fNargs = n;
235 }
236
237 KVClassMethod(Bool_t Virtual = kFALSE, Bool_t Const = kFALSE, Bool_t Inline = kFALSE)
238 : KVClassMember(), fVirtual(Virtual), fConst(Const), fNargs(0), fInline(Inline)
239 {
240 }
242 virtual ~KVClassMethod() {}
243 void Copy(TObject& obj) const;
244
245 void SetReturnType(const Char_t* type)
246 {
247 KVString s(type);
248 fFields.SetValue("ReturnType", s);
249 }
250 void SetClassName(const Char_t* name)
251 {
252 KVString s(name);
253 fFields.SetValue("ClassName", s);
254 }
255 void SetBaseClass(const Char_t* name)
256 {
257 KVString s(name);
258 fFields.SetValue("BaseClass", s);
259 }
260 void AddArgument(const Char_t* type, const Char_t* argname = "", const Char_t* defaultvalue = "")
261 {
262 KVString _type(type);
263 fFields.SetValue(Form("Arg_%d", ++fNargs), _type);
264 if (strcmp(defaultvalue, "")) {
265 KVString _s(defaultvalue);
266 fFields.SetValue(Form("Arg_%d_default", fNargs), _s);
267 }
268 if (strcmp(argname, "")) {
269 KVString _s(argname);
270 fFields.SetValue(Form("Arg_%d_name", fNargs), _s);
271 }
272 }
273 void AddArgument(Int_t i, const Char_t* type, const Char_t* argname = "", const Char_t* defaultvalue = "");
274 void SetMethodBody(const KVString& body)
275 {
276 fFields.SetValue("Body", body);
277 }
278 void SetMethodComment(const KVString& com)
279 {
280 fFields.SetValue("Comment", com);
281 }
283 {
284 if (fFields.HasParameter("ReturnType"))
285 return fFields.GetStringValue("ReturnType");
286 return "";
287 }
289 {
290 return fFields.GetStringValue("ClassName");
291 }
292
293 void SetConst(Bool_t c = kTRUE)
294 {
295 fConst = c;
296 }
297 void SetVirtual(Bool_t c = kTRUE)
298 {
299 fVirtual = c;
300 }
301
303 {
304 return fConst;
305 }
307 {
308 return fVirtual;
309 }
310 virtual Bool_t IsConstructor() const
311 {
312 return kFALSE;
313 }
314
315 void Print(Option_t* = "") const;
316
318 void WriteImplementation(KVString& decl);
319
320 void SetInline(Bool_t yes = kTRUE)
321 {
322 fInline = yes;
323 }
325 {
326 return fInline;
327 }
328 virtual Bool_t IsDestructor() const
329 {
330 return kFALSE;
331 }
333 {
335 return (!IsConstructor() && !IsDestructor());
336 }
337
338 ClassDef(KVClassMethod, 2) //KVClassFactory helper class - description of class method
339 };
340
348 Bool_t fCopyCtor;//kTRUE if method is the copy constructor
349 virtual void write_method_body(KVString& decl);
351
352 public:
356
357 virtual Bool_t IsConstructor() const
358 {
359 return kTRUE;
360 }
362 {
364 return IsCalled("default_ctor");
365 }
367 {
368 return fCopyCtor;
369 }
370 void SetCopyCtor(Bool_t c = kTRUE)
371 {
372 fCopyCtor = c;
373 }
375 {
377 fFields.SetValue(Form("Arg_%d_baseclass", i), 1);
378 }
380 {
382 fFields.SetValue(Form("Arg_%d_memvar", i), memvar);
383 }
384
385 ClassDef(KVClassConstructor, 1) //KVClassFactory helper class - description of constructor
386 };
387
388protected:
389 void AddMemberInitialiserConstructor(KVClassConstructor* = nullptr);
390
391public:
399
400 public:
403 {
404 SetName("destructor");
405 SetMethodComment("Destructor");
406 }
408 virtual Bool_t IsDestructor() const
409 {
410 return kTRUE;
411 }
412
413 ClassDef(KVClassDestructor, 1) //KVClassFactory helper class - description of destructor
414 };
415
417 KVClassFactory(const Char_t* classname,
418 const Char_t* classdesc,
419 const Char_t* base_class =
420 "", Bool_t withTemplate =
421 kFALSE, const Char_t* templateFile = "");
423 virtual ~KVClassFactory() {};
424#if ROOT_VERSION_CODE >= ROOT_VERSION(3,4,0)
425 void Copy(TObject& obj) const;
426#else
427 void Copy(TObject& obj);
428#endif
429
430 static void MakeClass(const Char_t* classname,
431 const Char_t* classdesc,
432 const Char_t* base_class =
433 "", Bool_t withTemplate =
434 kFALSE, const Char_t* templateFile = "");
435 void GenerateCode();
436
437 KVClassMember* AddMember(const Char_t* name, const Char_t* type, const Char_t* comment, const Char_t* access = "protected");
438 KVClassMethod* AddMethod(const Char_t* name, const Char_t* return_type, const Char_t* access = "public",
439 Bool_t isVirtual = kFALSE, Bool_t isConst = kFALSE);
440 KVClassConstructor* AddConstructor(const Char_t* argument_type = "",
441 const Char_t* argument_name = "", const Char_t* default_value = "", const Char_t* access = "public");
444 void AddDestructor(const TString& access = "public");
445 void AddMethod(const KVClassMethod& kvcm);
446 void AddMethodArgument(const Char_t* method_name, const Char_t* argument_type,
447 const Char_t* argument_name = "", const Char_t* default_value = "");
448 void AddMethodBody(const Char_t* method_name, const KVString& body);
449 void AddMethodComment(const Char_t* method_name, const KVString& comment);
450
451 void AddHeaderIncludeFile(const Char_t* filename);
452 void AddImplIncludeFile(const Char_t* filename);
453
455 {
456 return &fMethods;
457 }
459 {
460 return &fMembers;
461 }
462 KVClassMethod* GetMethod(const Char_t* name) const
463 {
465 }
467 {
468 return (KVClassConstructor*)GetMethod("default_ctor");
469 }
471 {
472 return (KVClassDestructor*)GetMethod("destructor");
473 }
474
475 const Char_t* GetClassName() const
476 {
477 return fClassName.Data();
478 }
479 void SetClassName(const Char_t* n)
480 {
481 fClassName = n;
482 }
484 {
488 return fClassPath != "" ? Form("%s%s.h", fClassPath.Data(), fClassName.Data()) : Form("%s.h", fClassName.Data());
489 }
490 const Char_t* GetImpFileName() const
491 {
495 return fClassPath != "" ? Form("%s%s.cpp", fClassPath.Data(), fClassName.Data()) : Form("%s.cpp", fClassName.Data());
496 }
497 void SetClassDesc(const Char_t* d)
498 {
499 fClassDesc = d;
500 }
501 const Char_t* GetClassDesc() const
502 {
503 return fClassDesc.Data();
504 }
505 void SetBaseClass(const Char_t* b)
506 {
510 if (fHasBaseClass) {
511 fBaseClass = TClass::GetClass(fBaseClassName);
513 }
514 }
515 const Char_t* GetBaseClass() const
516 {
517 return fBaseClassName.Data();
518 }
520 {
521 return fBaseClassName.Contains(",");
522 }
524 {
525 return fWithTemplate;
526 }
528 {
529 return fBaseClassTObject;
530 }
531 void SetTemplate(Bool_t temp, const Char_t* temp_file);
532 const Char_t* GetTemplateBase() const
533 {
534 return fTemplateBase;
535 }
537 {
538 return fMembers.GetEntries();
539 }
540
541 void Print(Option_t* opt = "") const;
542
544
545 void InlineAllMethods(bool yes = true);
546 void InlineAllConstructors(bool yes = true);
547
548 void SetOutputPath(const KVString& p)
549 {
552 fClassPath = p;
553 if (!fClassPath.EndsWith("/")) fClassPath.Append("/");
554 }
555 const Char_t* GetOutputPath() const
556 {
559 return fClassPath;
560 }
561
563 {
565 fInheritAllCtors = yes;
566 }
567
568 ClassDef(KVClassFactory, 5) //Factory for generating KaliVeda skeleton classes
569};
570
571#endif
int Int_t
#define d(i)
#define c(i)
bool Bool_t
int Ssiz_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
#define ClassDef(name, id)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
char * Form(const char *fmt,...)
Base class for KaliVeda framework.
Definition KVBase.h:142
void SetLabel(const Char_t *lab)
Definition KVBase.h:195
virtual Bool_t IsCalled(const Char_t *name) const
Definition KVBase.h:190
const Char_t * GetLabel() const
Definition KVBase.h:199
Constructor for a class generated with KVClassFactory.
virtual Bool_t IsConstructor() const
virtual void write_method_body(KVString &decl)
KVClassConstructor(KVClassFactory *ParentClass)
void SetMemberVariableNameForArgument(Int_t i, const Char_t *memvar)
Destructor for a class generated with KVClassFactory.
virtual Bool_t IsDestructor() const
Member variable in a class generated with KVClassFactory.
virtual void WriteDeclaration(KVString &)
Write declaration in the KVString object.
const Char_t * GetRealName() const
get short name without leading 'f'
void SetComment(const Char_t *c)
set comment for variable
void Print(Option_t *="") const
print the KVClass member
void SetAccess(const Char_t *acc="public")
set access type : public, protected or private
const Char_t * GetComment() const
get access type : public, protected or private
const Char_t * GetAccess() const
get access type : public, protected or private
void Copy(TObject &obj) const
copy this to obj
Method in a class generated with KVClassFactory.
virtual void write_method_body(KVString &decl)
void SetMethodComment(const KVString &com)
void Print(Option_t *="") const
print the KVClass method
KVClassMethod(Bool_t Virtual=kFALSE, Bool_t Const=kFALSE, Bool_t Inline=kFALSE)
virtual Bool_t IsDestructor() const
void SetConst(Bool_t c=kTRUE)
void WriteImplementation(KVString &decl)
void SetBaseClass(const Char_t *name)
void Copy(TObject &obj) const
copy this to obj
virtual Bool_t IsConstructor() const
void AddArgument(const Char_t *type, const Char_t *argname="", const Char_t *defaultvalue="")
void SetReturnType(const Char_t *type)
void SetClassName(const Char_t *name)
void SetVirtual(Bool_t c=kTRUE)
void SetInline(Bool_t yes=kTRUE)
void SetMethodBody(const KVString &body)
Factory class for generating skeleton files for new classes.
void Print(Option_t *opt="") const
Print infos on object.
void SetOutputPath(const KVString &p)
Bool_t fInlineAllCtors
kTRUE if all ctor implementations written in header
void WriteWhoWhen(std::ofstream &)
Bool_t WithMultipleBaseClasses() const
void SetTemplate(Bool_t temp, const Char_t *temp_file)
KVList fMembers
list of member variables for class
Bool_t fInlineAllMethods
kTRUE if all (non-ctor) method implementations written in header
const Char_t * GetOutputPath() const
void AddMethodComment(const Char_t *method_name, const KVString &comment)
Set the comments for method 'method_name' added to the class using AddMethod.
void WriteClassWithTemplateImp()
Writes the implementation file for the class.
KVString fTemplateClassName
name of template dummy class
Bool_t IsBaseClassTObject() const
void GenerateGettersAndSetters()
const Char_t * GetBaseClass() const
virtual ~KVClassFactory()
const Char_t * GetClassName() const
const Char_t * GetClassDesc() const
KVList fMethods
list of methods added to class
void GenerateCode()
Generate header and implementation file for currently-defined class.
TDatime fNow
for dating files
Bool_t fHasBaseClass
kTRUE if class derived from another
void SetClassName(const Char_t *n)
void SetInheritAllConstructors(Bool_t yes=kTRUE)
const KVList * GetListOfMethods() const
KVString fTemplateCPP
full path to template .cpp
void AddMemberInitialiserConstructor(KVClassConstructor *=nullptr)
TClass * fBaseClass
description of base class
Bool_t WithTemplate() const
void WriteClassHeader()
Write the class header file.
KVString fClassDesc
class description
Bool_t fInheritAllCtors
kTRUE if all ctor from base class should be inherited
KVClassFactory()
Default ctor.
KVString fClassPath
directory in which to write source files, if not working directory
static void MakeClass(const Char_t *classname, const Char_t *classdesc, const Char_t *base_class="", Bool_t withTemplate=kFALSE, const Char_t *templateFile="")
void AddHeaderIncludeFile(const Char_t *filename)
void Copy(TObject &obj) const
Copy the state of this KVClassFactory to the one referenced by 'obj'.
void AddDestructor(const TString &access="public")
Add default destructor to class.
void WriteClassDec(std::ofstream &)
void AddImplIncludeFile(const Char_t *filename)
KVString fTemplateH
full path to template .h
KVString fBaseClassName
name of base class
KVClassConstructor * GetDefaultCtor() const
Bool_t CheckTemplateFiles(const Char_t *base_class, const Char_t *templateFile)
const Char_t * GetHeaderFileName() const
void SetClassDesc(const Char_t *d)
const Char_t * GetImpFileName() const
void WritePreProc(std::ofstream &)
Int_t GetNumberOfMemberVariables() const
void AddMethodBody(const Char_t *method_name, const KVString &body)
Ssiz_t FindNextUncommentedLine(TString &, Ssiz_t beg=0)
KVClassMethod * GetMethod(const Char_t *name) const
void WriteClassWithTemplateHeader()
const Char_t * GetTemplateBase() const
void InlineAllMethods(bool yes=true)
Bool_t fBaseClassTObject
kTRUE if class derived from TObject
KVList fHeadInc
list of 'includes' to be added to header file
KVString fTemplateBase
template base name passed to SetTemplate method
void AddMethodArgument(const Char_t *method_name, const Char_t *argument_type, const Char_t *argument_name="", const Char_t *default_value="")
const KVList * GetListOfMembers() const
void InlineAllConstructors(bool yes=true)
KVString fClassName
name of class to generate
void SetBaseClass(const Char_t *b)
void AddGetSetMethods(const KVNameValueList &)
For each named parameter in the list, we add protected member variables with the name and type of the...
KVClassDestructor * GetDestructor() const
Bool_t fWithTemplate
true if class has a template
KVClassConstructor * AddConstructor(const Char_t *argument_type="", const Char_t *argument_name="", const Char_t *default_value="", const Char_t *access="public")
KVClassMember * AddMember(const Char_t *name, const Char_t *type, const Char_t *comment, const Char_t *access="protected")
KVString fAuthor
user who called ClassFactory to generate class
KVList fImpInc
list of 'includes' to be added to implementation file
KVClassMethod * AddMethod(const Char_t *name, const Char_t *return_type, const Char_t *access="public", Bool_t isVirtual=kFALSE, Bool_t isConst=kFALSE)
Extended TList class which owns its objects by default.
Definition KVList.h:28
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
void SetValue(const Char_t *name, value_type value)
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
T * get_object(const TString &name) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
Bool_t InheritsFrom(const char *cl) const override
virtual Int_t GetEntries() const
virtual void SetName(const char *name)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
const char * Data() const
TString & Append(char c, Ssiz_t rep=1)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
const Int_t n