summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenerators/cppheaderclassdeclarationblock.cpp
blob: 57ae0172bff7a447a4e0f31daffbe7d51c7b8b48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2004-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

/*  This code generated by:
 *      Author : thomas
 *      Date   : Mon Sep 1 2003
 */

#include "cppheaderclassdeclarationblock.h"
#include "cppcodegenerator.h"
#include "cppcodegenerationpolicy.h"
#include "cppcodedocumentation.h"
#include "../model_utils.h"
#include "../uml.h"

// Constructors/Destructors
//

CPPHeaderClassDeclarationBlock::CPPHeaderClassDeclarationBlock
  ( CPPHeaderCodeDocument * tqparentDoc, const TQString &startText, const TQString &endText, const TQString &comment)
        : OwnedHierarchicalCodeBlock(tqparentDoc->getParentClassifier(), tqparentDoc, startText, endText, comment)
{
    init(tqparentDoc, comment);
}

CPPHeaderClassDeclarationBlock::~CPPHeaderClassDeclarationBlock ( ) { }

//
// Methods
//

/**
 * load params from the appropriate XMI element node.
 */
void CPPHeaderClassDeclarationBlock::loadFromXMI ( TQDomElement & root )
{
    setAttributesFromNode(root);
}

/** set the class attributes from a passed object
 */
void CPPHeaderClassDeclarationBlock::setAttributesFromObject (TextBlock * obj)
{
    HierarchicalCodeBlock::setAttributesFromObject(obj);
}

/**
 * Save the XMI representation of this object
 */
void CPPHeaderClassDeclarationBlock::saveToXMI ( TQDomDocument & doc, TQDomElement & root ) {
    TQDomElement blockElement = doc.createElement( "cppheaderclassdeclarationblock" );

    setAttributesOnNode(doc, blockElement);

    root.appendChild( blockElement );
}

// Accessor methods
//

// Other methods
//

/**
 * update the start and end text for this hierarchicalcodeblock.
 */
void CPPHeaderClassDeclarationBlock::updateContent ( )
{

    CPPHeaderCodeDocument *tqparentDoc = dynamic_cast<CPPHeaderCodeDocument*>(getParentDocument());
    UMLClassifier *c = tqparentDoc->getParentClassifier();
    TQString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
    bool isInterface = tqparentDoc->tqparentIsInterface(); // a little shortcut
    TQString CPPHeaderClassName = CodeGenerator::cleanName(c->getName());
    bool forceDoc = UMLApp::app()->getCommonPolicy()->getCodeVerboseDocumentComments();

    // COMMENT

    //check if class is abstract.. it should have abstract methods
    if(!isInterface && c->getAbstract() && !c->hasAbstractOps())
    {
        getComment()->setText("******************************* Abstract Class ****************************"+endLine
                              +CPPHeaderClassName+" does not have any pure virtual methods, but its author"+endLine
                              +"  defined it as an abstract class, so you should not use it directly."+endLine
                              +"  Inherit from it instead and create only objects from the derived classes"+endLine
                              +"*****************************************************************************");
    } else {
        if(isInterface)
            getComment()->setText("Interface "+CPPHeaderClassName+endLine+c->getDoc());
        else
            getComment()->setText("Class "+CPPHeaderClassName+endLine+c->getDoc());
    }

    if(forceDoc || !c->getDoc().isEmpty())
        getComment()->setWriteOutText(true);
    else
        getComment()->setWriteOutText(false);


    // Now set START/ENDING Text
    TQString startText = "";

    /*
    */

    /*
        if(tqparentDoc->tqparentIsInterface())
                startText.append("interface ");
        else
    */
    startText.append("class ");

    startText.append(CPPHeaderClassName);

    // write inheritances out
    UMLClassifierList superclasses = c->findSuperClassConcepts();
    int nrof_superclasses = superclasses.count();

    // write out inheritance
    int i = 0;
    if(nrof_superclasses >0)
        startText.append(" : ");
    for (UMLClassifier * concept= superclasses.first(); concept; concept = superclasses.next())
    {
        startText.append(concept->getVisibility().toString() + ' ' +
                         CodeGenerator::cleanName(concept->getName()));
        if(i != (nrof_superclasses-1))
            startText.append(", ");
        i++;
    }

    // Set the header and end text for the hier.codeblock
    setStartText(startText+" {");

    // setEndText("}"); // not needed

}

void CPPHeaderClassDeclarationBlock::init (CPPHeaderCodeDocument *tqparentDoc, const TQString &comment)
{

    setComment(new CPPCodeDocumentation(tqparentDoc));
    getComment()->setText(comment);

    setEndText("};");

    updateContent();

}


#include "cppheaderclassdeclarationblock.moc"