summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenobjectwithtextblocks.h
blob: 0e522e83a79305b3cf7d76d1a8543718dc17b2fe (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/***************************************************************************
 *                                                                         *
 *   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   : Tue Aug 19 2003
 */

#ifndef CODEGENOBJECTWITHTEXTBLOCKS_H
#define CODEGENOBJECTWITHTEXTBLOCKS_H

#include <tqmap.h>
#include "codeaccessormethod.h"
#include "textblocklist.h"

class CodeBlock;
class CodeBlockWithComments;
class CodeClassField;
class CodeComment;
class CodeDocument;
class HierarchicalCodeBlock;
class TextBlock;


/**
  * class CodeGenObjectWithTextBlocks
  * This abstract class is for code generator objects which 'own' text blocks.
  */

class CodeGenObjectWithTextBlocks
{
public:

    // Constructors/Destructors
    //

    /**
     * Constructor
     */
    CodeGenObjectWithTextBlocks ( CodeDocument *tqparent );

    /**
     * Empty Destructor
     */
    virtual ~CodeGenObjectWithTextBlocks ( );

    /**
     * Add a TextBlock object to the m_textblockVector List
     * @return boolean value where false means not added because an TextBlock
     *                 object with that tag already exists in this document.
     */
    virtual bool addTextBlock ( TextBlock * add_object );

    /**
     * Remove a TextBlock object from m_textblockVector List
     */
    virtual bool removeTextBlock ( TextBlock * remove_object );

    /**
     * Insert a new text block before/after the existing text block. Returns
     * false if it cannot insert the textblock.
     */
    virtual bool insertTextBlock (TextBlock * newBlock, TextBlock * existingBlock, bool after) = 0;

    /**
     * Get the list of TextBlock objects held by m_textblockVector
     * @return TextBlockList list of TextBlock objects held by m_textblockVector
     */
    TextBlockList * getTextBlockList ( );

    /**
     * Will get a hierarchicalcodeblock from the document with given tag. IF the codeblock
     * doesn't exist, then it will create it at the end of the document textBlock
     * list and pass back a reference.
     * @return  HierarchicalCodeBlock
     * @param   tag
     * @param   comment
     * @param   indentLevel
     */
    virtual HierarchicalCodeBlock * getHierarchicalCodeBlock ( const TQString &tag, const TQString &comment, int indentLevel );

    /**
            * Will get a codeblockwithcomments from the document with given tag. IF the codeblock
            * doesn't exist, then it will create it at the end of the document textBlock
            * list and pass back a reference.
     * @return  CodeBlockWithComments
     * @param   tag
     * @param   comment
     * @param   indentLevel
     */
    virtual CodeBlockWithComments * getCodeBlockWithComments ( const TQString &tag, const TQString &comment, int indentLevel );

    /** allows the user to add a code comment to the end of the list
     * of text blocks in this document OR, if a text block already exists
     * with that tag, it will update it with the passed text as appropriate.
     * @return codeblock/comment pointer to the object which was created/updated.
     * @return   CodeComment
     * @param    tag
     * @param    text
     * @param    indentationLevel
     */
     CodeComment * addOrUpdateTaggedCodeComment (const TQString &tag = "", const TQString &text = "", int indentationLevel = 0 );

   /** allows the user to either add a code block with comments to the end of the list
    * of text blocks in this document OR, if a text block already exists
    * with that tag, it will update it with the passed text as appropriate.
    * @return codeblock/comment pointer to the object which was created/updated.
    * @return   CodeBlockWithComments
    * @param    tag
    * @param    text
    * @param    comment
    * @param    indentLevel
    * @param    forceUserBlockUpdate
    */
    CodeBlockWithComments * addOrUpdateTaggedCodeBlockWithComments (const TQString &tag, const TQString &text, const TQString &comment, int indentLevel, bool forceUserBlockUpdate );

    /**
     * @return  TextBlock
     * @param   tag
     */
    virtual TextBlock * findTextBlockByTag ( const TQString &tag );

    /**
     * @return  TQString
     * @param   prefix
     */
    virtual TQString getUniqueTag (const TQString& prefix = "" ) = 0;

    /** Virtual methods that return a new code document objects.
     */
    virtual CodeBlock * newCodeBlock() = 0;
    virtual CodeBlockWithComments * newCodeBlockWithComments() = 0;
    virtual HierarchicalCodeBlock * newHierarchicalCodeBlock() = 0;

    /** Find the direct tqparent for a given textblock. This
     * may be any object which holds text blocks, e.g. a CodeGenObjectWithTextBlocks.
     * @return tqparent object. Could return null if the textblock is missing from the
     * branch of the document tree being examined.
     */
    CodeGenObjectWithTextBlocks * findParentObjectForTaggedTextBlock (const TQString & tag);

protected:

    /** set attributes of the node that represents this class
     * in the XMI document.
     */
    virtual void setAttributesOnNode (TQDomDocument & doc, TQDomElement & elem );

    /** set the class attributes of this object from
     * the passed element node.
     */
    virtual void setAttributesFromNode ( TQDomElement & element);

    virtual void setAttributesFromObject (CodeGenObjectWithTextBlocks * obj);

    /**
      * in this vanilla version, we only load comments and codeblocks
      * as they are the only instanciatable (vanilla) things
      * this method should be overridden if this class is inherited
      * by some other class that is concrete and takes tqchildren
      * derived from codeblock/codecomment/hierarchicalcb/ownedhiercodeblock
      */
    virtual void loadChildTextBlocksFromNode ( TQDomElement & root);

    // reset/clear the inventory text blocks held by this object
    virtual void resetTextBlocks();

    TQMap<TQString, TextBlock *> m_textBlockTagMap;
    TextBlockList m_textblockVector;

    // find specific text block belonging to code classfields.
    // block may not presently be alocated t othe textblock list.
    virtual TextBlock * findCodeClassFieldTextBlockByTag( const TQString &tag) = 0;

private:

    void initFields ();

    // needed in order to use findTextBlocksByTag
    CodeDocument *m_pCodeDoc;

};

#endif // CODEGENOBJECTWITHTEXTBLOCKS_H