• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • codegenerators
  • cpp
cppsourcecodeoperation.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2003 Brian Thomas <thomas@mail630.gsfc.nasa.gov> *
8  * copyright (C) 2004-2013 *
9  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10  ***************************************************************************/
11 
12 #include "cppsourcecodeoperation.h"
13 
14 #include "cppcodegenerator.h"
15 #include "cppcodegenerationpolicy.h"
16 #include "cppsourcecodedocument.h"
17 #include "cppcodedocumentation.h"
18 #include "uml.h"
19 
20 CPPSourceCodeOperation::CPPSourceCodeOperation(CPPSourceCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment)
21  : CodeOperation (doc, parent, body, comment)
22 {
23  // lets not go with the default comment and instead use
24  // full-blown cpp documentation object instead
25  setComment(new CPPCodeDocumentation(doc));
26 
27  // these things never change..
28  setOverallIndentationLevel(0);
29  setEndMethodText("}");
30 }
31 
32 CPPSourceCodeOperation::~CPPSourceCodeOperation()
33 {
34 }
35 
36 void CPPSourceCodeOperation::updateContent()
37 {
38  CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
39  CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
40  bool isInlineMethod = policy->getOperationsAreInline();
41 
42  if (!isInlineMethod) {
43  setText(""); // change whatever it is to ""
44  }
45 }
46 
47 void CPPSourceCodeOperation::updateMethodDeclaration()
48 {
49  CPPSourceCodeDocument * doc = dynamic_cast<CPPSourceCodeDocument*>(getParentDocument());
50  CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
51  CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
52  UMLClassifier * c = doc->getParentClassifier();
53  UMLOperation * o = getParentOperation();
54  bool isInterface = doc->parentIsInterface();
55  bool isInlineMethod = policy->getOperationsAreInline();
56 
57  // first, the comment on the operation
58  QString comment = o->doc();
59  getComment()->setText(comment);
60 
61  QString returnType = o->getTypeName();
62  QString methodName = o->name();
63  QString paramStr;
64  QString className = CodeGenerator::cleanName(c->name());
65 
66  // assemble parameters
67  UMLAttributeList list = getParentOperation()->getParmList();
68  int nrofParam = list.count();
69  int paramNum = 0;
70  foreach (UMLAttribute* parm, list) {
71  QString rType = parm->getTypeName();
72  QString paramName = parm->name();
73  paramStr += rType + ' ' + paramName;
74  paramNum++;
75 
76  if (paramNum != nrofParam)
77  paramStr += ", ";
78  }
79 
80  // no return type for constructors/destructors
81  if (o->isLifeOperation())
82  returnType = "";
83  // if an operation isn't a constructor/destructor and it has no return type
84  // this operation should be void
85  else if (returnType.isEmpty())
86  returnType = QString("void");
87 
88  QString startText = returnType + ' ';
89 
90  // if a property has a friend stereotype, the operation should
91  // not be a class name
92  if (o->stereotype() != "friend")
93  startText += className + "::";
94  startText += methodName + " (" + paramStr + ')';
95  if (o->getConst())
96  startText += " const";
97  startText += " {";
98 
99  setStartMethodText(startText);
100 
101  // Only write this out if it is a child of an interface OR is abstract.
102  // and it is not inline
103  if (isInterface || o->isAbstract() || isInlineMethod)
104  {
105  setWriteOutText(false);
106  } else {
107  setWriteOutText(true);
108  }
109 
110 }
111 
112 #include "cppsourcecodeoperation.moc"
UMLOperation::getConst
bool getConst() const
Returns whether this operation is a query (C++ "const").
Definition: operation.cpp:411
CodeMethodBlock::setEndMethodText
void setEndMethodText(const QString &value)
Set the ending text that finishes this method after the body is printed.
Definition: codemethodblock.cpp:66
UMLClassifier
This class defines the non-graphical information required for a UML Classifier (ie a class or interfa...
Definition: classifier.h:39
CodeMethodBlock::setStartMethodText
void setStartMethodText(const QString &value)
Set the starting text that begins this method before the body is printed.
Definition: codemethodblock.cpp:58
CodeBlockWithComments::getComment
CodeComment * getComment() const
Get the Comment object.
Definition: codeblockwithcomments.cpp:46
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
cppsourcecodeoperation.h
CodeBlockWithComments::setOverallIndentationLevel
void setOverallIndentationLevel(int level)
A utility method that causes the comment and body of the code block to have the same indentation leve...
Definition: codeblockwithcomments.cpp:163
CPPSourceCodeOperation::CPPSourceCodeOperation
CPPSourceCodeOperation(CPPSourceCodeDocument *doc, UMLOperation *op, const QString &body="", const QString &comment="")
Constructor.
Definition: cppsourcecodeoperation.cpp:20
UMLAttribute
This class is used to set up information for an attribute.
Definition: attribute.h:27
UMLAttributeList
This sub-class adds copyInto and clone to the QPtrList base class.
Definition: umlattributelist.h:26
CPPSourceCodeOperation::updateContent
virtual void updateContent()
Just want to know whether or not to print out the body of the operation.
Definition: cppsourcecodeoperation.cpp:36
ClassifierCodeDocument::getParentClassifier
UMLClassifier * getParentClassifier()
Get the value of m_parentclassifier.
Definition: classifiercodedocument.cpp:271
UMLApp::policyExt
CodeGenPolicyExt * policyExt() const
Returns the CodeGenPolicyExt object.
Definition: uml.cpp:2148
UMLOperation::isLifeOperation
bool isLifeOperation()
Shortcut for (isConstructorOperation() || isDestructorOperation()).
Definition: operation.cpp:395
cppsourcecodedocument.h
CodeOperation
Definition: codeoperation.h:23
ClassifierCodeDocument::parentIsInterface
bool parentIsInterface()
Return if the parent classifier is an interface.
Definition: classifiercodedocument.cpp:413
TextBlock::setWriteOutText
void setWriteOutText(bool write)
Set the value of m_writeOutText Whether or not to include the text of this TextBlock into a file...
Definition: textblock.cpp:131
cppcodegenerator.h
cppcodegenerationpolicy.h
CPPSourceCodeDocument
A CPP UMLClassifier Source Code Document.
Definition: cppsourcecodedocument.h:22
CPPCodeDocumentation
class CPPCodeDocumentation A CPP code comment.
Definition: cppcodedocumentation.h:27
CodeMethodBlock::getParentDocument
CodeDocument * getParentDocument()
Get the parent code document.
Definition: codemethodblock.cpp:33
UMLObject::stereotype
QString stereotype(bool includeAdornments=false) const
Returns the stereotype.
Definition: umlobject.cpp:581
CodeOperation::getParentOperation
UMLOperation * getParentOperation()
Add a Parameter object to the m_parameterVector List.
Definition: codeoperation.cpp:64
cppcodedocumentation.h
CPPCodeGenerationPolicy
Definition: cppcodegenerationpolicy.h:23
UMLOperation
This class represents an operation in the UML model.
Definition: operation.h:24
Import_Rose::methodName
void methodName(const QString &m)
Definition: import_rose.cpp:43
CPPCodeGenerationPolicy::getOperationsAreInline
bool getOperationsAreInline()
Get the value of m_inlineOperations.
Definition: cppcodegenerationpolicy.cpp:100
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
CodeGenerator::cleanName
static QString cleanName(const QString &name)
Replaces spaces with underscores and capitalises as defined in m_modname.
Definition: codegenerator.cpp:609
CodeGenPolicyExt
Base class for programming language specific code generation policy extensions.
Definition: codegenpolicyext.h:28
CPPSourceCodeOperation::~CPPSourceCodeOperation
virtual ~CPPSourceCodeOperation()
Empty Destructor.
Definition: cppsourcecodeoperation.cpp:32
UMLObject::isAbstract
bool isAbstract() const
Returns the abstract state of the object.
Definition: umlobject.cpp:312
CPPSourceCodeOperation::updateMethodDeclaration
virtual void updateMethodDeclaration()
Update the doc and start text of this method.
Definition: cppsourcecodeoperation.cpp:47
CodeBlockWithComments::setComment
void setComment(CodeComment *object)
Set the Comment object.
Definition: codeblockwithcomments.cpp:38
UMLClassifierListItem::getTypeName
virtual QString getTypeName() const
Returns the type name of the UMLClassifierListItem.
Definition: classifierlistitem.cpp:110
uml.h
UMLObject::doc
QString doc() const
Returns the documentation for the object.
Definition: umlobject.cpp:404
UMLOperation::getParmList
UMLAttributeList getParmList() const
Returns a list of parameters.
Definition: operation.cpp:171
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:05:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal