umbrello 2.34.70-5524f40e1
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CppWriter Class Reference

#include <cppwriter.h>

Inheritance diagram for CppWriter:
Collaboration diagram for CppWriter:

Public Member Functions

 CppWriter ()
 
virtual ~CppWriter ()
 
virtual void writeClass (UMLClassifier *c)
 
virtual Uml::ProgrammingLanguage::Enum language () const
 
QStringList defaultDatatypes () const
 
virtual QStringList reservedKeywords () const
 
- Public Member Functions inherited from SimpleCodeGenerator
 SimpleCodeGenerator (bool createDirHierarchyForPackages=true)
 
virtual ~SimpleCodeGenerator ()
 
void writeCodeToFile (UMLClassifierList &concepts)
 
void writeCodeToFile ()
 
- Public Member Functions inherited from CodeGenerator
 CodeGenerator ()
 
virtual ~CodeGenerator ()
 
bool addCodeDocument (CodeDocument *add_object)
 
bool removeCodeDocument (CodeDocument *remove_object)
 
CodeDocumentListgetCodeDocumentList ()
 
QString getUniqueID (CodeDocument *codeDoc)
 
virtual void saveToXMI (QXmlStreamWriter &writer)
 
CodeDocumentfindCodeDocumentByID (const QString &id)
 
void setIncludeHeadings (bool i)
 
bool includeHeadings () const
 
void setHeadingFileDir (const QString &)
 
QString headingFileDir () const
 
void setForceDoc (bool f)
 
bool forceDoc () const
 
void setForceSections (bool f)
 
bool forceSections () const
 
virtual QString getHeadingFile (const QString &file)
 
QString findFileName (CodeDocument *codeDocument)
 
virtual void loadFromXMI (QDomElement &element)
 
CodeDocumentfindCodeDocumentByClassifier (UMLClassifier *classifier)
 
virtual bool isReservedKeyword (const QString &keyword)
 
virtual void createDefaultStereotypes ()
 

Private Member Functions

void writeIncludes (UMLClassifier *c, QTextStream &cpp)
 
void writeClassDecl (UMLClassifier *c, QTextStream &cpp)
 
void writeConstructorDecls (QTextStream &h)
 
void writeConstructorMethods (UMLClassifier *c, QTextStream &cpp)
 
void writeOperations (UMLClassifier *c, bool isHeaderMethod, Uml::Visibility::Enum permitScope, QTextStream &cpp)
 
void writeOperations (UMLClassifier *c, UMLOperationList &oplist, bool isHeaderMethod, QTextStream &cpp)
 
void writeAttributeDecls (UMLClassifier *c, Uml::Visibility::Enum visibility, bool writeStatic, QTextStream &stream)
 
void writeHeaderFieldDecl (UMLClassifier *c, Uml::Visibility::Enum permitVisibility, QTextStream &stream)
 
void writeHeaderAttributeAccessorMethods (UMLClassifier *c, Uml::Visibility::Enum visibility, bool writeStatic, QTextStream &stream)
 
void writeHeaderAttributeAccessorMethodDecls (UMLClassifier *c, Uml::Visibility::Enum permitVisibility, QTextStream &stream)
 
void writeHeaderAccessorMethodDecl (UMLClassifier *c, Uml::Visibility::Enum permitScope, QTextStream &stream)
 
void writeAssociationDecls (UMLAssociationList associations, Uml::Visibility::Enum permit, Uml::ID::Type id, QTextStream &stream)
 
void writeAssociationRoleDecl (QString fieldClassName, QString roleName, QString multi, QString doc, QTextStream &stream)
 
void writeAttributeMethods (UMLAttributeList attribs, Uml::Visibility::Enum visib, bool isHeaderMethod, bool isStatic, bool writeMethodBody, QTextStream &stream)
 
void writeAssociationMethods (UMLAssociationList associations, Uml::Visibility::Enum permitVisib, bool isHeaderMethod, bool writeMethodBody, bool writePointerVar, Uml::ID::Type id, QTextStream &stream)
 
void writeAssociationRoleMethod (const QString &fieldClassName, bool isHeaderMethod, bool writeMethodBody, const QString &roleName, const QString &multi, const QString &description, Uml::Changeability::Enum change, QTextStream &stream)
 
