umbrello API Documentation

cppsourcecodedocument.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) 2003-2006                                                *
00009  *  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                   *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Thu Aug 28 2003
00015  */
00016 
00028 // own header
00029 #include "cppsourcecodedocument.h"
00030 // qt/kde includes
00031 #include <kdebug.h>
00032 #include <qregexp.h>
00033 // app includes
00034 #include "cppcodegenerator.h"
00035 #include "cppcodegenerationpolicy.h"
00036 #include "cppcodedocumentation.h"
00037 #include "cppcodeclassfield.h"
00038 #include "cppsourcecodeclassfielddeclarationblock.h"
00039 #include "../uml.h"
00040 
00041 // Constructors/Destructors
00042 //
00043 
00044 CPPSourceCodeDocument::CPPSourceCodeDocument ( UMLClassifier * concept )
00045         : ClassifierCodeDocument (concept) {
00046     init ( );
00047 }
00048 
00049 CPPSourceCodeDocument::~CPPSourceCodeDocument ( ) { }
00050 
00051 //
00052 // Methods
00053 //
00054 
00055 // Accessor methods
00056 //
00057 
00058 // Other methods
00059 //
00060 
00061 QString CPPSourceCodeDocument::getCPPClassName (const QString &name) {
00062     return CodeGenerator::cleanName(name);
00063 }
00064 
00065 // Initialize this cpp classifier code document
00066 void CPPSourceCodeDocument::init ( ) {
00067 
00068     setFileExtension(".cpp");
00069 
00070     methodsBlock = 0;
00071     constructorBlock = 0;
00072 
00073     //initCodeClassFields(); // this is dubious because it calls down to
00074                              // CodeGenFactory::newCodeClassField(this)
00075                              // but "this" is still in construction at that time.
00076 
00077     // this will call updateContent() as well as other things that sync our document.
00078     //synchronize();
00079 }
00080 
00084 // in the vannilla version, we just tack all operations on the end
00085 // of the document
00086 bool CPPSourceCodeDocument::addCodeOperation (CodeOperation * op ) {
00087 
00088     if(!op->getParentOperation()->isLifeOperation())
00089     {
00090         return methodsBlock->addTextBlock(op);
00091     } else
00092         return constructorBlock->addTextBlock(op);
00093 }
00094 
00095 
00096 void CPPSourceCodeDocument::resetTextBlocks()
00097 {
00098 
00099     // all special pointers need to be zero'd out.
00100     methodsBlock = 0;
00101     constructorBlock = 0;
00102 
00103     // now do the traditional release of child text blocks
00104     ClassifierCodeDocument::resetTextBlocks();
00105 
00106 }
00107 
00108 // This method will cause the class to rebuild its text representation.
00109 // based on the parent classifier object.
00110 // For any situation in which this is called, we are either building the code
00111 // document up, or replacing/regenerating the existing auto-generated parts. As
00112 // such, we will want to insert everything we reasonably will want
00113 // during creation. We can set various parts of the document (esp. the
00114 // comments) to appear or not, as needed.
00115 void CPPSourceCodeDocument::updateContent( )
00116 {
00117 
00118     // Gather info on the various fields and parent objects of this class...
00119     //UMLClassifier * c = getParentClassifier();
00120     CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00121     CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00122     QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
00123 
00124     // first, set the global flag on whether or not to show classfield info
00125     CodeClassFieldList * cfList = getCodeClassFieldList();
00126     for(CodeClassField * field = cfList->first(); field; field = cfList->next())
00127         field->setWriteOutMethods(policy->getAutoGenerateAccessors());
00128 
00129     // attribute-based ClassFields
00130     // we do it this way to have the static fields sorted out from regular ones
00131     CodeClassFieldList staticAttribClassFields = getSpecificClassFields (CodeClassField::Attribute, true);
00132     CodeClassFieldList attribClassFields = getSpecificClassFields (CodeClassField::Attribute, false);
00133     // association-based ClassFields
00134     // don't care if they are static or not..all are lumped together
00135     CodeClassFieldList plainAssocClassFields = getSpecificClassFields ( CodeClassField::PlainAssociation );
00136     CodeClassFieldList aggregationClassFields = getSpecificClassFields ( CodeClassField::Aggregation );
00137     CodeClassFieldList compositionClassFields = getSpecificClassFields ( CodeClassField::Composition );
00138 
00139     // START GENERATING CODE/TEXT BLOCKS and COMMENTS FOR THE DOCUMENT
00140     //
00141 
00142     // INCLUDE CODEBLOCK
00143     QString includeStatement = "";
00144     // Include own header file
00145     QString myOwnName( getParentClassifier()->getName() );
00146     includeStatement.append("#include \""+CodeGenerator::cleanName(myOwnName.lower())+".h\""+endLine);
00147     CodeBlockWithComments * iblock = addOrUpdateTaggedCodeBlockWithComments("includes", includeStatement, QString::null, 0, false);
00148     iblock->setWriteOutText(true);
00149 
00150     // After the includes we have just 2 big blocks basically, the "constructor" block and the
00151     // block for the rest of our methods (operations + accessors)
00152 
00153     constructorBlock = getHierarchicalCodeBlock("constructionMethodsBlock", "Constructors/Destructors", 0);
00154     methodsBlock = getHierarchicalCodeBlock("otherMethodsBlock", "Methods", 0);
00155 
00156     // add accessors to the methods block
00157     methodsBlock->addCodeClassFieldMethods(staticAttribClassFields);
00158     methodsBlock->addCodeClassFieldMethods(attribClassFields);
00159     methodsBlock->addCodeClassFieldMethods(plainAssocClassFields);
00160     methodsBlock->addCodeClassFieldMethods(aggregationClassFields);
00161     methodsBlock->addCodeClassFieldMethods(compositionClassFields);
00162 
00163     // constructors and other operations are handled by the "addCodeOperation" method above.
00164 
00165 }
00166 
00167 
00168 #include "cppsourcecodedocument.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