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