1 #ifndef DTDAUX_HPP
2 #define DTDAUX_HPP
3 
4 /*  $Id: dtdaux.hpp 547822 2017-10-04 15:45:27Z gouriano $
5 * ===========================================================================
6 *
7 *                            PUBLIC DOMAIN NOTICE
8 *               National Center for Biotechnology Information
9 *
10 *  This software/database is a "United States Government Work" under the
11 *  terms of the United States Copyright Act.  It was written as part of
12 *  the author's official duties as a United States Government employee and
13 *  thus cannot be copyrighted.  This software/database is freely available
14 *  to the public for use. The National Library of Medicine and the U.S.
15 *  Government have not placed any restriction on its use or reproduction.
16 *
17 *  Although all reasonable efforts have been taken to ensure the accuracy
18 *  and reliability of the software and data, the NLM and the U.S.
19 *  Government do not and cannot warrant the performance or results that
20 *  may be obtained by using this software or data. The NLM and the U.S.
21 *  Government disclaim all warranties, express or implied, including
22 *  warranties of performance, merchantability or fitness for any particular
23 *  purpose.
24 *
25 *  Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Andrei Gourianov
30 *
31 * File Description:
32 *   DTD parser's auxiliary stuff:
33 *       DTDEntity
34 *       DTDAttribute
35 *       DTDElement
36 *       DTDEntityLexer
37 *
38 * ===========================================================================
39 */
40 
41 #include <corelib/ncbistd.hpp>
42 #include <corelib/ncbistre.hpp>
43 #include "comments.hpp"
44 #include "type.hpp"
45 #include <list>
46 #include <map>
47 
48 BEGIN_NCBI_SCOPE
49 
50 class CFileModules;
51 class CDataModule;
52 class CDataType;
53 class CDataMemberContainerType;
54 class CDataValue;
55 class CDataMember;
56 class CEnumDataType;
57 class CEnumDataTypeValue;
58 
59 
60 /////////////////////////////////////////////////////////////////////////////
61 // DTDEntity
62 
63 class DTDEntity
64 {
65 public:
66     DTDEntity(void);
67     DTDEntity(const DTDEntity& other);
68     virtual ~DTDEntity(void);
69 
70     enum EType {
71         eEntity,
72         eType,
73         eGroup,
74         eAttGroup,
75 
76         eWsdlInterface,
77         eWsdlBinding
78     };
79 
80     void SetName(const string& name);
81     const string& GetName(void) const;
82 
83     void SetData(const string& data);
84     const string& GetData(void) const;
85 
86     void SetExternal(void);
87     bool IsExternal(void) const;
88 
89     void SetType(EType type);
90     EType GetType(void) const;
91 
92     void SetParseAttributes( const string& namespaceName,
93         bool elementForm, bool attributeForm,
94         map<string,string>& prefixToNamespace);
95     void GetParseAttributes( string& namespaceName,
96         bool& elementForm, bool& attributeForm,
97         map<string,string>& prefixToNamespace) const;
98 private:
99     string m_Name;
100     string m_Data;
101     bool   m_External;
102     EType  m_Type;
103     string m_TargetNamespace;
104     bool m_ElementFormDefault;
105     bool m_AttributeFormDefault;
106     map<string,string> m_PrefixToNamespace;
107 };
108 
109 /////////////////////////////////////////////////////////////////////////////
110 // DTDAttribute
111 
112 class DTDAttribute
113 {
114 public:
115     DTDAttribute(void);
116     DTDAttribute(const DTDAttribute& other);
117     virtual ~DTDAttribute(void);
118 
119     enum EType {
120         eUnknown,
121         eUnknownGroup,
122 
123         eString,
124         eEnum,
125         eIntEnum,
126         eId,
127         eIdRef,
128         eIdRefs,
129         eNmtoken,
130         eNmtokens,
131         eEntity,
132         eEntities,
133         eNotation,
134 
135         eBoolean,
136         eInteger,
137         eBigInt,
138         eDouble,
139         eBase64Binary
140     };
141     enum EValueType {
142         eDefault,
143         eRequired,
144         eImplied,
145         eFixed,
146         eProhibited
147     };
148 
149     DTDAttribute& operator= (const DTDAttribute& other);
150     void Merge(const DTDAttribute& other);
151 
152     void SetSourceLine(int line);
153     int GetSourceLine(void) const;
154 
155     void SetName(const string& name);
156     const string& GetName(void) const;
157 
158     void SetType(EType type);
159     void SetTypeIfUnknown( EType type);
160     EType GetType(void) const;
161     void SetTypeName( const string& name);
162     const string& GetTypeName( void) const;
163 
164     void SetValueType(EValueType valueType);
165     EValueType GetValueType(void) const;
166 
167     void SetValue(const string& value);
168     const string& GetValue(void) const;
169 
170     void AddEnumValue(const string& value, int line, int id=0);
171     const list<string>& GetEnumValues(void) const;
172     int GetEnumValueSourceLine(const string& value) const;
173     int GetEnumValueId(const string& value) const;
174 
175     void SetNamespaceName(const string& name);
176     const string& GetNamespaceName(void) const;
SetQualified(bool qualified)177     void SetQualified(bool qualified)
178     {
179         m_Qualified = qualified;
180     }
IsQualified(void) const181     bool IsQualified(void) const
182     {
183         return m_Qualified;
184     }
185 
Comments(void)186     CComments& Comments(void)
187     {
188         return m_Comments;
189     }
GetComments(void) const190     const CComments& GetComments(void) const
191     {
192         return m_Comments;
193     }
194 private:
195     int m_SourceLine;
196     string m_Name;
197     string m_TypeName;
198     string m_NamespaceName;
199     EType m_Type;
200     EValueType m_ValueType;
201     string m_Value;
202     list<string> m_ListEnum;
203     map<string,int> m_ValueSourceLine;
204     map<string,int> m_ValueId;
205     bool m_Qualified;
206     CComments m_Comments;
207 };
208 
209 /////////////////////////////////////////////////////////////////////////////
210 // DTDElement
211 
212 class DTDElement
213 {
214 public:
215     DTDElement(void);
216     DTDElement(const DTDElement& other);
217     DTDElement& operator=(const DTDElement& other);
218     virtual ~DTDElement(void);
219 
220     enum EType {
221         eUnknown,
222         eUnknownGroup,
223 
224         eString,   // #PCDATA
225         eAny,      // ANY
226         eEmpty,    // EMPTY
227         eSequence, // (a,b,c)
228         eChoice,   // (a|b|c)
229         eSet,      // (a,b,c)
230 
231         eEnum,
232         eIntEnum,
233 
234         eBoolean,
235         eInteger,
236         eBigInt,
237         eDouble,
238         eOctetString,
239         eBase64Binary,
240 
241         eWsdlService,
242         eWsdlEndpoint,
243         eWsdlUnsupportedEndpoint,
244         eWsdlOperation,
245         eWsdlHeaderInput,
246         eWsdlInput,
247         eWsdlHeaderOutput,
248         eWsdlOutput,
249         eWsdlMessage,
250 
251         eAlias
252     };
253     enum EOccurrence {
254         eZero,
255         eOne,
256         eOneOrMore,
257         eZeroOrMore,
258         eZeroOrOne
259     };
260 
261     void SetSourceLine(int line);
262     int GetSourceLine(void) const;
263 
264     void SetName(const string& name);
265     const string& GetName(void) const;
266     void SetNamed(bool named=true);
267     bool IsNamed(void) const;
268 
269     void SetType( EType type);
270     void ResetType( EType type);
271     void SetTypeIfUnknown( EType type);
272     EType GetType(void) const;
273     void SetTypeName( const string& name);
274     const string& GetTypeName( void) const;
275 
276     void SetDefaultRefsOccurence(EOccurrence occ);
277     void SetOccurrence( const string& ref_name, EOccurrence occ);
278     EOccurrence GetOccurrence(const string& ref_name) const;
279 
280     void SetOccurrence( EOccurrence occ);
281     EOccurrence GetOccurrence(void) const;
282 
283     // i.e. element contains other elements
284     void AddContent( const string& ref_name);
285     bool RemoveContent( const string& ref_name);
286     void RemoveContent( void);
287     const list<string>& GetContent(void) const;
288 
289     // element is contained somewhere
290     void SetReferenced(void);
291     bool IsReferenced(void) const;
292 
293     // element does not have any specific name
294     void SetEmbedded(bool set=true);
295     bool IsEmbedded(void) const;
296     string CreateEmbeddedName(int depth) const;
297 
298     void AddAttribute(DTDAttribute& attrib);
299     bool HasAttributes(void) const;
300     const list<DTDAttribute>& GetAttributes(void) const;
301     list<DTDAttribute>& GetNonconstAttributes(void);
302     void MergeAttributes(void);
303 
304     void SetNamespaceName(const string& name);
305     const string& GetNamespaceName(void) const;
SetQualified(bool qualified)306     void SetQualified(bool qualified)
307     {
308         m_Qualified = qualified;
309     }
IsQualified(void) const310     bool IsQualified(void) const
311     {
312         return m_Qualified;
313     }
314 
315     void SetDefault(const string& value);
316     const string& GetDefault(void) const;
317 
SetNillable(bool nil)318     void SetNillable(bool nil) {
319         m_Nillable = nil;
320     }
IsNillable(void) const321     bool IsNillable(void) const {
322         return m_Nillable;
323     }
324 
SetGlobalType(bool def)325     void SetGlobalType(bool def) {
326         m_GlobalType = def;
327     }
IsGlobalType(void) const328     bool IsGlobalType(void) const {
329         return m_GlobalType;
330     }
SetGlobalGroup(bool def)331     void SetGlobalGroup(bool def) {
332         m_GlobalGroup = def;
333     }
IsGlobalGroup(void) const334     bool IsGlobalGroup(void) const {
335         return m_GlobalGroup;
336     }
337 
Comments(void)338     CComments& Comments(void)
339     {
340         return m_Comments;
341     }
GetComments(void) const342     const CComments& GetComments(void) const
343     {
344         return m_Comments;
345     }
AttribComments(void)346     CComments& AttribComments(void)
347     {
348         return m_AttribComments;
349     }
GetAttribComments(void) const350     const CComments& GetAttribComments(void) const
351     {
352         return m_AttribComments;
353     }
354 
AddFacet(const CMemberFacet & c)355     void AddFacet(const CMemberFacet& c) {
356         m_Restrictions.push_back(c);
357     }
GetRestrictions(void) const358     const list<CMemberFacet>& GetRestrictions(void) const {
359         return m_Restrictions;
360     }
361 private:
362     int m_SourceLine;
363     string m_Name;
364     string m_TypeName;
365     string m_NamespaceName;
366     string m_Default;
367     EType m_Type;
368     EOccurrence m_Occ;
369     list<string> m_Refs;
370     list<DTDAttribute> m_Attrib;
371     map<string,EOccurrence> m_RefOcc;
372     bool m_Refd;
373     bool m_Embd;
374     bool m_Named;
375     bool m_Qualified;
376     bool m_Nillable;
377     bool m_GlobalType, m_GlobalGroup;
378     CComments m_Comments;
379     CComments m_AttribComments;
380     list<CMemberFacet> m_Restrictions;
381 };
382 
383 END_NCBI_SCOPE
384 
385 #endif // DTDAUX_HPP
386