• 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
cppheadercodeaccessormethod.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 // own header
13 #include "cppheadercodeaccessormethod.h"
14 
15 // local includes
16 #include "attribute.h"
17 #include "classifiercodedocument.h"
18 #include "cppcodegenerator.h"
19 #include "cppsourcecodedocument.h"
20 #include "cppcodegenerationpolicy.h"
21 #include "cppcodeclassfield.h"
22 #include "cppcodedocumentation.h"
23 #include "umlobject.h"
24 #include "umlrole.h"
25 #include "uml.h"
26 
27 CPPHeaderCodeAccessorMethod::CPPHeaderCodeAccessorMethod(CodeClassField * field, CodeAccessorMethod::AccessorType type)
28  : CodeAccessorMethod(field)
29 {
30  setType(type);
31 }
32 
33 void CPPHeaderCodeAccessorMethod::update()
34 {
35  updateMethodDeclaration();
36  updateContent();
37 }
38 
39 CPPHeaderCodeAccessorMethod::~CPPHeaderCodeAccessorMethod()
40 {
41 }
42 
43 // we basically want to update the body of this method
44 void CPPHeaderCodeAccessorMethod::updateContent()
45 {
46  CodeClassField * parentField = getParentClassField();
47  CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
48  CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
49  CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
50  bool isInlineMethod = policy->getAccessorsAreInline();
51  // Uml::Visibility scope = parentField->getVisibility();
52  QString variableName = cppfield->getFieldName();
53  QString itemClassName = cppfield->getTypeName();
54  QString text = "";
55 
56  if(isInlineMethod) {
57  switch(getType()) {
58  case CodeAccessorMethod::ADD:
59  text = policy->getVectorMethodAppend(variableName, itemClassName);
60  break;
61  case CodeAccessorMethod::REMOVE:
62  text = policy->getVectorMethodRemove(variableName, itemClassName);
63  break;
64  case CodeAccessorMethod::SET:
65  text = variableName+" = value;";
66  break;
67  case CodeAccessorMethod::LIST:
68  case CodeAccessorMethod::GET:
69  default:
70  text = "return " + variableName + ';';
71  break;
72  }
73  }
74 
75  setText(text);
76 }
77 
78 // we basically want to update the start text of this method
79 void CPPHeaderCodeAccessorMethod::updateMethodDeclaration()
80 {
81  CodeClassField * parentField = getParentClassField();
82  ClassifierCodeDocument * doc = parentField->getParentDocument();
83  CodeGenPolicyExt *pe = UMLApp::app()->policyExt();
84  CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
85  CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
86 
87  bool isInlineMethod = policy->getAccessorsAreInline();
88  QString tag = policy->getDocToolTag();
89 
90  QString vectorClassName = policy->getVectorClassName();
91  QString fieldName = cppfield->getFieldName();
92  QString fieldType = cppfield->getTypeName();
93  QString objectType = cppfield->getListObjectType();
94  if(objectType.isEmpty())
95  objectType = fieldName;
96 
97  QString methodReturnType = "void";
98  QString methodName; // "get"+cppdoc->capitalizeFirstLetter(fieldName);
99  QString methodParams = QChar(' '); // "get"+cppdoc->capitalizeFirstLetter(fieldName);
100  QString headerText;
101  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
102 
103  switch(getType()) {
104  case CodeAccessorMethod::ADD:
105  methodName = "add_"+fieldType;
106  methodReturnType = "void";
107  methodParams = objectType+" value ";
108  headerText = "Add a "+fieldName+" object to the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"return void";
109  break;
110  case CodeAccessorMethod::REMOVE:
111  methodName = "remove_"+fieldType;
112  methodParams = objectType+" value ";
113  methodReturnType = "void";
114  headerText = "Remove a "+fieldName+" object from the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"return void";
115  break;
116  case CodeAccessorMethod::LIST:
117  methodName = "get_"+fieldType+"_list";
118  methodReturnType = vectorClassName;
119  headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"return "+vectorClassName+"with list of objects";
120  break;
121  case CodeAccessorMethod::SET:
122  methodName = "set_"+fieldName;
123  methodParams = fieldType+" value ";
124  methodReturnType = "void";
125  headerText = "Set the value of "+fieldName+endLine+getParentObject()->doc()+endLine+tag+"param value the value of "+fieldName;
126  break;
127  case CodeAccessorMethod::GET:
128  default:
129  methodName = "get_"+fieldName;
130  methodReturnType = fieldType;
131  headerText = "Get the value of "+fieldName+endLine+getParentObject()->doc()+endLine+tag+"return the value of "+fieldName;
132  break;
133  }
134 
135  // set header
136  CPPCodeDocumentation * header = new CPPCodeDocumentation(doc);
137  if(!getParentObject()->doc().isEmpty())
138  header->setText(headerText);
139  setComment(header);
140 
141  // set start/end method text
142  QString startText = methodReturnType + ' ' + methodName + " (" + methodParams +')';
143  if (isInlineMethod)
144  startText += " {";
145  else
146  startText += ';';
147  QString endText = (isInlineMethod ? "}" : "");
148 
149  setStartMethodText(startText);
150  setEndMethodText(endText);
151 
152  setOverallIndentationLevel(1);
153 }
154 
155 #include "cppheadercodeaccessormethod.moc"
CodeAccessorMethod::setType
void setType(AccessorType type)
Set the type of accessor method this is.
Definition: codeaccessormethod.cpp:72
CPPCodeClassField::getFieldName
QString getFieldName()
Definition: cppcodeclassfield.cpp:39
umlobject.h
CodeClassField
class CodeClassField a special type of parameter.
Definition: codeclassfield.h:29
CPPCodeGenerationPolicy::getVectorClassName
QString getVectorClassName()
Definition: cppcodegenerationpolicy.cpp:172
OwnedCodeBlock::getParentObject
UMLObject * getParentObject()
Get the value of m_parentObject.
Definition: ownedcodeblock.cpp:64
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
CPPHeaderCodeAccessorMethod::CPPHeaderCodeAccessorMethod
CPPHeaderCodeAccessorMethod(CodeClassField *field, CodeAccessorMethod::AccessorType type)
Empty Constructor.
Definition: cppheadercodeaccessormethod.cpp:27
cppcodeclassfield.h
ClassifierCodeDocument
class ClassifierCodeDocument A CodeDocument which represents a UMLClassifier (e.g.
Definition: classifiercodedocument.h:33
CodeAccessorMethod::REMOVE
Definition: codeaccessormethod.h:32
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
umlrole.h
CodeGenerationPolicy::getNewLineEndingChars
QString getNewLineEndingChars() const
Utility function to get the actual characters.
Definition: codegenerationpolicy.cpp:248
CodeAccessorMethod::getType
AccessorType getType()
Utility method to get the value of the parent object of the parent classifield.
Definition: codeaccessormethod.cpp:64
CodeAccessorMethod::getParentClassField
CodeClassField * getParentClassField()
Get the value of m_parentclassfield.
Definition: codeaccessormethod.cpp:40
CodeAccessorMethod::AccessorType
AccessorType
Definition: codeaccessormethod.h:32
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
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
CPPCodeGenerationPolicy::getVectorMethodRemove
QString getVectorMethodRemove(const QString &variableName="", const QString &itemClassName="")
Definition: cppcodegenerationpolicy.cpp:266
CPPHeaderCodeAccessorMethod::updateContent
virtual void updateContent()
This is the method called from within syncToparent() to update the body of the method.
Definition: cppheadercodeaccessormethod.cpp:44
CPPHeaderCodeAccessorMethod::~CPPHeaderCodeAccessorMethod
virtual ~CPPHeaderCodeAccessorMethod()
Empty Destructor.
Definition: cppheadercodeaccessormethod.cpp:39
CodeParameter::getParentDocument
ClassifierCodeDocument * getParentDocument()
Get the parent Code Document.
Definition: codeparameter.cpp:133
UMLApp::policyExt
CodeGenPolicyExt * policyExt() const
Returns the CodeGenPolicyExt object.
Definition: uml.cpp:2148
cppsourcecodedocument.h
CodeAccessorMethod::SET
Definition: codeaccessormethod.h:32
attribute.h
CPPCodeGenerationPolicy::getAccessorsAreInline
bool getAccessorsAreInline()
Get the value of m_inlineAccessors.
Definition: cppcodegenerationpolicy.cpp:81
CodeAccessorMethod::LIST
Definition: codeaccessormethod.h:32
cppcodegenerator.h
cppcodegenerationpolicy.h
CPPCodeClassField
Definition: cppcodeclassfield.h:21
CodeAccessorMethod
Definition: codeaccessormethod.h:20
CodeAccessorMethod::ADD
Definition: codeaccessormethod.h:32
CPPCodeDocumentation
class CPPCodeDocumentation A CPP code comment.
Definition: cppcodedocumentation.h:27
UMLApp::commonPolicy
CodeGenerationPolicy * commonPolicy() const
Returns the default code generation policy.
Definition: uml.cpp:2132
CPPHeaderCodeAccessorMethod::update
void update()
Must be called before this object is usable.
Definition: cppheadercodeaccessormethod.cpp:33
cppcodedocumentation.h
CPPCodeGenerationPolicy
Definition: cppcodegenerationpolicy.h:23
Import_Rose::methodName
void methodName(const QString &m)
Definition: import_rose.cpp:43
CodeAccessorMethod::GET
Definition: codeaccessormethod.h:32
CodeGenPolicyExt
Base class for programming language specific code generation policy extensions.
Definition: codegenpolicyext.h:28
CPPCodeGenerationPolicy::getVectorMethodAppend
QString getVectorMethodAppend(const QString &variableName="", const QString &itemClassName="")
More flexible generation.
Definition: cppcodegenerationpolicy.cpp:255
CPPHeaderCodeAccessorMethod::updateMethodDeclaration
virtual void updateMethodDeclaration()
This is the method called from within syncToparent().
Definition: cppheadercodeaccessormethod.cpp:79
classifiercodedocument.h
CodeClassField::getListObjectType
QString getListObjectType()
Definition: codeclassfield.cpp:112
CodeClassField::getTypeName
QString getTypeName()
Get the value of m_dialog.
Definition: codeclassfield.cpp:94
CodeBlockWithComments::setComment
void setComment(CodeComment *object)
Set the Comment object.
Definition: codeblockwithcomments.cpp:38
CPPCodeGenerationPolicy::getDocToolTag
QString getDocToolTag()
Definition: cppcodegenerationpolicy.cpp:212
cppheadercodeaccessormethod.h
uml.h
UMLObject::doc
QString doc() const
Returns the documentation for the object.
Definition: umlobject.cpp:404
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