d44e3c4f |
1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | * which accompanies this distribution, and is available at |
6 | * http://www.eclipse.org/legal/epl-v10.html |
7 | * |
8 | * Contributors: |
9 | * Balasko, Jeno |
10 | * Szabo, Bence Janos |
11 | * |
12 | ******************************************************************************/ |
3abe9331 |
13 | #ifndef ATTRIBUTETYPE_HH_ |
14 | #define ATTRIBUTETYPE_HH_ |
15 | |
16 | #include "SimpleType.hh" |
17 | #include "GeneralTypes.hh" |
18 | #include "GeneralFunctions.hh" |
19 | #include "GeneralFunctions.hh" |
20 | #include "TTCN3Module.hh" |
21 | #include "TTCN3ModuleInventory.hh" |
22 | #include "ComplexType.hh" |
23 | #include "Annotation.hh" |
24 | |
25 | /** |
26 | * Type that contains information of a field of a TTCN-3 record or union |
27 | * |
28 | */ |
29 | class AttributeType : public SimpleType { |
30 | bool isAnyAttr; |
31 | |
32 | UseValue useVal; |
33 | |
34 | Mstring actualPath; |
35 | |
36 | Mstring nameSpace; |
37 | |
38 | bool used; // To know if already in the extended or restricted type |
39 | |
40 | TTCN3Module * origModule; |
41 | |
42 | public: |
43 | explicit AttributeType(ComplexType * a_complextype); |
44 | AttributeType(const AttributeType & other); |
45 | AttributeType & operator=(const AttributeType & rhs); |
46 | virtual ~AttributeType(); |
47 | void setTypeOfField(const Mstring& in); |
48 | void setNameOfField(const Mstring& in); |
49 | |
50 | void setOrigModule(TTCN3Module * m) { |
51 | origModule = m; |
52 | } |
53 | |
54 | const TTCN3Module * getOrigModule() const { |
55 | return origModule; |
56 | } |
57 | void setToAnyAttribute(); |
58 | void modifyValues(); |
59 | |
60 | void setUseVal(UseValue use_value) { |
61 | useVal = use_value; |
62 | } |
63 | void setFieldPath(const Mstring path); |
64 | void collectVariants(List<Mstring>& container); |
65 | |
66 | UseValue getUseVal() const { |
67 | return useVal; |
68 | } |
69 | |
70 | bool getUsed() const { |
71 | return used; |
72 | } |
73 | |
74 | void setUsed(bool use) { |
75 | used = use; |
76 | } |
77 | |
78 | const Mstring& getNameSpaceAttribute() const { |
79 | return nameSpace; |
80 | } |
81 | |
82 | void addNameSpaceAttribute(Mstring namespace_) { |
83 | if(nameSpace.empty()){ |
84 | nameSpace = namespace_; |
85 | }else { |
86 | nameSpace += " " + namespace_; |
87 | } |
88 | } |
89 | void nameConversion_names(QualifiedNames& used); |
90 | void applyUseAttribute(); |
91 | void applyNamespaceAttribute(VariantMode varLabel); |
92 | |
93 | void applyMinMaxOccursAttribute(unsigned long long min, unsigned long long max); |
94 | |
95 | const Mstring& getPath() const { |
96 | return actualPath; |
97 | } |
98 | |
99 | bool isAnyAttribute() const { |
100 | return isAnyAttr; |
101 | } |
102 | |
86be9305 |
103 | void printToFile(FILE* file) { |
104 | printToFile(file, 0); |
105 | } |
3abe9331 |
106 | void printToFile(FILE* file, unsigned level); |
107 | |
108 | void dump(unsigned int depth) const; |
109 | |
110 | }; |
111 | |
112 | inline bool compareAttributeNameSpaces(AttributeType * lhs, AttributeType * rhs) { |
113 | if (lhs->isAnyAttribute()) { |
114 | return false; |
115 | } |
116 | if (lhs->getOrigModule()->getTargetNamespace() == Mstring("NoTargetNamespace") && rhs->getOrigModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) { |
117 | return false; |
118 | } else if (lhs->getOrigModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) { |
119 | return true; |
120 | } else if (rhs->getOrigModule()->getTargetNamespace() == Mstring("NoTargetNamespace")) { |
121 | return false; |
122 | } else { |
123 | return lhs->getOrigModule()->getTargetNamespace() <= rhs->getOrigModule()->getTargetNamespace(); |
124 | } |
125 | } |
126 | |
127 | inline bool compareAttributeTypes(AttributeType * lhs, AttributeType * rhs) { |
128 | if (lhs->isAnyAttribute()) { |
129 | return false; |
130 | } |
131 | if (lhs->getOrigModule()->getTargetNamespace() == rhs->getOrigModule()->getTargetNamespace()) { |
132 | return lhs->getName().originalValueWoPrefix < rhs->getName().originalValueWoPrefix; |
133 | } else { |
134 | return false; |
135 | } |
136 | } |
137 | |
138 | |
139 | #endif /* ATTRIBUTETYPE_HH_ */ |