summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2016-10-21 07:59:19 (GMT)
committerRalf Habacker <ralf.habacker@freenet.de>2016-10-21 07:59:19 (GMT)
commitd4f45447822d251e6ff780da47f158c05e74474a (patch)
tree4eb2d1b51160f096c4f0213363e14a173b265627
parent828f7dac7316cf8b0b13e290b51fcd114b3e06d1 (diff)
Write out typedefs located in classes for default code generator.
CCBUG:371274
-rw-r--r--umbrello/codegenerators/cpp/cppwriter.cpp24
-rw-r--r--umbrello/codegenerators/cpp/cppwriter.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/umbrello/codegenerators/cpp/cppwriter.cpp b/umbrello/codegenerators/cpp/cppwriter.cpp
index a895539..6aab628 100644
--- a/umbrello/codegenerators/cpp/cppwriter.cpp
+++ b/umbrello/codegenerators/cpp/cppwriter.cpp
@@ -17,6 +17,7 @@
#include "association.h"
#include "classifier.h"
#include "codegen_utils.h"
+#include "datatype.h"
#include "debug_utils.h"
#include "model_utils.h"
#include "uml.h"
@@ -450,6 +451,7 @@ void CppWriter::writeClassDecl(UMLClassifier *c, QTextStream &cpp)
// PUBLIC attribs/methods
cpp << "public:" << m_endl << m_endl; // print visibility decl.
+ writeDataTypes(c, Uml::Visibility::Public, cpp);
// for public: constructors are first ops we print out
if (!c->isInterface())
writeConstructorDecls(cpp);
@@ -460,6 +462,7 @@ void CppWriter::writeClassDecl(UMLClassifier *c, QTextStream &cpp)
// PROTECTED attribs/methods
//
cpp << "protected" << ":" << m_endl << m_endl; // print visibility decl.
+ writeDataTypes(c, Uml::Visibility::Protected, cpp);
writeHeaderFieldDecl(c, Uml::Visibility::Protected, cpp);
writeHeaderAccessorMethodDecl(c, Uml::Visibility::Protected, cpp);
writeOperations(c, true, Uml::Visibility::Protected, cpp);
@@ -467,6 +470,7 @@ void CppWriter::writeClassDecl(UMLClassifier *c, QTextStream &cpp)
// PRIVATE attribs/methods
//
cpp << "private" << ":" << m_endl << m_endl; // print visibility decl.
+ writeDataTypes(c, Uml::Visibility::Private, cpp);
writeHeaderFieldDecl(c, Uml::Visibility::Private, cpp);
writeHeaderAccessorMethodDecl(c, Uml::Visibility::Private, cpp);
writeOperations(c, true, Uml::Visibility::Private, cpp);
@@ -1111,6 +1115,26 @@ void CppWriter::writeConstructorMethods(UMLClassifier * c, QTextStream &stream)
}
/**
+ * Write all datatypes for a given class.
+ * @param c the class for which we are generating code
+ * @param permitScope what type of method to write (by Scope)
+ * @param cpp the stream associated with the output file
+ */
+void CppWriter::writeDataTypes(UMLClassifier *c, Uml::Visibility::Enum permitScope, QTextStream &stream)
+{
+ foreach (UMLObject* o, c->containedObjects()) {
+ if (o->visibility() != permitScope)
+ continue;
+ if (!o->isUMLDatatype())
+ continue;
+ UMLDatatype *d = o->asUMLDatatype();
+ if (d && d->isReference() && d->originType()) {
+ stream << indent() << "typedef " << d->originType()->name() << " " << d->name() << ";" << m_endl;
+ }
+ }
+}
+
+/**
* Replaces `string' with STRING_TYPENAME.
*/
QString CppWriter::fixTypeName(const QString &string)
diff --git a/umbrello/codegenerators/cpp/cppwriter.h b/umbrello/codegenerators/cpp/cppwriter.h
index d23c729..0846a88 100644
--- a/umbrello/codegenerators/cpp/cppwriter.h
+++ b/umbrello/codegenerators/cpp/cppwriter.h
@@ -129,6 +129,7 @@ private:
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);