Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 767eb5f68adb4bf582d942d5a006cbe4a549046b (plain) (blame)
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
[module CppClassHeader('http://www.eclipse.org/uml2/5.0.0/UML', 'http://www.eclipse.org/papyrus/C_Cpp/1')/]
[import org::eclipse::papyrus::acceleo::GenUtils/]
[import org::eclipse::papyrus::cpp::codegen::utils::CppGenUtils/]
[import org::eclipse::papyrus::cpp::codegen::utils::ClassUtils/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::Constants/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::CppIncludeUtils/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassIncludeClassDeclaration/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassTypeAndEnum/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassFriendDeclaration/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassInheritedDeclarations/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassAttributesDeclaration/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsDeclaration/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::clazz::CppClassOperationsImplementation/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::operation::CppOperations/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppTemplates/]
[import org::eclipse::papyrus::cpp::codegen::acceleo::util::CppDocumentation/]

[template public classUnionOrStruct(classifier : Classifier)]
[if (hasStereotype(C_Cpp::Union))]
    'union'
[else]
	[if (oclIsKindOf(DataType))]
        [VisibilityKind::public.resetVisibility()/]
        struct
	[else]
        [VisibilityKind::private.resetVisibility()/]
        class
	[/if]
[/if]
[/template]

[comment default initializer for non-static attributes with a default value
TODO: should be disabled by default, since non-static members can be initialized directly
in C++ 011/]
[template public defaultInitializer(classifier : Classifier) post(trim())]
[comment
Bug 422373: The default initializer should not be generated if there are any user-defined
            constructors.  In plain C++ code, the existence of a constructor with parameters
            means that the compiler will not synthesize a default one.

            E.g., this would be invalid in plain C++ code:
            class T1 { };
            class T2 { public: T(int); };
            T1 * t1 = new T1;     // OK, sythesized default constructor used
            T2 * t2a = new T2(5); // OK, user-defined constructor used
            T2 * t2b = new T2; // ERROR, default constructor was not synthesized

            Also, if the user has provided a default constructor in the code, we don't need
            to generate a second copy here.  A default constructor should only be generated
            here if the compiler would have synthesized one anyhow.  Otherwise the default
            property values should be set in the constructors that are generated by
            CppClassOperationsDeclaration.
/]
[if getOwnedOperations()->any(hasStereotype(standard::Create)) = null]
    [let attributeList : OrderedSet(Property) = attribute->select(	
    	(isStatic = false) and
    	(defaultValue <> null) and
    	(defaultValue.stringValue() <> null))]
    [if not attributeList->isEmpty()]
    	[classifier.name/]() : [for (a : Property | attributeList) separator(', ')
    		][name/]([defaultValue.stringValue()/])[/for] {}
    [/if][/let]
[/if]
[/template]


[template public CppClassHeader(class : Classifier)]
#ifndef [getFullNameUC()/]_H
#define [getFullNameUC()/]_H

/************************************************************
              [class.name/] class header
 ************************************************************/

[for (path : String |
	Sequence{ _package.cppOwnerPackageIncludePath() }
		->addAll( CppClassAllIncludes() )
		->flatten()
		->asOrderedSet())]
[path.IncludeDirective()/]
[/for]

[CppIncludeHeader()/]

[openNS()/] 

/************************************************************/
[CppElementDoc()/]
[templateSignature()/][classUnionOrStruct()/] [class.name/][CppClassInheritedDeclarations()/] {
[CppClassIncludeFriendDeclaration()/][CppClassTypeAndEnum()/]
    [VisibilityKind::public.getSection(defaultInitializer())/]
    [VisibilityKind::public.getSection(CppClassAttributesDeclaration(VisibilityKind::public))/]
    [VisibilityKind::public.getSection(CppClassOperationsDeclaration(VisibilityKind::public))/]

    [VisibilityKind::protected.getSection(CppClassAttributesDeclaration(VisibilityKind::protected))/]
    [VisibilityKind::protected.getSection(CppClassOperationsDeclaration(VisibilityKind::protected))/]

    [VisibilityKind::private.getSection(CppClassAttributesDeclaration(VisibilityKind::private))/]
    [VisibilityKind::private.getSection(CppClassOperationsDeclaration(VisibilityKind::private))/]
};
/************************************************************/
/* External declarations (package visibility)               */
[CppClassAttributesDeclaration(VisibilityKind::_package)/]
[CppClassOperationsDeclaration(VisibilityKind::_package)/]
/************************************************************/

[if isTemplate()]
/************************************************************/
/* Template functions                                       */
[CppClassOperationsImplementation(false)/]
[/if]

/* Inline functions                                         */
[CppClassOperationsImplementation(true)/]
[closeNS()/]

/************************************************************
              End of [class.name/] class header
 ************************************************************/

#endif
[/template]

Back to the top