umbrello API Documentation

cppsourcecodeaccessormethod.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2007                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Fri Aug 31 2003
00015  */
00016 
00017 // own header
00018 #include "cppsourcecodeaccessormethod.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
00024 #include "../attribute.h"
00025 #include "../classifiercodedocument.h"
00026 #include "../umlobject.h"
00027 #include "../umlrole.h"
00028 #include "../uml.h"
00029 
00030 #include "cppcodegenerator.h"
00031 #include "cppcodegenerationpolicy.h"
00032 #include "cppcodeclassfield.h"
00033 #include "cppcodedocumentation.h"
00034 
00035 // Constructors/Destructors
00036 //
00037 
00038 CPPSourceCodeAccessorMethod::CPPSourceCodeAccessorMethod ( CodeClassField * field, CodeAccessorMethod::AccessorType type)
00039         : CodeAccessorMethod ( field )
00040 {
00041     setType(type);
00042     setEndMethodText("}");
00043 }
00044 
00045 void CPPSourceCodeAccessorMethod::update()
00046 {
00047     updateMethodDeclaration();
00048     updateContent();
00049 }
00050 
00051 CPPSourceCodeAccessorMethod::~CPPSourceCodeAccessorMethod ( ) { }
00052 
00053 // Other
00054 //
00055 
00056 // we basically want to update the body of this method
00057 void CPPSourceCodeAccessorMethod::updateContent( )
00058 {
00059     CodeClassField * parentField = getParentClassField();
00060     CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
00061     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00062     CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00063     bool isInlineMethod = policy->getAccessorsAreInline( );
00064 
00065     QString variableName = cppfield->getFieldName();
00066     QString itemClassName = cppfield->getTypeName();
00067     QString text = "";
00068 
00069     if(isInlineMethod) {
00070         switch(getType()) {
00071         case CodeAccessorMethod::ADD:
00072             text = policy->getVectorMethodAppend(variableName, itemClassName);
00073             break;
00074         case CodeAccessorMethod::REMOVE:
00075             text = policy->getVectorMethodRemove(variableName, itemClassName);
00076             break;
00077         case CodeAccessorMethod::SET:
00078             text = variableName+" = value;";
00079             break;
00080         case CodeAccessorMethod::LIST:
00081         case CodeAccessorMethod::GET:
00082         default:
00083             text = "return "+variableName+';';
00084             break;
00085         }
00086     }
00087 
00088     setText(text);
00089 }
00090 
00091 // we basically want to update the start text of this method
00092 void CPPSourceCodeAccessorMethod::updateMethodDeclaration()
00093 {
00094 
00095     CodeClassField * parentField = getParentClassField();
00096     ClassifierCodeDocument * doc = parentField->getParentDocument();
00097     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00098     CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00099     CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField);
00100     UMLClassifier * c = doc->getParentClassifier();
00101 
00102     bool isInlineMethod = policy->getAccessorsAreInline( );
00103 
00104     QString vectorClassName = policy->getVectorClassName();
00105     QString fieldName = cppfield->getFieldName();
00106     QString fieldType = cppfield->getTypeName();
00107     QString objectType = cppfield->getListObjectType();
00108     if(objectType.isEmpty())
00109         objectType = fieldName;
00110 
00111     QString methodReturnType = "void";
00112     QString methodName = ""; // "get"+cppdoc->capitalizeFirstLetter(fieldName);
00113     QString methodParams = " "; // "get"+cppdoc->capitalizeFirstLetter(fieldName);
00114     QString headerText = "";
00115     QString className = CodeGenerator::cleanName(c->getName());
00116     QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
00117 
00118     switch(getType()) {
00119     case CodeAccessorMethod::ADD:
00120         methodName = "add_"+fieldType;
00121         methodReturnType = "void";
00122         methodParams = objectType+" value ";
00123         headerText = "Add a "+fieldName+" object to the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void";
00124         break;
00125     case CodeAccessorMethod::REMOVE:
00126         methodName = "remove_"+fieldType;
00127         methodParams = objectType+" value ";
00128         methodReturnType = "void";
00129         headerText = "Remove a "+fieldName+" object from the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void";
00130         break;
00131     case CodeAccessorMethod::LIST:
00132         methodName = "get_"+fieldType+"_list";
00133         methodReturnType = vectorClassName;
00134         headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return "+vectorClassName+"with list of objects";
00135         break;
00136     case CodeAccessorMethod::SET:
00137         methodName = "set_"+fieldName;
00138         methodParams = fieldType+" value ";
00139         methodReturnType = "void";
00140         headerText = "Set the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@param value the value of "+fieldName;
00141         break;
00142     case CodeAccessorMethod::GET:
00143     default:
00144         methodName = "get_"+fieldName;
00145         methodReturnType = fieldType;
00146         headerText = "Get the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return the value of "+fieldName;
00147         break;
00148     }
00149 
00150     // set header
00151     CPPCodeDocumentation * header = new CPPCodeDocumentation(doc);
00152     if(!getParentObject()->getDoc().isEmpty())
00153         header->setText(headerText);
00154     setComment(header);
00155 
00156     // set start method text (EndText never changes)
00157     setStartMethodText(methodReturnType+' '+className+"::"+methodName+" ("+methodParams+')' + " {");
00158 
00159     setOverallIndentationLevel(0);
00160 
00161     // these ONLY appear if they arent inline
00162     if(isInlineMethod)
00163         setWriteOutText(false);
00164 
00165 }
00166 
00167 
00168 
00169 #include "cppsourcecodeaccessormethod.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:56 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003