void writeSingleAttributeAccessorMethods (const QString &fieldClassName, const QString &Name, const QString &fieldName, const QString &description, Uml::Changeability::Enum change, bool isHeaderMethod, bool isStatic, bool writeMethodBody, QTextStream &cpp)
 
void writeVectorAttributeAccessorMethods (const QString &fieldClassName, const QString &fieldVarName, const QString &fieldName, const QString &description, Uml::Changeability::Enum change, bool isHeaderMethod, bool writeMethodBody, QTextStream &stream)
 
void writeComment (const QString &text, const QString &indent, QTextStream &cpp)
 
void writeDocumentation (QString header, QString body, QString end, QTextStream &cpp)
 
void writeHeaderFile (UMLClassifier *c, QFile &file)
 
void writeSourceFile (UMLClassifier *c, QFile &file)
 
void printTextAsSeparateLinesWithIndent (const QString &text, const QString &indent, QTextStream &stream)
 
void printAssociationIncludeDecl (UMLAssociationList list, Uml::ID::Type this_id, QTextStream &stream)
 
void writeInitAttributeMethod (UMLClassifier *c, QTextStream &stream)
 
void writeInitAttributeDecl (UMLClassifier *c, QTextStream &stream)
 
void writeDataTypes (UMLClassifier *c, Uml::Visibility::Enum permitScope, QTextStream &stream)
 
QString umlObjectName (UMLObject *obj)
 
QString fixTypeName (const QString &string)
 
QString fixInitialStringDeclValue (const QString &value, const QString &type)
 
QString getAttributeVariableName (UMLAttribute *at)
 
QString getAttributeMethodBaseName (const QString &fieldName)
 
void writeBlankLine (QTextStream &stream)
 
CPPCodeGenerationPolicypolicyExt ()
 

Private Attributes

QString VECTOR_METHOD_APPEND
 
QString VECTOR_METHOD_REMOVE
 
QString VECTOR_METHOD_INIT
 
QString OBJECT_METHOD_INIT
 
bool INLINE_ASSOCIATION_METHODS
 
QStringList ObjectFieldVariables
 
QStringList VectorFieldVariables
 
bool m_stringIncludeRequired
 

Additional Inherited Members

- Public Types inherited from CodeGenerator
enum  GenerationState { Generated , Failed , Skipped }
 
- Public Slots inherited from SimpleCodeGenerator
virtual void syncCodeToDocument ()
 
- Public Slots inherited from CodeGenerator
virtual void syncCodeToDocument ()
 
- Signals inherited from CodeGenerator
void codeGenerated (UMLClassifier *concept, bool generated)
 
void codeGenerated (UMLClassifier *concept, CodeGenerator::GenerationState result)
 
void showGeneratedFile (const QString &filename)
 
- Static Public Member Functions inherited from CodeGenerator
static QString cleanName (const QString &name)
 
static QString formatDoc (const QString &text, const QString &linePrefix=QLatin1String(" *"), int lineWidth=80)
 
static QString formatSourceCode (const QString &code, const QString &indentation)
 
static void findObjectsRelated (UMLClassifier *c, UMLPackageList &cList)
 
- Protected Member Functions inherited from SimpleCodeGenerator
QString findFileName (UMLPackage *concept, const QString &ext)
 
QString overwritableName (UMLPackage *concept, const QString &name, const QString &ext)
 
bool hasDefaultValueAttr (UMLClassifier *c)
 
bool hasAbstractOps (UMLClassifier *c)
 
QString indent ()
 
virtual void initFromParentDocument ()
 
- Protected Member Functions inherited from CodeGenerator
QString overwritableName (const QString &name, const QString &extension)
 
bool openFile (QFile &file, const QString &name)
 
void writeListedCodeDocsToFile (CodeDocumentList *docs)
 
virtual void finalizeRun ()
 
- Protected Attributes inherited from SimpleCodeGenerator
QString className_
 
QString fileName_
 
QMap< UMLPackage *, QString > m_fileMap
 
bool m_createDirHierarchyForPackages
 
QString m_indentation
 
int m_indentLevel
 
QString m_endl
 
