1 #ifndef SERIALDEF__HPP
2 #define SERIALDEF__HPP
3 
4 /*  $Id: serialdef.hpp 574303 2018-11-08 19:59:04Z 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: Eugene Vasilchenko
30 *
31 * File Description:
32 *   Constants used in serial library
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 
37 
38 /** @addtogroup GenClassSupport
39  *
40  * @{
41  */
42 
43 
44 BEGIN_NCBI_SCOPE
45 
46 // forward declaration of two main classes
47 class CTypeRef;
48 class CTypeInfo;
49 
50 class CEnumeratedTypeValues;
51 
52 class CObjectIStream;
53 class CObjectOStream;
54 
55 class CObjectStreamCopier;
56 
57 // typedef for object references (constant and nonconstant)
58 typedef void* TObjectPtr;
59 typedef const void* TConstObjectPtr;
60 
61 // shortcut typedef: almost everywhere in code we have pointer to const CTypeInfo
62 typedef const CTypeInfo* TTypeInfo;
63 typedef TTypeInfo (*TTypeInfoGetter)(void);
64 typedef TTypeInfo (*TTypeInfoGetter1)(TTypeInfo);
65 typedef TTypeInfo (*TTypeInfoGetter2)(TTypeInfo, TTypeInfo);
66 typedef CTypeInfo* (*TTypeInfoCreator)(void);
67 typedef CTypeInfo* (*TTypeInfoCreator1)(TTypeInfo);
68 typedef CTypeInfo* (*TTypeInfoCreator2)(TTypeInfo, TTypeInfo);
69 
70 /// Data file format
71 enum ESerialDataFormat {
72     eSerial_None         = 0,
73     eSerial_AsnText      = 1,      ///< ASN.1 text
74     eSerial_AsnBinary    = 2,      ///< ASN.1 binary
75     eSerial_Xml          = 3,      ///< XML
76     eSerial_Json         = 4       ///< JSON
77 };
78 
79 /// Formatting flags
80 enum ESerial_AsnText_Flags {
81     fSerial_AsnText_NoIndentation = 1<<7, ///< do not use indentation
82     fSerial_AsnText_NoEol         = 1<<6  ///< do not write end-of-line symbol
83 };
84 typedef unsigned int TSerial_AsnText_Flags;
85 
86 enum ESerial_Xml_Flags {
87     fSerial_Xml_NoIndentation = 1<<7, ///< do not use indentation
88     fSerial_Xml_NoEol         = 1<<6, ///< do not write end-of-line symbol
89     fSerial_Xml_NoXmlDecl     = 1<<5, ///< do not write XMLDecl
90     fSerial_Xml_NoRefDTD      = 1<<4, ///< do not use reference to a DTD
91     fSerial_Xml_RefSchema     = 1<<3, ///< use reference to a Schema
92     fSerial_Xml_NoSchemaLoc   = 1<<2  ///< do not write schemaLocation data
93 };
94 typedef unsigned int TSerial_Xml_Flags;
95 
96 enum ESerial_Json_Flags {
97     fSerial_Json_NoIndentation = 1<<7, ///< do not use indentation
98     fSerial_Json_NoEol         = 1<<6  ///< do not write end-of-line symbol
99 };
100 typedef unsigned int TSerial_Json_Flags;
101 
102 #define SERIAL_VERIFY_DATA_GET    "SERIAL_VERIFY_DATA_GET"
103 #define SERIAL_VERIFY_DATA_WRITE  "SERIAL_VERIFY_DATA_WRITE"
104 #define SERIAL_VERIFY_DATA_READ   "SERIAL_VERIFY_DATA_READ"
105 
106 /// Data verification parameters
107 enum ESerialVerifyData {
108     eSerialVerifyData_Default = 0,   ///< use current default
109     eSerialVerifyData_No,            ///< do not verify
110     eSerialVerifyData_Never,         ///< never verify (even if set to verify later on)
111     eSerialVerifyData_Yes,           ///< do verify
112     eSerialVerifyData_Always,        ///< always verify (even if set not to later on)
113     eSerialVerifyData_DefValue,      ///< initialize field with default
114     eSerialVerifyData_DefValueAlways ///< initialize field with default
115 };
116 
117 /// Skip unknown members parameters
118 enum ESerialSkipUnknown {
119     eSerialSkipUnknown_Default = 0, ///< use current default
120     eSerialSkipUnknown_No,          ///< do not skip (throw exception)
121     eSerialSkipUnknown_Never,       ///< never skip (even if set to skip later on)
122     eSerialSkipUnknown_Yes,         ///< do skip
123     eSerialSkipUnknown_Always       ///< always skip (even if set not to later on)
124 };
125 
126 /// File open flags
127 enum ESerialOpenFlags {
128     eSerial_StdWhenEmpty = 1 << 0, ///< use std stream when filename is empty
129     eSerial_StdWhenDash  = 1 << 1, ///< use std stream when filename is "-"
130     eSerial_StdWhenStd   = 1 << 2, ///< use std when filename is "stdin"/"stdout"
131     eSerial_StdWhenMask  = 15,
132     eSerial_StdWhenAny   = eSerial_StdWhenMask,
133     eSerial_UseFileForReread = 1 << 4
134 };
135 typedef int TSerialOpenFlags;
136 
137 /// Type family
138 enum ETypeFamily {
139     eTypeFamilyPrimitive,
140     eTypeFamilyClass,
141     eTypeFamilyChoice,
142     eTypeFamilyContainer,
143     eTypeFamilyPointer
144 };
145 
146 /// Primitive value type
147 enum EPrimitiveValueType {
148     ePrimitiveValueSpecial,        ///< null, void
149     ePrimitiveValueBool,           ///< bool
150     ePrimitiveValueChar,           ///< char
151     ePrimitiveValueInteger,        ///< (signed|unsigned) (char|short|int|long)
152     ePrimitiveValueReal,           ///< float|double
153     ePrimitiveValueString,         ///< string|char*|const char*
154     ePrimitiveValueEnum,           ///< enum
155     ePrimitiveValueOctetString,    ///< vector<(signed|unsigned)? char>
156     ePrimitiveValueBitString,      //
157 #ifdef NCBI_STRICT_GI
158     //ePrimitiveValueGi,
159 #endif
160     ePrimitiveValueAny,
161     ePrimitiveValueOther
162 };
163 
164 enum EContainerType {
165     eContainerVector,              ///< allows indexing & access to size
166     eContainerList,                ///< only sequential access
167     eContainerSet,
168     eContainerMap
169 };
170 
171 
172 /// How to process non-printing character in the ASN VisibleString
173 enum EFixNonPrint {
174     eFNP_Skip,             ///< skip, post no error message
175     eFNP_Allow,            ///< pass through unchanged, post no error message
176     eFNP_Replace,          ///< replace with '#' silently
177     eFNP_ReplaceAndWarn,   ///< replace with '#', post an error of severity ERROR
178     eFNP_Throw,            ///< replace with '#', throw an exception
179     eFNP_Abort,            ///< replace with '#', post an error of severity FATAL
180 
181     eFNP_Default
182 };
183 
184 /// String type
185 enum EStringType {
186     eStringTypeVisible,  ///< VisibleString (in ASN.1 sense)
187     eStringTypeUTF8      ///< UTF8-encoded string
188 };
189 
190 /// How to assign and compare child sub-objects of serial objects
191 enum ESerialRecursionMode {
192     eRecursive,            ///< Recursively
193     eShallow,              ///< Assign/Compare pointers only
194     eShallowChildless      ///< Set sub-object pointers to 0
195 };
196 
197 /// Defines namespace qualification of XML tags
198 enum ENsQualifiedMode {
199     eNSQNotSet = 0,
200     eNSUnqualified,
201     eNSQualified
202 };
203 
204 enum class EDataSpec {
205     eUnknown  = 0,
206     eASN      = 0,
207     eDTD,
208     eXSD,
209     eJSON
210 };
211 
212 enum class ESerialFacet {
213     eMinLength = 1,
214     eMaxLength,
215     eLength,
216     ePattern,
217 
218     eInclusiveMinimum,
219     eExclusiveMinimum,
220     eInclusiveMaximum,
221     eExclusiveMaximum,
222     eMultipleOf,
223 
224     eMinItems,
225     eMaxItems,
226     eUniqueItems
227 };
228 
229 /// Type used for indexing class members and choice variants
230 typedef size_t TMemberIndex;
231 
232 typedef int TEnumValueType;
233 
234 /// Start if member indexing
235 const TMemberIndex kFirstMemberIndex = 1;
236 /// Special value returned from FindMember
237 const TMemberIndex kInvalidMember = kFirstMemberIndex - 1;
238 /// Special value for marking empty choice
239 const TMemberIndex kEmptyChoice = kInvalidMember;
240 
241 typedef ssize_t TPointerOffsetType;
242 
243 
244 /* @} */
245 
246 
247 END_NCBI_SCOPE
248 
249 #endif  /* SERIALDEF__HPP */
250