umbrello API Documentation

cppcodeclassfield.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   : Mon Sep 1 2003
00015  */
00016 
00017 // own header
00018 #include "cppcodeclassfield.h"
00019 
00020 // qt/kde includes
00021 #include <kdebug.h>
00022 
00023 // local includes
00024 #include "../codegenerator.h"
00025 #include "../classifiercodedocument.h"
00026 #include "../attribute.h"
00027 #include "../umlobject.h"
00028 #include "../umlrole.h"
00029 #include "../uml.h"
00030 #include "cppcodegenerationpolicy.h"
00031 
00032 
00033 // Constructors/Destructors
00034 //
00035 
00036 CPPCodeClassField::CPPCodeClassField (ClassifierCodeDocument * parentDoc, UMLRole * role)
00037         : CodeClassField(parentDoc, role)
00038 {
00039 
00040 }
00041 
00042 CPPCodeClassField::CPPCodeClassField (ClassifierCodeDocument * parentDoc, UMLAttribute * attrib)
00043         : CodeClassField(parentDoc, attrib)
00044 {
00045 
00046 }
00047 
00048 CPPCodeClassField::~CPPCodeClassField ( ) { }
00049 
00050 //
00051 // Methods
00052 //
00053 
00054 // Other methods
00055 //
00056 
00057 QString CPPCodeClassField::getFieldName() {
00058     if (parentIsAttribute())
00059     {
00060         UMLAttribute * at = (UMLAttribute*) getParentObject();
00061         return cleanName(at->getName());
00062     }
00063     else
00064     {
00065         UMLRole * role = (UMLRole*) getParentObject();
00066         QString roleName = role->getName();
00067         if(fieldIsSingleValue()) {
00068             return roleName.replace(0, 1, roleName.left(1).lower());
00069         } else {
00070             return roleName.lower() + "Vector";
00071         }
00072     }
00073 }
00074 
00075 QString CPPCodeClassField::getListFieldClassName () {
00076     CodeGenPolicyExt * p = UMLApp::app()->getPolicyExt();
00077     CPPCodeGenerationPolicy *policy = dynamic_cast<CPPCodeGenerationPolicy*>(p);
00078     return policy->getVectorClassName();
00079 }
00080 
00081 QString CPPCodeClassField::getInitialValue() {
00082 
00083     if (parentIsAttribute())
00084     {
00085         UMLAttribute * at = dynamic_cast<UMLAttribute*>( getParentObject() );
00086         if (at) {
00087             return fixInitialStringDeclValue(at->getInitialValue(), getTypeName());
00088         } else {
00089             kError() << "CPPCodeClassField::getInitialValue: parent object is not a UMLAttribute"
00090             << endl;
00091             return "";
00092         }
00093     }
00094     else
00095     {
00096         if(fieldIsSingleValue()) {
00097             // FIX : IF the multiplicity is "1" then we should init a new object here, if its 0 or 1,
00098             //       then we can just return 'empty' string (minor problem).
00099             return "";
00100         } else {
00101             return " new "+getListFieldClassName()+"( )";
00102         }
00103     }
00104 
00105 }
00106 
00107 
00108 #include "cppcodeclassfield.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:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003