1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 ///////////////////////////////////////////////////////////////////////////////
11 * Created on: Oct 17, 2008
15 #ifndef XERATTRIBUTES_H_
16 #define XERATTRIBUTES_H_
20 #include "../common/memory.h"
26 struct NamespaceRestriction // union member, no constructor allowed
29 /** URIs for ANY-ATTRIBUTES and ANY-ELEMENT. NULL is used to represent
34 NOTHING, ///< anyElement
35 FROM, ///< anyElement from ...
36 EXCEPT ///< anyElement except ...
39 // #define ABSENT ((char*)5) just use NULL
41 void FreeNamespaceRestriction(NamespaceRestriction& nsr);
44 struct NamespaceSpecification
46 /** How to transform the ASN/TTCN name to XML name */
48 NO_MANGLING, ///< no change
49 CAPITALIZED, ///< change the first letter to uppercase
50 UNCAPITALIZED,///< change the first letter to lowercase
51 UPPERCASED, ///< change all letters to uppercase
52 LOWERCASED, ///< change all letters to lowercase
53 // The underlying type of the enum is an integral type that can cover
54 // all the enum values. Using a value which doesn't fit into signed int,
55 // we try to force the underlying type to be _unsigned_ int.
56 FORCE_UNSIGNED = UINT_MAX
58 enum { ALL = LOWERCASED+1 }; // should be one bigger than the last of NameMangling
60 /** The URI for the NAMESPACE encoding instruction, or TextToBeUsed for TEXT.
61 * May be a valid pointer or any of the NameMangling enum values,
63 * For NAMESPACE, NULL (NO_MANGLING) means that no NAMESPACE instruction
64 * is assigned directly; UNCAPITALIZED means that an explicit "cancel
65 * all namespaces" instruction was applied: "namespace '' prefix ''" */
67 char * uri; // for NAMESPACE
68 char * new_text; // for TEXT
69 NameMangling keyword; // for TEXT
71 /** The prefix for the NAME encoding instruction or the Target for TEXT.
72 * May be XerAttributes::ALL for "text all as ...cased", or 0 for "text" */
74 char * prefix; // for NAMESPACE
75 char * target; // for TEXT
79 inline void free_name_or_kw(char *s)
81 if (s > (char*)NamespaceSpecification::ALL) {
86 /** XER attributes during compilation.
88 * @todo members are ordered alphabetically, this should be changed to
89 * be more space efficient (pointers, then integers, then booleans)
93 // Compiler-generated copy constructor and assignment NOT safe.
94 // Must disable or implement own.
95 XerAttributes(const XerAttributes&);
96 XerAttributes& operator=(const XerAttributes&);
98 //enum PI_Location { NOWHERE, BEFORE_TAG, BEFORE_VALUE, AFTER_TAG, AFTER_VALUE };
99 enum WhitespaceAction { PRESERVE, REPLACE, COLLAPSE };
100 enum Form { // a bit mask
102 // Global defaults for the module:
103 ELEMENT_DEFAULT_QUALIFIED = 1,
104 ATTRIBUTE_DEFAULT_QUALIFIED = 2,
105 // Locally set values (applied directly to the type or field)
106 UNQUALIFIED = 4, //< "form as unqualified"
107 QUALIFIED = 8, //< "form as qualified"
108 LOCALLY_SET = (QUALIFIED | UNQUALIFIED)
111 /** Name change action.
113 * When importing XSD into ASN.1 or TTCN-3, some names might need to be
114 * changed to protect the guilty (make them valid ASN.1/TTCN.3).
115 * The NAME encoding instruction describes how to get back to the XML
116 * tag name. The original name may be retrieved with one of the "canned" actions
117 * (change the case of the first or all letters) or by storing the original
118 * name in full (usually if characters were appended to remove name clashes).
120 * This union and the related code makes the assumption that not only
121 * 0, but 1,2,3,4 will not appear as valid pointers. Switch statements
122 * operating on the kw_ member must have cases for the enumeration values,
123 * the default case means that the nn_ member is in fact active
124 * and contains a pointer to the string. Remember to free/alloc new space
125 * in this situation. */
127 NamespaceSpecification::NameMangling kw_;
134 /// If the NameChange structure contains a string, free it.
135 static void FreeNameChange(NameChange& n);
136 /// If the NamespaceSpecification contains a string, free it.
137 static void FreeNamespace(NamespaceSpecification& ns);
140 NamespaceRestriction anyAttributes_;
141 NamespaceRestriction anyElement_;
142 /// Base64 encoding for string-like types (XSD:base64Binary)
144 /// No scientific notation for float
146 /// String parsed out from the encoding attribute
147 char * defaultForEmpty_;
148 /// Value object constructed by Type::chk_xer() from defaultForEmpty_
149 Common::Value *defaultValue_;
150 /// Global element in XSD
152 /// Give values to text nodes. Applied to record containing a record of string
154 /// Qualified or unqualified form for local elements and attributes
155 unsigned short form_;
158 /// space-separated values for record-of/set-of
160 /// How to get back the XML name
162 NamespaceSpecification namespace_;
163 //struct { PI_Location position_; /*const*/ char * value_; } pi_or_comment_;
164 /// Number of TEXT instructions stored.
166 /// Pointer to an array for the TEXT encoding instruction
167 NamespaceSpecification *text_; // re-use of struct
168 /// No XML tag, just the value
176 WhitespaceAction whitespace_;
178 void print(const char *type_name) const;
180 /** Override/merge XER attributes from @p other.
182 * Boolean attributes (attribute_, base64_, decimal_, embedValues_,
183 * list_, untagged_, useNil_, useNumber_, useOrder_, useQName_, useType_,
184 * useUnion_) are merged.
185 * In case of "Value" attributes (anyAttributes_, anyElement_, name_,
186 * namespace_, text_, whitespace_) the value in @p other overwrites
187 * the value in @p this.
189 * @param other set of XER attributes
190 * @return the merged object (@p *this)
191 * @pre @a other must not be @t empty() */
192 XerAttributes& operator |= (const XerAttributes& other);
194 /** Return true if no attribute is set, false otherwise */
198 inline bool has_ae(const XerAttributes *xa) {
199 return xa->anyElement_.type_ != NamespaceRestriction::UNUSED;
202 inline bool has_aa(const XerAttributes *xa) {
203 return xa->anyAttributes_.type_ != NamespaceRestriction::UNUSED;
207 #endif /* XERATTRIBUTES_H_ */