class CodeGenerator

CodeGenerator is the basis class for all CodeGenerators. More...

Definition#include <./codegenerator.h>
InheritsQObject (unknown) [public ]
Inherited byCppWriter, JavaWriter
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Signals

Protected Methods

Protected Members


Detailed Description

CodeGenerator is the basis class for all CodeGenerators. It provides the Interface trough wich all Generators are invoked and the all the basicfunctionality. The only thing it doesnt do is to generate code =)

If you want to implement a CodeGenerator for some language follow these steps:

Create a class which inherits CodeGenerator. This class can have any name, I use names like CppWriter for the Cpp Generator, JavaWriter for the Java Generator and so on, but you can use what you want.

The only method which you should implement in your class is:

void writeClass(UMLConcept *)

in which you get a pointer to the UMLConcept (class) for which you have to write the code, and you write a file with the code.

The code you generate should be output to "outputDirectory" and you should respect the OverwritePolicy specified. You should call findFileName(..) to get an appropiate file name, and then you can call openFile if you want, but if you want to do it yourself you must check the overwrite policy :

OverwritePolicy can have the following values - Ok: if there is a file named the same as what you want to name your output file, you can overwrite the old file. - Ask:if there is a file named the same as what you want to name your output file, you should ask the User what to do, and give him the option to overwrite the file write the code to a different file, or to abort the generation of this class. - Never: you cannot overwrite any files. If there is a file already named the same as what you want to name your output file, you have to choose another name which doesnt exist. I suggest you add some suffix, like "fileName1.h", "fileName2.h" until you find an appropiate name.

Finally put your generator in a library which can be dlopened together with a factory class (see below) and you are ready to go.

enum OverwritePolicy {Ok=0, Ask, Never}

OverwritePolicy

enum ModifyNamePolicy {No=0 ,Underscore, Capitalise}

ModifyNamePolicy

 CodeGenerator ( QObject *parent = 0, const char *name = 0 )

CodeGenerator

 ~CodeGenerator ()

~CodeGenerator

[virtual]

void  generateAllClasses ()

generateAllClasses

void  generateCode ( QPtrList<UMLConcept> &list )

generateCode

Generate code for the list of classes given.

void  generateCode ( UMLConcept *c)

generateCode

Generate code for class c

inline void  setDocument (UMLDoc *d)

setDocument

inline void  setOutputDirectory (QString d)

setOutputDirectory

inline QString  outputDirectory ()

outputDirectory

[const]

inline void  setOverwritePolicy (OverwritePolicy p)

setOverwritePolicy

inline OverwritePolicy  overwritePolicy ()

overwritePolicy

[const]

inline void  setModifyNamePolicy (ModifyNamePolicy p)

setModifyNamePolicy

inline ModifyNamePolicy  modifyNamePolicy ()

modifyNamePolicy

[const]

inline void  setIncludeHeadings (bool i)

setIncludeHeadings

inline bool  includeHeadings ()

includeHeadings

[const]

inline void  setHeadingFileDir (const QString &)

setHeadingFileDir

inline QString  headingFileDir ()

headingFileDir

[const]

inline void  setForceDoc (bool f)

setForceDoc

inline bool  forceDoc ()

forceDoc

[const]

inline void  setForceSections (bool f)

setForceSections

inline bool  forceSections ()

forceSections

[const]

void  codeGenerated (UMLConcept *c)

codeGenerated

[signal]

This signal is emited when code for UMLConcept c has been successfuly generated

void  writeClass (UMLConcept *)

writeClass

[protected virtual]

To be implemented by the Language Writers

QString  findFileName (UMLConcept *c,QString ext)

findFileName

[protected]

Finds an appropiate file name for class c, taking into account the Overwrite Policy and asking the user what to do if need be. (if policy == Ask)

Parameters:
cthe class for which an output file name is desired.
extthe extension (or suffix) used for output files

Returns: the file name that should be used. (without extension)

bool  openFile (QFile &file, QString name)

openFile

[protected]

Opens a file named "name" for writing in the outputDirectory. If something goes wrong, it infroms the user and sets the file to point to stderr if this function returns true, you know you can write to the file

QString  getHeadingFile (QString file)

getHeadingFile

[protected]

Gets the heading file (as a string) to be inserted at the begining of the generated file. you give the file type as parameter and get the string. if fileName starts with a period (.) then fileName is the extension (.cpp, .h, .java) if fileName starts with another character you are requesting a specific file (mylicensefile.txt). The files can have parameters which are denoted by %parameter%.

current parameters are %author% %date% %time% %filepath%

QString  cleanName (QString)

cleanName

[protected]

QString  formatDoc (const QString &text, const QString &linePrefix="* ", int lineWidth=80)

formatDoc

[protected]

Format documentation for output in source files

Parameters:
textthe documentation which has to be formatted
linePrefixthe prefix which has to be added in the beginnig of each line
lineWidththe line width used for word-wrapping the documentation

Returns: the formatted documentation text

void  findObjectsRelated (UMLConcept *c, QList<UMLConcept> &cList)

findObjectsRelated

[protected]

Finds all classes in the current document to which objects of class c are in some way related. Posible relations are Associations (gneratlization, composition, etc) as well as parameters to methos and return values this is useful in deciding which classes/files to import/include in code generation @c the class for which relations are to be found @cList a reference to the list into which return the result

bool  hasDefaultValueAttr (UMLConcept *c)

hasDefaultValueAttr

[protected]

bool  hasAbstractOps (UMLConcept *c)

hasAbstractOps

[protected]

QDir m_outputDirectory

m_outputDirectory

[protected]

OverwritePolicy m_overwrite

m_overwrite

[protected]

ModifyNamePolicy m_modname

m_modname

[protected]

QDir m_headingFiles

m_headingFiles

[protected]

UMLDoc * m_doc

m_doc

[protected]

bool m_forceDoc

m_forceDoc

[protected]

bool m_forceSections

m_forceSections

[protected]

bool m_includeHeadings

m_includeHeadings

[protected]

QMap<UMLConcept*,QString> * m_fileMap

m_fileMap

[protected]

void  setDocument (UMLDoc *d)

setDocument

[protected]

void  setOutputDirectory (QString d)

setOutputDirectory

[protected]

QString  outputDirectory ()

outputDirectory

[protected const]

void  setOverwritePolicy (OverwritePolicy p)

setOverwritePolicy

[protected]

CodeGenerator::OverwritePolicy  overwritePolicy ()

overwritePolicy

[protected const]

void  setModifyNamePolicy (ModifyNamePolicy p)

setModifyNamePolicy

[protected]

CodeGenerator::ModifyNamePolicy  modifyNamePolicy ()

modifyNamePolicy

[protected const]

void  setHeadingFileDir (const QString &path)

setHeadingFileDir

[protected]

QString  headingFileDir ()

headingFileDir

[protected const]

void  setForceDoc (bool f)

setForceDoc

[protected]

bool  forceDoc ()

forceDoc

[protected const]

void  setForceSections (bool f)

setForceSections

[protected]

bool  forceSections ()

forceSections

[protected const]

void  setIncludeHeadings (bool i)

setIncludeHeadings

[protected]

bool  includeHeadings ()

includeHeadings

[protected const]


Generated by: jr on radge on Wed Sep 25 00:11:47 2002, using kdoc 2.0a54.