summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codeclassfield.h
blob: d5542bd325213173b2ac923bfa2755d0b89fb2b7 (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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/***************************************************************************
 *                                                                         *
 *   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   : Fri Jun 20 2003
 */



#ifndef CODECLASSFIELD_H
#define CODECLASSFIELD_H

#include "codeaccessormethodlist.h"
#include "codeclassfielddeclarationblock.h"
#include "codeparameter.h"
#include "codeaccessormethod.h"

// #include "codeclassfielddialog.h"


class ClassifierCodeDocument;
class UMLAttribute;
class UMLObject;
class UMLRole;

/**
  * class CodeClassField
  * a special type of parameter.. occurs on class declarations.
  */

class CodeClassField : public CodeParameter
{
    Q_OBJECT
public:

    enum ClassFieldType { Attribute, PlainAssociation, Self, Aggregation, Composition, Unknown_Assoc };

    // Constructors/Destructors
    //

    /**
     * Constructors
     */
    CodeClassField ( ClassifierCodeDocument * parentDoc , UMLAttribute * attrib );
    CodeClassField ( ClassifierCodeDocument * parentDoc , UMLRole * role);

    /**
     * Finish off initializations of the object.
     * This is necessary as a separate method because we cannot call
     * virtual methods that are reimplemented in a language specific class
     * during our own construction (the own object is not finished being
     * constructed and therefore the C++ dispatch mechanism does not yet
     * work as expected.)
     */
    void finishInitialization();

    // CodeClassField ( ClassifierCodeDocument * doc , UMLRole role);

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

    // Public attributes
    //

    // Public attribute accessor methods
    //

    /**
     * Get the value of m_dialog
     * @return the value of m_dialog
     */
    //  CodeClassFieldDialog getDialog ( );

    // Determine if this cf is attribute or some type of association
    TQString getTypeName ( );

    /**
     * @return  CodeClassFieldDeclarationBlock representing the declaration statement of this class field
     */
    CodeClassFieldDeclarationBlock * getDeclarationCodeBlock( );

    /**
     * Get the list of Method objects held by m_methodVector
     * @return CodeAccessorMethodList list of Method objects held by
     * m_methodVector
     */
    CodeAccessorMethodList getMethodList();

    /** Utility method to allow finding particular accessor method of this
         *  code class field by its type identifier.
     */
    CodeAccessorMethod * findMethodByType(CodeAccessorMethod::AccessorType type, int role_id = -1);

    /** Determine whether the parent object in this classfield indicates that it is
     *  a single variable or a List (Vector). One day this will be done correctly with special
     *  multiplicity object.
     */
    bool fieldIsSingleValue ( );

    /**
     * Get the type of classfield this is.
     */
    ClassFieldType getClassFieldType();

    // quick utility call to figure out if parent is an attribute or not
    bool parentIsAttribute ( );

    // get the type of object that will be added/removed from lists
    // of objects (as per specification of associations)
    TQString getListObjectType();

    /** determine if we will *allow* methods to be viewable.
     * this flag is often used to toggle autogeneration of accessor
     * methods in the code class field.
     */
    bool getWriteOutMethods ();

    /** determine if we will *allow* methods to be viewable.
     * this flag is often used to toggle autogeneration of accessor
     * methods in the code class field.
     */
    void setWriteOutMethods( bool val);

    /** Find the minimum number of things that can occur in an association
      * If mistakenly called on attribute CF's the default value of is "0"
      * is returned. Similarly, if the association (role) CF doesn't have a multiplicty
      * 0 is returned.
      */
    int minimumListOccurances( );

    /** Find the maximum number of things that can occur in an association
      * If mistakenly called on attribute CF's the default value of is "1"
      * is returned. If the association (role) CF doesn't have a multiplicty
      * or has a "*" specified then '-1' (unbounded) is returned.
      */
    int maximumListOccurances( );

    /**
     * Save the XMI representation of this object
     */
    virtual void saveToXMI ( TQDomDocument & doc, TQDomElement & root );

    /**
     * load params from the appropriate XMI element node.
     */
    virtual void loadFromXMI ( TQDomElement & root );

    /** Force the syncronization of the content (methods and declarations)
         *  of this class field.
     */
    virtual void synchronize ();

protected:

    /** Set the parent UMLobject appropriately.
     */
    void setParentUMLObject (UMLObject * obj);

    //  CodeClassFieldDialog * m_dialog;

    /** a little utility method to make life easier for code document programmers
     */
    TQString cleanName(const TQString &name);

    /** another utility method to make life easier for code document programmers
     * this one fixes the initial declared value of string attributes so that if
     * its empty or lacking quotations, it comes out as ""
     */
    TQString fixInitialStringDeclValue(const TQString& val, const TQString &type);

    // set the list class name
    void setListClassName ( const TQString &className );

    /**
     * Add a Method object to the m_methodVector List
     */
    bool addMethod ( CodeAccessorMethod * add );

    TQString getUMLObjectName(UMLObject *obj);

    /**
     * Remove a Method object from m_methodVector List
     */
    bool removeMethod ( CodeAccessorMethod * remove);

    // Updates the status of the accessor methods
    // as to whether or not they should be written out.
    void updateContent();

private:

    TQString m_listClassName;
    ClassFieldType m_classFieldType;
    CodeClassFieldDeclarationBlock * m_declCodeBlock;
    CodeAccessorMethodList m_methodVector; // the list of methods related to this codeclassfield
    bool m_parentIsAttribute;

    /** This flag tells if we want the methods to have the possibility
      * of being written out. IF the value is false, then all methods
      * are never written out.
      */
    bool m_writeOutMethods;

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

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

    /** init class fields */
    void initFields(bool inConstructor = false);

    // initialize the accessor methods for this field
    void initAccessorMethods();

signals:

    void modified ();

};

#endif // CODECLASSFIELD_H