umbrello: CppWriter Class Reference

umbrello 2.38.5 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Member Functions | Private Attributes | List of all members
CppWriter Class Reference

`#include <cppwriter.h>`

Inheritance 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)
CodeDocumentList * | getCodeDocumentList ()
QString | getUniqueID (CodeDocument *codeDoc)
virtual void | saveToXMI (QXmlStreamWriter &writer)
CodeDocument * | findCodeDocumentByID (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 | setSectionCommentPolicy (CodeGenerationPolicy::WriteSectionCommentsPolicy f)
bool | forceSections () const
virtual QString | getHeadingFile (const QString &file)
QString | findFileName (CodeDocument *codeDocument)
virtual void | loadFromXMI (QDomElement &element)
CodeDocument * | findCodeDocumentByClassifier (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)
CPPCodeGenerationPolicy * | policyExt ()

## 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=QStringLiteral(" *"), int lineWidth=80)
static QString | formatFullDocBlock (const QString &text, const QString &blockHeader=QStringLiteral("/* "), const QString &blockFooter=QStringLiteral(" */"), const QString &linePrefix=QStringLiteral(" *"), 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
UMLDoc * | m_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.

## ◆ ~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.

## ◆ fixInitialStringDeclValue()

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

Check that initial values of strings have quotes around them.

## ◆ fixTypeName()

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

Replaces `string' with STRING_TYPENAME.

## ◆ getAttributeMethodBaseName()

QString CppWriter::getAttributeMethodBaseName | ( | const QString & | fieldName | ) |
| private

## ◆ getAttributeVariableName()

QString CppWriter::getAttributeVariableName | ( | UMLAttribute * | at | ) |
| private

Determine what the variable name of this attribute should be.

## ◆ 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.

## ◆ 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).

## ◆ 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.

## ◆ reservedKeywords()

QStringList CppWriter::reservedKeywords | ( |  | ) | const
| virtual

Get list of reserved keywords.

Returns
  the list of reserved keywords

Reimplemented from CodeGenerator.

## ◆ 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.

## ◆ 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.

## ◆ 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.

## ◆ writeAssociationRoleDecl()

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

Writes out an association as an attribute using Vector.

## ◆ 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.

## ◆ writeAttributeDecls()

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

Writes the attribute declarations.

Parameters

  c | the classifier
  visibility | the visibility of the attribs to print out
  writeStatic | whether to write static or non-static attributes out
  stream | text stream

## ◆ 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.

## ◆ 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

  c | the class to generate code for

Implements SimpleCodeGenerator.

## ◆ writeClassDecl()

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

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

## ◆ writeComment()

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

Writes a general 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.

## ◆ writeConstructorMethods()

void CppWriter::writeConstructorMethods | ( | UMLClassifier * | c,
|  | QTextStream & | cpp )
| private

## ◆ writeDataTypes()

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

Write all datatypes for a given class.

Parameters

  c | the class for which we are generating code
  permitScope | what type of method to write (by Scope)
  stream | QTextStream serialization target

## ◆ writeDocumentation()

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

Writes a documentation comment.

## ◆ writeHeaderAccessorMethodDecl()

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

## ◆ 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

## ◆ 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.

## ◆ writeHeaderFile()

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

Write the header file for this classifier.

## ◆ writeIncludes()

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

write includes

Parameters

  c | uml classifier
  stream | text stream

## ◆ writeInitAttributeDecl()

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

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

## ◆ writeInitAttributeMethod()

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

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

## ◆ 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

  c | the class for which we are generating code
  isHeaderMethod | true when writing to a header file, false for body file
  permitScope | what type of method to write (by Scope)
  cpp | the stream associated with the output file

## ◆ 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

  c | the class for which we are generating code
  oplist | the list of operations you want to write
  isHeaderMethod | true when writing to a header file, false for body file
  cpp | the stream associated with the output file

## ◆ 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.

## ◆ writeSourceFile()

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

Write the source code body file for this classifier.

## ◆ 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.

## 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:

- umbrello/codegenerators/cpp/cppwriter.h
- umbrello/codegenerators/cpp/cppwriter.cpp