- Protected Attributes inherited from CodeGenerator
QHash< QString, CodeDocument * > m_codeDocumentDictionary
 
bool m_applyToAllRemaining
 
UMLDocm_document
 

Detailed Description

Class CppWriter is a code generator for UMLClassifier objects. Create an instance of this class, and feed it a UMLClassifier when calling writeClass and it will generate both a header (.h) and source (.cpp) file for that classifier. Note: This is the "old" code generator that does not support code editing in the Modeller but uses significantly less file space because the source code is not replicated in the XMI file.

Constructor & Destructor Documentation

◆ CppWriter()

CppWriter::CppWriter ( )

Constructor, initialises a couple of variables.

Here is the call graph for this function:

◆ ~CppWriter()

CppWriter::~CppWriter ( )
virtual

Destructor, empty.

Member Function Documentation

◆ defaultDatatypes()

QStringList CppWriter::defaultDatatypes ( ) const
virtual

Add C++ primitives as datatypes.

Returns
the list of default datatypes

Reimplemented from CodeGenerator.

Here is the call graph for this function:

◆ fixInitialStringDeclValue()

QString CppWriter::fixInitialStringDeclValue ( const QString &  value,
const QString &  type 
)
private

Check that initial values of strings have quotes around them.

Here is the call graph for this function:

◆ fixTypeName()

QString CppWriter::fixTypeName ( const QString &  string)
private

