• 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
cppheadercodeoperation.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 "cppheadercodeoperation.h"
13 
14 #include "cppcodegenerator.h"
15 #include "cppcodegenerationpolicy.h"
16 #include "cppheadercodedocument.h"
17 #include "cppcodedocumentation.h"
18 #include "uml.h"
19 
20 CPPHeaderCodeOperation::CPPHeaderCodeOperation
21  (CPPHeaderCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment)
22  : CodeOperation (doc, parent, body, comment)
23 {
24  // lets not go with the default comment and instead use
25  // full-blown cpp documentation object instead
26  setComment(new CPPCodeDocumentation(doc));
27 
28  // these things never change..
29  setOverallIndentationLevel(1);
30 
31  setText("");
32  setStartMethodText("");
33  setEndMethodText("");
34 }
35 
36 CPPHeaderCodeOperation::~CPPHeaderCodeOperation()
37 {
38 }
39 
40 // we basically just want to know whether or not to print out
41 // the body of the operation.
42 // In C++ if the operations are inline, then we DO print out
43 // the body text.
44 void CPPHeaderCodeOperation::updateContent()
45 {
46  CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
47  CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
48  bool isInlineMethod = policy->getOperationsAreInline();
49 
50  if(isInlineMethod)
51  setText(""); // change whatever it is to "";
52 }
53 
54 // we basically want to update the doc and start text of this method
55 void CPPHeaderCodeOperation::updateMethodDeclaration()
56 {
57  ClassifierCodeDocument *ccd = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
58  bool isInterface = ccd->parentIsInterface();
59  UMLOperation * o = getParentOperation();
60 
61  CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
62  CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
63  bool isInlineMethod = policy->getOperationsAreInline();
64  QString tag = policy->getDocToolTag();
65 
66  QString endLine = getNewLineEndingChars();
67 
68  // first, the comment on the operation, IF its autogenerated/empty
69  QString comment = o->doc();
70  if(comment.isEmpty() && contentType() == CodeBlock::AutoGenerated)
71  {
72  UMLAttributeList parameters = o->getParmList();
73  foreach (UMLAttribute* currentAtt, parameters) {
74  comment += endLine + tag + "param " + currentAtt->name() + ' ';
75  comment += currentAtt->doc();
76  }
77  getComment()->setText(comment);
78  }
79 
80  // no return type for constructors
81  QString methodReturnType = o->getTypeName();
82  QString methodName = o->name();
83  QString paramStr = QString("");
84 
85  // assemble parameters
86  UMLAttributeList list = getParentOperation()->getParmList();
87  int nrofParam = list.count();
88  int paramNum = 0;
89  foreach (UMLAttribute* parm, list) {
90  QString rType = parm->getTypeName();
91  QString paramName = parm->name();
92  QString initialValue = parm->getInitialValue();
93  paramStr += rType + ' ' + paramName;
94  if(!initialValue.isEmpty())
95  paramStr += '=' + initialValue;
96 
97  paramNum++;
98 
99  if (paramNum != nrofParam)
100  paramStr += ", ";
101  }
102 
103  // if an operation isn't a constructor or a destructor and it has no return type
104  if (o->isLifeOperation()) // constructor/destructor has no type
105  methodReturnType = "";
106  else if (methodReturnType.isEmpty()) // this operation should be 'void'
107  methodReturnType = QString("void");
108 
109  // set start/end method text
110  QString prototype = methodReturnType+' '+methodName+" ("+paramStr+')';
111 
112  QString startText;
113  QString endText;
114 
115  applyStereotypes (prototype, o, isInlineMethod, isInterface, startText, endText);
116 
117  setStartMethodText(prototype+startText);
118  setEndMethodText(endText);
119 }
120 
121 int CPPHeaderCodeOperation::lastEditableLine()
122 {
123  ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
124  UMLOperation * o = getParentOperation();
125  if(doc->parentIsInterface() || o->isAbstract())
126  return -1; // very last line is NOT editable as its a one-line declaration w/ no body in
127  // an interface.
128  return 0;
129 }
130 
131 void CPPHeaderCodeOperation::applyStereotypes (QString& prototype, UMLOperation * pOp,
132  bool inlinePolicy, bool interface,
133  QString& start, QString& end)
134 {
135  // if the class is an interface, all methods will be declared as pure
136  // virtual functions
137  start = (inlinePolicy ? " {" : ";");
138  end = (inlinePolicy ? "}" : "");
139  if (pOp->getConst())
140  prototype += " const";
141  if (interface || pOp->isAbstract()) {
142  // constructor can't be virtual or abstract
143  if (!pOp->isLifeOperation()) {
144  prototype = "virtual " + prototype + " = 0";
145  if (inlinePolicy) {
146  start = ';';
147  end = "";
148  }
149  }
150  } // constructors could not be declared as static
151  else if (pOp->isStatic() && !pOp->isLifeOperation()) {
152  prototype = "static " + prototype;
153  }
154  // apply the stereotypes
155  if (!pOp->stereotype().isEmpty()) {
156  if ((pOp->stereotype() == "friend") || (pOp->stereotype(false) == "virtual")) {
157  if (!pOp->isLifeOperation() && !(interface || pOp->isAbstract()) && !pOp->isStatic())
158  prototype = pOp->stereotype() + ' ' + prototype;
159  }
160  }
161 }
162 
163 #include "cppheadercodeoperation.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
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
CPPHeaderCodeOperation::CPPHeaderCodeOperation
CPPHeaderCodeOperation(CPPHeaderCodeDocument *doc, UMLOperation *op, const QString &body="", const QString &comment="")
Constructor.
Definition: cppheadercodeoperation.cpp:21
ClassifierCodeDocument
class ClassifierCodeDocument A CodeDocument which represents a UMLClassifier (e.g.
Definition: classifiercodedocument.h:33
UMLAttribute::getInitialValue
QString getInitialValue() const
Returns The initial value of the UMLAttribute.
Definition: attribute.cpp:98
CPPHeaderCodeDocument
class CPPHeaderCodeDocument A CPP UMLClassifier Header Code Document.
Definition: cppheadercodedocument.h:35
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
CodeBlock::AutoGenerated
the content was generated by code generation itself
Definition: codeblock.h:28
CPPHeaderCodeOperation::updateMethodDeclaration
virtual void updateMethodDeclaration()
This is the method called from within syncToparent().
Definition: cppheadercodeoperation.cpp:55
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
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
CodeBlock::contentType
ContentType contentType() const
Get the value of m_contentType specifies whether the content (text) of this object was generated by t...
Definition: codeblock.cpp:54
CPPHeaderCodeOperation::applyStereotypes
virtual void applyStereotypes(QString &, UMLOperation *, bool, bool, QString &, QString &)
Check to see if we have a valid stereotype to apply in the operation.
Definition: cppheadercodeoperation.cpp:131
TextBlock::getNewLineEndingChars
static QString getNewLineEndingChars()
Get the new line chars which ends the line.
Definition: textblock.cpp:172
CPPHeaderCodeOperation::lastEditableLine
virtual int lastEditableLine()
Definition: cppheadercodeoperation.cpp:121
cppheadercodeoperation.h
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
CodeOperation
Definition: codeoperation.h:23
ClassifierCodeDocument::parentIsInterface
bool parentIsInterface()
Return if the parent classifier is an interface.
Definition: classifiercodedocument.cpp:413
cppcodegenerator.h
cppcodegenerationpolicy.h
CPPHeaderCodeOperation::updateContent
virtual void updateContent()
This is the method called from within syncToparent() to update the body of the method.
Definition: cppheadercodeoperation.cpp:44
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
UMLObject::isStatic
bool isStatic() const
Returns true if this UMLObject has classifier scope, otherwise false (the default).
Definition: umlobject.cpp:335
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
cppheadercodedocument.h
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
CodeGenPolicyExt
Base class for programming language specific code generation policy extensions.
Definition: codegenpolicyext.h:28
UMLObject::isAbstract
bool isAbstract() const
Returns the abstract state of the object.
Definition: umlobject.cpp:312
UMLClassifierListItem::getTypeName
virtual QString getTypeName() const
Returns the type name of the UMLClassifierListItem.
Definition: classifierlistitem.cpp:110
CPPHeaderCodeOperation::~CPPHeaderCodeOperation
virtual ~CPPHeaderCodeOperation()
Empty Destructor.
Definition: cppheadercodeoperation.cpp:36
CPPCodeGenerationPolicy::getDocToolTag
QString getDocToolTag()
Definition: cppcodegenerationpolicy.cpp:212
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