summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenerationpolicy.h
blob: e27a651953e20b407475a2de482ad461becc821e (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/***************************************************************************
 *                                                                         *
 *   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 CODEGENERATIONPOLICY_H
#define CODEGENERATIONPOLICY_H

#include <tqobject.h>
#include <tqdir.h>
#include <tqdom.h>

class TQWidget;
class TDEConfig;
class CodeGenerationPolicyPage;

/**
  * class CodeGenerationPolicy
  * This class describes the code generation policy for this project.
  */

class CodeGenerationPolicy : public TQObject {
    TQ_OBJECT
  
public:

    /**
     * OverwritePolicy  can have the following values
     *  - Ok: if there is a file named the same as what you want to name your output file,
     *        you can overwrite the old file.
     *  - Ask:if there is a file named the same as what you want to name your output file,
     *        you should ask the User what to do, and give him the option to overwrite the file
     *        write the code to a different file, or to abort the generation of this class.
     *  - Never: you cannot overwrite any files. Generates a new file name like "fileName1.h", "fileName2.h"
     *        until you find an appropriate name.
     *  - Cancel: Do not output anything.  This is only set if the user chooses Apply to All Remaining Files
     *            and clicks on Do not Output  in the Ask dialog
     */
    enum OverwritePolicy {Ok=0, Ask, Never, Cancel};
    enum ModifyNamePolicy {No=0, Underscore, Capitalise};
    enum NewLineType {UNIX=0, DOS, MAC};
    enum IndentationType {NONE=0, TAB, SPACE};
    enum CommentStyle { SingleLine=0, MultiLine };
    enum ScopePolicy { Public=200, Private, Protected, FromParent };

    // set some reasonable defaults
    OverwritePolicy  defaultOverwritePolicy()          const;
    bool             defaultVerboseSectionComments()   const;
    bool             defaultVerboseDocumentComments()  const;
    bool             defaultIncludeHeadings()          const;
    NewLineType      defaultLineEndingType()           const;
    IndentationType  defaultIndentType()               const;
    int              defaultIndentAmount()             const;
    ModifyNamePolicy defaultModifyNamePolicy()         const;
    CommentStyle     defaultCommentStyle()             const;
    ScopePolicy      defaultAttribAccessorScope()      const;
    ScopePolicy      defaultAssocFieldScope()          const;
    bool             defaultAutoGenerateConstructors() const;

    // Constructors/Destructors
    //

    /**
     * Constructor
     */
    // note that as the code gen policy may be the 'default' policy, it may
    // not be coupled with a code generator.
    CodeGenerationPolicy (CodeGenerationPolicy * clone = 0);
    CodeGenerationPolicy (TDEConfig * config );

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

    // Public attributes
    //

    // Public attribute accessor methods
    //

    /**
     * Set the value of m_overwritePolicy
     * Policy of how to deal with overwriting existing files.
     * OverwritePolicy  can have the following values
     *  - Ok: if there is a file named the same as what you want to name your output file,
     *        you can overwrite the old file.
     *  - Ask:if there is a file named the same as what you want to name your output file,
     *        you should ask the User what to do, and give him the option to overwrite the file
     *        write the code to a different file, or to abort the generation of this class.
     *  - Never: you cannot overwrite any files. Generates a new file name like "fileName1.h", "fileName2.h"
     *        until you find an appropriate name.
     *  - Cancel: Do not output anything.  This is only set if the user chooses Apply to All Remaining Files
     *            and clicks on Do not Output  in the Ask dialog
     *
     * @param new_var the new value of m_overwritePolicy
     */
    void setOverwritePolicy ( OverwritePolicy new_var );

    /**
     * Get the value of m_overwritePolicy
     * Policy of how to deal with overwriting existing files. Allowed values are "Ok", "Ask",
     * "Never" "Cancel".
     * @return the value of m_overwritePolicy
     */
    OverwritePolicy getOverwritePolicy ( ) const;


    /**
     * Set the value of m_codeVerboseSectionComments
     * Whether or not verbose code commenting for sections is desired. If true, comments
     * for sections will be written even if the section is empty.
     * @param new_var the new value of m_codeVerboseSectionComments
     */
    void setCodeVerboseSectionComments ( bool new_var );

    /**
     * Get the value of m_codeVerboseSectionComments
     * Whether or not verbose code commenting for sections is desired. If true, comments
     * for sections will be written even if the section is empty.
     * @return the value of m_codeVerboseSectionComments
     */
    bool getCodeVerboseSectionComments ( ) const;


    /**
     * Set the value of m_codeVerboseDocumentComments
     * Whether or not verbose code commenting for documentation is desired. If true,
     * documentation for various code will be written even if no code would normally be
     * created at that point in the file.
     * @param new_var the new value of m_codeVerboseDocumentComments
     */
    void setCodeVerboseDocumentComments ( bool new_var );

    /**
     * Get the value of m_codeVerboseDocumentComments
     * Whether or not verbose code commenting for documentation is desired. If true,
     * documentation for various code will be written even if no code would normally be
     * created at that point in the file.
     * @return the value of m_codeVerboseDocumentComments
     */
    bool getCodeVerboseDocumentComments ( ) const;

    /**
     * Set the value of m_headingFileDir
     * location of the header file template.
     * @param path the new path of m_headingFileDir
     */
    void setHeadingFileDir ( const TQString & path);

    /**
     * Get the value of m_headingFileDir
     * location of the header file template.
     * @return the value of m_headingFileDir
     */
    TQString getHeadingFileDir ( ) const;


    /**
     * Set the value of m_includeHeadings
     * @param new_var the new value of m_includeHeadings
     */
    void setIncludeHeadings ( bool new_var );

    /**
     * Get the value of m_includeHeadings
     * @return the value of m_includeHeadings
     */
    bool getIncludeHeadings ( ) const;


    /**
     * Set the value of m_outputDirectory
     * location of where output files will go.
     * @param new_var the new value of m_outputDirectory
     */
    void setOutputDirectory ( TQDir new_var );

    /**
     * Get the value of m_outputDirectory
     * location of where output files will go.
     * @return the value of m_outputDirectory
     */
    TQDir getOutputDirectory ( );

    /**
     * Set the value of m_lineEndingType
     * What line ending characters to use.
     * @param new_var the new value of m_lineEndingType
     */
    void setLineEndingType ( NewLineType new_var );

    /**
     * Get the value of m_lineEndingType
     * What line ending characters to use.
     * @return the value of m_lineEndingType
     */
    NewLineType getLineEndingType ( );

    /** Utility function to get the actual characters.
     */
    TQString getNewLineEndingChars ( ) const;

    /**
     * Set the value of m_indentationType
     * The amount and type of whitespace to indent with.
     * @param type the new value of m_indentationType
     */
    void  setIndentationType ( IndentationType type );

    /**
     * Get the value of m_indentationType
     */
    IndentationType getIndentationType ( );

    /** How many units to indent for each indentation level.
     */
    void  setIndentationAmount ( int amount );
    int getIndentationAmount ( );

    /**
     * Get the string representation of each level of indentation.
     * The amount and type of whitespace to indent with.
     * @return the value of m_indentationType
     */
    TQString getIndentation ( ) const;

    /**
     * Set the value of m_modifyPolicy
     * @param new_var the new value of m_modifyPolicy
     */
    void setModifyPolicy ( ModifyNamePolicy new_var );

    /**
     * Get the value of m_modifyPolicy
     * @return the value of m_modifyPolicy
     */
    ModifyNamePolicy getModifyPolicy ( ) const;

    /**
     * Set the value of m_autoGenerateConstructors
     * @param var     the new value
     */
    void setAutoGenerateConstructors ( bool var );

    /**
     * Get the value of m_autoGenerateConstructors
     * @return value the boolean value of m_autoGenerateConstructors
     */
    bool getAutoGenerateConstructors ( );

    /**
     * Set the value of m_attributeAccessorScope
     * @param var the new value
     */
    void setAttributeAccessorScope(ScopePolicy var);

    /**
     * Get the value of m_attributeAccessorScope
     * @return the ScopePolicy value of m_attributeAccessorScope
     */
    ScopePolicy getAttributeAccessorScope();

    /**
     * Set the value of m_associationFieldScope
     * @param var the new value
     */
    void setAssociationFieldScope(ScopePolicy var);

    /**
     * Get the value of m_associationFieldScope
     * @return the ScopePolicy value of m_associationFieldScope
     */
    ScopePolicy getAssociationFieldScope();

    /**
     * Create a new dialog interface for this object.
     * @return dialog object
     */
    virtual CodeGenerationPolicyPage * createPage ( TQWidget *parent = 0, const char * name = 0);

    /**
      *  Gets the heading file (as a string) to be inserted at the
      *  beginning of the generated file. you give the file type as
      *  parameter and get the string. if fileName starts with a
      *  period (.) then fileName is the extension (.cpp, .h,
      *  .java) if fileName starts with another character you are
      *  requesting a specific file (mylicensefile.txt).  The files
      *  can have parameters which are denoted by %parameter%.
      *
      *  current parameters are
      *  %author%
      *  %date%
      *  %time%
      *  %filepath%
      */
    TQString getHeadingFile(const TQString& str);

    /**
     * set the defaults for this code generator from the passed generator.
     */
    virtual void setDefaults (CodeGenerationPolicy * defaults, bool emitUpdateSignal = true);

    /**
     * set the defaults from a config file for this code generator from the passed TDEConfig pointer.
     */
    virtual void setDefaults(TDEConfig * config, bool emitUpdateSignal = true);

    /**
     * write Default params to passed TDEConfig pointer.
     */
    virtual void writeConfig (TDEConfig * config);

    void emitModifiedCodeContentSig();

    /**
     * Set the value of m_commentStyle
     * @param new_var the new value of m_commentStyle
     */
    void setCommentStyle ( CommentStyle new_var );

    /**
     * Get the value of m_commentStyle
     * @return the value of m_commentStyle
     */
    CommentStyle getCommentStyle ( );

signals:

    // this signal is sent whenever a change is made to the policy
    // which could modifiy code document content
    void modifiedCodeContent();

protected:

    // Policy of how to deal with overwriting existing files. Allowed values are "ask", "yes" and "no".
    OverwritePolicy m_overwritePolicy;

    // Whether or not verbose code commenting for sections is desired.
    // If true, comments for sections will be written even if the section is empty.
    bool m_codeVerboseSectionComments;

    // Whether or not verbose code commenting for documentation is desired.
    // If true, documentation for various code will be written even if no
    //code would normally be created at that point in the file.
    bool m_codeVerboseDocumentComments;

    TQDir m_headingFiles; // location of the header file template.
    bool m_includeHeadings;
    TQDir m_outputDirectory; // location of where output files will go.
    NewLineType m_lineEndingType; // What type of line ending characters to use.
    IndentationType m_indentationType; // The amount and type of whitespace to indent with.
    int m_indentationAmount; // The amount of units to indent with.
    ModifyNamePolicy m_modifyPolicy;
    bool m_autoGenerateConstructors;
    CommentStyle m_commentStyle;
    ScopePolicy m_attributeAccessorScope;
    ScopePolicy m_associationFieldScope;

    // these 2 private fields 'cache' the string values of other fields we may frequently call for
    TQString m_lineEndingChars;
    TQString m_indentation;

    void calculateIndentation ( );

protected:

    void initFields ( );

};

#endif // CODEGENERATIONPOLICY_H