Replaces `string' with STRING_TYPENAME.

Here is the call graph for this function:

◆ getAttributeMethodBaseName()

QString CppWriter::getAttributeMethodBaseName ( const QString &  fieldName)
private
Here is the call graph for this function:

◆ getAttributeVariableName()

QString CppWriter::getAttributeVariableName ( UMLAttribute at)
private

Determine what the variable name of this attribute should be.

Here is the call graph for this function:

◆ language()

Uml::ProgrammingLanguage::Enum CppWriter::language ( ) const
virtual

Returns "C++".

Returns
the programming language identifier

Implements CodeGenerator.

◆ policyExt()

CPPCodeGenerationPolicy * CppWriter::policyExt ( )
private

Return the policy object.

Here is the call graph for this function:

◆ printAssociationIncludeDecl()

void CppWriter::printAssociationIncludeDecl ( UMLAssociationList  list,
Uml::ID::Type  myId,
QTextStream &  stream 
)
private

Intelligently print out header include/forward decl. for associated classes. Note: To prevent circular including when both classifiers on either end of an association have roles we need to have forward declaration of the other class...but only IF it is not THIS class (as could happen in self-association relationship).

Here is the call graph for this function:

◆ printTextAsSeparateLinesWithIndent()

void CppWriter::printTextAsSeparateLinesWithIndent ( const QString &  text,
const QString &  indent,
QTextStream &  stream 
)
private

Utility method to break up a block of text, which has embedded newline chars, and print them to a stream as separate lines of text, indented as directed.

Here is the call graph for this function:

◆ reservedKeywords()

QStringList CppWriter::reservedKeywords ( ) const
virtual

Get list of reserved keywords.

Returns
the list of reserved keywords

Reimplemented from CodeGenerator.

Here is the call graph for this function:

◆ umlObjectName()

QString CppWriter::umlObjectName ( UMLObject obj)
private

Returns the name of the given object (if it exists). Note: Methods like this _shouldn't_ be needed IF we properly did things thruought the code.

Here is the call graph for this function:

◆ writeAssociationDecls()

void CppWriter::writeAssociationDecls ( UMLAssociationList  associations,
Uml::Visibility::Enum  permitScope,
Uml::ID::Type  id,
QTextStream &  h 
)
private

Searches a list of associations for appropriate ones to write out as attributes.

Here is the call graph for this function:

◆ writeAssociationMethods()

void CppWriter::writeAssociationMethods ( UMLAssociationList  associations,
Uml::Visibility::Enum  permitVisib,
bool  isHeaderMethod,
bool  writeMethodBody,
bool  writePointerVar,
Uml::ID::Type  myID,
QTextStream &  stream 
)
private

Calls writeAssociationRoleMethod() on each of the associations in the given list for either source or header files.

Here is the call graph for this function:

◆ writeAssociationRoleDecl()

void CppWriter::writeAssociationRoleDecl ( QString  fieldClassName,
QString  roleName,
QString  multi,
QString  doc,
QTextStream &  stream 
)
private

Writes out an association as an attribute using Vector.

Here is the call graph for this function:

◆ writeAssociationRoleMethod()

void CppWriter::writeAssociationRoleMethod ( const QString &  fieldClassName,
bool  isHeaderMethod,
bool  writeMethodBody,
const QString &  roleName,
const QString &  multi,
const QString &  description,
Uml::Changeability::Enum  change,
QTextStream &  stream 
)
private

Calls writeSingleAttributeAccessorMethods() or writeVectorAttributeAccessorMethods() on the association role.

Here is the call graph for this function:

◆ writeAttributeDecls()

void CppWriter::writeAttributeDecls ( UMLClassifier c,
Uml::Visibility::Enum  visibility,
bool  writeStatic,
QTextStream &  stream 
)
private

Writes the attribute declarations.

Parameters
cthe classifier
visibilitythe visibility of the attribs to print out
writeStaticwhether to write static or non-static attributes out
streamtext stream
Here is the call graph for this function:

◆ writeAttributeMethods()

void CppWriter::writeAttributeMethods ( UMLAttributeList  attribs,
Uml::Visibility::Enum  visibility,
bool  isHeaderMethod,
bool  isStatic,
bool  writeMethodBody,
QTextStream &  stream 
)
private

This is for writing *source* or *header* file attribute methods. Calls writeSingleAttributeAccessorMethods() on each of the attributes in attribs list.

Here is the call graph for this function:

◆ writeBlankLine()

void CppWriter::writeBlankLine ( QTextStream &  stream)
private

Write a blank line.

◆ writeClass()

void CppWriter::writeClass ( UMLClassifier c)
virtual

Call this method to generate cpp code for a UMLClassifier.

Parameters
cthe class to generate code for

Implements SimpleCodeGenerator.

Here is the call graph for this function:

◆ writeClassDecl()

void CppWriter::writeClassDecl ( UMLClassifier c,
QTextStream &  cpp 
)
private

Writes class's documentation to the class header "public abstract class Foo extents {".

Here is the call graph for this function:

◆ writeComment()

void CppWriter::writeComment ( const QString &  comment,
const QString &  myIndent,
QTextStream &  cpp 
)
private

Writes a // style comment.

◆ writeConstructorDecls()

void CppWriter::writeConstructorDecls ( QTextStream &  stream)
private

Writes the comment and class constructor declaration or methods. Note: One day, this should print out non-empty constructor operations too.

Here is the call graph for this function:

◆ writeConstructorMethods()

void CppWriter::writeConstructorMethods ( UMLClassifier c,
QTextStream &  cpp 
)
private
Here is the call graph for this function:

◆ writeDataTypes()

void CppWriter::writeDataTypes ( UMLClassifier c,
Uml::Visibility::Enum  permitScope,
QTextStream &  stream 
)
private

Write all datatypes for a given class.

Parameters
cthe class for which we are generating code
permitScopewhat type of method to write (by Scope)
streamQTextStream serialization target
Here is the call graph for this function:

◆ writeDocumentation()

void CppWriter::writeDocumentation ( QString  header,
QString  body,
QString  end,
QTextStream &  cpp 
)
private

Writes a documentation comment.

Here is the call graph for this function:

◆ writeHeaderAccessorMethodDecl()

void CppWriter::writeHeaderAccessorMethodDecl ( UMLClassifier c,
Uml::Visibility::Enum  permitScope,
QTextStream &  stream 
)
private
Here is the call graph for this function:

◆ writeHeaderAttributeAccessorMethodDecls()

void CppWriter::writeHeaderAttributeAccessorMethodDecls ( UMLClassifier c,
Uml::Visibility::Enum  permitVisibility,
QTextStream &  stream 
)
private

◆ writeHeaderAttributeAccessorMethods()

void CppWriter::writeHeaderAttributeAccessorMethods ( UMLClassifier c,
Uml::Visibility::Enum  visibility,
bool  writeStatic,
QTextStream &  stream 
)
private
Here is the call graph for this function:

◆ writeHeaderFieldDecl()

void CppWriter::writeHeaderFieldDecl ( UMLClassifier c,
Uml::Visibility::Enum  permitScope,
QTextStream &  stream 
)
private

Write out fields and operations for this class selected on a particular visibility.

Here is the call graph for this function:

◆ writeHeaderFile()

void CppWriter::writeHeaderFile ( UMLClassifier c,
QFile &  file 
)
private

Write the header file for this classifier.

Here is the call graph for this function:

◆ writeIncludes()

void CppWriter::writeIncludes ( UMLClassifier c,
QTextStream &  stream 
)
private

write includes

Parameters
cuml classifier
streamtext stream
Here is the call graph for this function:

◆ writeInitAttributeDecl()

void CppWriter::writeInitAttributeDecl ( UMLClassifier c,
QTextStream &  stream 
)
private

If needed, write out the declaration for the method to initialize attributes of our class.

Here is the call graph for this function:

◆ writeInitAttributeMethod()

void CppWriter::writeInitAttributeMethod ( UMLClassifier c,
QTextStream &  stream 
)
private

If needed, write out the method to initialize attributes of our class.

Here is the call graph for this function:

◆ writeOperations() [1/2]

void CppWriter::writeOperations ( UMLClassifier c,
bool  isHeaderMethod,
Uml::Visibility::Enum  permitScope,
QTextStream &  cpp 
)
private

Write all ooperations for a given class.

Parameters
cthe class for which we are generating code
isHeaderMethodtrue when writing to a header file, false for body file
permitScopewhat type of method to write (by Scope)
cppthe stream associated with the output file
Here is the call graph for this function:

◆ writeOperations() [2/2]

void CppWriter::writeOperations ( UMLClassifier c,
UMLOperationList oplist,
bool  isHeaderMethod,
QTextStream &  cpp 
)
private

Write a list of operations for a given class. Writes operation in either header or source file.

Parameters
cthe class for which we are generating code
oplistthe list of operations you want to write
isHeaderMethodtrue when writing to a header file, false for body file
cppthe stream associated with the output file
Here is the call graph for this function:

◆ writeSingleAttributeAccessorMethods()

void CppWriter::writeSingleAttributeAccessorMethods ( const QString &  fieldClassName,
const QString &  fieldVarName,
const QString &  fieldName,
const QString &  description,
Uml::Changeability::Enum  change,
bool  isHeaderMethod,
bool  isStatic,
bool  writeMethodBody,
QTextStream &  stream 
)
private

Writes getFoo() and setFoo() accessor methods for the attribute.

Here is the call graph for this function:

◆ writeSourceFile()

void CppWriter::writeSourceFile ( UMLClassifier c,
QFile &  file 
)
private

Write the source code body file for this classifier.

Here is the call graph for this function:

◆ writeVectorAttributeAccessorMethods()

void CppWriter::writeVectorAttributeAccessorMethods ( const QString &  fieldClassName,
const QString &  fieldVarName,
const QString &  fieldName,
const QString &  description,
Uml::Changeability::Enum  changeType,
bool  isHeaderMethod,
bool  writeMethodBody,
QTextStream &  stream 
)
private

Writes addFoo() and removeFoo() accessor methods for the Vector attribute.

Here is the call graph for this function:

Member Data Documentation

◆ INLINE_ASSOCIATION_METHODS

bool CppWriter::INLINE_ASSOCIATION_METHODS
private

Create association methods for class attributes/associations/operations as inline decl in header.

◆ m_stringIncludeRequired

bool CppWriter::m_stringIncludeRequired
private

◆ OBJECT_METHOD_INIT

QString CppWriter::OBJECT_METHOD_INIT
private

◆ ObjectFieldVariables

QStringList CppWriter::ObjectFieldVariables
private

◆ VECTOR_METHOD_APPEND

QString CppWriter::VECTOR_METHOD_APPEND
private

◆ VECTOR_METHOD_INIT

QString CppWriter::VECTOR_METHOD_INIT
private

◆ VECTOR_METHOD_REMOVE

QString CppWriter::VECTOR_METHOD_REMOVE
private

◆ VectorFieldVariables

QStringList CppWriter::VectorFieldVariables
private

The documentation for this class was generated from the following files: