umbrello API Documentation

cppheadercodeaccessormethod.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 "cppheadercodeaccessormethod.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
00024 #include "../attribute.h"
00025 #include "../classifiercodedocument.h"
00026 #include "cppcodegenerator.h"
00027 #include "../umlobject.h"
00028 #include "../umlrole.h"
00029 #include "../uml.h"
00030 
00031 #include "cppsourcecodedocument.h"
00032 #include "cppcodegenerationpolicy.h"
00033 #include "cppcodeclassfield.h"
00034 #include "cppcodedocumentation.h"
00035 
00036 // Constructors/Destructors
00037 //
00038 
00039 CPPHeaderCodeAccessorMethod::CPPHeaderCodeAccessorMethod ( CodeClassField * field, CodeAccessorMethod::AccessorType type)
00040         : CodeAccessorMethod ( field )
00041 {
00042     setType(type);
00043 }
00044 
00045 void CPPHeaderCodeAccessorMethod::update()
00046 {
00047     updateMethodDeclaration();
00048     updateContent();
00049 }
00050 
00051 CPPHeaderCodeAccessorMethod::~CPPHeaderCodeAccessorMethod ( ) { }
00052 
00053 // Other
00054 //
00055 
00056 // we basically want to update the body of this method
00057 void CPPHeaderCodeAccessorMethod::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     Uml::Visibility scope = parentField->getVisibility();
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 CPPHeaderCodeAccessorMethod::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 
00101     bool isInlineMethod = policy->getAccessorsAreInline( );
00102 
00103     QString vectorClassName = policy->getVectorClassName();
00104     QString fieldName = cppfield->getFieldName();
00105     QString fieldType = cppfield->getTypeName();
00106     QString objectType = cppfield->getListObjectType();
00107     if(objectType.isEmpty())
00108         objectType = fieldName;
00109 
00110     QString methodReturnType = "void";
00111     QString methodName = ""; // "get"+cppdoc->capitalizeFirstLetter(fieldName);
00112     QString methodParams = " "; // "get"+cppdoc->capitalizeFirstLetter(fieldName);
00113     QString headerText = "";
00114     QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
00115 
00116     switch(getType()) {
00117     case CodeAccessorMethod::ADD:
00118         methodName = "add_"+fieldType;
00119         methodReturnType = "void";
00120         methodParams = objectType+" value ";
00121         headerText = "Add a "+fieldName+" object to the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void";
00122         break;
00123     case CodeAccessorMethod::REMOVE:
00124         methodName = "remove_"+fieldType;
00125         methodParams = objectType+" value ";
00126         methodReturnType = "void";
00127         headerText = "Remove a "+fieldName+" object from the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void";
00128         break;
00129     case CodeAccessorMethod::LIST:
00130         methodName = "get_"+fieldType+"_list";
00131         methodReturnType = vectorClassName;
00132         headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return "+vectorClassName+"with list of objects";
00133         break;
00134     case CodeAccessorMethod::SET:
00135         methodName = "set_"+fieldName;
00136         methodParams = fieldType+" value ";
00137         methodReturnType = "void";
00138         headerText = "Set the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@param value the value of "+fieldName;
00139         break;
00140     case CodeAccessorMethod::GET:
00141     default:
00142         methodName = "get_"+fieldName;
00143         methodReturnType = fieldType;
00144         headerText = "Get the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return the value of "+fieldName;
00145         break;
00146     }
00147 
00148     // set header
00149     CPPCodeDocumentation * header = new CPPCodeDocumentation(doc);
00150     if(!getParentObject()->getDoc().isEmpty())
00151         header->setText(headerText);
00152     setComment(header);
00153 
00154     // set start/end method text
00155     QString startText = methodReturnType + ' ' + methodName + " (" + methodParams +')';
00156     if (isInlineMethod)
00157         startText += " {";
00158     else
00159         startText += ';';
00160     QString endText = (isInlineMethod ? "}" : "");
00161 
00162     setStartMethodText(startText);
00163     setEndMethodText(endText);
00164 
00165     setOverallIndentationLevel(1);
00166 }
00167 
00168 
00169 
00170 #include "cppheadercodeaccessormethod.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