diff options
Diffstat (limited to 'libxsde')
699 files changed, 75955 insertions, 0 deletions
diff --git a/libxsde/makefile b/libxsde/makefile new file mode 100644 index 0000000..dc644f3 --- /dev/null +++ b/libxsde/makefile @@ -0,0 +1,26 @@ +# file : libxsde/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make + +default := $(out_base)/ +install := $(out_base)/.install +clean := $(out_base)/.clean + +.PHONY: $(default) $(install) $(clean) + +$(default): $(out_base)/xsde/ +$(clean): $(out_base)/xsde/.clean + +$(install): + $(call install-dir,$(src_base)/xsde,$(install_inc_dir)/xsde) + $(call install-data,$(src_base)/GPLv2,$(install_doc_dir)/libxsde/GPLv2) + $(call install-data,$(src_base)/LICENSE,$(install_doc_dir)/libxsde/LICENSE) + $(call install-data,$(src_base)/README,$(install_doc_dir)/libxsde/README) + + +$(call include,$(bld_root)/install.make) + +$(call import,$(src_base)/xsde/makefile) diff --git a/libxsde/xsde/c/expat/COPYING b/libxsde/xsde/c/expat/COPYING new file mode 100644 index 0000000..dcb4506 --- /dev/null +++ b/libxsde/xsde/c/expat/COPYING @@ -0,0 +1,22 @@ +Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + and Clark Cooper +Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/libxsde/xsde/c/expat/ascii.h b/libxsde/xsde/c/expat/ascii.h new file mode 100644 index 0000000..337e5bb --- /dev/null +++ b/libxsde/xsde/c/expat/ascii.h @@ -0,0 +1,85 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#define ASCII_A 0x41 +#define ASCII_B 0x42 +#define ASCII_C 0x43 +#define ASCII_D 0x44 +#define ASCII_E 0x45 +#define ASCII_F 0x46 +#define ASCII_G 0x47 +#define ASCII_H 0x48 +#define ASCII_I 0x49 +#define ASCII_J 0x4A +#define ASCII_K 0x4B +#define ASCII_L 0x4C +#define ASCII_M 0x4D +#define ASCII_N 0x4E +#define ASCII_O 0x4F +#define ASCII_P 0x50 +#define ASCII_Q 0x51 +#define ASCII_R 0x52 +#define ASCII_S 0x53 +#define ASCII_T 0x54 +#define ASCII_U 0x55 +#define ASCII_V 0x56 +#define ASCII_W 0x57 +#define ASCII_X 0x58 +#define ASCII_Y 0x59 +#define ASCII_Z 0x5A + +#define ASCII_a 0x61 +#define ASCII_b 0x62 +#define ASCII_c 0x63 +#define ASCII_d 0x64 +#define ASCII_e 0x65 +#define ASCII_f 0x66 +#define ASCII_g 0x67 +#define ASCII_h 0x68 +#define ASCII_i 0x69 +#define ASCII_j 0x6A +#define ASCII_k 0x6B +#define ASCII_l 0x6C +#define ASCII_m 0x6D +#define ASCII_n 0x6E +#define ASCII_o 0x6F +#define ASCII_p 0x70 +#define ASCII_q 0x71 +#define ASCII_r 0x72 +#define ASCII_s 0x73 +#define ASCII_t 0x74 +#define ASCII_u 0x75 +#define ASCII_v 0x76 +#define ASCII_w 0x77 +#define ASCII_x 0x78 +#define ASCII_y 0x79 +#define ASCII_z 0x7A + +#define ASCII_0 0x30 +#define ASCII_1 0x31 +#define ASCII_2 0x32 +#define ASCII_3 0x33 +#define ASCII_4 0x34 +#define ASCII_5 0x35 +#define ASCII_6 0x36 +#define ASCII_7 0x37 +#define ASCII_8 0x38 +#define ASCII_9 0x39 + +#define ASCII_TAB 0x09 +#define ASCII_SPACE 0x20 +#define ASCII_EXCL 0x21 +#define ASCII_QUOT 0x22 +#define ASCII_AMP 0x26 +#define ASCII_APOS 0x27 +#define ASCII_MINUS 0x2D +#define ASCII_PERIOD 0x2E +#define ASCII_COLON 0x3A +#define ASCII_SEMI 0x3B +#define ASCII_LT 0x3C +#define ASCII_EQUALS 0x3D +#define ASCII_GT 0x3E +#define ASCII_LSQB 0x5B +#define ASCII_RSQB 0x5D +#define ASCII_UNDERSCORE 0x5F diff --git a/libxsde/xsde/c/expat/asciitab.h b/libxsde/xsde/c/expat/asciitab.h new file mode 100644 index 0000000..79a15c2 --- /dev/null +++ b/libxsde/xsde/c/expat/asciitab.h @@ -0,0 +1,36 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, +/* 0x0C */ BT_NONXML, BT_CR, BT_NONXML, BT_NONXML, +/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, +/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, +/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, +/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, +/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, +/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, +/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, +/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, +/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, diff --git a/libxsde/xsde/c/expat/config.h b/libxsde/xsde/c/expat/config.h new file mode 100644 index 0000000..41c8fdf --- /dev/null +++ b/libxsde/xsde/c/expat/config.h @@ -0,0 +1,42 @@ +#ifndef XSDE_C_EXPAT_CONFIG_H +#define XSDE_C_EXPAT_CONFIG_H + +#include <xsde/config.h> + + +#if XSDE_BYTEORDER == 1234 +# define BYTEORDER 1234 +#elif XSDE_BYTEORDER == 4321 +# define BYTEORDER 4321 +#else +# error XSDE_BYTEORDER is not defined or defined to an invalid value +#endif + + +#define XML_NS 1 +#define XML_DTD 1 +#define XML_CONTEXT_BYTES 1024 + +#define UNUSED(x) (void)x; + +/* Windows + * + */ +#if defined(XSDE_PLATFORM_WIN32) || defined (XSDE_PLATFORM_WINCE) + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#undef WIN32_LEAN_AND_MEAN + +#define HAVE_MEMMOVE 1 + +#endif /* XSDE_PLATFORM_WIN32 || XSDE_PLATFORM_WINCE */ + +/* POSIX + * + */ +#ifdef XSDE_PLATFORM_POSIX +#define HAVE_MEMMOVE 1 +#endif + +#endif /* XSDE_C_EXPAT_CONFIG_H */ diff --git a/libxsde/xsde/c/expat/expat.h b/libxsde/xsde/c/expat/expat.h new file mode 100644 index 0000000..2dd29ff --- /dev/null +++ b/libxsde/xsde/c/expat/expat.h @@ -0,0 +1,1013 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef Expat_INCLUDED +#define Expat_INCLUDED 1 + +#ifdef __VMS +/* 0 1 2 3 0 1 2 3 + 1234567890123456789012345678901 1234567890123456789012345678901 */ +#define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler +#define XML_SetUnparsedEntityDeclHandler XML_SetUnparsedEntDeclHandler +#define XML_SetStartNamespaceDeclHandler XML_SetStartNamespcDeclHandler +#define XML_SetExternalEntityRefHandlerArg XML_SetExternalEntRefHandlerArg +#endif + +#include <stdlib.h> +#include <xsde/c/expat/expat_external.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct XML_ParserStruct; +typedef struct XML_ParserStruct *XML_Parser; + +/* Should this be defined using stdbool.h when C99 is available? */ +typedef unsigned char XML_Bool; +#define XML_TRUE ((XML_Bool) 1) +#define XML_FALSE ((XML_Bool) 0) + +/* The XML_Status enum gives the possible return values for several + API functions. The preprocessor #defines are included so this + stanza can be added to code that still needs to support older + versions of Expat 1.95.x: + + #ifndef XML_STATUS_OK + #define XML_STATUS_OK 1 + #define XML_STATUS_ERROR 0 + #endif + + Otherwise, the #define hackery is quite ugly and would have been + dropped. +*/ +enum XML_Status { + XML_STATUS_ERROR = 0, +#define XML_STATUS_ERROR XML_STATUS_ERROR + XML_STATUS_OK = 1, +#define XML_STATUS_OK XML_STATUS_OK + XML_STATUS_SUSPENDED = 2 +#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED +}; + +enum XML_Error { + XML_ERROR_NONE, + XML_ERROR_NO_MEMORY, + XML_ERROR_SYNTAX, + XML_ERROR_NO_ELEMENTS, + XML_ERROR_INVALID_TOKEN, + XML_ERROR_UNCLOSED_TOKEN, + XML_ERROR_PARTIAL_CHAR, + XML_ERROR_TAG_MISMATCH, + XML_ERROR_DUPLICATE_ATTRIBUTE, + XML_ERROR_JUNK_AFTER_DOC_ELEMENT, + XML_ERROR_PARAM_ENTITY_REF, + XML_ERROR_UNDEFINED_ENTITY, + XML_ERROR_RECURSIVE_ENTITY_REF, + XML_ERROR_ASYNC_ENTITY, + XML_ERROR_BAD_CHAR_REF, + XML_ERROR_BINARY_ENTITY_REF, + XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, + XML_ERROR_MISPLACED_XML_PI, + XML_ERROR_UNKNOWN_ENCODING, + XML_ERROR_INCORRECT_ENCODING, + XML_ERROR_UNCLOSED_CDATA_SECTION, + XML_ERROR_EXTERNAL_ENTITY_HANDLING, + XML_ERROR_NOT_STANDALONE, + XML_ERROR_UNEXPECTED_STATE, + XML_ERROR_ENTITY_DECLARED_IN_PE, + XML_ERROR_FEATURE_REQUIRES_XML_DTD, + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, + /* Added in 1.95.7. */ + XML_ERROR_UNBOUND_PREFIX, + /* Added in 1.95.8. */ + XML_ERROR_UNDECLARING_PREFIX, + XML_ERROR_INCOMPLETE_PE, + XML_ERROR_XML_DECL, + XML_ERROR_TEXT_DECL, + XML_ERROR_PUBLICID, + XML_ERROR_SUSPENDED, + XML_ERROR_NOT_SUSPENDED, + XML_ERROR_ABORTED, + XML_ERROR_FINISHED, + XML_ERROR_SUSPEND_PE, + /* Added in 2.0. */ + XML_ERROR_RESERVED_PREFIX_XML, + XML_ERROR_RESERVED_PREFIX_XMLNS, + XML_ERROR_RESERVED_NAMESPACE_URI +}; + +enum XML_Content_Type { + XML_CTYPE_EMPTY = 1, + XML_CTYPE_ANY, + XML_CTYPE_MIXED, + XML_CTYPE_NAME, + XML_CTYPE_CHOICE, + XML_CTYPE_SEQ +}; + +enum XML_Content_Quant { + XML_CQUANT_NONE, + XML_CQUANT_OPT, + XML_CQUANT_REP, + XML_CQUANT_PLUS +}; + +/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be + XML_CQUANT_NONE, and the other fields will be zero or NULL. + If type == XML_CTYPE_MIXED, then quant will be NONE or REP and + numchildren will contain number of elements that may be mixed in + and children point to an array of XML_Content cells that will be + all of XML_CTYPE_NAME type with no quantification. + + If type == XML_CTYPE_NAME, then the name points to the name, and + the numchildren field will be zero and children will be NULL. The + quant fields indicates any quantifiers placed on the name. + + CHOICE and SEQ will have name NULL, the number of children in + numchildren and children will point, recursively, to an array + of XML_Content cells. + + The EMPTY, ANY, and MIXED types will only occur at top level. +*/ + +typedef struct XML_cp XML_Content; + +struct XML_cp { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + XML_Char * name; + unsigned int numchildren; + XML_Content * children; +}; + + +/* This is called for an element declaration. See above for + description of the model argument. It's the caller's responsibility + to free model when finished with it. +*/ +typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData, + const XML_Char *name, + XML_Content *model); + +XMLPARSEAPI(void) +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl); + +/* The Attlist declaration handler is called for *each* attribute. So + a single Attlist declaration with multiple attributes declared will + generate multiple calls to this handler. The "default" parameter + may be NULL in the case of the "#IMPLIED" or "#REQUIRED" + keyword. The "isrequired" parameter will be true and the default + value will be NULL in the case of "#REQUIRED". If "isrequired" is + true and default is non-NULL, then this is a "#FIXED" default. +*/ +typedef void (XMLCALL *XML_AttlistDeclHandler) ( + void *userData, + const XML_Char *elname, + const XML_Char *attname, + const XML_Char *att_type, + const XML_Char *dflt, + int isrequired); + +XMLPARSEAPI(void) +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl); + +/* The XML declaration handler is called for *both* XML declarations + and text declarations. The way to distinguish is that the version + parameter will be NULL for text declarations. The encoding + parameter may be NULL for XML declarations. The standalone + parameter will be -1, 0, or 1 indicating respectively that there + was no standalone parameter in the declaration, that it was given + as no, or that it was given as yes. +*/ +typedef void (XMLCALL *XML_XmlDeclHandler) (void *userData, + const XML_Char *version, + const XML_Char *encoding, + int standalone); + +XMLPARSEAPI(void) +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler xmldecl); + + +typedef struct { + void *(*malloc_fcn)(size_t size); + void *(*realloc_fcn)(void *ptr, size_t size); + void (*free_fcn)(void *ptr); +} XML_Memory_Handling_Suite; + +/* Constructs a new parser; encoding is the encoding specified by the + external protocol or NULL if there is none specified. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate(const XML_Char *encoding); + +/* Constructs a new parser and namespace processor. Element type + names and attribute names that belong to a namespace will be + expanded; unprefixed attribute names are never expanded; unprefixed + element type names are expanded only if there is a default + namespace. The expanded name is the concatenation of the namespace + URI, the namespace separator character, and the local part of the + name. If the namespace separator is '\0' then the namespace URI + and the local part will be concatenated without any separator. + It is a programming error to use the separator '\0' with namespace + triplets (see XML_SetReturnNSTriplet). +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); + + +/* Constructs a new parser using the memory management suite referred to + by memsuite. If memsuite is NULL, then use the standard library memory + suite. If namespaceSeparator is non-NULL it creates a parser with + namespace processing as described above. The character pointed at + will serve as the namespace separator. + + All further memory operations used for the created parser will come from + the given suite. +*/ +XMLPARSEAPI(XML_Parser) +XML_ParserCreate_MM(const XML_Char *encoding, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *namespaceSeparator); + +/* Prepare a parser object to be re-used. This is particularly + valuable when memory allocation overhead is disproportionatly high, + such as when a large number of small documnents need to be parsed. + All handlers are cleared from the parser, except for the + unknownEncodingHandler. The parser's external state is re-initialized + except for the values of ns and ns_triplets. + + Added in Expat 1.95.3. +*/ +XMLPARSEAPI(XML_Bool) +XML_ParserReset(XML_Parser parser, const XML_Char *encoding); + +/* atts is array of name/value pairs, terminated by 0; + names and values are 0 terminated. +*/ +typedef void (XMLCALL *XML_StartElementHandler) (void *userData, + const XML_Char *name, + const XML_Char **atts); + +typedef void (XMLCALL *XML_EndElementHandler) (void *userData, + const XML_Char *name); + + +/* s is not 0 terminated. */ +typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData, + const XML_Char *s, + int len); + +/* target and data are 0 terminated */ +typedef void (XMLCALL *XML_ProcessingInstructionHandler) ( + void *userData, + const XML_Char *target, + const XML_Char *data); + +/* data is 0 terminated */ +typedef void (XMLCALL *XML_CommentHandler) (void *userData, + const XML_Char *data); + +typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData); +typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData); + +/* This is called for any characters in the XML document for which + there is no applicable handler. This includes both characters that + are part of markup which is of a kind that is not reported + (comments, markup declarations), or characters that are part of a + construct which could be reported but for which no handler has been + supplied. The characters are passed exactly as they were in the XML + document except that they will be encoded in UTF-8 or UTF-16. + Line boundaries are not normalized. Note that a byte order mark + character is not passed to the default handler. There are no + guarantees about how characters are divided between calls to the + default handler: for example, a comment might be split between + multiple calls. +*/ +typedef void (XMLCALL *XML_DefaultHandler) (void *userData, + const XML_Char *s, + int len); + +/* This is called for the start of the DOCTYPE declaration, before + any DTD or internal subset is parsed. +*/ +typedef void (XMLCALL *XML_StartDoctypeDeclHandler) ( + void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); + +/* This is called for the start of the DOCTYPE declaration when the + closing > is encountered, but after processing any external + subset. +*/ +typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); + +/* This is called for entity declarations. The is_parameter_entity + argument will be non-zero if the entity is a parameter entity, zero + otherwise. + + For internal entities (<!ENTITY foo "bar">), value will + be non-NULL and systemId, publicID, and notationName will be NULL. + The value string is NOT nul-terminated; the length is provided in + the value_length argument. Since it is legal to have zero-length + values, do not use this argument to test for internal entities. + + For external entities, value will be NULL and systemId will be + non-NULL. The publicId argument will be NULL unless a public + identifier was provided. The notationName argument will have a + non-NULL value only for unparsed entity declarations. + + Note that is_parameter_entity can't be changed to XML_Bool, since + that would break binary compatibility. +*/ +typedef void (XMLCALL *XML_EntityDeclHandler) ( + void *userData, + const XML_Char *entityName, + int is_parameter_entity, + const XML_Char *value, + int value_length, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +XMLPARSEAPI(void) +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler); + +/* OBSOLETE -- OBSOLETE -- OBSOLETE + This handler has been superceded by the EntityDeclHandler above. + It is provided here for backward compatibility. + + This is called for a declaration of an unparsed (NDATA) entity. + The base argument is whatever was set by XML_SetBase. The + entityName, systemId and notationName arguments will never be + NULL. The other arguments may be. +*/ +typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) ( + void *userData, + const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName); + +/* This is called for a declaration of notation. The base argument is + whatever was set by XML_SetBase. The notationName will never be + NULL. The other arguments can be. +*/ +typedef void (XMLCALL *XML_NotationDeclHandler) ( + void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* When namespace processing is enabled, these are called once for + each namespace declaration. The call to the start and end element + handlers occur between the calls to the start and end namespace + declaration handlers. For an xmlns attribute, prefix will be + NULL. For an xmlns="" attribute, uri will be NULL. +*/ +typedef void (XMLCALL *XML_StartNamespaceDeclHandler) ( + void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +typedef void (XMLCALL *XML_EndNamespaceDeclHandler) ( + void *userData, + const XML_Char *prefix); + +/* This is called if the document is not standalone, that is, it has an + external subset or a reference to a parameter entity, but does not + have standalone="yes". If this handler returns XML_STATUS_ERROR, + then processing will not continue, and the parser will return a + XML_ERROR_NOT_STANDALONE error. + If parameter entity parsing is enabled, then in addition to the + conditions above this handler will only be called if the referenced + entity was actually read. +*/ +typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData); + +/* This is called for a reference to an external parsed general + entity. The referenced entity is not automatically parsed. The + application can parse it immediately or later using + XML_ExternalEntityParserCreate. + + The parser argument is the parser parsing the entity containing the + reference; it can be passed as the parser argument to + XML_ExternalEntityParserCreate. The systemId argument is the + system identifier as specified in the entity declaration; it will + not be NULL. + + The base argument is the system identifier that should be used as + the base for resolving systemId if systemId was relative; this is + set by XML_SetBase; it may be NULL. + + The publicId argument is the public identifier as specified in the + entity declaration, or NULL if none was specified; the whitespace + in the public identifier will have been normalized as required by + the XML spec. + + The context argument specifies the parsing context in the format + expected by the context argument to XML_ExternalEntityParserCreate; + context is valid only until the handler returns, so if the + referenced entity is to be parsed later, it must be copied. + context is NULL only when the entity is a parameter entity. + + The handler should return XML_STATUS_ERROR if processing should not + continue because of a fatal error in the handling of the external + entity. In this case the calling parser will return an + XML_ERROR_EXTERNAL_ENTITY_HANDLING error. + + Note that unlike other handlers the first argument is the parser, + not userData. +*/ +typedef int (XMLCALL *XML_ExternalEntityRefHandler) ( + XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* This is called in two situations: + 1) An entity reference is encountered for which no declaration + has been read *and* this is not an error. + 2) An internal entity reference is read, but not expanded, because + XML_SetDefaultHandler has been called. + Note: skipped parameter entities in declarations and skipped general + entities in attribute values cannot be reported, because + the event would be out of sync with the reporting of the + declarations or attribute values +*/ +typedef void (XMLCALL *XML_SkippedEntityHandler) ( + void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +/* This structure is filled in by the XML_UnknownEncodingHandler to + provide information to the parser about encodings that are unknown + to the parser. + + The map[b] member gives information about byte sequences whose + first byte is b. + + If map[b] is c where c is >= 0, then b by itself encodes the + Unicode scalar value c. + + If map[b] is -1, then the byte sequence is malformed. + + If map[b] is -n, where n >= 2, then b is the first byte of an + n-byte sequence that encodes a single Unicode scalar value. + + The data member will be passed as the first argument to the convert + function. + + The convert function is used to convert multibyte sequences; s will + point to a n-byte sequence where map[(unsigned char)*s] == -n. The + convert function must return the Unicode scalar value represented + by this byte sequence or -1 if the byte sequence is malformed. + + The convert function may be NULL if the encoding is a single-byte + encoding, that is if map[b] >= -1 for all bytes b. + + When the parser is finished with the encoding, then if release is + not NULL, it will call release passing it the data member; once + release has been called, the convert function will not be called + again. + + Expat places certain restrictions on the encodings that are supported + using this mechanism. + + 1. Every ASCII character that can appear in a well-formed XML document, + other than the characters + + $@\^`{}~ + + must be represented by a single byte, and that byte must be the + same byte that represents that character in ASCII. + + 2. No character may require more than 4 bytes to encode. + + 3. All characters encoded must have Unicode scalar values <= + 0xFFFF, (i.e., characters that would be encoded by surrogates in + UTF-16 are not allowed). Note that this restriction doesn't + apply to the built-in support for UTF-8 and UTF-16. + + 4. No Unicode character may be encoded by more than one distinct + sequence of bytes. +*/ +typedef struct { + int map[256]; + void *data; + int (XMLCALL *convert)(void *data, const char *s); + void (XMLCALL *release)(void *data); +} XML_Encoding; + +/* This is called for an encoding that is unknown to the parser. + + The encodingHandlerData argument is that which was passed as the + second argument to XML_SetUnknownEncodingHandler. + + The name argument gives the name of the encoding as specified in + the encoding declaration. + + If the callback can provide information about the encoding, it must + fill in the XML_Encoding structure, and return XML_STATUS_OK. + Otherwise it must return XML_STATUS_ERROR. + + If info does not describe a suitable encoding, then the parser will + return an XML_UNKNOWN_ENCODING error. +*/ +typedef int (XMLCALL *XML_UnknownEncodingHandler) ( + void *encodingHandlerData, + const XML_Char *name, + XML_Encoding *info); + +XMLPARSEAPI(void) +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end); + +XMLPARSEAPI(void) +XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler handler); + +XMLPARSEAPI(void) +XML_SetEndElementHandler(XML_Parser parser, + XML_EndElementHandler handler); + +XMLPARSEAPI(void) +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler); + +XMLPARSEAPI(void) +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler); +XMLPARSEAPI(void) +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler); + +XMLPARSEAPI(void) +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end); + +XMLPARSEAPI(void) +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start); + +XMLPARSEAPI(void) +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end); + +/* This sets the default handler and also inhibits expansion of + internal entities. These entity references will be passed to the + default handler, or to the skipped entity handler, if one is set. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler); + +/* This sets the default handler but does not inhibit expansion of + internal entities. The entity reference will not be passed to the + default handler. +*/ +XMLPARSEAPI(void) +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler); + +XMLPARSEAPI(void) +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end); + +XMLPARSEAPI(void) +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler); + +XMLPARSEAPI(void) +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start); + +XMLPARSEAPI(void) +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end); + +XMLPARSEAPI(void) +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler); + +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler); + +/* If a non-NULL value for arg is specified here, then it will be + passed as the first argument to the external entity ref handler + instead of the parser object. +*/ +XMLPARSEAPI(void) +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, + void *arg); + +XMLPARSEAPI(void) +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler); + +XMLPARSEAPI(void) +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *encodingHandlerData); + +/* This can be called within a handler for a start element, end + element, processing instruction or character data. It causes the + corresponding markup to be passed to the default handler. +*/ +XMLPARSEAPI(void) +XML_DefaultCurrent(XML_Parser parser); + +/* If do_nst is non-zero, and namespace processing is in effect, and + a name has a prefix (i.e. an explicit namespace qualifier) then + that name is returned as a triplet in a single string separated by + the separator character specified when the parser was created: URI + + sep + local_name + sep + prefix. + + If do_nst is zero, then namespace information is returned in the + default manner (URI + sep + local_name) whether or not the name + has a prefix. + + Note: Calling XML_SetReturnNSTriplet after XML_Parse or + XML_ParseBuffer has no effect. +*/ + +XMLPARSEAPI(void) +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); + +/* This value is passed as the userData argument to callbacks. */ +XMLPARSEAPI(void) +XML_SetUserData(XML_Parser parser, void *userData); + +/* Returns the last value set by XML_SetUserData or NULL. */ +#define XML_GetUserData(parser) (*(void **)(parser)) + +/* This is equivalent to supplying an encoding argument to + XML_ParserCreate. On success XML_SetEncoding returns non-zero, + zero otherwise. + Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer + has no effect and returns XML_STATUS_ERROR. +*/ +XMLPARSEAPI(enum XML_Status) +XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); + +/* If this function is called, then the parser will be passed as the + first argument to callbacks instead of userData. The userData will + still be accessible using XML_GetUserData. +*/ +XMLPARSEAPI(void) +XML_UseParserAsHandlerArg(XML_Parser parser); + +/* If useDTD == XML_TRUE is passed to this function, then the parser + will assume that there is an external subset, even if none is + specified in the document. In such a case the parser will call the + externalEntityRefHandler with a value of NULL for the systemId + argument (the publicId and context arguments will be NULL as well). + Note: For the purpose of checking WFC: Entity Declared, passing + useDTD == XML_TRUE will make the parser behave as if the document + had a DTD with an external subset. + Note: If this function is called, then this must be done before + the first call to XML_Parse or XML_ParseBuffer, since it will + have no effect after that. Returns + XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. + Note: If the document does not have a DOCTYPE declaration at all, + then startDoctypeDeclHandler and endDoctypeDeclHandler will not + be called, despite an external subset being parsed. + Note: If XML_DTD is not defined when Expat is compiled, returns + XML_ERROR_FEATURE_REQUIRES_XML_DTD. +*/ +XMLPARSEAPI(enum XML_Error) +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); + + +/* Sets the base to be used for resolving relative URIs in system + identifiers in declarations. Resolving relative identifiers is + left to the application: this value will be passed through as the + base argument to the XML_ExternalEntityRefHandler, + XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base + argument will be copied. Returns XML_STATUS_ERROR if out of memory, + XML_STATUS_OK otherwise. +*/ +XMLPARSEAPI(enum XML_Status) +XML_SetBase(XML_Parser parser, const XML_Char *base); + +XMLPARSEAPI(const XML_Char *) +XML_GetBase(XML_Parser parser); + +/* Returns the number of the attribute/value pairs passed in last call + to the XML_StartElementHandler that were specified in the start-tag + rather than defaulted. Each attribute/value pair counts as 2; thus + this correspondds to an index into the atts array passed to the + XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetSpecifiedAttributeCount(XML_Parser parser); + +/* Returns the index of the ID attribute passed in the last call to + XML_StartElementHandler, or -1 if there is no ID attribute. Each + attribute/value pair counts as 2; thus this correspondds to an + index into the atts array passed to the XML_StartElementHandler. +*/ +XMLPARSEAPI(int) +XML_GetIdAttributeIndex(XML_Parser parser); + +/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is + detected. The last call to XML_Parse must have isFinal true; len + may be zero for this call (or any other). + + Though the return values for these functions has always been + described as a Boolean value, the implementation, at least for the + 1.95.x series, has always returned exactly one of the XML_Status + values. +*/ +XMLPARSEAPI(enum XML_Status) +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); + +XMLPARSEAPI(void *) +XML_GetBuffer(XML_Parser parser, int len); + +XMLPARSEAPI(enum XML_Status) +XML_ParseBuffer(XML_Parser parser, int len, int isFinal); + +/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. + Must be called from within a call-back handler, except when aborting + (resumable = 0) an already suspended parser. Some call-backs may + still follow because they would otherwise get lost. Examples: + - endElementHandler() for empty elements when stopped in + startElementHandler(), + - endNameSpaceDeclHandler() when stopped in endElementHandler(), + and possibly others. + + Can be called from most handlers, including DTD related call-backs, + except when parsing an external parameter entity and resumable != 0. + Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. + Possible error codes: + - XML_ERROR_SUSPENDED: when suspending an already suspended parser. + - XML_ERROR_FINISHED: when the parser has already finished. + - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. + + When resumable != 0 (true) then parsing is suspended, that is, + XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. + Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() + return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. + + *Note*: + This will be applied to the current parser instance only, that is, if + there is a parent parser then it will continue parsing when the + externalEntityRefHandler() returns. It is up to the implementation of + the externalEntityRefHandler() to call XML_StopParser() on the parent + parser (recursively), if one wants to stop parsing altogether. + + When suspended, parsing can be resumed by calling XML_ResumeParser(). +*/ +XMLPARSEAPI(enum XML_Status) +XML_StopParser(XML_Parser parser, XML_Bool resumable); + +/* Resumes parsing after it has been suspended with XML_StopParser(). + Must not be called from within a handler call-back. Returns same + status codes as XML_Parse() or XML_ParseBuffer(). + Additional error code XML_ERROR_NOT_SUSPENDED possible. + + *Note*: + This must be called on the most deeply nested child parser instance + first, and on its parent parser only after the child parser has finished, + to be applied recursively until the document entity's parser is restarted. + That is, the parent parser will not resume by itself and it is up to the + application to call XML_ResumeParser() on it at the appropriate moment. +*/ +XMLPARSEAPI(enum XML_Status) +XML_ResumeParser(XML_Parser parser); + +enum XML_Parsing { + XML_INITIALIZED, + XML_PARSING, + XML_FINISHED, + XML_SUSPENDED +}; + +typedef struct { + enum XML_Parsing parsing; + XML_Bool finalBuffer; +} XML_ParsingStatus; + +/* Returns status of parser with respect to being initialized, parsing, + finished, or suspended and processing the final buffer. + XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, + XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED +*/ +XMLPARSEAPI(void) +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); + +/* Creates an XML_Parser object that can parse an external general + entity; context is a '\0'-terminated string specifying the parse + context; encoding is a '\0'-terminated string giving the name of + the externally specified encoding, or NULL if there is no + externally specified encoding. The context string consists of a + sequence of tokens separated by formfeeds (\f); a token consisting + of a name specifies that the general entity of the name is open; a + token of the form prefix=uri specifies the namespace for a + particular prefix; a token of the form =uri specifies the default + namespace. This can be called at any point after the first call to + an ExternalEntityRefHandler so longer as the parser has not yet + been freed. The new parser is completely independent and may + safely be used in a separate thread. The handlers and userData are + initialized from the parser argument. Returns NULL if out of memory. + Otherwise returns a new XML_Parser object. +*/ +XMLPARSEAPI(XML_Parser) +XML_ExternalEntityParserCreate(XML_Parser parser, + const XML_Char *context, + const XML_Char *encoding); + +enum XML_ParamEntityParsing { + XML_PARAM_ENTITY_PARSING_NEVER, + XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, + XML_PARAM_ENTITY_PARSING_ALWAYS +}; + +/* Controls parsing of parameter entities (including the external DTD + subset). If parsing of parameter entities is enabled, then + references to external parameter entities (including the external + DTD subset) will be passed to the handler set with + XML_SetExternalEntityRefHandler. The context passed will be 0. + + Unlike external general entities, external parameter entities can + only be parsed synchronously. If the external parameter entity is + to be parsed, it must be parsed during the call to the external + entity ref handler: the complete sequence of + XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and + XML_ParserFree calls must be made during this call. After + XML_ExternalEntityParserCreate has been called to create the parser + for the external parameter entity (context must be 0 for this + call), it is illegal to make any calls on the old parser until + XML_ParserFree has been called on the newly created parser. + If the library has been compiled without support for parameter + entity parsing (ie without XML_DTD being defined), then + XML_SetParamEntityParsing will return 0 if parsing of parameter + entities is requested; otherwise it will return non-zero. + Note: If XML_SetParamEntityParsing is called after XML_Parse or + XML_ParseBuffer, then it has no effect and will always return 0. +*/ +XMLPARSEAPI(int) +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing parsing); + +/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then + XML_GetErrorCode returns information about the error. +*/ +XMLPARSEAPI(enum XML_Error) +XML_GetErrorCode(XML_Parser parser); + +/* These functions return information about the current parse + location. They may be called from any callback called to report + some parse event; in this case the location is the location of the + first of the sequence of characters that generated the event. When + called from callbacks generated by declarations in the document + prologue, the location identified isn't as neatly defined, but will + be within the relevant markup. When called outside of the callback + functions, the position indicated will be just past the last parse + event (regardless of whether there was an associated callback). + + They may also be called after returning from a call to XML_Parse + or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then + the location is the location of the character at which the error + was detected; otherwise the location is the location of the last + parse event, as described above. +*/ +XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); +XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); +XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); + +/* Return the number of bytes in the current event. + Returns 0 if the event is in an internal entity. +*/ +XMLPARSEAPI(int) +XML_GetCurrentByteCount(XML_Parser parser); + +/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets + the integer pointed to by offset to the offset within this buffer + of the current parse position, and sets the integer pointed to by size + to the size of this buffer (the number of input bytes). Otherwise + returns a NULL pointer. Also returns a NULL pointer if a parse isn't + active. + + NOTE: The character pointer returned should not be used outside + the handler that makes the call. +*/ +XMLPARSEAPI(const char *) +XML_GetInputContext(XML_Parser parser, + int *offset, + int *size); + +/* For backwards compatibility with previous versions. */ +#define XML_GetErrorLineNumber XML_GetCurrentLineNumber +#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber +#define XML_GetErrorByteIndex XML_GetCurrentByteIndex + +/* Frees the content model passed to the element declaration handler */ +XMLPARSEAPI(void) +XML_FreeContentModel(XML_Parser parser, XML_Content *model); + +/* Exposing the memory handling functions used in Expat */ +XMLPARSEAPI(void *) +XML_MemMalloc(XML_Parser parser, size_t size); + +XMLPARSEAPI(void *) +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); + +XMLPARSEAPI(void) +XML_MemFree(XML_Parser parser, void *ptr); + +/* Frees memory used by the parser. */ +XMLPARSEAPI(void) +XML_ParserFree(XML_Parser parser); + +/* Returns a string describing the error. */ +XMLPARSEAPI(const XML_LChar *) +XML_ErrorString(enum XML_Error code); + +/* Return a string containing the version number of this expat */ +XMLPARSEAPI(const XML_LChar *) +XML_ExpatVersion(void); + +typedef struct { + int major; + int minor; + int micro; +} XML_Expat_Version; + +/* Return an XML_Expat_Version structure containing numeric version + number information for this version of expat. +*/ +XMLPARSEAPI(XML_Expat_Version) +XML_ExpatVersionInfo(void); + +/* Added in Expat 1.95.5. */ +enum XML_FeatureEnum { + XML_FEATURE_END = 0, + XML_FEATURE_UNICODE, + XML_FEATURE_UNICODE_WCHAR_T, + XML_FEATURE_DTD, + XML_FEATURE_CONTEXT_BYTES, + XML_FEATURE_MIN_SIZE, + XML_FEATURE_SIZEOF_XML_CHAR, + XML_FEATURE_SIZEOF_XML_LCHAR, + XML_FEATURE_NS + /* Additional features must be added to the end of this enum. */ +}; + +typedef struct { + enum XML_FeatureEnum feature; + const XML_LChar *name; + long int value; +} XML_Feature; + +XMLPARSEAPI(const XML_Feature *) +XML_GetFeatureList(void); + + +/* Expat follows the GNU/Linux convention of odd number minor version for + beta/development releases and even number minor version for stable + releases. Micro is bumped with each release, and set to 0 with each + change to major or minor version. +*/ +#define XML_MAJOR_VERSION 2 +#define XML_MINOR_VERSION 0 +#define XML_MICRO_VERSION 0 + +#ifdef __cplusplus +} +#endif + +#endif /* not Expat_INCLUDED */ diff --git a/libxsde/xsde/c/expat/expat_external.h b/libxsde/xsde/c/expat/expat_external.h new file mode 100644 index 0000000..ea2279e --- /dev/null +++ b/libxsde/xsde/c/expat/expat_external.h @@ -0,0 +1,119 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef Expat_External_INCLUDED +#define Expat_External_INCLUDED 1 + +/* Link to Expat API statically */ + +#define XML_STATIC 1 + +/* External API definitions */ + +#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__) +#define XML_USE_MSC_EXTENSIONS 1 +#endif + +/* Expat tries very hard to make the API boundary very specifically + defined. There are two macros defined to control this boundary; + each of these can be defined before including this header to + achieve some different behavior, but doing so it not recommended or + tested frequently. + + XMLCALL - The calling convention to use for all calls across the + "library boundary." This will default to cdecl, and + try really hard to tell the compiler that's what we + want. + + XMLIMPORT - Whatever magic is needed to note that a function is + to be imported from a dynamically loaded library + (.dll, .so, or .sl, depending on your platform). + + The XMLCALL macro was added in Expat 1.95.7. The only one which is + expected to be directly useful in client code is XMLCALL. + + Note that on at least some Unix versions, the Expat library must be + compiled with the cdecl calling convention as the default since + system headers may assume the cdecl convention. +*/ +#ifndef XMLCALL +#if defined(XML_USE_MSC_EXTENSIONS) +#define XMLCALL __cdecl +#elif defined(__GNUC__) && defined(__i386) +#define XMLCALL __attribute__((cdecl)) +#else +/* For any platform which uses this definition and supports more than + one calling convention, we need to extend this definition to + declare the convention used on that platform, if it's possible to + do so. + + If this is the case for your platform, please file a bug report + with information on how to identify your platform via the C + pre-processor and how to specify the same calling convention as the + platform's malloc() implementation. +*/ +#define XMLCALL +#endif +#endif /* not defined XMLCALL */ + + +#if !defined(XML_STATIC) && !defined(XMLIMPORT) +#ifndef XML_BUILDING_EXPAT +/* using Expat from an application */ + +#ifdef XML_USE_MSC_EXTENSIONS +#define XMLIMPORT __declspec(dllimport) +#endif + +#endif +#endif /* not defined XML_STATIC */ + + +/* If we didn't define it above, define it away: */ +#ifndef XMLIMPORT +#define XMLIMPORT +#endif + + +#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef XML_UNICODE_WCHAR_T +#define XML_UNICODE +#endif + +#ifdef XML_UNICODE /* Information is UTF-16 encoded. */ +#ifdef XML_UNICODE_WCHAR_T +typedef wchar_t XML_Char; +typedef wchar_t XML_LChar; +#else +typedef unsigned short XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE_WCHAR_T */ +#else /* Information is UTF-8 encoded. */ +typedef char XML_Char; +typedef char XML_LChar; +#endif /* XML_UNICODE */ + +#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */ +#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400 +typedef __int64 XML_Index; +typedef unsigned __int64 XML_Size; +#else +typedef long long XML_Index; +typedef unsigned long long XML_Size; +#endif +#else +typedef long XML_Index; +typedef unsigned long XML_Size; +#endif /* XML_LARGE_SIZE */ + +#ifdef __cplusplus +} +#endif + +#endif /* not Expat_External_INCLUDED */ diff --git a/libxsde/xsde/c/expat/iasciitab.h b/libxsde/xsde/c/expat/iasciitab.h new file mode 100644 index 0000000..24a1d5c --- /dev/null +++ b/libxsde/xsde/c/expat/iasciitab.h @@ -0,0 +1,37 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* Like asciitab.h, except that 0xD has code BT_S rather than BT_CR */ +/* 0x00 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x04 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x08 */ BT_NONXML, BT_S, BT_LF, BT_NONXML, +/* 0x0C */ BT_NONXML, BT_S, BT_NONXML, BT_NONXML, +/* 0x10 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x14 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x18 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x1C */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0x20 */ BT_S, BT_EXCL, BT_QUOT, BT_NUM, +/* 0x24 */ BT_OTHER, BT_PERCNT, BT_AMP, BT_APOS, +/* 0x28 */ BT_LPAR, BT_RPAR, BT_AST, BT_PLUS, +/* 0x2C */ BT_COMMA, BT_MINUS, BT_NAME, BT_SOL, +/* 0x30 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x34 */ BT_DIGIT, BT_DIGIT, BT_DIGIT, BT_DIGIT, +/* 0x38 */ BT_DIGIT, BT_DIGIT, BT_COLON, BT_SEMI, +/* 0x3C */ BT_LT, BT_EQUALS, BT_GT, BT_QUEST, +/* 0x40 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x44 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x48 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x4C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x50 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x54 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x58 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_LSQB, +/* 0x5C */ BT_OTHER, BT_RSQB, BT_OTHER, BT_NMSTRT, +/* 0x60 */ BT_OTHER, BT_HEX, BT_HEX, BT_HEX, +/* 0x64 */ BT_HEX, BT_HEX, BT_HEX, BT_NMSTRT, +/* 0x68 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x6C */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x70 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x74 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0x78 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0x7C */ BT_VERBAR, BT_OTHER, BT_OTHER, BT_OTHER, diff --git a/libxsde/xsde/c/expat/internal.h b/libxsde/xsde/c/expat/internal.h new file mode 100644 index 0000000..ff056c6 --- /dev/null +++ b/libxsde/xsde/c/expat/internal.h @@ -0,0 +1,73 @@ +/* internal.h + + Internal definitions used by Expat. This is not needed to compile + client code. + + The following calling convention macros are defined for frequently + called functions: + + FASTCALL - Used for those internal functions that have a simple + body and a low number of arguments and local variables. + + PTRCALL - Used for functions called though function pointers. + + PTRFASTCALL - Like PTRCALL, but for low number of arguments. + + inline - Used for selected internal functions for which inlining + may improve performance on some platforms. + + Note: Use of these macros is based on judgement, not hard rules, + and therefore subject to change. +*/ + +#if defined(__GNUC__) && defined(__i386__) +/* We'll use this version by default only where we know it helps. + + regparm() generates warnings on Solaris boxes. See SF bug #692878. + + Instability reported with egcs on a RedHat Linux 7.3. + Let's comment out: + #define FASTCALL __attribute__((stdcall, regparm(3))) + and let's try this: +*/ +#define FASTCALL __attribute__((regparm(3))) +#define PTRFASTCALL __attribute__((regparm(3))) +#endif + +/* Using __fastcall seems to have an unexpected negative effect under + MS VC++, especially for function pointers, so we won't use it for + now on that platform. It may be reconsidered for a future release + if it can be made more effective. + Likely reason: __fastcall on Windows is like stdcall, therefore + the compiler cannot perform stack optimizations for call clusters. +*/ + +/* Make sure all of these are defined if they aren't already. */ + +#ifndef FASTCALL +#define FASTCALL +#endif + +#ifndef PTRCALL +#define PTRCALL +#endif + +#ifndef PTRFASTCALL +#define PTRFASTCALL +#endif + +#ifndef XML_MIN_SIZE +#if !defined(__cplusplus) && !defined(inline) +#ifdef __GNUC__ +#define inline __inline +#endif /* __GNUC__ */ +#endif +#endif /* XML_MIN_SIZE */ + +#ifdef __cplusplus +#define inline inline +#else +#ifndef inline +#define inline +#endif +#endif diff --git a/libxsde/xsde/c/expat/latin1tab.h b/libxsde/xsde/c/expat/latin1tab.h new file mode 100644 index 0000000..53c25d7 --- /dev/null +++ b/libxsde/xsde/c/expat/latin1tab.h @@ -0,0 +1,36 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +/* 0x80 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x84 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x88 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x8C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x90 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x94 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x98 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0x9C */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA4 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xA8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, +/* 0xAC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xB0 */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xB4 */ BT_OTHER, BT_NMSTRT, BT_OTHER, BT_NAME, +/* 0xB8 */ BT_OTHER, BT_OTHER, BT_NMSTRT, BT_OTHER, +/* 0xBC */ BT_OTHER, BT_OTHER, BT_OTHER, BT_OTHER, +/* 0xC0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xC4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xC8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xCC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xD0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xD4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0xD8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xDC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xE8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xEC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xF0 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xF4 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_OTHER, +/* 0xF8 */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, +/* 0xFC */ BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, BT_NMSTRT, diff --git a/libxsde/xsde/c/expat/nametab.h b/libxsde/xsde/c/expat/nametab.h new file mode 100644 index 0000000..b05e62c --- /dev/null +++ b/libxsde/xsde/c/expat/nametab.h @@ -0,0 +1,150 @@ +static const unsigned namingBitmap[] = { +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0x00000000, 0x04000000, 0x87FFFFFE, 0x07FFFFFE, +0x00000000, 0x00000000, 0xFF7FFFFF, 0xFF7FFFFF, +0xFFFFFFFF, 0x7FF3FFFF, 0xFFFFFDFE, 0x7FFFFFFF, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFE00F, 0xFC31FFFF, +0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, +0xFFFFFFFF, 0xF80001FF, 0x00000003, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFD740, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, +0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, +0xFFFF0003, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, +0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, +0x0000007F, 0x00000000, 0xFFFF0000, 0x000707FF, +0x00000000, 0x07FFFFFE, 0x000007FE, 0xFFFE0000, +0xFFFFFFFF, 0x7CFFFFFF, 0x002F7FFF, 0x00000060, +0xFFFFFFE0, 0x23FFFFFF, 0xFF000000, 0x00000003, +0xFFF99FE0, 0x03C5FDFF, 0xB0000000, 0x00030003, +0xFFF987E0, 0x036DFDFF, 0x5E000000, 0x001C0000, +0xFFFBAFE0, 0x23EDFDFF, 0x00000000, 0x00000001, +0xFFF99FE0, 0x23CDFDFF, 0xB0000000, 0x00000003, +0xD63DC7E0, 0x03BFC718, 0x00000000, 0x00000000, +0xFFFDDFE0, 0x03EFFDFF, 0x00000000, 0x00000003, +0xFFFDDFE0, 0x03EFFDFF, 0x40000000, 0x00000003, +0xFFFDDFE0, 0x03FFFDFF, 0x00000000, 0x00000003, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFE, 0x000D7FFF, 0x0000003F, 0x00000000, +0xFEF02596, 0x200D6CAE, 0x0000001F, 0x00000000, +0x00000000, 0x00000000, 0xFFFFFEFF, 0x000003FF, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xFFFFFFFF, 0xFFFF003F, 0x007FFFFF, +0x0007DAED, 0x50000000, 0x82315001, 0x002C62AB, +0x40000000, 0xF580C900, 0x00000007, 0x02010800, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0x0FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x03FFFFFF, +0x3F3FFFFF, 0xFFFFFFFF, 0xAAFF3F3F, 0x3FFFFFFF, +0xFFFFFFFF, 0x5FDFFFFF, 0x0FCF1FDC, 0x1FDC1FFF, +0x00000000, 0x00004C40, 0x00000000, 0x00000000, +0x00000007, 0x00000000, 0x00000000, 0x00000000, +0x00000080, 0x000003FE, 0xFFFFFFFE, 0xFFFFFFFF, +0x001FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x07FFFFFF, +0xFFFFFFE0, 0x00001FFF, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0x0000003F, 0x00000000, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, +0xFFFFFFFF, 0x0000000F, 0x00000000, 0x00000000, +0x00000000, 0x07FF6000, 0x87FFFFFE, 0x07FFFFFE, +0x00000000, 0x00800000, 0xFF7FFFFF, 0xFF7FFFFF, +0x00FFFFFF, 0x00000000, 0xFFFF0000, 0xFFFFFFFF, +0xFFFFFFFF, 0xF80001FF, 0x00030003, 0x00000000, +0xFFFFFFFF, 0xFFFFFFFF, 0x0000003F, 0x00000003, +0xFFFFD7C0, 0xFFFFFFFB, 0x547F7FFF, 0x000FFFFD, +0xFFFFDFFE, 0xFFFFFFFF, 0xDFFEFFFF, 0xFFFFFFFF, +0xFFFF007B, 0xFFFFFFFF, 0xFFFF199F, 0x033FCFFF, +0x00000000, 0xFFFE0000, 0x027FFFFF, 0xFFFFFFFE, +0xFFFE007F, 0xBBFFFFFB, 0xFFFF0016, 0x000707FF, +0x00000000, 0x07FFFFFE, 0x0007FFFF, 0xFFFF03FF, +0xFFFFFFFF, 0x7CFFFFFF, 0xFFEF7FFF, 0x03FF3DFF, +0xFFFFFFEE, 0xF3FFFFFF, 0xFF1E3FFF, 0x0000FFCF, +0xFFF99FEE, 0xD3C5FDFF, 0xB080399F, 0x0003FFCF, +0xFFF987E4, 0xD36DFDFF, 0x5E003987, 0x001FFFC0, +0xFFFBAFEE, 0xF3EDFDFF, 0x00003BBF, 0x0000FFC1, +0xFFF99FEE, 0xF3CDFDFF, 0xB0C0398F, 0x0000FFC3, +0xD63DC7EC, 0xC3BFC718, 0x00803DC7, 0x0000FF80, +0xFFFDDFEE, 0xC3EFFDFF, 0x00603DDF, 0x0000FFC3, +0xFFFDDFEC, 0xC3EFFDFF, 0x40603DDF, 0x0000FFC3, +0xFFFDDFEC, 0xC3FFFDFF, 0x00803DCF, 0x0000FFC3, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xFFFFFFFE, 0x07FF7FFF, 0x03FF7FFF, 0x00000000, +0xFEF02596, 0x3BFF6CAE, 0x03FF3F5F, 0x00000000, +0x03000000, 0xC2A003FF, 0xFFFFFEFF, 0xFFFE03FF, +0xFEBF0FDF, 0x02FE3FFF, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x1FFF0000, 0x00000002, +0x000000A0, 0x003EFFFE, 0xFFFFFFFE, 0xFFFFFFFF, +0x661FFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0x77FFFFFF, +}; +static const unsigned char nmstrtPages[] = { +0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x00, +0x00, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, +0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, +0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x15, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static const unsigned char namePages[] = { +0x19, 0x03, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x00, +0x00, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, +0x10, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x13, +0x26, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x27, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x17, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, +0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x18, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; diff --git a/libxsde/xsde/c/expat/utf8tab.h b/libxsde/xsde/c/expat/utf8tab.h new file mode 100644 index 0000000..7bb3e77 --- /dev/null +++ b/libxsde/xsde/c/expat/utf8tab.h @@ -0,0 +1,37 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + + +/* 0x80 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x84 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x88 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x8C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x90 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x94 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x98 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0x9C */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xA8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xAC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB0 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB4 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xB8 */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xBC */ BT_TRAIL, BT_TRAIL, BT_TRAIL, BT_TRAIL, +/* 0xC0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xC4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xC8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xCC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD0 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD4 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xD8 */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xDC */ BT_LEAD2, BT_LEAD2, BT_LEAD2, BT_LEAD2, +/* 0xE0 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xE4 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xE8 */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xEC */ BT_LEAD3, BT_LEAD3, BT_LEAD3, BT_LEAD3, +/* 0xF0 */ BT_LEAD4, BT_LEAD4, BT_LEAD4, BT_LEAD4, +/* 0xF4 */ BT_LEAD4, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0xF8 */ BT_NONXML, BT_NONXML, BT_NONXML, BT_NONXML, +/* 0xFC */ BT_NONXML, BT_NONXML, BT_MALFORM, BT_MALFORM, diff --git a/libxsde/xsde/c/expat/xmlparse.c b/libxsde/xsde/c/expat/xmlparse.c new file mode 100644 index 0000000..6eac810 --- /dev/null +++ b/libxsde/xsde/c/expat/xmlparse.c @@ -0,0 +1,6260 @@ +/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include <stddef.h> +#include <string.h> /* memset(), memcpy() */ +#include <assert.h> + +#define XML_BUILDING_EXPAT 1 + +#include "config.h" + +#include "expat.h" + +#ifdef XML_UNICODE +#define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX +#define XmlConvert XmlUtf16Convert +#define XmlGetInternalEncoding XmlGetUtf16InternalEncoding +#define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS +#define XmlEncode XmlUtf16Encode +#define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1)) +typedef unsigned short ICHAR; +#else +#define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX +#define XmlConvert XmlUtf8Convert +#define XmlGetInternalEncoding XmlGetUtf8InternalEncoding +#define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS +#define XmlEncode XmlUtf8Encode +#define MUST_CONVERT(enc, s) (!(enc)->isUtf8) +typedef char ICHAR; +#endif + + +#ifndef XML_NS + +#define XmlInitEncodingNS XmlInitEncoding +#define XmlInitUnknownEncodingNS XmlInitUnknownEncoding +#undef XmlGetInternalEncodingNS +#define XmlGetInternalEncodingNS XmlGetInternalEncoding +#define XmlParseXmlDeclNS XmlParseXmlDecl + +#endif + +#ifdef XML_UNICODE + +#ifdef XML_UNICODE_WCHAR_T +#define XML_T(x) (const wchar_t)x +#define XML_L(x) L ## x +#else +#define XML_T(x) (const unsigned short)x +#define XML_L(x) x +#endif + +#else + +#define XML_T(x) x +#define XML_L(x) x + +#endif + +/* Round up n to be a multiple of sz, where sz is a power of 2. */ +#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) + +/* Handle the case where memmove() doesn't exist. */ +#ifndef HAVE_MEMMOVE +#ifdef HAVE_BCOPY +#define memmove(d,s,l) bcopy((s),(d),(l)) +#else +#error memmove does not exist on this platform, nor is a substitute available +#endif /* HAVE_BCOPY */ +#endif /* HAVE_MEMMOVE */ + +#include "internal.h" +#include "xmltok.h" +#include "xmlrole.h" + +typedef const XML_Char *KEY; + +typedef struct { + KEY name; +} NAMED; + +typedef struct { + NAMED **v; + unsigned char power; + size_t size; + size_t used; + const XML_Memory_Handling_Suite *mem; +} HASH_TABLE; + +/* Basic character hash algorithm, taken from Python's string hash: + h = h * 1000003 ^ character, the constant being a prime number. + +*/ +#ifdef XML_UNICODE +#define CHAR_HASH(h, c) \ + (((h) * 0xF4243) ^ (unsigned short)(c)) +#else +#define CHAR_HASH(h, c) \ + (((h) * 0xF4243) ^ (unsigned char)(c)) +#endif + +/* For probing (after a collision) we need a step size relative prime + to the hash table size, which is a power of 2. We use double-hashing, + since we can calculate a second hash value cheaply by taking those bits + of the first hash value that were discarded (masked out) when the table + index was calculated: index = hash & mask, where mask = table->size - 1. + We limit the maximum step size to table->size / 4 (mask >> 2) and make + it odd, since odd numbers are always relative prime to a power of 2. +*/ +#define SECOND_HASH(hash, mask, power) \ + ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) +#define PROBE_STEP(hash, mask, power) \ + ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) + +typedef struct { + NAMED **p; + NAMED **end; +} HASH_TABLE_ITER; + +#define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ +#define INIT_DATA_BUF_SIZE 1024 +#define INIT_ATTS_SIZE 16 +#define INIT_ATTS_VERSION 0xFFFFFFFF +#define INIT_BLOCK_SIZE 1024 +#define INIT_BUFFER_SIZE 1024 + +#define EXPAND_SPARE 24 + +typedef struct binding { + struct prefix *prefix; + struct binding *nextTagBinding; + struct binding *prevPrefixBinding; + const struct attribute_id *attId; + XML_Char *uri; + int uriLen; + int uriAlloc; +} BINDING; + +typedef struct prefix { + const XML_Char *name; + BINDING *binding; +} PREFIX; + +typedef struct { + const XML_Char *str; + const XML_Char *localPart; + const XML_Char *prefix; + int strLen; + int uriLen; + int prefixLen; +} TAG_NAME; + +/* TAG represents an open element. + The name of the element is stored in both the document and API + encodings. The memory buffer 'buf' is a separately-allocated + memory area which stores the name. During the XML_Parse()/ + XMLParseBuffer() when the element is open, the memory for the 'raw' + version of the name (in the document encoding) is shared with the + document buffer. If the element is open across calls to + XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to + contain the 'raw' name as well. + + A parser re-uses these structures, maintaining a list of allocated + TAG objects in a free list. +*/ +typedef struct tag { + struct tag *parent; /* parent of this element */ + const char *rawName; /* tagName in the original encoding */ + int rawNameLength; + TAG_NAME name; /* tagName in the API encoding */ + char *buf; /* buffer for name components */ + char *bufEnd; /* end of the buffer */ + BINDING *bindings; +} TAG; + +typedef struct { + const XML_Char *name; + const XML_Char *textPtr; + int textLen; /* length in XML_Chars */ + int processed; /* # of processed bytes - when suspended */ + const XML_Char *systemId; + const XML_Char *base; + const XML_Char *publicId; + const XML_Char *notation; + XML_Bool open; + XML_Bool is_param; + XML_Bool is_internal; /* true if declared in internal subset outside PE */ +} ENTITY; + +typedef struct { + enum XML_Content_Type type; + enum XML_Content_Quant quant; + const XML_Char * name; + int firstchild; + int lastchild; + int childcnt; + int nextsib; +} CONTENT_SCAFFOLD; + +#define INIT_SCAFFOLD_ELEMENTS 32 + +typedef struct block { + struct block *next; + int size; + XML_Char s[1]; +} BLOCK; + +typedef struct { + BLOCK *blocks; + BLOCK *freeBlocks; + const XML_Char *end; + XML_Char *ptr; + XML_Char *start; + const XML_Memory_Handling_Suite *mem; +} STRING_POOL; + +/* The XML_Char before the name is used to determine whether + an attribute has been specified. */ +typedef struct attribute_id { + XML_Char *name; + PREFIX *prefix; + XML_Bool maybeTokenized; + XML_Bool xmlns; +} ATTRIBUTE_ID; + +typedef struct { + const ATTRIBUTE_ID *id; + XML_Bool isCdata; + const XML_Char *value; +} DEFAULT_ATTRIBUTE; + +typedef struct { + unsigned long version; + unsigned long hash; + const XML_Char *uriName; +} NS_ATT; + +typedef struct { + const XML_Char *name; + PREFIX *prefix; + const ATTRIBUTE_ID *idAtt; + int nDefaultAtts; + int allocDefaultAtts; + DEFAULT_ATTRIBUTE *defaultAtts; +} ELEMENT_TYPE; + +typedef struct { + HASH_TABLE generalEntities; + HASH_TABLE elementTypes; + HASH_TABLE attributeIds; + HASH_TABLE prefixes; + STRING_POOL pool; + STRING_POOL entityValuePool; + /* false once a parameter entity reference has been skipped */ + XML_Bool keepProcessing; + /* true once an internal or external PE reference has been encountered; + this includes the reference to an external subset */ + XML_Bool hasParamEntityRefs; + XML_Bool standalone; +#ifdef XML_DTD + /* indicates if external PE has been read */ + XML_Bool paramEntityRead; + HASH_TABLE paramEntities; +#endif /* XML_DTD */ + PREFIX defaultPrefix; + /* === scaffolding for building content model === */ + XML_Bool in_eldecl; + CONTENT_SCAFFOLD *scaffold; + unsigned contentStringLen; + unsigned scaffSize; + unsigned scaffCount; + int scaffLevel; + int *scaffIndex; +} DTD; + +typedef struct open_internal_entity { + const char *internalEventPtr; + const char *internalEventEndPtr; + struct open_internal_entity *next; + ENTITY *entity; + int startTagLevel; + XML_Bool betweenDecl; /* WFC: PE Between Declarations */ +} OPEN_INTERNAL_ENTITY; + +typedef enum XML_Error PTRCALL Processor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr); + +static Processor prologProcessor; +static Processor prologInitProcessor; +static Processor contentProcessor; +static Processor cdataSectionProcessor; +#ifdef XML_DTD +static Processor ignoreSectionProcessor; +static Processor externalParEntProcessor; +static Processor externalParEntInitProcessor; +static Processor entityValueProcessor; +static Processor entityValueInitProcessor; +#endif /* XML_DTD */ +static Processor epilogProcessor; +static Processor errorProcessor; +static Processor externalEntityInitProcessor; +static Processor externalEntityInitProcessor2; +static Processor externalEntityInitProcessor3; +static Processor externalEntityContentProcessor; +static Processor internalEntityProcessor; + +static enum XML_Error +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName); +static enum XML_Error +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next); +static enum XML_Error +initializeEncoding(XML_Parser parser); +static enum XML_Error +doProlog(XML_Parser parser, const ENCODING *enc, const char *s, + const char *end, int tok, const char *next, const char **nextPtr, + XML_Bool haveMore); +static enum XML_Error +processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl); +static enum XML_Error +doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, + const char *start, const char *end, const char **endPtr, + XML_Bool haveMore); +static enum XML_Error +doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore); +#ifdef XML_DTD +static enum XML_Error +doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, + const char *end, const char **nextPtr, XML_Bool haveMore); +#endif /* XML_DTD */ + +static enum XML_Error +storeAtts(XML_Parser parser, const ENCODING *, const char *s, + TAG_NAME *tagNamePtr, BINDING **bindingsPtr); +static enum XML_Error +addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, + const XML_Char *uri, BINDING **bindingsPtr); +static int +defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, + XML_Bool isId, const XML_Char *dfltValue, XML_Parser parser); +static enum XML_Error +storeAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, + const char *, const char *, STRING_POOL *); +static enum XML_Error +appendAttributeValue(XML_Parser parser, const ENCODING *, XML_Bool isCdata, + const char *, const char *, STRING_POOL *); +static ATTRIBUTE_ID * +getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static int +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); +static enum XML_Error +storeEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static int +reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end); +static int +reportComment(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); +static void +reportDefault(XML_Parser parser, const ENCODING *enc, const char *start, + const char *end); + +static const XML_Char * getContext(XML_Parser parser); +static XML_Bool +setContext(XML_Parser parser, const XML_Char *context); + +static void FASTCALL normalizePublicId(XML_Char *s); + +static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms); +/* do not call if parentParser != NULL */ +static void dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms); +static void +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); +static int +dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); +static int +copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *); + +static NAMED * +lookup(HASH_TABLE *table, KEY name, size_t createSize); +static void FASTCALL +hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL hashTableClear(HASH_TABLE *); +static void FASTCALL hashTableDestroy(HASH_TABLE *); +static void FASTCALL +hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); +static NAMED * FASTCALL hashTableIterNext(HASH_TABLE_ITER *); + +static void FASTCALL +poolInit(STRING_POOL *, const XML_Memory_Handling_Suite *ms); +static void FASTCALL poolClear(STRING_POOL *); +static void FASTCALL poolDestroy(STRING_POOL *); +static XML_Char * +poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Char * +poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end); +static XML_Bool FASTCALL poolGrow(STRING_POOL *pool); +static const XML_Char * FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s); +static const XML_Char * +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n); +static const XML_Char * FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s); + +static int FASTCALL nextScaffoldPart(XML_Parser parser); +static XML_Content * build_model(XML_Parser parser); +static ELEMENT_TYPE * +getElementType(XML_Parser parser, const ENCODING *enc, + const char *ptr, const char *end); + +static XML_Parser +parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, + DTD *dtd); +static void +parserInit(XML_Parser parser, const XML_Char *encodingName); + +#define poolStart(pool) ((pool)->start) +#define poolEnd(pool) ((pool)->ptr) +#define poolLength(pool) ((pool)->ptr - (pool)->start) +#define poolChop(pool) ((void)--(pool->ptr)) +#define poolLastChar(pool) (((pool)->ptr)[-1]) +#define poolDiscard(pool) ((pool)->ptr = (pool)->start) +#define poolFinish(pool) ((pool)->start = (pool)->ptr) +#define poolAppendChar(pool, c) \ + (((pool)->ptr == (pool)->end && !poolGrow(pool)) \ + ? 0 \ + : ((*((pool)->ptr)++ = c), 1)) + +struct XML_ParserStruct { + /* The first member must be userData so that the XML_GetUserData + macro works. */ + void *m_userData; + void *m_handlerArg; + char *m_buffer; + const XML_Memory_Handling_Suite m_mem; + /* first character to be parsed */ + const char *m_bufferPtr; + /* past last character to be parsed */ + char *m_bufferEnd; + /* allocated end of buffer */ + const char *m_bufferLim; + XML_Index m_parseEndByteIndex; + const char *m_parseEndPtr; + XML_Char *m_dataBuf; + XML_Char *m_dataBufEnd; + XML_StartElementHandler m_startElementHandler; + XML_EndElementHandler m_endElementHandler; + XML_CharacterDataHandler m_characterDataHandler; + XML_ProcessingInstructionHandler m_processingInstructionHandler; + XML_CommentHandler m_commentHandler; + XML_StartCdataSectionHandler m_startCdataSectionHandler; + XML_EndCdataSectionHandler m_endCdataSectionHandler; + XML_DefaultHandler m_defaultHandler; + XML_StartDoctypeDeclHandler m_startDoctypeDeclHandler; + XML_EndDoctypeDeclHandler m_endDoctypeDeclHandler; + XML_UnparsedEntityDeclHandler m_unparsedEntityDeclHandler; + XML_NotationDeclHandler m_notationDeclHandler; + XML_StartNamespaceDeclHandler m_startNamespaceDeclHandler; + XML_EndNamespaceDeclHandler m_endNamespaceDeclHandler; + XML_NotStandaloneHandler m_notStandaloneHandler; + XML_ExternalEntityRefHandler m_externalEntityRefHandler; + XML_Parser m_externalEntityRefHandlerArg; + XML_SkippedEntityHandler m_skippedEntityHandler; + XML_UnknownEncodingHandler m_unknownEncodingHandler; + XML_ElementDeclHandler m_elementDeclHandler; + XML_AttlistDeclHandler m_attlistDeclHandler; + XML_EntityDeclHandler m_entityDeclHandler; + XML_XmlDeclHandler m_xmlDeclHandler; + const ENCODING *m_encoding; + INIT_ENCODING m_initEncoding; + const ENCODING *m_internalEncoding; + const XML_Char *m_protocolEncodingName; + XML_Bool m_ns; + XML_Bool m_ns_triplets; + void *m_unknownEncodingMem; + void *m_unknownEncodingData; + void *m_unknownEncodingHandlerData; + void (XMLCALL *m_unknownEncodingRelease)(void *); + PROLOG_STATE m_prologState; + Processor *m_processor; + enum XML_Error m_errorCode; + const char *m_eventPtr; + const char *m_eventEndPtr; + const char *m_positionPtr; + OPEN_INTERNAL_ENTITY *m_openInternalEntities; + OPEN_INTERNAL_ENTITY *m_freeInternalEntities; + XML_Bool m_defaultExpandInternalEntities; + int m_tagLevel; + ENTITY *m_declEntity; + const XML_Char *m_doctypeName; + const XML_Char *m_doctypeSysid; + const XML_Char *m_doctypePubid; + const XML_Char *m_declAttributeType; + const XML_Char *m_declNotationName; + const XML_Char *m_declNotationPublicId; + ELEMENT_TYPE *m_declElementType; + ATTRIBUTE_ID *m_declAttributeId; + XML_Bool m_declAttributeIsCdata; + XML_Bool m_declAttributeIsId; + DTD *m_dtd; + const XML_Char *m_curBase; + TAG *m_tagStack; + TAG *m_freeTagList; + BINDING *m_inheritedBindings; + BINDING *m_freeBindingList; + int m_attsSize; + int m_nSpecifiedAtts; + int m_idAttIndex; + ATTRIBUTE *m_atts; + NS_ATT *m_nsAtts; + unsigned long m_nsAttsVersion; + unsigned char m_nsAttsPower; + POSITION m_position; + STRING_POOL m_tempPool; + STRING_POOL m_temp2Pool; + char *m_groupConnector; + unsigned int m_groupSize; + XML_Char m_namespaceSeparator; + XML_Parser m_parentParser; + XML_ParsingStatus m_parsingStatus; +#ifdef XML_DTD + XML_Bool m_isParamEntity; + XML_Bool m_useForeignDTD; + enum XML_ParamEntityParsing m_paramEntityParsing; +#endif +}; + +#define MALLOC(s) (parser->m_mem.malloc_fcn((s))) +#define REALLOC(p,s) (parser->m_mem.realloc_fcn((p),(s))) +#define FREE(p) (parser->m_mem.free_fcn((p))) + +#define userData (parser->m_userData) +#define handlerArg (parser->m_handlerArg) +#define startElementHandler (parser->m_startElementHandler) +#define endElementHandler (parser->m_endElementHandler) +#define characterDataHandler (parser->m_characterDataHandler) +#define processingInstructionHandler \ + (parser->m_processingInstructionHandler) +#define commentHandler (parser->m_commentHandler) +#define startCdataSectionHandler \ + (parser->m_startCdataSectionHandler) +#define endCdataSectionHandler (parser->m_endCdataSectionHandler) +#define defaultHandler (parser->m_defaultHandler) +#define startDoctypeDeclHandler (parser->m_startDoctypeDeclHandler) +#define endDoctypeDeclHandler (parser->m_endDoctypeDeclHandler) +#define unparsedEntityDeclHandler \ + (parser->m_unparsedEntityDeclHandler) +#define notationDeclHandler (parser->m_notationDeclHandler) +#define startNamespaceDeclHandler \ + (parser->m_startNamespaceDeclHandler) +#define endNamespaceDeclHandler (parser->m_endNamespaceDeclHandler) +#define notStandaloneHandler (parser->m_notStandaloneHandler) +#define externalEntityRefHandler \ + (parser->m_externalEntityRefHandler) +#define externalEntityRefHandlerArg \ + (parser->m_externalEntityRefHandlerArg) +#define internalEntityRefHandler \ + (parser->m_internalEntityRefHandler) +#define skippedEntityHandler (parser->m_skippedEntityHandler) +#define unknownEncodingHandler (parser->m_unknownEncodingHandler) +#define elementDeclHandler (parser->m_elementDeclHandler) +#define attlistDeclHandler (parser->m_attlistDeclHandler) +#define entityDeclHandler (parser->m_entityDeclHandler) +#define xmlDeclHandler (parser->m_xmlDeclHandler) +#define encoding (parser->m_encoding) +#define initEncoding (parser->m_initEncoding) +#define internalEncoding (parser->m_internalEncoding) +#define unknownEncodingMem (parser->m_unknownEncodingMem) +#define unknownEncodingData (parser->m_unknownEncodingData) +#define unknownEncodingHandlerData \ + (parser->m_unknownEncodingHandlerData) +#define unknownEncodingRelease (parser->m_unknownEncodingRelease) +#define protocolEncodingName (parser->m_protocolEncodingName) +#define ns (parser->m_ns) +#define ns_triplets (parser->m_ns_triplets) +#define prologState (parser->m_prologState) +#define processor (parser->m_processor) +#define errorCode (parser->m_errorCode) +#define eventPtr (parser->m_eventPtr) +#define eventEndPtr (parser->m_eventEndPtr) +#define positionPtr (parser->m_positionPtr) +#define position (parser->m_position) +#define openInternalEntities (parser->m_openInternalEntities) +#define freeInternalEntities (parser->m_freeInternalEntities) +#define defaultExpandInternalEntities \ + (parser->m_defaultExpandInternalEntities) +#define tagLevel (parser->m_tagLevel) +#define buffer (parser->m_buffer) +#define bufferPtr (parser->m_bufferPtr) +#define bufferEnd (parser->m_bufferEnd) +#define parseEndByteIndex (parser->m_parseEndByteIndex) +#define parseEndPtr (parser->m_parseEndPtr) +#define bufferLim (parser->m_bufferLim) +#define dataBuf (parser->m_dataBuf) +#define dataBufEnd (parser->m_dataBufEnd) +#define _dtd (parser->m_dtd) +#define curBase (parser->m_curBase) +#define declEntity (parser->m_declEntity) +#define doctypeName (parser->m_doctypeName) +#define doctypeSysid (parser->m_doctypeSysid) +#define doctypePubid (parser->m_doctypePubid) +#define declAttributeType (parser->m_declAttributeType) +#define declNotationName (parser->m_declNotationName) +#define declNotationPublicId (parser->m_declNotationPublicId) +#define declElementType (parser->m_declElementType) +#define declAttributeId (parser->m_declAttributeId) +#define declAttributeIsCdata (parser->m_declAttributeIsCdata) +#define declAttributeIsId (parser->m_declAttributeIsId) +#define freeTagList (parser->m_freeTagList) +#define freeBindingList (parser->m_freeBindingList) +#define inheritedBindings (parser->m_inheritedBindings) +#define tagStack (parser->m_tagStack) +#define atts (parser->m_atts) +#define attsSize (parser->m_attsSize) +#define nSpecifiedAtts (parser->m_nSpecifiedAtts) +#define idAttIndex (parser->m_idAttIndex) +#define nsAtts (parser->m_nsAtts) +#define nsAttsVersion (parser->m_nsAttsVersion) +#define nsAttsPower (parser->m_nsAttsPower) +#define tempPool (parser->m_tempPool) +#define temp2Pool (parser->m_temp2Pool) +#define groupConnector (parser->m_groupConnector) +#define groupSize (parser->m_groupSize) +#define namespaceSeparator (parser->m_namespaceSeparator) +#define parentParser (parser->m_parentParser) +#define ps_parsing (parser->m_parsingStatus.parsing) +#define ps_finalBuffer (parser->m_parsingStatus.finalBuffer) +#ifdef XML_DTD +#define isParamEntity (parser->m_isParamEntity) +#define useForeignDTD (parser->m_useForeignDTD) +#define paramEntityParsing (parser->m_paramEntityParsing) +#endif /* XML_DTD */ + +XML_Parser XMLCALL +XML_ParserCreate(const XML_Char *encodingName) +{ + return XML_ParserCreate_MM(encodingName, NULL, NULL); +} + +XML_Parser XMLCALL +XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) +{ + XML_Char tmp[2]; + *tmp = nsSep; + return XML_ParserCreate_MM(encodingName, NULL, tmp); +} + +static const XML_Char implicitContext[] = { + 'x', 'm', 'l', '=', 'h', 't', 't', 'p', ':', '/', '/', + 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', + 'X', 'M', 'L', '/', '1', '9', '9', '8', '/', + 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0' +}; + +XML_Parser XMLCALL +XML_ParserCreate_MM(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep) +{ + XML_Parser parser = parserCreate(encodingName, memsuite, nameSep, NULL); + if (parser != NULL && ns) { + /* implicit context only set for root parser, since child + parsers (i.e. external entity parsers) will inherit it + */ + if (!setContext(parser, implicitContext)) { + XML_ParserFree(parser); + return NULL; + } + } + return parser; +} + +static XML_Parser +parserCreate(const XML_Char *encodingName, + const XML_Memory_Handling_Suite *memsuite, + const XML_Char *nameSep, + DTD *dtd) +{ + XML_Parser parser; + + if (memsuite) { + XML_Memory_Handling_Suite *mtemp; + parser = (XML_Parser) + memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = memsuite->malloc_fcn; + mtemp->realloc_fcn = memsuite->realloc_fcn; + mtemp->free_fcn = memsuite->free_fcn; + } + } + else { + XML_Memory_Handling_Suite *mtemp; + parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = malloc; + mtemp->realloc_fcn = realloc; + mtemp->free_fcn = free; + } + } + + if (!parser) + return parser; + + buffer = NULL; + bufferLim = NULL; + + attsSize = INIT_ATTS_SIZE; + atts = (ATTRIBUTE *)MALLOC(attsSize * sizeof(ATTRIBUTE)); + if (atts == NULL) { + FREE(parser); + return NULL; + } + dataBuf = (XML_Char *)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); + if (dataBuf == NULL) { + FREE(atts); + FREE(parser); + return NULL; + } + dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE; + + if (dtd) + _dtd = dtd; + else { + _dtd = dtdCreate(&parser->m_mem); + if (_dtd == NULL) { + FREE(dataBuf); + FREE(atts); + FREE(parser); + return NULL; + } + } + + freeBindingList = NULL; + freeTagList = NULL; + freeInternalEntities = NULL; + + groupSize = 0; + groupConnector = NULL; + + unknownEncodingHandler = NULL; + unknownEncodingHandlerData = NULL; + + namespaceSeparator = '!'; + ns = XML_FALSE; + ns_triplets = XML_FALSE; + + nsAtts = NULL; + nsAttsVersion = 0; + nsAttsPower = 0; + + poolInit(&tempPool, &(parser->m_mem)); + poolInit(&temp2Pool, &(parser->m_mem)); + parserInit(parser, encodingName); + + if (encodingName && !protocolEncodingName) { + XML_ParserFree(parser); + return NULL; + } + + if (nameSep) { + ns = XML_TRUE; + internalEncoding = XmlGetInternalEncodingNS(); + namespaceSeparator = *nameSep; + } + else { + internalEncoding = XmlGetInternalEncoding(); + } + + return parser; +} + +static void +parserInit(XML_Parser parser, const XML_Char *encodingName) +{ + processor = prologInitProcessor; + XmlPrologStateInit(&prologState); + protocolEncodingName = (encodingName != NULL + ? poolCopyString(&tempPool, encodingName) + : NULL); + curBase = NULL; + XmlInitEncoding(&initEncoding, &encoding, 0); + userData = NULL; + handlerArg = NULL; + startElementHandler = NULL; + endElementHandler = NULL; + characterDataHandler = NULL; + processingInstructionHandler = NULL; + commentHandler = NULL; + startCdataSectionHandler = NULL; + endCdataSectionHandler = NULL; + defaultHandler = NULL; + startDoctypeDeclHandler = NULL; + endDoctypeDeclHandler = NULL; + unparsedEntityDeclHandler = NULL; + notationDeclHandler = NULL; + startNamespaceDeclHandler = NULL; + endNamespaceDeclHandler = NULL; + notStandaloneHandler = NULL; + externalEntityRefHandler = NULL; + externalEntityRefHandlerArg = parser; + skippedEntityHandler = NULL; + elementDeclHandler = NULL; + attlistDeclHandler = NULL; + entityDeclHandler = NULL; + xmlDeclHandler = NULL; + bufferPtr = buffer; + bufferEnd = buffer; + parseEndByteIndex = 0; + parseEndPtr = NULL; + declElementType = NULL; + declAttributeId = NULL; + declEntity = NULL; + doctypeName = NULL; + doctypeSysid = NULL; + doctypePubid = NULL; + declAttributeType = NULL; + declNotationName = NULL; + declNotationPublicId = NULL; + declAttributeIsCdata = XML_FALSE; + declAttributeIsId = XML_FALSE; + memset(&position, 0, sizeof(POSITION)); + errorCode = XML_ERROR_NONE; + eventPtr = NULL; + eventEndPtr = NULL; + positionPtr = NULL; + openInternalEntities = NULL; + defaultExpandInternalEntities = XML_TRUE; + tagLevel = 0; + tagStack = NULL; + inheritedBindings = NULL; + nSpecifiedAtts = 0; + unknownEncodingMem = NULL; + unknownEncodingRelease = NULL; + unknownEncodingData = NULL; + parentParser = NULL; + ps_parsing = XML_INITIALIZED; +#ifdef XML_DTD + isParamEntity = XML_FALSE; + useForeignDTD = XML_FALSE; + paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; +#endif +} + +/* moves list of bindings to freeBindingList */ +static void FASTCALL +moveToFreeBindingList(XML_Parser parser, BINDING *bindings) +{ + while (bindings) { + BINDING *b = bindings; + bindings = bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + } +} + +XML_Bool XMLCALL +XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) +{ + TAG *tStk; + OPEN_INTERNAL_ENTITY *openEntityList; + if (parentParser) + return XML_FALSE; + /* move tagStack to freeTagList */ + tStk = tagStack; + while (tStk) { + TAG *tag = tStk; + tStk = tStk->parent; + tag->parent = freeTagList; + moveToFreeBindingList(parser, tag->bindings); + tag->bindings = NULL; + freeTagList = tag; + } + /* move openInternalEntities to freeInternalEntities */ + openEntityList = openInternalEntities; + while (openEntityList) { + OPEN_INTERNAL_ENTITY *openEntity = openEntityList; + openEntityList = openEntity->next; + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + moveToFreeBindingList(parser, inheritedBindings); + FREE(unknownEncodingMem); + if (unknownEncodingRelease) + unknownEncodingRelease(unknownEncodingData); + poolClear(&tempPool); + poolClear(&temp2Pool); + parserInit(parser, encodingName); + dtdReset(_dtd, &parser->m_mem); + return setContext(parser, implicitContext); +} + +enum XML_Status XMLCALL +XML_SetEncoding(XML_Parser parser, const XML_Char *encodingName) +{ + /* Block after XML_Parse()/XML_ParseBuffer() has been called. + XXX There's no way for the caller to determine which of the + XXX possible error cases caused the XML_STATUS_ERROR return. + */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return XML_STATUS_ERROR; + if (encodingName == NULL) + protocolEncodingName = NULL; + else { + protocolEncodingName = poolCopyString(&tempPool, encodingName); + if (!protocolEncodingName) + return XML_STATUS_ERROR; + } + return XML_STATUS_OK; +} + +XML_Parser XMLCALL +XML_ExternalEntityParserCreate(XML_Parser oldParser, + const XML_Char *context, + const XML_Char *encodingName) +{ + XML_Parser parser = oldParser; + DTD *newDtd = NULL; + DTD *oldDtd = _dtd; + XML_StartElementHandler oldStartElementHandler = startElementHandler; + XML_EndElementHandler oldEndElementHandler = endElementHandler; + XML_CharacterDataHandler oldCharacterDataHandler = characterDataHandler; + XML_ProcessingInstructionHandler oldProcessingInstructionHandler + = processingInstructionHandler; + XML_CommentHandler oldCommentHandler = commentHandler; + XML_StartCdataSectionHandler oldStartCdataSectionHandler + = startCdataSectionHandler; + XML_EndCdataSectionHandler oldEndCdataSectionHandler + = endCdataSectionHandler; + XML_DefaultHandler oldDefaultHandler = defaultHandler; + XML_UnparsedEntityDeclHandler oldUnparsedEntityDeclHandler + = unparsedEntityDeclHandler; + XML_NotationDeclHandler oldNotationDeclHandler = notationDeclHandler; + XML_StartNamespaceDeclHandler oldStartNamespaceDeclHandler + = startNamespaceDeclHandler; + XML_EndNamespaceDeclHandler oldEndNamespaceDeclHandler + = endNamespaceDeclHandler; + XML_NotStandaloneHandler oldNotStandaloneHandler = notStandaloneHandler; + XML_ExternalEntityRefHandler oldExternalEntityRefHandler + = externalEntityRefHandler; + XML_SkippedEntityHandler oldSkippedEntityHandler = skippedEntityHandler; + XML_UnknownEncodingHandler oldUnknownEncodingHandler + = unknownEncodingHandler; + XML_ElementDeclHandler oldElementDeclHandler = elementDeclHandler; + XML_AttlistDeclHandler oldAttlistDeclHandler = attlistDeclHandler; + XML_EntityDeclHandler oldEntityDeclHandler = entityDeclHandler; + XML_XmlDeclHandler oldXmlDeclHandler = xmlDeclHandler; + ELEMENT_TYPE * oldDeclElementType = declElementType; + + void *oldUserData = userData; + void *oldHandlerArg = handlerArg; + XML_Bool oldDefaultExpandInternalEntities = defaultExpandInternalEntities; + XML_Parser oldExternalEntityRefHandlerArg = externalEntityRefHandlerArg; +#ifdef XML_DTD + enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing; + int oldInEntityValue = prologState.inEntityValue; +#endif + XML_Bool oldns_triplets = ns_triplets; + +#ifdef XML_DTD + if (!context) + newDtd = oldDtd; +#endif /* XML_DTD */ + + /* Note that the magical uses of the pre-processor to make field + access look more like C++ require that `parser' be overwritten + here. This makes this function more painful to follow than it + would be otherwise. + */ + if (ns) { + XML_Char tmp[2]; + *tmp = namespaceSeparator; + parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); + } + else { + parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); + } + + if (!parser) + return NULL; + + startElementHandler = oldStartElementHandler; + endElementHandler = oldEndElementHandler; + characterDataHandler = oldCharacterDataHandler; + processingInstructionHandler = oldProcessingInstructionHandler; + commentHandler = oldCommentHandler; + startCdataSectionHandler = oldStartCdataSectionHandler; + endCdataSectionHandler = oldEndCdataSectionHandler; + defaultHandler = oldDefaultHandler; + unparsedEntityDeclHandler = oldUnparsedEntityDeclHandler; + notationDeclHandler = oldNotationDeclHandler; + startNamespaceDeclHandler = oldStartNamespaceDeclHandler; + endNamespaceDeclHandler = oldEndNamespaceDeclHandler; + notStandaloneHandler = oldNotStandaloneHandler; + externalEntityRefHandler = oldExternalEntityRefHandler; + skippedEntityHandler = oldSkippedEntityHandler; + unknownEncodingHandler = oldUnknownEncodingHandler; + elementDeclHandler = oldElementDeclHandler; + attlistDeclHandler = oldAttlistDeclHandler; + entityDeclHandler = oldEntityDeclHandler; + xmlDeclHandler = oldXmlDeclHandler; + declElementType = oldDeclElementType; + userData = oldUserData; + if (oldUserData == oldHandlerArg) + handlerArg = userData; + else + handlerArg = parser; + if (oldExternalEntityRefHandlerArg != oldParser) + externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg; + defaultExpandInternalEntities = oldDefaultExpandInternalEntities; + ns_triplets = oldns_triplets; + parentParser = oldParser; +#ifdef XML_DTD + paramEntityParsing = oldParamEntityParsing; + prologState.inEntityValue = oldInEntityValue; + if (context) { +#endif /* XML_DTD */ + if (!dtdCopy(_dtd, oldDtd, &parser->m_mem) + || !setContext(parser, context)) { + XML_ParserFree(parser); + return NULL; + } + processor = externalEntityInitProcessor; +#ifdef XML_DTD + } + else { + /* The DTD instance referenced by _dtd is shared between the document's + root parser and external PE parsers, therefore one does not need to + call setContext. In addition, one also *must* not call setContext, + because this would overwrite existing prefix->binding pointers in + _dtd with ones that get destroyed with the external PE parser. + This would leave those prefixes with dangling pointers. + */ + isParamEntity = XML_TRUE; + XmlPrologStateInitExternalEntity(&prologState); + processor = externalParEntInitProcessor; + } +#endif /* XML_DTD */ + return parser; +} + +static void FASTCALL +destroyBindings(BINDING *bindings, XML_Parser parser) +{ + for (;;) { + BINDING *b = bindings; + if (!b) + break; + bindings = b->nextTagBinding; + FREE(b->uri); + FREE(b); + } +} + +void XMLCALL +XML_ParserFree(XML_Parser parser) +{ + TAG *tagList; + OPEN_INTERNAL_ENTITY *entityList; + if (parser == NULL) + return; + /* free tagStack and freeTagList */ + tagList = tagStack; + for (;;) { + TAG *p; + if (tagList == NULL) { + if (freeTagList == NULL) + break; + tagList = freeTagList; + freeTagList = NULL; + } + p = tagList; + tagList = tagList->parent; + FREE(p->buf); + destroyBindings(p->bindings, parser); + FREE(p); + } + /* free openInternalEntities and freeInternalEntities */ + entityList = openInternalEntities; + for (;;) { + OPEN_INTERNAL_ENTITY *openEntity; + if (entityList == NULL) { + if (freeInternalEntities == NULL) + break; + entityList = freeInternalEntities; + freeInternalEntities = NULL; + } + openEntity = entityList; + entityList = entityList->next; + FREE(openEntity); + } + + destroyBindings(freeBindingList, parser); + destroyBindings(inheritedBindings, parser); + poolDestroy(&tempPool); + poolDestroy(&temp2Pool); +#ifdef XML_DTD + /* external parameter entity parsers share the DTD structure + parser->m_dtd with the root parser, so we must not destroy it + */ + if (!isParamEntity && _dtd) +#else + if (_dtd) +#endif /* XML_DTD */ + dtdDestroy(_dtd, (XML_Bool)!parentParser, &parser->m_mem); + FREE((void *)atts); + FREE(groupConnector); + FREE(buffer); + FREE(dataBuf); + FREE(nsAtts); + FREE(unknownEncodingMem); + if (unknownEncodingRelease) + unknownEncodingRelease(unknownEncodingData); + FREE(parser); +} + +void XMLCALL +XML_UseParserAsHandlerArg(XML_Parser parser) +{ + handlerArg = parser; +} + +enum XML_Error XMLCALL +XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD) +{ +#ifdef XML_DTD + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING; + useForeignDTD = useDTD; + return XML_ERROR_NONE; +#else + return XML_ERROR_FEATURE_REQUIRES_XML_DTD; +#endif +} + +void XMLCALL +XML_SetReturnNSTriplet(XML_Parser parser, int do_nst) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return; + ns_triplets = do_nst ? XML_TRUE : XML_FALSE; +} + +void XMLCALL +XML_SetUserData(XML_Parser parser, void *p) +{ + if (handlerArg == userData) + handlerArg = userData = p; + else + userData = p; +} + +enum XML_Status XMLCALL +XML_SetBase(XML_Parser parser, const XML_Char *p) +{ + if (p) { + p = poolCopyString(&_dtd->pool, p); + if (!p) + return XML_STATUS_ERROR; + curBase = p; + } + else + curBase = NULL; + return XML_STATUS_OK; +} + +const XML_Char * XMLCALL +XML_GetBase(XML_Parser parser) +{ + return curBase; +} + +int XMLCALL +XML_GetSpecifiedAttributeCount(XML_Parser parser) +{ + return nSpecifiedAtts; +} + +int XMLCALL +XML_GetIdAttributeIndex(XML_Parser parser) +{ + return idAttIndex; +} + +void XMLCALL +XML_SetElementHandler(XML_Parser parser, + XML_StartElementHandler start, + XML_EndElementHandler end) +{ + startElementHandler = start; + endElementHandler = end; +} + +void XMLCALL +XML_SetStartElementHandler(XML_Parser parser, + XML_StartElementHandler start) { + startElementHandler = start; +} + +void XMLCALL +XML_SetEndElementHandler(XML_Parser parser, + XML_EndElementHandler end) { + endElementHandler = end; +} + +void XMLCALL +XML_SetCharacterDataHandler(XML_Parser parser, + XML_CharacterDataHandler handler) +{ + characterDataHandler = handler; +} + +void XMLCALL +XML_SetProcessingInstructionHandler(XML_Parser parser, + XML_ProcessingInstructionHandler handler) +{ + processingInstructionHandler = handler; +} + +void XMLCALL +XML_SetCommentHandler(XML_Parser parser, + XML_CommentHandler handler) +{ + commentHandler = handler; +} + +void XMLCALL +XML_SetCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start, + XML_EndCdataSectionHandler end) +{ + startCdataSectionHandler = start; + endCdataSectionHandler = end; +} + +void XMLCALL +XML_SetStartCdataSectionHandler(XML_Parser parser, + XML_StartCdataSectionHandler start) { + startCdataSectionHandler = start; +} + +void XMLCALL +XML_SetEndCdataSectionHandler(XML_Parser parser, + XML_EndCdataSectionHandler end) { + endCdataSectionHandler = end; +} + +void XMLCALL +XML_SetDefaultHandler(XML_Parser parser, + XML_DefaultHandler handler) +{ + defaultHandler = handler; + defaultExpandInternalEntities = XML_FALSE; +} + +void XMLCALL +XML_SetDefaultHandlerExpand(XML_Parser parser, + XML_DefaultHandler handler) +{ + defaultHandler = handler; + defaultExpandInternalEntities = XML_TRUE; +} + +void XMLCALL +XML_SetDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start, + XML_EndDoctypeDeclHandler end) +{ + startDoctypeDeclHandler = start; + endDoctypeDeclHandler = end; +} + +void XMLCALL +XML_SetStartDoctypeDeclHandler(XML_Parser parser, + XML_StartDoctypeDeclHandler start) { + startDoctypeDeclHandler = start; +} + +void XMLCALL +XML_SetEndDoctypeDeclHandler(XML_Parser parser, + XML_EndDoctypeDeclHandler end) { + endDoctypeDeclHandler = end; +} + +void XMLCALL +XML_SetUnparsedEntityDeclHandler(XML_Parser parser, + XML_UnparsedEntityDeclHandler handler) +{ + unparsedEntityDeclHandler = handler; +} + +void XMLCALL +XML_SetNotationDeclHandler(XML_Parser parser, + XML_NotationDeclHandler handler) +{ + notationDeclHandler = handler; +} + +void XMLCALL +XML_SetNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start, + XML_EndNamespaceDeclHandler end) +{ + startNamespaceDeclHandler = start; + endNamespaceDeclHandler = end; +} + +void XMLCALL +XML_SetStartNamespaceDeclHandler(XML_Parser parser, + XML_StartNamespaceDeclHandler start) { + startNamespaceDeclHandler = start; +} + +void XMLCALL +XML_SetEndNamespaceDeclHandler(XML_Parser parser, + XML_EndNamespaceDeclHandler end) { + endNamespaceDeclHandler = end; +} + +void XMLCALL +XML_SetNotStandaloneHandler(XML_Parser parser, + XML_NotStandaloneHandler handler) +{ + notStandaloneHandler = handler; +} + +void XMLCALL +XML_SetExternalEntityRefHandler(XML_Parser parser, + XML_ExternalEntityRefHandler handler) +{ + externalEntityRefHandler = handler; +} + +void XMLCALL +XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg) +{ + if (arg) + externalEntityRefHandlerArg = (XML_Parser)arg; + else + externalEntityRefHandlerArg = parser; +} + +void XMLCALL +XML_SetSkippedEntityHandler(XML_Parser parser, + XML_SkippedEntityHandler handler) +{ + skippedEntityHandler = handler; +} + +void XMLCALL +XML_SetUnknownEncodingHandler(XML_Parser parser, + XML_UnknownEncodingHandler handler, + void *data) +{ + unknownEncodingHandler = handler; + unknownEncodingHandlerData = data; +} + +void XMLCALL +XML_SetElementDeclHandler(XML_Parser parser, + XML_ElementDeclHandler eldecl) +{ + elementDeclHandler = eldecl; +} + +void XMLCALL +XML_SetAttlistDeclHandler(XML_Parser parser, + XML_AttlistDeclHandler attdecl) +{ + attlistDeclHandler = attdecl; +} + +void XMLCALL +XML_SetEntityDeclHandler(XML_Parser parser, + XML_EntityDeclHandler handler) +{ + entityDeclHandler = handler; +} + +void XMLCALL +XML_SetXmlDeclHandler(XML_Parser parser, + XML_XmlDeclHandler handler) { + xmlDeclHandler = handler; +} + +int XMLCALL +XML_SetParamEntityParsing(XML_Parser parser, + enum XML_ParamEntityParsing peParsing) +{ + /* block after XML_Parse()/XML_ParseBuffer() has been called */ + if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED) + return 0; +#ifdef XML_DTD + paramEntityParsing = peParsing; + return 1; +#else + return peParsing == XML_PARAM_ENTITY_PARSING_NEVER; +#endif +} + +enum XML_Status XMLCALL +XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + ps_parsing = XML_PARSING; + } + + if (len == 0) { + ps_finalBuffer = (XML_Bool)isFinal; + if (!isFinal) + return XML_STATUS_OK; + positionPtr = bufferPtr; + parseEndPtr = bufferEnd; + + /* If data are left over from last buffer, and we now know that these + data are the final chunk of input, then we have to check them again + to detect errors based on that fact. + */ + errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); + + if (errorCode == XML_ERROR_NONE) { + switch (ps_parsing) { + case XML_SUSPENDED: + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return XML_STATUS_SUSPENDED; + case XML_INITIALIZED: + case XML_PARSING: + ps_parsing = XML_FINISHED; + /* fall through */ + default: + return XML_STATUS_OK; + } + } + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } +#ifndef XML_CONTEXT_BYTES + else if (bufferPtr == bufferEnd) { + const char *end; + int nLeftOver; + enum XML_Error result; + parseEndByteIndex += len; + positionPtr = s; + ps_finalBuffer = (XML_Bool)isFinal; + + errorCode = processor(parser, s, parseEndPtr = s + len, &end); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + result = XML_STATUS_OK; + if (isFinal) { + ps_parsing = XML_FINISHED; + return result; + } + } + } + + XmlUpdatePosition(encoding, positionPtr, end, &position); + nLeftOver = s + len - end; + if (nLeftOver) { + if (buffer == NULL || nLeftOver > bufferLim - buffer) { + /* FIXME avoid integer overflow */ + char *temp; + temp = (buffer == NULL + ? (char *)MALLOC(len * 2) + : (char *)REALLOC(buffer, len * 2)); + if (temp == NULL) { + errorCode = XML_ERROR_NO_MEMORY; + return XML_STATUS_ERROR; + } + buffer = temp; + if (!buffer) { + errorCode = XML_ERROR_NO_MEMORY; + eventPtr = eventEndPtr = NULL; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + bufferLim = buffer + len * 2; + } + memcpy(buffer, end, nLeftOver); + } + bufferPtr = buffer; + bufferEnd = buffer + nLeftOver; + positionPtr = bufferPtr; + parseEndPtr = bufferEnd; + eventPtr = bufferPtr; + eventEndPtr = bufferPtr; + return result; + } +#endif /* not defined XML_CONTEXT_BYTES */ + else { + void *buff = XML_GetBuffer(parser, len); + if (buff == NULL) + return XML_STATUS_ERROR; + else { + memcpy(buff, s, len); + return XML_ParseBuffer(parser, len, isFinal); + } + } +} + +enum XML_Status XMLCALL +XML_ParseBuffer(XML_Parser parser, int len, int isFinal) +{ + const char *start; + enum XML_Status result = XML_STATUS_OK; + + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + ps_parsing = XML_PARSING; + } + + start = bufferPtr; + positionPtr = start; + bufferEnd += len; + parseEndPtr = bufferEnd; + parseEndByteIndex += len; + ps_finalBuffer = (XML_Bool)isFinal; + + errorCode = processor(parser, start, parseEndPtr, &bufferPtr); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (isFinal) { + ps_parsing = XML_FINISHED; + return result; + } + default: ; /* should not happen */ + } + } + + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return result; +} + +void * XMLCALL +XML_GetBuffer(XML_Parser parser, int len) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + errorCode = XML_ERROR_SUSPENDED; + return NULL; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return NULL; + default: ; + } + + if (len > bufferLim - bufferEnd) { + /* FIXME avoid integer overflow */ + int neededSize = len + (int)(bufferEnd - bufferPtr); +#ifdef XML_CONTEXT_BYTES + int keep = (int)(bufferPtr - buffer); + + if (keep > XML_CONTEXT_BYTES) + keep = XML_CONTEXT_BYTES; + neededSize += keep; +#endif /* defined XML_CONTEXT_BYTES */ + if (neededSize <= bufferLim - buffer) { +#ifdef XML_CONTEXT_BYTES + if (keep < bufferPtr - buffer) { + int offset = (int)(bufferPtr - buffer) - keep; + memmove(buffer, &buffer[offset], bufferEnd - bufferPtr + keep); + bufferEnd -= offset; + bufferPtr -= offset; + } +#else + memmove(buffer, bufferPtr, bufferEnd - bufferPtr); + bufferEnd = buffer + (bufferEnd - bufferPtr); + bufferPtr = buffer; +#endif /* not defined XML_CONTEXT_BYTES */ + } + else { + char *newBuf; + int bufferSize = (int)(bufferLim - bufferPtr); + if (bufferSize == 0) + bufferSize = INIT_BUFFER_SIZE; + do { + bufferSize *= 2; + } while (bufferSize < neededSize); + newBuf = (char *)MALLOC(bufferSize); + if (newBuf == 0) { + errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } + bufferLim = newBuf + bufferSize; +#ifdef XML_CONTEXT_BYTES + if (bufferPtr) { + int keep = (int)(bufferPtr - buffer); + if (keep > XML_CONTEXT_BYTES) + keep = XML_CONTEXT_BYTES; + memcpy(newBuf, &bufferPtr[-keep], bufferEnd - bufferPtr + keep); + FREE(buffer); + buffer = newBuf; + bufferEnd = buffer + (bufferEnd - bufferPtr) + keep; + bufferPtr = buffer + keep; + } + else { + bufferEnd = newBuf + (bufferEnd - bufferPtr); + bufferPtr = buffer = newBuf; + } +#else + if (bufferPtr) { + memcpy(newBuf, bufferPtr, bufferEnd - bufferPtr); + FREE(buffer); + } + bufferEnd = newBuf + (bufferEnd - bufferPtr); + bufferPtr = buffer = newBuf; +#endif /* not defined XML_CONTEXT_BYTES */ + } + } + return bufferEnd; +} + +enum XML_Status XMLCALL +XML_StopParser(XML_Parser parser, XML_Bool resumable) +{ + switch (ps_parsing) { + case XML_SUSPENDED: + if (resumable) { + errorCode = XML_ERROR_SUSPENDED; + return XML_STATUS_ERROR; + } + ps_parsing = XML_FINISHED; + break; + case XML_FINISHED: + errorCode = XML_ERROR_FINISHED; + return XML_STATUS_ERROR; + default: + if (resumable) { +#ifdef XML_DTD + if (isParamEntity) { + errorCode = XML_ERROR_SUSPEND_PE; + return XML_STATUS_ERROR; + } +#endif + ps_parsing = XML_SUSPENDED; + } + else + ps_parsing = XML_FINISHED; + } + return XML_STATUS_OK; +} + +enum XML_Status XMLCALL +XML_ResumeParser(XML_Parser parser) +{ + enum XML_Status result = XML_STATUS_OK; + + if (ps_parsing != XML_SUSPENDED) { + errorCode = XML_ERROR_NOT_SUSPENDED; + return XML_STATUS_ERROR; + } + ps_parsing = XML_PARSING; + + errorCode = processor(parser, bufferPtr, parseEndPtr, &bufferPtr); + + if (errorCode != XML_ERROR_NONE) { + eventEndPtr = eventPtr; + processor = errorProcessor; + return XML_STATUS_ERROR; + } + else { + switch (ps_parsing) { + case XML_SUSPENDED: + result = XML_STATUS_SUSPENDED; + break; + case XML_INITIALIZED: + case XML_PARSING: + if (ps_finalBuffer) { + ps_parsing = XML_FINISHED; + return result; + } + default: ; + } + } + + XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position); + positionPtr = bufferPtr; + return result; +} + +void XMLCALL +XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status) +{ + assert(status != NULL); + *status = parser->m_parsingStatus; +} + +enum XML_Error XMLCALL +XML_GetErrorCode(XML_Parser parser) +{ + return errorCode; +} + +XML_Index XMLCALL +XML_GetCurrentByteIndex(XML_Parser parser) +{ + if (eventPtr) + return parseEndByteIndex - (parseEndPtr - eventPtr); + return -1; +} + +int XMLCALL +XML_GetCurrentByteCount(XML_Parser parser) +{ + if (eventEndPtr && eventPtr) + return (int)(eventEndPtr - eventPtr); + return 0; +} + +const char * XMLCALL +XML_GetInputContext(XML_Parser parser, int *offset, int *size) +{ +#ifdef XML_CONTEXT_BYTES + if (eventPtr && buffer) { + *offset = (int)(eventPtr - buffer); + *size = (int)(bufferEnd - buffer); + return buffer; + } +#endif /* defined XML_CONTEXT_BYTES */ + return (char *) 0; +} + +XML_Size XMLCALL +XML_GetCurrentLineNumber(XML_Parser parser) +{ + if (eventPtr && eventPtr >= positionPtr) { + XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); + positionPtr = eventPtr; + } + return position.lineNumber + 1; +} + +XML_Size XMLCALL +XML_GetCurrentColumnNumber(XML_Parser parser) +{ + if (eventPtr && eventPtr >= positionPtr) { + XmlUpdatePosition(encoding, positionPtr, eventPtr, &position); + positionPtr = eventPtr; + } + return position.columnNumber; +} + +void XMLCALL +XML_FreeContentModel(XML_Parser parser, XML_Content *model) +{ + FREE(model); +} + +void * XMLCALL +XML_MemMalloc(XML_Parser parser, size_t size) +{ + return MALLOC(size); +} + +void * XMLCALL +XML_MemRealloc(XML_Parser parser, void *ptr, size_t size) +{ + return REALLOC(ptr, size); +} + +void XMLCALL +XML_MemFree(XML_Parser parser, void *ptr) +{ + FREE(ptr); +} + +void XMLCALL +XML_DefaultCurrent(XML_Parser parser) +{ + if (defaultHandler) { + if (openInternalEntities) + reportDefault(parser, + internalEncoding, + openInternalEntities->internalEventPtr, + openInternalEntities->internalEventEndPtr); + else + reportDefault(parser, encoding, eventPtr, eventEndPtr); + } +} + +const XML_LChar * XMLCALL +XML_ErrorString(enum XML_Error code) +{ + static const XML_LChar* const message[] = { + 0, + XML_L("out of memory"), + XML_L("syntax error"), + XML_L("no element found"), + XML_L("not well-formed (invalid token)"), + XML_L("unclosed token"), + XML_L("partial character"), + XML_L("mismatched tag"), + XML_L("duplicate attribute"), + XML_L("junk after document element"), + XML_L("illegal parameter entity reference"), + XML_L("undefined entity"), + XML_L("recursive entity reference"), + XML_L("asynchronous entity"), + XML_L("reference to invalid character number"), + XML_L("reference to binary entity"), + XML_L("reference to external entity in attribute"), + XML_L("XML or text declaration not at start of entity"), + XML_L("unknown encoding"), + XML_L("encoding specified in XML declaration is incorrect"), + XML_L("unclosed CDATA section"), + XML_L("error in processing external entity reference"), + XML_L("document is not standalone"), + XML_L("unexpected parser state - please send a bug report"), + XML_L("entity declared in parameter entity"), + XML_L("requested feature requires XML_DTD support in Expat"), + XML_L("cannot change setting once parsing has begun"), + XML_L("unbound prefix"), + XML_L("must not undeclare prefix"), + XML_L("incomplete markup in parameter entity"), + XML_L("XML declaration not well-formed"), + XML_L("text declaration not well-formed"), + XML_L("illegal character(s) in public id"), + XML_L("parser suspended"), + XML_L("parser not suspended"), + XML_L("parsing aborted"), + XML_L("parsing finished"), + XML_L("cannot suspend in external parameter entity"), + XML_L("reserved prefix (xml) must not be undeclared or bound to another namespace name"), + XML_L("reserved prefix (xmlns) must not be declared or undeclared"), + XML_L("prefix must not be bound to one of the reserved namespace names") + }; + if (code > 0 && code < sizeof(message)/sizeof(message[0])) + return message[code]; + return NULL; +} + +const XML_LChar * XMLCALL +XML_ExpatVersion(void) { + + /* V1 is used to string-ize the version number. However, it would + string-ize the actual version macro *names* unless we get them + substituted before being passed to V1. CPP is defined to expand + a macro, then rescan for more expansions. Thus, we use V2 to expand + the version macros, then CPP will expand the resulting V1() macro + with the correct numerals. */ + /* ### I'm assuming cpp is portable in this respect... */ + +#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c) +#define V2(a,b,c) XML_L("expat_")V1(a,b,c) + + return V2(XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); + +#undef V1 +#undef V2 +} + +XML_Expat_Version XMLCALL +XML_ExpatVersionInfo(void) +{ + XML_Expat_Version version; + + version.major = XML_MAJOR_VERSION; + version.minor = XML_MINOR_VERSION; + version.micro = XML_MICRO_VERSION; + + return version; +} + +const XML_Feature * XMLCALL +XML_GetFeatureList(void) +{ + static const XML_Feature features[] = { + {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), + sizeof(XML_Char)}, + {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), + sizeof(XML_LChar)}, +#ifdef XML_UNICODE + {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, +#endif +#ifdef XML_UNICODE_WCHAR_T + {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, +#endif +#ifdef XML_DTD + {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, +#endif +#ifdef XML_CONTEXT_BYTES + {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), + XML_CONTEXT_BYTES}, +#endif +#ifdef XML_MIN_SIZE + {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, +#endif +#ifdef XML_NS + {XML_FEATURE_NS, XML_L("XML_NS"), 0}, +#endif + {XML_FEATURE_END, NULL, 0} + }; + + return features; +} + +/* Initially tag->rawName always points into the parse buffer; + for those TAG instances opened while the current parse buffer was + processed, and not yet closed, we need to store tag->rawName in a more + permanent location, since the parse buffer is about to be discarded. +*/ +static XML_Bool +storeRawNames(XML_Parser parser) +{ + TAG *tag = tagStack; + while (tag) { + int bufSize; + int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); + char *rawNameBuf = tag->buf + nameLen; + /* Stop if already stored. Since tagStack is a stack, we can stop + at the first entry that has already been copied; everything + below it in the stack is already been accounted for in a + previous call to this function. + */ + if (tag->rawName == rawNameBuf) + break; + /* For re-use purposes we need to ensure that the + size of tag->buf is a multiple of sizeof(XML_Char). + */ + bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); + if (bufSize > tag->bufEnd - tag->buf) { + char *temp = (char *)REALLOC(tag->buf, bufSize); + if (temp == NULL) + return XML_FALSE; + /* if tag->name.str points to tag->buf (only when namespace + processing is off) then we have to update it + */ + if (tag->name.str == (XML_Char *)tag->buf) + tag->name.str = (XML_Char *)temp; + /* if tag->name.localPart is set (when namespace processing is on) + then update it as well, since it will always point into tag->buf + */ + if (tag->name.localPart) + tag->name.localPart = (XML_Char *)temp + (tag->name.localPart - + (XML_Char *)tag->buf); + tag->buf = temp; + tag->bufEnd = temp + bufSize; + rawNameBuf = temp + nameLen; + } + memcpy(rawNameBuf, tag->rawName, tag->rawNameLength); + tag->rawName = rawNameBuf; + tag = tag->parent; + } + return XML_TRUE; +} + +static enum XML_Error PTRCALL +contentProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doContent(parser, 0, encoding, start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result == XML_ERROR_NONE) { + if (!storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + processor = externalEntityInitProcessor2; + return externalEntityInitProcessor2(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor2(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + const char *next = start; /* XmlContentTok doesn't always set the last arg */ + int tok = XmlContentTok(encoding, start, end, &next); + switch (tok) { + case XML_TOK_BOM: + /* If we are at the end of the buffer, this would cause the next stage, + i.e. externalEntityInitProcessor3, to pass control directly to + doContent (by detecting XML_TOK_NONE) without processing any xml text + declaration - causing the error XML_ERROR_MISPLACED_XML_PI in doContent. + */ + if (next == end && !ps_finalBuffer) { + *endPtr = next; + return XML_ERROR_NONE; + } + start = next; + break; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + eventPtr = start; + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + eventPtr = start; + return XML_ERROR_PARTIAL_CHAR; + } + processor = externalEntityInitProcessor3; + return externalEntityInitProcessor3(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityInitProcessor3(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + int tok; + const char *next = start; /* XmlContentTok doesn't always set the last arg */ + eventPtr = start; + tok = XmlContentTok(encoding, start, end, &next); + eventEndPtr = next; + + switch (tok) { + case XML_TOK_XML_DECL: + { + enum XML_Error result; + result = processXmlDecl(parser, 1, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (ps_parsing) { + case XML_SUSPENDED: + *endPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + start = next; + } + } + break; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *endPtr = start; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + } + processor = externalEntityContentProcessor; + tagLevel = 1; + return externalEntityContentProcessor(parser, start, end, endPtr); +} + +static enum XML_Error PTRCALL +externalEntityContentProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doContent(parser, 1, encoding, start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result == XML_ERROR_NONE) { + if (!storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; +} + +static enum XML_Error +doContent(XML_Parser parser, + int startTagLevel, + const ENCODING *enc, + const char *s, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + /* save one level of indirection */ + DTD * const dtd = _dtd; + + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + + for (;;) { + const char *next = s; /* XmlContentTok doesn't always set the last arg */ + int tok = XmlContentTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_TRAILING_CR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + *eventEndPP = end; + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, end); + /* We are at the end of the final buffer, should we check for + XML_SUSPENDED, XML_FINISHED? + */ + if (startTagLevel == 0) + return XML_ERROR_NO_ELEMENTS; + if (tagLevel != startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + *nextPtr = end; + return XML_ERROR_NONE; + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + if (startTagLevel > 0) { + if (tagLevel != startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_NO_ELEMENTS; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_ENTITY_REF: + { + const XML_Char *name; + ENTITY *entity; + XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (ch) { + if (characterDataHandler) + characterDataHandler(handlerArg, &ch, 1); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + name = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); + poolDiscard(&dtd->pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity or default handler. + */ + if (!dtd->hasParamEntityRefs || dtd->standalone) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->notation) + return XML_ERROR_BINARY_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + if (!defaultExpandInternalEntities) { + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, entity->name, 0); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + result = processInternalEntity(parser, entity, XML_FALSE); + if (result != XML_ERROR_NONE) + return result; + } + else if (externalEntityRefHandler) { + const XML_Char *context; + entity->open = XML_TRUE; + context = getContext(parser); + entity->open = XML_FALSE; + if (!context) + return XML_ERROR_NO_MEMORY; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + context, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + poolDiscard(&tempPool); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + case XML_TOK_START_TAG_NO_ATTS: + /* fall through */ + case XML_TOK_START_TAG_WITH_ATTS: + { + TAG *tag; + enum XML_Error result; + XML_Char *toPtr; + if (freeTagList) { + tag = freeTagList; + freeTagList = freeTagList->parent; + } + else { + tag = (TAG *)MALLOC(sizeof(TAG)); + if (!tag) + return XML_ERROR_NO_MEMORY; + tag->buf = (char *)MALLOC(INIT_TAG_BUF_SIZE); + if (!tag->buf) { + FREE(tag); + return XML_ERROR_NO_MEMORY; + } + tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; + } + tag->bindings = NULL; + tag->parent = tagStack; + tagStack = tag; + tag->name.localPart = NULL; + tag->name.prefix = NULL; + tag->rawName = s + enc->minBytesPerChar; + tag->rawNameLength = XmlNameLength(enc, tag->rawName); + ++tagLevel; + { + const char *rawNameEnd = tag->rawName + tag->rawNameLength; + const char *fromPtr = tag->rawName; + toPtr = (XML_Char *)tag->buf; + for (;;) { + int bufSize; + int convLen; + XmlConvert(enc, + &fromPtr, rawNameEnd, + (ICHAR **)&toPtr, (ICHAR *)tag->bufEnd - 1); + convLen = (int)(toPtr - (XML_Char *)tag->buf); + if (fromPtr == rawNameEnd) { + tag->name.strLen = convLen; + break; + } + bufSize = (int)(tag->bufEnd - tag->buf) << 1; + { + char *temp = (char *)REALLOC(tag->buf, bufSize); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + tag->buf = temp; + tag->bufEnd = temp + bufSize; + toPtr = (XML_Char *)temp + convLen; + } + } + } + tag->name.str = (XML_Char *)tag->buf; + *toPtr = XML_T('\0'); + result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); + if (result) + return result; + if (startElementHandler) + startElementHandler(handlerArg, tag->name.str, + (const XML_Char **)atts); + else if (defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&tempPool); + break; + } + case XML_TOK_EMPTY_ELEMENT_NO_ATTS: + /* fall through */ + case XML_TOK_EMPTY_ELEMENT_WITH_ATTS: + { + const char *rawName = s + enc->minBytesPerChar; + enum XML_Error result; + BINDING *bindings = NULL; + XML_Bool noElmHandlers = XML_TRUE; + TAG_NAME name; + name.str = poolStoreString(&tempPool, enc, rawName, + rawName + XmlNameLength(enc, rawName)); + if (!name.str) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + result = storeAtts(parser, enc, s, &name, &bindings); + if (result) + return result; + poolFinish(&tempPool); + if (startElementHandler) { + startElementHandler(handlerArg, name.str, (const XML_Char **)atts); + noElmHandlers = XML_FALSE; + } + if (endElementHandler) { + if (startElementHandler) + *eventPP = *eventEndPP; + endElementHandler(handlerArg, name.str); + noElmHandlers = XML_FALSE; + } + if (noElmHandlers && defaultHandler) + reportDefault(parser, enc, s, next); + poolClear(&tempPool); + while (bindings) { + BINDING *b = bindings; + if (endNamespaceDeclHandler) + endNamespaceDeclHandler(handlerArg, b->prefix->name); + bindings = bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + b->prefix->binding = b->prevPrefixBinding; + } + } + if (tagLevel == 0) + return epilogProcessor(parser, next, end, nextPtr); + break; + case XML_TOK_END_TAG: + if (tagLevel == startTagLevel) + return XML_ERROR_ASYNC_ENTITY; + else { + int len; + const char *rawName; + TAG *tag = tagStack; + tagStack = tag->parent; + tag->parent = freeTagList; + freeTagList = tag; + rawName = s + enc->minBytesPerChar*2; + len = XmlNameLength(enc, rawName); + if (len != tag->rawNameLength + || memcmp(tag->rawName, rawName, len) != 0) { + *eventPP = rawName; + return XML_ERROR_TAG_MISMATCH; + } + --tagLevel; + if (endElementHandler) { + const XML_Char *localPart; + const XML_Char *prefix; + XML_Char *uri; + localPart = tag->name.localPart; + if (ns && localPart) { + /* localPart and prefix may have been overwritten in + tag->name.str, since this points to the binding->uri + buffer which gets re-used; so we have to add them again + */ + uri = (XML_Char *)tag->name.str + tag->name.uriLen; + /* don't need to check for space - already done in storeAtts() */ + while (*localPart) *uri++ = *localPart++; + prefix = (XML_Char *)tag->name.prefix; + if (ns_triplets && prefix) { + *uri++ = namespaceSeparator; + while (*prefix) *uri++ = *prefix++; + } + *uri = XML_T('\0'); + } + endElementHandler(handlerArg, tag->name.str); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + while (tag->bindings) { + BINDING *b = tag->bindings; + if (endNamespaceDeclHandler) + endNamespaceDeclHandler(handlerArg, b->prefix->name); + tag->bindings = tag->bindings->nextTagBinding; + b->nextTagBinding = freeBindingList; + freeBindingList = b; + b->prefix->binding = b->prevPrefixBinding; + } + if (tagLevel == 0) + return epilogProcessor(parser, next, end, nextPtr); + } + break; + case XML_TOK_CHAR_REF: + { + int n = XmlCharRefNumber(enc, s); + if (n < 0) + return XML_ERROR_BAD_CHAR_REF; + if (characterDataHandler) { + XML_Char buf[XML_ENCODE_MAX]; + characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + } + break; + case XML_TOK_XML_DECL: + return XML_ERROR_MISPLACED_XML_PI; + case XML_TOK_DATA_NEWLINE: + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_CDATA_SECT_OPEN: + { + enum XML_Error result; + if (startCdataSectionHandler) + startCdataSectionHandler(handlerArg); +#if 0 + /* Suppose you doing a transformation on a document that involves + changing only the character data. You set up a defaultHandler + and a characterDataHandler. The defaultHandler simply copies + characters through. The characterDataHandler does the + transformation and writes the characters out escaping them as + necessary. This case will fail to work if we leave out the + following two lines (because & and < inside CDATA sections will + be incorrectly escaped). + + However, now we have a start/endCdataSectionHandler, so it seems + easier to let the user deal with this. + */ + else if (characterDataHandler) + characterDataHandler(handlerArg, dataBuf, 0); +#endif + else if (defaultHandler) + reportDefault(parser, enc, s, next); + result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (!next) { + processor = cdataSectionProcessor; + return result; + } + } + break; + case XML_TOK_TRAILING_RSQB: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + if (characterDataHandler) { + if (MUST_CONVERT(enc, s)) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + characterDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + } + else + characterDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)end - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, end); + /* We are at the end of the final buffer, should we check for + XML_SUSPENDED, XML_FINISHED? + */ + if (startTagLevel == 0) { + *eventPP = end; + return XML_ERROR_NO_ELEMENTS; + } + if (tagLevel != startTagLevel) { + *eventPP = end; + return XML_ERROR_ASYNC_ENTITY; + } + *nextPtr = end; + return XML_ERROR_NONE; + case XML_TOK_DATA_CHARS: + if (characterDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + characterDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } + } + else + characterDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_PI: + if (!reportProcessingInstruction(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_COMMENT: + if (!reportComment(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + break; + default: + if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + } + *eventPP = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } + /* not reached */ +} + +/* Precondition: all arguments must be non-NULL; + Purpose: + - normalize attributes + - check attributes for well-formedness + - generate namespace aware attribute names (URI, prefix) + - build list of attributes for startElementHandler + - default attributes + - process namespace declarations (check and report them) + - generate namespace aware element name (URI, prefix) +*/ +static enum XML_Error +storeAtts(XML_Parser parser, const ENCODING *enc, + const char *attStr, TAG_NAME *tagNamePtr, + BINDING **bindingsPtr) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + ELEMENT_TYPE *elementType; + int nDefaultAtts; + const XML_Char **appAtts; /* the attribute list for the application */ + int attIndex = 0; + int prefixLen; + int i; + int n; + XML_Char *uri; + int nPrefixes = 0; + BINDING *binding; + const XML_Char *localPart; + + /* lookup the element type name */ + elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0); + if (!elementType) { + const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str); + if (!name) + return XML_ERROR_NO_MEMORY; + elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name, + sizeof(ELEMENT_TYPE)); + if (!elementType) + return XML_ERROR_NO_MEMORY; + if (ns && !setElementTypePrefix(parser, elementType)) + return XML_ERROR_NO_MEMORY; + } + nDefaultAtts = elementType->nDefaultAtts; + + /* get the attributes from the tokenizer */ + n = XmlGetAttributes(enc, attStr, attsSize, atts); + if (n + nDefaultAtts > attsSize) { + int oldAttsSize = attsSize; + ATTRIBUTE *temp; + attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; + temp = (ATTRIBUTE *)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + atts = temp; + if (n > oldAttsSize) + XmlGetAttributes(enc, attStr, n, atts); + } + + appAtts = (const XML_Char **)atts; + for (i = 0; i < n; i++) { + /* add the name and value to the attribute list */ + ATTRIBUTE_ID *attId = getAttributeId(parser, enc, atts[i].name, + atts[i].name + + XmlNameLength(enc, atts[i].name)); + if (!attId) + return XML_ERROR_NO_MEMORY; + /* Detect duplicate attributes by their QNames. This does not work when + namespace processing is turned on and different prefixes for the same + namespace are used. For this case we have a check further down. + */ + if ((attId->name)[-1]) { + if (enc == encoding) + eventPtr = atts[i].name; + return XML_ERROR_DUPLICATE_ATTRIBUTE; + } + (attId->name)[-1] = 1; + appAtts[attIndex++] = attId->name; + if (!atts[i].normalized) { + enum XML_Error result; + XML_Bool isCdata = XML_TRUE; + + /* figure out whether declared as other than CDATA */ + if (attId->maybeTokenized) { + int j; + for (j = 0; j < nDefaultAtts; j++) { + if (attId == elementType->defaultAtts[j].id) { + isCdata = elementType->defaultAtts[j].isCdata; + break; + } + } + } + + /* normalize the attribute value */ + result = storeAttributeValue(parser, enc, isCdata, + atts[i].valuePtr, atts[i].valueEnd, + &tempPool); + if (result) + return result; + appAtts[attIndex] = poolStart(&tempPool); + poolFinish(&tempPool); + } + else { + /* the value did not need normalizing */ + appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, + atts[i].valueEnd); + if (appAtts[attIndex] == 0) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + } + /* handle prefixed attribute names */ + if (attId->prefix) { + if (attId->xmlns) { + /* deal with namespace declarations here */ + enum XML_Error result = addBinding(parser, attId->prefix, attId, + appAtts[attIndex], bindingsPtr); + if (result) + return result; + --attIndex; + } + else { + /* deal with other prefixed names later */ + attIndex++; + nPrefixes++; + (attId->name)[-1] = 2; + } + } + else + attIndex++; + } + + /* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */ + nSpecifiedAtts = attIndex; + if (elementType->idAtt && (elementType->idAtt->name)[-1]) { + for (i = 0; i < attIndex; i += 2) + if (appAtts[i] == elementType->idAtt->name) { + idAttIndex = i; + break; + } + } + else + idAttIndex = -1; + + /* do attribute defaulting */ + for (i = 0; i < nDefaultAtts; i++) { + const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i; + if (!(da->id->name)[-1] && da->value) { + if (da->id->prefix) { + if (da->id->xmlns) { + enum XML_Error result = addBinding(parser, da->id->prefix, da->id, + da->value, bindingsPtr); + if (result) + return result; + } + else { + (da->id->name)[-1] = 2; + nPrefixes++; + appAtts[attIndex++] = da->id->name; + appAtts[attIndex++] = da->value; + } + } + else { + (da->id->name)[-1] = 1; + appAtts[attIndex++] = da->id->name; + appAtts[attIndex++] = da->value; + } + } + } + appAtts[attIndex] = 0; + + /* expand prefixed attribute names, check for duplicates, + and clear flags that say whether attributes were specified */ + i = 0; + if (nPrefixes) { + int j; /* hash table index */ + unsigned long version = nsAttsVersion; + int nsAttsSize = (int)1 << nsAttsPower; + /* size of hash table must be at least 2 * (# of prefixed attributes) */ + if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */ + NS_ATT *temp; + /* hash table size must also be a power of 2 and >= 8 */ + while (nPrefixes >> nsAttsPower++); + if (nsAttsPower < 3) + nsAttsPower = 3; + nsAttsSize = (int)1 << nsAttsPower; + temp = (NS_ATT *)REALLOC(nsAtts, nsAttsSize * sizeof(NS_ATT)); + if (!temp) + return XML_ERROR_NO_MEMORY; + nsAtts = temp; + version = 0; /* force re-initialization of nsAtts hash table */ + } + /* using a version flag saves us from initializing nsAtts every time */ + if (!version) { /* initialize version flags when version wraps around */ + version = INIT_ATTS_VERSION; + for (j = nsAttsSize; j != 0; ) + nsAtts[--j].version = version; + } + nsAttsVersion = --version; + + /* expand prefixed names and check for duplicates */ + for (; i < attIndex; i += 2) { + const XML_Char *s = appAtts[i]; + if (s[-1] == 2) { /* prefixed */ + ATTRIBUTE_ID *id; + const BINDING *b; + unsigned long uriHash = 0; + ((XML_Char *)s)[-1] = 0; /* clear flag */ + id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0); + b = id->prefix->binding; + if (!b) + return XML_ERROR_UNBOUND_PREFIX; + + /* as we expand the name we also calculate its hash value */ + for (j = 0; j < b->uriLen; j++) { + const XML_Char c = b->uri[j]; + if (!poolAppendChar(&tempPool, c)) + return XML_ERROR_NO_MEMORY; + uriHash = CHAR_HASH(uriHash, c); + } + while (*s++ != XML_T(':')) + ; + do { /* copies null terminator */ + const XML_Char c = *s; + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + uriHash = CHAR_HASH(uriHash, c); + } while (*s++); + + { /* Check hash table for duplicate of expanded name (uriName). + Derived from code in lookup(HASH_TABLE *table, ...). + */ + unsigned char step = 0; + unsigned long mask = nsAttsSize - 1; + j = uriHash & mask; /* index into hash table */ + while (nsAtts[j].version == version) { + /* for speed we compare stored hash values first */ + if (uriHash == nsAtts[j].hash) { + const XML_Char *s1 = poolStart(&tempPool); + const XML_Char *s2 = nsAtts[j].uriName; + /* s1 is null terminated, but not s2 */ + for (; *s1 == *s2 && *s1 != 0; s1++, s2++); + if (*s1 == 0) + return XML_ERROR_DUPLICATE_ATTRIBUTE; + } + if (!step) + step = PROBE_STEP(uriHash, mask, nsAttsPower); + j < step ? (j += nsAttsSize - step) : (j -= step); + } + } + + if (ns_triplets) { /* append namespace separator and prefix */ + tempPool.ptr[-1] = namespaceSeparator; + s = b->prefix->name; + do { + if (!poolAppendChar(&tempPool, *s)) + return XML_ERROR_NO_MEMORY; + } while (*s++); + } + + /* store expanded name in attribute list */ + s = poolStart(&tempPool); + poolFinish(&tempPool); + appAtts[i] = s; + + /* fill empty slot with new version, uriName and hash value */ + nsAtts[j].version = version; + nsAtts[j].hash = uriHash; + nsAtts[j].uriName = s; + + if (!--nPrefixes) { + i += 2; + break; + } + } + else /* not prefixed */ + ((XML_Char *)s)[-1] = 0; /* clear flag */ + } + } + /* clear flags for the remaining attributes */ + for (; i < attIndex; i += 2) + ((XML_Char *)(appAtts[i]))[-1] = 0; + for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) + binding->attId->name[-1] = 0; + + if (!ns) + return XML_ERROR_NONE; + + /* expand the element type name */ + if (elementType->prefix) { + binding = elementType->prefix->binding; + if (!binding) + return XML_ERROR_UNBOUND_PREFIX; + localPart = tagNamePtr->str; + while (*localPart++ != XML_T(':')) + ; + } + else if (dtd->defaultPrefix.binding) { + binding = dtd->defaultPrefix.binding; + localPart = tagNamePtr->str; + } + else + return XML_ERROR_NONE; + prefixLen = 0; + if (ns_triplets && binding->prefix->name) { + for (; binding->prefix->name[prefixLen++];) + ; /* prefixLen includes null terminator */ + } + tagNamePtr->localPart = localPart; + tagNamePtr->uriLen = binding->uriLen; + tagNamePtr->prefix = binding->prefix->name; + tagNamePtr->prefixLen = prefixLen; + for (i = 0; localPart[i++];) + ; /* i includes null terminator */ + n = i + binding->uriLen + prefixLen; + if (n > binding->uriAlloc) { + TAG *p; + uri = (XML_Char *)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); + if (!uri) + return XML_ERROR_NO_MEMORY; + binding->uriAlloc = n + EXPAND_SPARE; + memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); + for (p = tagStack; p; p = p->parent) + if (p->name.str == binding->uri) + p->name.str = uri; + FREE(binding->uri); + binding->uri = uri; + } + /* if namespaceSeparator != '\0' then uri includes it already */ + uri = binding->uri + binding->uriLen; + memcpy(uri, localPart, i * sizeof(XML_Char)); + /* we always have a namespace separator between localPart and prefix */ + if (prefixLen) { + uri += i - 1; + *uri = namespaceSeparator; /* replace null terminator */ + memcpy(uri + 1, binding->prefix->name, prefixLen * sizeof(XML_Char)); + } + tagNamePtr->str = binding->uri; + return XML_ERROR_NONE; +} + +/* addBinding() overwrites the value of prefix->binding without checking. + Therefore one must keep track of the old value outside of addBinding(). +*/ +static enum XML_Error +addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, + const XML_Char *uri, BINDING **bindingsPtr) +{ + static const XML_Char xmlNamespace[] = { + 'h', 't', 't', 'p', ':', '/', '/', + 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', + 'X', 'M', 'L', '/', '1', '9', '9', '8', '/', + 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0' + }; + static const int xmlLen = + (int)sizeof(xmlNamespace)/sizeof(XML_Char) - 1; + static const XML_Char xmlnsNamespace[] = { + 'h', 't', 't', 'p', ':', '/', '/', + 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/', + '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0' + }; + static const int xmlnsLen = + (int)sizeof(xmlnsNamespace)/sizeof(XML_Char) - 1; + + XML_Bool mustBeXML = XML_FALSE; + XML_Bool isXML = XML_TRUE; + XML_Bool isXMLNS = XML_TRUE; + + BINDING *b; + int len; + + /* empty URI is only valid for default namespace per XML NS 1.0 (not 1.1) */ + if (*uri == XML_T('\0') && prefix->name) + return XML_ERROR_UNDECLARING_PREFIX; + + if (prefix->name + && prefix->name[0] == XML_T('x') + && prefix->name[1] == XML_T('m') + && prefix->name[2] == XML_T('l')) { + + /* Not allowed to bind xmlns */ + if (prefix->name[3] == XML_T('n') + && prefix->name[4] == XML_T('s') + && prefix->name[5] == XML_T('\0')) + return XML_ERROR_RESERVED_PREFIX_XMLNS; + + if (prefix->name[3] == XML_T('\0')) + mustBeXML = XML_TRUE; + } + + for (len = 0; uri[len]; len++) { + if (isXML && (len > xmlLen || uri[len] != xmlNamespace[len])) + isXML = XML_FALSE; + + if (!mustBeXML && isXMLNS + && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) + isXMLNS = XML_FALSE; + } + isXML = isXML && len == xmlLen; + isXMLNS = isXMLNS && len == xmlnsLen; + + if (mustBeXML != isXML) + return mustBeXML ? XML_ERROR_RESERVED_PREFIX_XML + : XML_ERROR_RESERVED_NAMESPACE_URI; + + if (isXMLNS) + return XML_ERROR_RESERVED_NAMESPACE_URI; + + if (namespaceSeparator) + len++; + if (freeBindingList) { + b = freeBindingList; + if (len > b->uriAlloc) { + XML_Char *temp = (XML_Char *)REALLOC(b->uri, + sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + b->uri = temp; + b->uriAlloc = len + EXPAND_SPARE; + } + freeBindingList = b->nextTagBinding; + } + else { + b = (BINDING *)MALLOC(sizeof(BINDING)); + if (!b) + return XML_ERROR_NO_MEMORY; + b->uri = (XML_Char *)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); + if (!b->uri) { + FREE(b); + return XML_ERROR_NO_MEMORY; + } + b->uriAlloc = len + EXPAND_SPARE; + } + b->uriLen = len; + memcpy(b->uri, uri, len * sizeof(XML_Char)); + if (namespaceSeparator) + b->uri[len - 1] = namespaceSeparator; + b->prefix = prefix; + b->attId = attId; + b->prevPrefixBinding = prefix->binding; + /* NULL binding when default namespace undeclared */ + if (*uri == XML_T('\0') && prefix == &_dtd->defaultPrefix) + prefix->binding = NULL; + else + prefix->binding = b; + b->nextTagBinding = *bindingsPtr; + *bindingsPtr = b; + /* if attId == NULL then we are not starting a namespace scope */ + if (attId && startNamespaceDeclHandler) + startNamespaceDeclHandler(handlerArg, prefix->name, + prefix->binding ? uri : 0); + return XML_ERROR_NONE; +} + +/* The idea here is to avoid using stack for each CDATA section when + the whole file is parsed with one call. +*/ +static enum XML_Error PTRCALL +cdataSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doCdataSection(parser, encoding, &start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result != XML_ERROR_NONE) + return result; + if (start) { + if (parentParser) { /* we are parsing an external entity */ + processor = externalEntityContentProcessor; + return externalEntityContentProcessor(parser, start, end, endPtr); + } + else { + processor = contentProcessor; + return contentProcessor(parser, start, end, endPtr); + } + } + return result; +} + +/* startPtr gets set to non-null if the section is closed, and to null if + the section is not yet closed. +*/ +static enum XML_Error +doCdataSection(XML_Parser parser, + const ENCODING *enc, + const char **startPtr, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + const char *s = *startPtr; + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + *eventPP = s; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + *startPtr = NULL; + + for (;;) { + const char *next; + int tok = XmlCdataSectionTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_CDATA_SECT_CLOSE: + if (endCdataSectionHandler) + endCdataSectionHandler(handlerArg); +#if 0 + /* see comment under XML_TOK_CDATA_SECT_OPEN */ + else if (characterDataHandler) + characterDataHandler(handlerArg, dataBuf, 0); +#endif + else if (defaultHandler) + reportDefault(parser, enc, s, next); + *startPtr = next; + *nextPtr = next; + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + else + return XML_ERROR_NONE; + case XML_TOK_DATA_NEWLINE: + if (characterDataHandler) { + XML_Char c = 0xA; + characterDataHandler(handlerArg, &c, 1); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_DATA_CHARS: + if (characterDataHandler) { + if (MUST_CONVERT(enc, s)) { + for (;;) { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = next; + characterDataHandler(handlerArg, dataBuf, + (int)(dataPtr - (ICHAR *)dataBuf)); + if (s == next) + break; + *eventPP = s; + } + } + else + characterDataHandler(handlerArg, + (XML_Char *)s, + (int)((XML_Char *)next - (XML_Char *)s)); + } + else if (defaultHandler) + reportDefault(parser, enc, s, next); + break; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_PARTIAL: + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_CDATA_SECTION; + default: + *eventPP = next; + return XML_ERROR_UNEXPECTED_STATE; + } + + *eventPP = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } + /* not reached */ +} + +#ifdef XML_DTD + +/* The idea here is to avoid using stack for each IGNORE section when + the whole file is parsed with one call. +*/ +static enum XML_Error PTRCALL +ignoreSectionProcessor(XML_Parser parser, + const char *start, + const char *end, + const char **endPtr) +{ + enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, + endPtr, (XML_Bool)!ps_finalBuffer); + if (result != XML_ERROR_NONE) + return result; + if (start) { + processor = prologProcessor; + return prologProcessor(parser, start, end, endPtr); + } + return result; +} + +/* startPtr gets set to non-null is the section is closed, and to null + if the section is not yet closed. +*/ +static enum XML_Error +doIgnoreSection(XML_Parser parser, + const ENCODING *enc, + const char **startPtr, + const char *end, + const char **nextPtr, + XML_Bool haveMore) +{ + const char *next; + int tok; + const char *s = *startPtr; + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + *eventPP = s; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + *eventPP = s; + *startPtr = NULL; + tok = XmlIgnoreSectionTok(enc, s, end, &next); + *eventEndPP = next; + switch (tok) { + case XML_TOK_IGNORE_SECT: + if (defaultHandler) + reportDefault(parser, enc, s, next); + *startPtr = next; + *nextPtr = next; + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + else + return XML_ERROR_NONE; + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_PARTIAL: + case XML_TOK_NONE: + if (haveMore) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */ + default: + *eventPP = next; + return XML_ERROR_UNEXPECTED_STATE; + } + /* not reached */ +} + +#endif /* XML_DTD */ + +static enum XML_Error +initializeEncoding(XML_Parser parser) +{ + const char *s; +#ifdef XML_UNICODE + char encodingBuf[128]; + if (!protocolEncodingName) + s = NULL; + else { + int i; + for (i = 0; protocolEncodingName[i]; i++) { + if (i == sizeof(encodingBuf) - 1 + || (protocolEncodingName[i] & ~0x7f) != 0) { + encodingBuf[0] = '\0'; + break; + } + encodingBuf[i] = (char)protocolEncodingName[i]; + } + encodingBuf[i] = '\0'; + s = encodingBuf; + } +#else + s = protocolEncodingName; +#endif + if ((ns ? XmlInitEncodingNS : XmlInitEncoding)(&initEncoding, &encoding, s)) + return XML_ERROR_NONE; + return handleUnknownEncoding(parser, protocolEncodingName); +} + +static enum XML_Error +processXmlDecl(XML_Parser parser, int isGeneralTextEntity, + const char *s, const char *next) +{ + const char *encodingName = NULL; + const XML_Char *storedEncName = NULL; + const ENCODING *newEncoding = NULL; + const char *version = NULL; + const char *versionend; + const XML_Char *storedversion = NULL; + int standalone = -1; + if (!(ns + ? XmlParseXmlDeclNS + : XmlParseXmlDecl)(isGeneralTextEntity, + encoding, + s, + next, + &eventPtr, + &version, + &versionend, + &encodingName, + &newEncoding, + &standalone)) { + if (isGeneralTextEntity) + return XML_ERROR_TEXT_DECL; + else + return XML_ERROR_XML_DECL; + } + if (!isGeneralTextEntity && standalone == 1) { + _dtd->standalone = XML_TRUE; +#ifdef XML_DTD + if (paramEntityParsing == XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE) + paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; +#endif /* XML_DTD */ + } + if (xmlDeclHandler) { + if (encodingName != NULL) { + storedEncName = poolStoreString(&temp2Pool, + encoding, + encodingName, + encodingName + + XmlNameLength(encoding, encodingName)); + if (!storedEncName) + return XML_ERROR_NO_MEMORY; + poolFinish(&temp2Pool); + } + if (version) { + storedversion = poolStoreString(&temp2Pool, + encoding, + version, + versionend - encoding->minBytesPerChar); + if (!storedversion) + return XML_ERROR_NO_MEMORY; + } + xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); + } + else if (defaultHandler) + reportDefault(parser, encoding, s, next); + if (protocolEncodingName == NULL) { + if (newEncoding) { + if (newEncoding->minBytesPerChar != encoding->minBytesPerChar) { + eventPtr = encodingName; + return XML_ERROR_INCORRECT_ENCODING; + } + encoding = newEncoding; + } + else if (encodingName) { + enum XML_Error result; + if (!storedEncName) { + storedEncName = poolStoreString( + &temp2Pool, encoding, encodingName, + encodingName + XmlNameLength(encoding, encodingName)); + if (!storedEncName) + return XML_ERROR_NO_MEMORY; + } + result = handleUnknownEncoding(parser, storedEncName); + poolClear(&temp2Pool); + if (result == XML_ERROR_UNKNOWN_ENCODING) + eventPtr = encodingName; + return result; + } + } + + if (storedEncName || storedversion) + poolClear(&temp2Pool); + + return XML_ERROR_NONE; +} + +static enum XML_Error +handleUnknownEncoding(XML_Parser parser, const XML_Char *encodingName) +{ + if (unknownEncodingHandler) { + XML_Encoding info; + int i; + for (i = 0; i < 256; i++) + info.map[i] = -1; + info.convert = NULL; + info.data = NULL; + info.release = NULL; + if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, + &info)) { + ENCODING *enc; + unknownEncodingMem = MALLOC(XmlSizeOfUnknownEncoding()); + if (!unknownEncodingMem) { + if (info.release) + info.release(info.data); + return XML_ERROR_NO_MEMORY; + } + enc = (ns + ? XmlInitUnknownEncodingNS + : XmlInitUnknownEncoding)(unknownEncodingMem, + info.map, + info.convert, + info.data); + if (enc) { + unknownEncodingData = info.data; + unknownEncodingRelease = info.release; + encoding = enc; + return XML_ERROR_NONE; + } + } + if (info.release != NULL) + info.release(info.data); + } + return XML_ERROR_UNKNOWN_ENCODING; +} + +static enum XML_Error PTRCALL +prologInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + processor = prologProcessor; + return prologProcessor(parser, s, end, nextPtr); +} + +#ifdef XML_DTD + +static enum XML_Error PTRCALL +externalParEntInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + enum XML_Error result = initializeEncoding(parser); + if (result != XML_ERROR_NONE) + return result; + + /* we know now that XML_Parse(Buffer) has been called, + so we consider the external parameter entity read */ + _dtd->paramEntityRead = XML_TRUE; + + if (prologState.inEntityValue) { + processor = entityValueInitProcessor; + return entityValueInitProcessor(parser, s, end, nextPtr); + } + else { + processor = externalParEntProcessor; + return externalParEntProcessor(parser, s, end, nextPtr); + } +} + +static enum XML_Error PTRCALL +entityValueInitProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + int tok; + const char *start = s; + const char *next = start; + eventPtr = start; + + for (;;) { + tok = XmlPrologTok(encoding, start, end, &next); + eventEndPtr = next; + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + /* found end of entity value - can store it now */ + return storeEntityValue(parser, encoding, s, end); + } + else if (tok == XML_TOK_XML_DECL) { + enum XML_Error result; + result = processXmlDecl(parser, 0, start, next); + if (result != XML_ERROR_NONE) + return result; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + *nextPtr = next; + } + /* stop scanning for text declaration - we found one */ + processor = entityValueProcessor; + return entityValueProcessor(parser, next, end, nextPtr); + } + /* If we are at the end of the buffer, this would cause XmlPrologTok to + return XML_TOK_NONE on the next call, which would then cause the + function to exit with *nextPtr set to s - that is what we want for other + tokens, but not for the BOM - we would rather like to skip it; + then, when this routine is entered the next time, XmlPrologTok will + return XML_TOK_INVALID, since the BOM is still in the buffer + */ + else if (tok == XML_TOK_BOM && next == end && !ps_finalBuffer) { + *nextPtr = next; + return XML_ERROR_NONE; + } + start = next; + eventPtr = start; + } +} + +static enum XML_Error PTRCALL +externalParEntProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *next = s; + int tok; + + tok = XmlPrologTok(encoding, s, end, &next); + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + } + /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. + However, when parsing an external subset, doProlog will not accept a BOM + as valid, and report a syntax error, so we have to skip the BOM + */ + else if (tok == XML_TOK_BOM) { + s = next; + tok = XmlPrologTok(encoding, s, end, &next); + } + + processor = prologProcessor; + return doProlog(parser, encoding, s, end, tok, next, + nextPtr, (XML_Bool)!ps_finalBuffer); +} + +static enum XML_Error PTRCALL +entityValueProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *start = s; + const char *next = s; + const ENCODING *enc = encoding; + int tok; + + for (;;) { + tok = XmlPrologTok(enc, start, end, &next); + if (tok <= 0) { + if (!ps_finalBuffer && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: /* start == end */ + default: + break; + } + /* found end of entity value - can store it now */ + return storeEntityValue(parser, enc, s, end); + } + start = next; + } +} + +#endif /* XML_DTD */ + +static enum XML_Error PTRCALL +prologProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + const char *next = s; + int tok = XmlPrologTok(encoding, s, end, &next); + return doProlog(parser, encoding, s, end, tok, next, + nextPtr, (XML_Bool)!ps_finalBuffer); +} + +static enum XML_Error +doProlog(XML_Parser parser, + const ENCODING *enc, + const char *s, + const char *end, + int tok, + const char *next, + const char **nextPtr, + XML_Bool haveMore) +{ +#ifdef XML_DTD + static const XML_Char externalSubsetName[] = { '#' , '\0' }; +#endif /* XML_DTD */ + static const XML_Char atypeCDATA[] = { 'C', 'D', 'A', 'T', 'A', '\0' }; + static const XML_Char atypeID[] = { 'I', 'D', '\0' }; + static const XML_Char atypeIDREF[] = { 'I', 'D', 'R', 'E', 'F', '\0' }; + static const XML_Char atypeIDREFS[] = { 'I', 'D', 'R', 'E', 'F', 'S', '\0' }; + static const XML_Char atypeENTITY[] = { 'E', 'N', 'T', 'I', 'T', 'Y', '\0' }; + static const XML_Char atypeENTITIES[] = + { 'E', 'N', 'T', 'I', 'T', 'I', 'E', 'S', '\0' }; + static const XML_Char atypeNMTOKEN[] = { + 'N', 'M', 'T', 'O', 'K', 'E', 'N', '\0' }; + static const XML_Char atypeNMTOKENS[] = { + 'N', 'M', 'T', 'O', 'K', 'E', 'N', 'S', '\0' }; + static const XML_Char notationPrefix[] = { + 'N', 'O', 'T', 'A', 'T', 'I', 'O', 'N', '(', '\0' }; + static const XML_Char enumValueSep[] = { '|', '\0' }; + static const XML_Char enumValueStart[] = { '(', '\0' }; + + /* save one level of indirection */ + DTD * const dtd = _dtd; + + const char **eventPP; + const char **eventEndPP; + enum XML_Content_Quant quant; + + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + + for (;;) { + int role; + XML_Bool handleDefault = XML_TRUE; + *eventPP = s; + *eventEndPP = next; + if (tok <= 0) { + if (haveMore && tok != XML_TOK_INVALID) { + *nextPtr = s; + return XML_ERROR_NONE; + } + switch (tok) { + case XML_TOK_INVALID: + *eventPP = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + return XML_ERROR_PARTIAL_CHAR; + case XML_TOK_NONE: +#ifdef XML_DTD + /* for internal PE NOT referenced between declarations */ + if (enc != encoding && !openInternalEntities->betweenDecl) { + *nextPtr = s; + return XML_ERROR_NONE; + } + /* WFC: PE Between Declarations - must check that PE contains + complete markup, not only for external PEs, but also for + internal PEs if the reference occurs between declarations. + */ + if (isParamEntity || enc != encoding) { + if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) + == XML_ROLE_ERROR) + return XML_ERROR_INCOMPLETE_PE; + *nextPtr = s; + return XML_ERROR_NONE; + } +#endif /* XML_DTD */ + return XML_ERROR_NO_ELEMENTS; + default: + tok = -tok; + next = end; + break; + } + } + role = XmlTokenRole(&prologState, tok, s, next, enc); + switch (role) { + case XML_ROLE_XML_DECL: + { + enum XML_Error result = processXmlDecl(parser, 0, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = encoding; + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_DOCTYPE_NAME: + if (startDoctypeDeclHandler) { + doctypeName = poolStoreString(&tempPool, enc, s, next); + if (!doctypeName) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + doctypePubid = NULL; + handleDefault = XML_FALSE; + } + doctypeSysid = NULL; /* always initialize to NULL */ + break; + case XML_ROLE_DOCTYPE_INTERNAL_SUBSET: + if (startDoctypeDeclHandler) { + startDoctypeDeclHandler(handlerArg, doctypeName, doctypeSysid, + doctypePubid, 1); + doctypeName = NULL; + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + break; +#ifdef XML_DTD + case XML_ROLE_TEXT_DECL: + { + enum XML_Error result = processXmlDecl(parser, 1, s, next); + if (result != XML_ERROR_NONE) + return result; + enc = encoding; + handleDefault = XML_FALSE; + } + break; +#endif /* XML_DTD */ + case XML_ROLE_DOCTYPE_PUBLIC_ID: +#ifdef XML_DTD + useForeignDTD = XML_FALSE; + declEntity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; +#endif /* XML_DTD */ + dtd->hasParamEntityRefs = XML_TRUE; + if (startDoctypeDeclHandler) { + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + doctypePubid = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!doctypePubid) + return XML_ERROR_NO_MEMORY; + normalizePublicId((XML_Char *)doctypePubid); + poolFinish(&tempPool); + handleDefault = XML_FALSE; + goto alreadyChecked; + } + /* fall through */ + case XML_ROLE_ENTITY_PUBLIC_ID: + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + alreadyChecked: + if (dtd->keepProcessing && declEntity) { + XML_Char *tem = poolStoreString(&dtd->pool, + enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!tem) + return XML_ERROR_NO_MEMORY; + normalizePublicId(tem); + declEntity->publicId = tem; + poolFinish(&dtd->pool); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_DOCTYPE_CLOSE: + if (doctypeName) { + startDoctypeDeclHandler(handlerArg, doctypeName, + doctypeSysid, doctypePubid, 0); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + /* doctypeSysid will be non-NULL in the case of a previous + XML_ROLE_DOCTYPE_SYSTEM_ID, even if startDoctypeDeclHandler + was not set, indicating an external subset + */ +#ifdef XML_DTD + if (doctypeSysid || useForeignDTD) { + XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; + dtd->hasParamEntityRefs = XML_TRUE; + if (paramEntityParsing && externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!entity) + return XML_ERROR_NO_MEMORY; + if (useForeignDTD) + entity->base = curBase; + dtd->paramEntityRead = XML_FALSE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + if (dtd->paramEntityRead) { + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + } + /* if we didn't read the foreign DTD then this means that there + is no external subset and we must reset dtd->hasParamEntityRefs + */ + else if (!doctypeSysid) + dtd->hasParamEntityRefs = hadParamEntityRefs; + /* end of DTD - no need to update dtd->keepProcessing */ + } + useForeignDTD = XML_FALSE; + } +#endif /* XML_DTD */ + if (endDoctypeDeclHandler) { + endDoctypeDeclHandler(handlerArg); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_INSTANCE_START: +#ifdef XML_DTD + /* if there is no DOCTYPE declaration then now is the + last chance to read the foreign DTD + */ + if (useForeignDTD) { + XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs; + dtd->hasParamEntityRefs = XML_TRUE; + if (paramEntityParsing && externalEntityRefHandler) { + ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!entity) + return XML_ERROR_NO_MEMORY; + entity->base = curBase; + dtd->paramEntityRead = XML_FALSE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + if (dtd->paramEntityRead) { + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + } + /* if we didn't read the foreign DTD then this means that there + is no external subset and we must reset dtd->hasParamEntityRefs + */ + else + dtd->hasParamEntityRefs = hadParamEntityRefs; + /* end of DTD - no need to update dtd->keepProcessing */ + } + } +#endif /* XML_DTD */ + processor = contentProcessor; + return contentProcessor(parser, s, end, nextPtr); + case XML_ROLE_ATTLIST_ELEMENT_NAME: + declElementType = getElementType(parser, enc, s, next); + if (!declElementType) + return XML_ERROR_NO_MEMORY; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_NAME: + declAttributeId = getAttributeId(parser, enc, s, next); + if (!declAttributeId) + return XML_ERROR_NO_MEMORY; + declAttributeIsCdata = XML_FALSE; + declAttributeType = NULL; + declAttributeIsId = XML_FALSE; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_CDATA: + declAttributeIsCdata = XML_TRUE; + declAttributeType = atypeCDATA; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ID: + declAttributeIsId = XML_TRUE; + declAttributeType = atypeID; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_IDREF: + declAttributeType = atypeIDREF; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_IDREFS: + declAttributeType = atypeIDREFS; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ENTITY: + declAttributeType = atypeENTITY; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_ENTITIES: + declAttributeType = atypeENTITIES; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN: + declAttributeType = atypeNMTOKEN; + goto checkAttListDeclHandler; + case XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS: + declAttributeType = atypeNMTOKENS; + checkAttListDeclHandler: + if (dtd->keepProcessing && attlistDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ATTRIBUTE_ENUM_VALUE: + case XML_ROLE_ATTRIBUTE_NOTATION_VALUE: + if (dtd->keepProcessing && attlistDeclHandler) { + const XML_Char *prefix; + if (declAttributeType) { + prefix = enumValueSep; + } + else { + prefix = (role == XML_ROLE_ATTRIBUTE_NOTATION_VALUE + ? notationPrefix + : enumValueStart); + } + if (!poolAppendString(&tempPool, prefix)) + return XML_ERROR_NO_MEMORY; + if (!poolAppend(&tempPool, enc, s, next)) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_IMPLIED_ATTRIBUTE_VALUE: + case XML_ROLE_REQUIRED_ATTRIBUTE_VALUE: + if (dtd->keepProcessing) { + if (!defineAttribute(declElementType, declAttributeId, + declAttributeIsCdata, declAttributeIsId, + 0, parser)) + return XML_ERROR_NO_MEMORY; + if (attlistDeclHandler && declAttributeType) { + if (*declAttributeType == XML_T('(') + || (*declAttributeType == XML_T('N') + && declAttributeType[1] == XML_T('O'))) { + /* Enumerated or Notation type */ + if (!poolAppendChar(&tempPool, XML_T(')')) + || !poolAppendChar(&tempPool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + poolFinish(&tempPool); + } + *eventEndPP = s; + attlistDeclHandler(handlerArg, declElementType->name, + declAttributeId->name, declAttributeType, + 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: + case XML_ROLE_FIXED_ATTRIBUTE_VALUE: + if (dtd->keepProcessing) { + const XML_Char *attVal; + enum XML_Error result = + storeAttributeValue(parser, enc, declAttributeIsCdata, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar, + &dtd->pool); + if (result) + return result; + attVal = poolStart(&dtd->pool); + poolFinish(&dtd->pool); + /* ID attributes aren't allowed to have a default */ + if (!defineAttribute(declElementType, declAttributeId, + declAttributeIsCdata, XML_FALSE, attVal, parser)) + return XML_ERROR_NO_MEMORY; + if (attlistDeclHandler && declAttributeType) { + if (*declAttributeType == XML_T('(') + || (*declAttributeType == XML_T('N') + && declAttributeType[1] == XML_T('O'))) { + /* Enumerated or Notation type */ + if (!poolAppendChar(&tempPool, XML_T(')')) + || !poolAppendChar(&tempPool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + declAttributeType = tempPool.start; + poolFinish(&tempPool); + } + *eventEndPP = s; + attlistDeclHandler(handlerArg, declElementType->name, + declAttributeId->name, declAttributeType, + attVal, + role == XML_ROLE_FIXED_ATTRIBUTE_VALUE); + poolClear(&tempPool); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_ENTITY_VALUE: + if (dtd->keepProcessing) { + enum XML_Error result = storeEntityValue(parser, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (declEntity) { + declEntity->textPtr = poolStart(&dtd->entityValuePool); + declEntity->textLen = (int)(poolLength(&dtd->entityValuePool)); + poolFinish(&dtd->entityValuePool); + if (entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + declEntity->is_param, + declEntity->textPtr, + declEntity->textLen, + curBase, 0, 0, 0); + handleDefault = XML_FALSE; + } + } + else + poolDiscard(&dtd->entityValuePool); + if (result != XML_ERROR_NONE) + return result; + } + break; + case XML_ROLE_DOCTYPE_SYSTEM_ID: +#ifdef XML_DTD + useForeignDTD = XML_FALSE; +#endif /* XML_DTD */ + dtd->hasParamEntityRefs = XML_TRUE; + if (startDoctypeDeclHandler) { + doctypeSysid = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (doctypeSysid == NULL) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } +#ifdef XML_DTD + else + /* use externalSubsetName to make doctypeSysid non-NULL + for the case where no startDoctypeDeclHandler is set */ + doctypeSysid = externalSubsetName; +#endif /* XML_DTD */ + if (!dtd->standalone +#ifdef XML_DTD + && !paramEntityParsing +#endif /* XML_DTD */ + && notStandaloneHandler + && !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; +#ifndef XML_DTD + break; +#else /* XML_DTD */ + if (!declEntity) { + declEntity = (ENTITY *)lookup(&dtd->paramEntities, + externalSubsetName, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + declEntity->publicId = NULL; + } + /* fall through */ +#endif /* XML_DTD */ + case XML_ROLE_ENTITY_SYSTEM_ID: + if (dtd->keepProcessing && declEntity) { + declEntity->systemId = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!declEntity->systemId) + return XML_ERROR_NO_MEMORY; + declEntity->base = curBase; + poolFinish(&dtd->pool); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_ENTITY_COMPLETE: + if (dtd->keepProcessing && declEntity && entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + declEntity->is_param, + 0,0, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + 0); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_ENTITY_NOTATION_NAME: + if (dtd->keepProcessing && declEntity) { + declEntity->notation = poolStoreString(&dtd->pool, enc, s, next); + if (!declEntity->notation) + return XML_ERROR_NO_MEMORY; + poolFinish(&dtd->pool); + if (unparsedEntityDeclHandler) { + *eventEndPP = s; + unparsedEntityDeclHandler(handlerArg, + declEntity->name, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + declEntity->notation); + handleDefault = XML_FALSE; + } + else if (entityDeclHandler) { + *eventEndPP = s; + entityDeclHandler(handlerArg, + declEntity->name, + 0,0,0, + declEntity->base, + declEntity->systemId, + declEntity->publicId, + declEntity->notation); + handleDefault = XML_FALSE; + } + } + break; + case XML_ROLE_GENERAL_ENTITY_NAME: + { + if (XmlPredefinedEntityName(enc, s, next)) { + declEntity = NULL; + break; + } + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + declEntity = (ENTITY *)lookup(&dtd->generalEntities, name, + sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + if (declEntity->name != name) { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + else { + poolFinish(&dtd->pool); + declEntity->publicId = NULL; + declEntity->is_param = XML_FALSE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + declEntity->is_internal = !(parentParser || openInternalEntities); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + } + else { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + } + break; + case XML_ROLE_PARAM_ENTITY_NAME: +#ifdef XML_DTD + if (dtd->keepProcessing) { + const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next); + if (!name) + return XML_ERROR_NO_MEMORY; + declEntity = (ENTITY *)lookup(&dtd->paramEntities, + name, sizeof(ENTITY)); + if (!declEntity) + return XML_ERROR_NO_MEMORY; + if (declEntity->name != name) { + poolDiscard(&dtd->pool); + declEntity = NULL; + } + else { + poolFinish(&dtd->pool); + declEntity->publicId = NULL; + declEntity->is_param = XML_TRUE; + /* if we have a parent parser or are reading an internal parameter + entity, then the entity declaration is not considered "internal" + */ + declEntity->is_internal = !(parentParser || openInternalEntities); + if (entityDeclHandler) + handleDefault = XML_FALSE; + } + } + else { + poolDiscard(&dtd->pool); + declEntity = NULL; + } +#else /* not XML_DTD */ + declEntity = NULL; +#endif /* XML_DTD */ + break; + case XML_ROLE_NOTATION_NAME: + declNotationPublicId = NULL; + declNotationName = NULL; + if (notationDeclHandler) { + declNotationName = poolStoreString(&tempPool, enc, s, next); + if (!declNotationName) + return XML_ERROR_NO_MEMORY; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_NOTATION_PUBLIC_ID: + if (!XmlIsPublicId(enc, s, next, eventPP)) + return XML_ERROR_PUBLICID; + if (declNotationName) { /* means notationDeclHandler != NULL */ + XML_Char *tem = poolStoreString(&tempPool, + enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!tem) + return XML_ERROR_NO_MEMORY; + normalizePublicId(tem); + declNotationPublicId = tem; + poolFinish(&tempPool); + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_NOTATION_SYSTEM_ID: + if (declNotationName && notationDeclHandler) { + const XML_Char *systemId + = poolStoreString(&tempPool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!systemId) + return XML_ERROR_NO_MEMORY; + *eventEndPP = s; + notationDeclHandler(handlerArg, + declNotationName, + curBase, + systemId, + declNotationPublicId); + handleDefault = XML_FALSE; + } + poolClear(&tempPool); + break; + case XML_ROLE_NOTATION_NO_SYSTEM_ID: + if (declNotationPublicId && notationDeclHandler) { + *eventEndPP = s; + notationDeclHandler(handlerArg, + declNotationName, + curBase, + 0, + declNotationPublicId); + handleDefault = XML_FALSE; + } + poolClear(&tempPool); + break; + case XML_ROLE_ERROR: + switch (tok) { + case XML_TOK_PARAM_ENTITY_REF: + /* PE references in internal subset are + not allowed within declarations. */ + return XML_ERROR_PARAM_ENTITY_REF; + case XML_TOK_XML_DECL: + return XML_ERROR_MISPLACED_XML_PI; + default: + return XML_ERROR_SYNTAX; + } +#ifdef XML_DTD + case XML_ROLE_IGNORE_SECT: + { + enum XML_Error result; + if (defaultHandler) + reportDefault(parser, enc, s, next); + handleDefault = XML_FALSE; + result = doIgnoreSection(parser, enc, &next, end, nextPtr, haveMore); + if (result != XML_ERROR_NONE) + return result; + else if (!next) { + processor = ignoreSectionProcessor; + return result; + } + } + break; +#endif /* XML_DTD */ + case XML_ROLE_GROUP_OPEN: + if (prologState.level >= groupSize) { + if (groupSize) { + char *temp = (char *)REALLOC(groupConnector, groupSize *= 2); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + groupConnector = temp; + if (dtd->scaffIndex) { + int *temp = (int *)REALLOC(dtd->scaffIndex, + groupSize * sizeof(int)); + if (temp == NULL) + return XML_ERROR_NO_MEMORY; + dtd->scaffIndex = temp; + } + } + else { + groupConnector = (char *)MALLOC(groupSize = 32); + if (!groupConnector) + return XML_ERROR_NO_MEMORY; + } + } + groupConnector[prologState.level] = 0; + if (dtd->in_eldecl) { + int myindex = nextScaffoldPart(parser); + if (myindex < 0) + return XML_ERROR_NO_MEMORY; + dtd->scaffIndex[dtd->scaffLevel] = myindex; + dtd->scaffLevel++; + dtd->scaffold[myindex].type = XML_CTYPE_SEQ; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + case XML_ROLE_GROUP_SEQUENCE: + if (groupConnector[prologState.level] == '|') + return XML_ERROR_SYNTAX; + groupConnector[prologState.level] = ','; + if (dtd->in_eldecl && elementDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_GROUP_CHOICE: + if (groupConnector[prologState.level] == ',') + return XML_ERROR_SYNTAX; + if (dtd->in_eldecl + && !groupConnector[prologState.level] + && (dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + != XML_CTYPE_MIXED) + ) { + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + = XML_CTYPE_CHOICE; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + groupConnector[prologState.level] = '|'; + break; + case XML_ROLE_PARAM_ENTITY_REF: +#ifdef XML_DTD + case XML_ROLE_INNER_PARAM_ENTITY_REF: + dtd->hasParamEntityRefs = XML_TRUE; + if (!paramEntityParsing) + dtd->keepProcessing = dtd->standalone; + else { + const XML_Char *name; + ENTITY *entity; + name = poolStoreString(&dtd->pool, enc, + s + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); + poolDiscard(&dtd->pool); + /* first, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal, + otherwise call the skipped entity handler + */ + if (prologState.documentEntity && + (dtd->standalone + ? !openInternalEntities + : !dtd->hasParamEntityRefs)) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + dtd->keepProcessing = dtd->standalone; + /* cannot report skipped entities in declarations */ + if ((role == XML_ROLE_PARAM_ENTITY_REF) && skippedEntityHandler) { + skippedEntityHandler(handlerArg, name, 1); + handleDefault = XML_FALSE; + } + break; + } + if (entity->open) + return XML_ERROR_RECURSIVE_ENTITY_REF; + if (entity->textPtr) { + enum XML_Error result; + XML_Bool betweenDecl = + (role == XML_ROLE_PARAM_ENTITY_REF ? XML_TRUE : XML_FALSE); + result = processInternalEntity(parser, entity, betweenDecl); + if (result != XML_ERROR_NONE) + return result; + handleDefault = XML_FALSE; + break; + } + if (externalEntityRefHandler) { + dtd->paramEntityRead = XML_FALSE; + entity->open = XML_TRUE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) { + entity->open = XML_FALSE; + return XML_ERROR_EXTERNAL_ENTITY_HANDLING; + } + entity->open = XML_FALSE; + handleDefault = XML_FALSE; + if (!dtd->paramEntityRead) { + dtd->keepProcessing = dtd->standalone; + break; + } + } + else { + dtd->keepProcessing = dtd->standalone; + break; + } + } +#endif /* XML_DTD */ + if (!dtd->standalone && + notStandaloneHandler && + !notStandaloneHandler(handlerArg)) + return XML_ERROR_NOT_STANDALONE; + break; + + /* Element declaration stuff */ + + case XML_ROLE_ELEMENT_NAME: + if (elementDeclHandler) { + declElementType = getElementType(parser, enc, s, next); + if (!declElementType) + return XML_ERROR_NO_MEMORY; + dtd->scaffLevel = 0; + dtd->scaffCount = 0; + dtd->in_eldecl = XML_TRUE; + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_ANY: + case XML_ROLE_CONTENT_EMPTY: + if (dtd->in_eldecl) { + if (elementDeclHandler) { + XML_Content * content = (XML_Content *) MALLOC(sizeof(XML_Content)); + if (!content) + return XML_ERROR_NO_MEMORY; + content->quant = XML_CQUANT_NONE; + content->name = NULL; + content->numchildren = 0; + content->children = NULL; + content->type = ((role == XML_ROLE_CONTENT_ANY) ? + XML_CTYPE_ANY : + XML_CTYPE_EMPTY); + *eventEndPP = s; + elementDeclHandler(handlerArg, declElementType->name, content); + handleDefault = XML_FALSE; + } + dtd->in_eldecl = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_PCDATA: + if (dtd->in_eldecl) { + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel - 1]].type + = XML_CTYPE_MIXED; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_CONTENT_ELEMENT: + quant = XML_CQUANT_NONE; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_OPT: + quant = XML_CQUANT_OPT; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_REP: + quant = XML_CQUANT_REP; + goto elementContent; + case XML_ROLE_CONTENT_ELEMENT_PLUS: + quant = XML_CQUANT_PLUS; + elementContent: + if (dtd->in_eldecl) { + ELEMENT_TYPE *el; + const XML_Char *name; + int nameLen; + const char *nxt = (quant == XML_CQUANT_NONE + ? next + : next - enc->minBytesPerChar); + int myindex = nextScaffoldPart(parser); + if (myindex < 0) + return XML_ERROR_NO_MEMORY; + dtd->scaffold[myindex].type = XML_CTYPE_NAME; + dtd->scaffold[myindex].quant = quant; + el = getElementType(parser, enc, s, nxt); + if (!el) + return XML_ERROR_NO_MEMORY; + name = el->name; + dtd->scaffold[myindex].name = name; + nameLen = 0; + for (; name[nameLen++]; ); + dtd->contentStringLen += nameLen; + if (elementDeclHandler) + handleDefault = XML_FALSE; + } + break; + + case XML_ROLE_GROUP_CLOSE: + quant = XML_CQUANT_NONE; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_OPT: + quant = XML_CQUANT_OPT; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_REP: + quant = XML_CQUANT_REP; + goto closeGroup; + case XML_ROLE_GROUP_CLOSE_PLUS: + quant = XML_CQUANT_PLUS; + closeGroup: + if (dtd->in_eldecl) { + if (elementDeclHandler) + handleDefault = XML_FALSE; + dtd->scaffLevel--; + dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel]].quant = quant; + if (dtd->scaffLevel == 0) { + if (!handleDefault) { + XML_Content *model = build_model(parser); + if (!model) + return XML_ERROR_NO_MEMORY; + *eventEndPP = s; + elementDeclHandler(handlerArg, declElementType->name, model); + } + dtd->in_eldecl = XML_FALSE; + dtd->contentStringLen = 0; + } + } + break; + /* End element declaration stuff */ + + case XML_ROLE_PI: + if (!reportProcessingInstruction(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + handleDefault = XML_FALSE; + break; + case XML_ROLE_COMMENT: + if (!reportComment(parser, enc, s, next)) + return XML_ERROR_NO_MEMORY; + handleDefault = XML_FALSE; + break; + case XML_ROLE_NONE: + switch (tok) { + case XML_TOK_BOM: + handleDefault = XML_FALSE; + break; + } + break; + case XML_ROLE_DOCTYPE_NONE: + if (startDoctypeDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ENTITY_NONE: + if (dtd->keepProcessing && entityDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_NOTATION_NONE: + if (notationDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ATTLIST_NONE: + if (dtd->keepProcessing && attlistDeclHandler) + handleDefault = XML_FALSE; + break; + case XML_ROLE_ELEMENT_NONE: + if (elementDeclHandler) + handleDefault = XML_FALSE; + break; + } /* end of big switch */ + + if (handleDefault && defaultHandler) + reportDefault(parser, enc, s, next); + + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: + s = next; + tok = XmlPrologTok(enc, s, end, &next); + } + } + /* not reached */ +} + +static enum XML_Error PTRCALL +epilogProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + processor = epilogProcessor; + eventPtr = s; + for (;;) { + const char *next = NULL; + int tok = XmlPrologTok(encoding, s, end, &next); + eventEndPtr = next; + switch (tok) { + /* report partial linebreak - it might be the last token */ + case -XML_TOK_PROLOG_S: + if (defaultHandler) { + reportDefault(parser, encoding, s, next); + if (ps_parsing == XML_FINISHED) + return XML_ERROR_ABORTED; + } + *nextPtr = next; + return XML_ERROR_NONE; + case XML_TOK_NONE: + *nextPtr = s; + return XML_ERROR_NONE; + case XML_TOK_PROLOG_S: + if (defaultHandler) + reportDefault(parser, encoding, s, next); + break; + case XML_TOK_PI: + if (!reportProcessingInstruction(parser, encoding, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_COMMENT: + if (!reportComment(parser, encoding, s, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_INVALID: + eventPtr = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (!ps_finalBuffer) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_UNCLOSED_TOKEN; + case XML_TOK_PARTIAL_CHAR: + if (!ps_finalBuffer) { + *nextPtr = s; + return XML_ERROR_NONE; + } + return XML_ERROR_PARTIAL_CHAR; + default: + return XML_ERROR_JUNK_AFTER_DOC_ELEMENT; + } + eventPtr = s = next; + switch (ps_parsing) { + case XML_SUSPENDED: + *nextPtr = next; + return XML_ERROR_NONE; + case XML_FINISHED: + return XML_ERROR_ABORTED; + default: ; + } + } +} + +static enum XML_Error +processInternalEntity(XML_Parser parser, ENTITY *entity, + XML_Bool betweenDecl) +{ + const char *textStart, *textEnd; + const char *next; + enum XML_Error result; + OPEN_INTERNAL_ENTITY *openEntity; + + if (freeInternalEntities) { + openEntity = freeInternalEntities; + freeInternalEntities = openEntity->next; + } + else { + openEntity = (OPEN_INTERNAL_ENTITY *)MALLOC(sizeof(OPEN_INTERNAL_ENTITY)); + if (!openEntity) + return XML_ERROR_NO_MEMORY; + } + entity->open = XML_TRUE; + entity->processed = 0; + openEntity->next = openInternalEntities; + openInternalEntities = openEntity; + openEntity->entity = entity; + openEntity->startTagLevel = tagLevel; + openEntity->betweenDecl = betweenDecl; + openEntity->internalEventPtr = NULL; + openEntity->internalEventEndPtr = NULL; + textStart = (char *)entity->textPtr; + textEnd = (char *)(entity->textPtr + entity->textLen); + +#ifdef XML_DTD + if (entity->is_param) { + int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, internalEncoding, textStart, textEnd, tok, + next, &next, XML_FALSE); + } + else +#endif /* XML_DTD */ + result = doContent(parser, tagLevel, internalEncoding, textStart, + textEnd, &next, XML_FALSE); + + if (result == XML_ERROR_NONE) { + if (textEnd != next && ps_parsing == XML_SUSPENDED) { + entity->processed = (int)(next - textStart); + processor = internalEntityProcessor; + } + else { + entity->open = XML_FALSE; + openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + } + return result; +} + +static enum XML_Error PTRCALL +internalEntityProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + ENTITY *entity; + const char *textStart, *textEnd; + const char *next; + enum XML_Error result; + OPEN_INTERNAL_ENTITY *openEntity = openInternalEntities; + if (!openEntity) + return XML_ERROR_UNEXPECTED_STATE; + + entity = openEntity->entity; + textStart = ((char *)entity->textPtr) + entity->processed; + textEnd = (char *)(entity->textPtr + entity->textLen); + +#ifdef XML_DTD + if (entity->is_param) { + int tok = XmlPrologTok(internalEncoding, textStart, textEnd, &next); + result = doProlog(parser, internalEncoding, textStart, textEnd, tok, + next, &next, XML_FALSE); + } + else +#endif /* XML_DTD */ + result = doContent(parser, openEntity->startTagLevel, internalEncoding, + textStart, textEnd, &next, XML_FALSE); + + if (result != XML_ERROR_NONE) + return result; + else if (textEnd != next && ps_parsing == XML_SUSPENDED) { + entity->processed = (int)(next - (char *)entity->textPtr); + return result; + } + else { + entity->open = XML_FALSE; + openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = freeInternalEntities; + freeInternalEntities = openEntity; + } + +#ifdef XML_DTD + if (entity->is_param) { + int tok; + processor = prologProcessor; + tok = XmlPrologTok(encoding, s, end, &next); + return doProlog(parser, encoding, s, end, tok, next, nextPtr, + (XML_Bool)!ps_finalBuffer); + } + else +#endif /* XML_DTD */ + { + processor = contentProcessor; + /* see externalEntityContentProcessor vs contentProcessor */ + return doContent(parser, parentParser ? 1 : 0, encoding, s, end, + nextPtr, (XML_Bool)!ps_finalBuffer); + } +} + +static enum XML_Error PTRCALL +errorProcessor(XML_Parser parser, + const char *s, + const char *end, + const char **nextPtr) +{ + UNUSED(s); + UNUSED(end); + UNUSED(nextPtr); + + return errorCode; +} + +static enum XML_Error +storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool) +{ + enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, + end, pool); + if (result) + return result; + if (!isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) + poolChop(pool); + if (!poolAppendChar(pool, XML_T('\0'))) + return XML_ERROR_NO_MEMORY; + return XML_ERROR_NONE; +} + +static enum XML_Error +appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + for (;;) { + const char *next; + int tok = XmlAttributeValueTok(enc, ptr, end, &next); + switch (tok) { + case XML_TOK_NONE: + return XML_ERROR_NONE; + case XML_TOK_INVALID: + if (enc == encoding) + eventPtr = next; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_PARTIAL: + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_INVALID_TOKEN; + case XML_TOK_CHAR_REF: + { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, ptr); + if (n < 0) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + if (!isCdata + && n == 0x20 /* space */ + && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + n = XmlEncode(n, (ICHAR *)buf); + if (!n) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BAD_CHAR_REF; + } + for (i = 0; i < n; i++) { + if (!poolAppendChar(pool, buf[i])) + return XML_ERROR_NO_MEMORY; + } + } + break; + case XML_TOK_DATA_CHARS: + if (!poolAppend(pool, enc, ptr, next)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_TRAILING_CR: + next = ptr + enc->minBytesPerChar; + /* fall through */ + case XML_TOK_ATTRIBUTE_VALUE_S: + case XML_TOK_DATA_NEWLINE: + if (!isCdata && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) + break; + if (!poolAppendChar(pool, 0x20)) + return XML_ERROR_NO_MEMORY; + break; + case XML_TOK_ENTITY_REF: + { + const XML_Char *name; + ENTITY *entity; + char checkEntityDecl; + XML_Char ch = (XML_Char) XmlPredefinedEntityName(enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (ch) { + if (!poolAppendChar(pool, ch)) + return XML_ERROR_NO_MEMORY; + break; + } + name = poolStoreString(&temp2Pool, enc, + ptr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) + return XML_ERROR_NO_MEMORY; + entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0); + poolDiscard(&temp2Pool); + /* First, determine if a check for an existing declaration is needed; + if yes, check that the entity exists, and that it is internal. + */ + if (pool == &dtd->pool) /* are we called from prolog? */ + checkEntityDecl = +#ifdef XML_DTD + prologState.documentEntity && +#endif /* XML_DTD */ + (dtd->standalone + ? !openInternalEntities + : !dtd->hasParamEntityRefs); + else /* if (pool == &tempPool): we are called from content */ + checkEntityDecl = !dtd->hasParamEntityRefs || dtd->standalone; + if (checkEntityDecl) { + if (!entity) + return XML_ERROR_UNDEFINED_ENTITY; + else if (!entity->is_internal) + return XML_ERROR_ENTITY_DECLARED_IN_PE; + } + else if (!entity) { + /* Cannot report skipped entity here - see comments on + skippedEntityHandler. + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + */ + /* Cannot call the default handler because this would be + out of sync with the call to the startElementHandler. + if ((pool == &tempPool) && defaultHandler) + reportDefault(parser, enc, ptr, next); + */ + break; + } + if (entity->open) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_RECURSIVE_ENTITY_REF; + } + if (entity->notation) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_BINARY_ENTITY_REF; + } + if (!entity->textPtr) { + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF; + } + else { + enum XML_Error result; + const XML_Char *textEnd = entity->textPtr + entity->textLen; + entity->open = XML_TRUE; + result = appendAttributeValue(parser, internalEncoding, isCdata, + (char *)entity->textPtr, + (char *)textEnd, pool); + entity->open = XML_FALSE; + if (result) + return result; + } + } + break; + default: + if (enc == encoding) + eventPtr = ptr; + return XML_ERROR_UNEXPECTED_STATE; + } + ptr = next; + } + /* not reached */ +} + +static enum XML_Error +storeEntityValue(XML_Parser parser, + const ENCODING *enc, + const char *entityTextPtr, + const char *entityTextEnd) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + STRING_POOL *pool = &(dtd->entityValuePool); + enum XML_Error result = XML_ERROR_NONE; +#ifdef XML_DTD + int oldInEntityValue = prologState.inEntityValue; + prologState.inEntityValue = 1; +#endif /* XML_DTD */ + /* never return Null for the value argument in EntityDeclHandler, + since this would indicate an external entity; therefore we + have to make sure that entityValuePool.start is not null */ + if (!pool->blocks) { + if (!poolGrow(pool)) + return XML_ERROR_NO_MEMORY; + } + + for (;;) { + const char *next; + int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next); + switch (tok) { + case XML_TOK_PARAM_ENTITY_REF: +#ifdef XML_DTD + if (isParamEntity || enc != encoding) { + const XML_Char *name; + ENTITY *entity; + name = poolStoreString(&tempPool, enc, + entityTextPtr + enc->minBytesPerChar, + next - enc->minBytesPerChar); + if (!name) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0); + poolDiscard(&tempPool); + if (!entity) { + /* not a well-formedness error - see XML 1.0: WFC Entity Declared */ + /* cannot report skipped entity here - see comments on + skippedEntityHandler + if (skippedEntityHandler) + skippedEntityHandler(handlerArg, name, 0); + */ + dtd->keepProcessing = dtd->standalone; + goto endEntityValue; + } + if (entity->open) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_RECURSIVE_ENTITY_REF; + goto endEntityValue; + } + if (entity->systemId) { + if (externalEntityRefHandler) { + dtd->paramEntityRead = XML_FALSE; + entity->open = XML_TRUE; + if (!externalEntityRefHandler(externalEntityRefHandlerArg, + 0, + entity->base, + entity->systemId, + entity->publicId)) { + entity->open = XML_FALSE; + result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; + goto endEntityValue; + } + entity->open = XML_FALSE; + if (!dtd->paramEntityRead) + dtd->keepProcessing = dtd->standalone; + } + else + dtd->keepProcessing = dtd->standalone; + } + else { + entity->open = XML_TRUE; + result = storeEntityValue(parser, + internalEncoding, + (char *)entity->textPtr, + (char *)(entity->textPtr + + entity->textLen)); + entity->open = XML_FALSE; + if (result) + goto endEntityValue; + } + break; + } +#endif /* XML_DTD */ + /* In the internal subset, PE references are not legal + within markup declarations, e.g entity values in this case. */ + eventPtr = entityTextPtr; + result = XML_ERROR_PARAM_ENTITY_REF; + goto endEntityValue; + case XML_TOK_NONE: + result = XML_ERROR_NONE; + goto endEntityValue; + case XML_TOK_ENTITY_REF: + case XML_TOK_DATA_CHARS: + if (!poolAppend(pool, enc, entityTextPtr, next)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + break; + case XML_TOK_TRAILING_CR: + next = entityTextPtr + enc->minBytesPerChar; + /* fall through */ + case XML_TOK_DATA_NEWLINE: + if (pool->end == pool->ptr && !poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = 0xA; + break; + case XML_TOK_CHAR_REF: + { + XML_Char buf[XML_ENCODE_MAX]; + int i; + int n = XmlCharRefNumber(enc, entityTextPtr); + if (n < 0) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + n = XmlEncode(n, (ICHAR *)buf); + if (!n) { + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_BAD_CHAR_REF; + goto endEntityValue; + } + for (i = 0; i < n; i++) { + if (pool->end == pool->ptr && !poolGrow(pool)) { + result = XML_ERROR_NO_MEMORY; + goto endEntityValue; + } + *(pool->ptr)++ = buf[i]; + } + } + break; + case XML_TOK_PARTIAL: + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_INVALID_TOKEN; + goto endEntityValue; + case XML_TOK_INVALID: + if (enc == encoding) + eventPtr = next; + result = XML_ERROR_INVALID_TOKEN; + goto endEntityValue; + default: + if (enc == encoding) + eventPtr = entityTextPtr; + result = XML_ERROR_UNEXPECTED_STATE; + goto endEntityValue; + } + entityTextPtr = next; + } +endEntityValue: +#ifdef XML_DTD + prologState.inEntityValue = oldInEntityValue; +#endif /* XML_DTD */ + return result; +} + +static void FASTCALL +normalizeLines(XML_Char *s) +{ + XML_Char *p; + for (;; s++) { + if (*s == XML_T('\0')) + return; + if (*s == 0xD) + break; + } + p = s; + do { + if (*s == 0xD) { + *p++ = 0xA; + if (*++s == 0xA) + s++; + } + else + *p++ = *s++; + } while (*s); + *p = XML_T('\0'); +} + +static int +reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + const XML_Char *target; + XML_Char *data; + const char *tem; + if (!processingInstructionHandler) { + if (defaultHandler) + reportDefault(parser, enc, start, end); + return 1; + } + start += enc->minBytesPerChar * 2; + tem = start + XmlNameLength(enc, start); + target = poolStoreString(&tempPool, enc, start, tem); + if (!target) + return 0; + poolFinish(&tempPool); + data = poolStoreString(&tempPool, enc, + XmlSkipS(enc, tem), + end - enc->minBytesPerChar*2); + if (!data) + return 0; + normalizeLines(data); + processingInstructionHandler(handlerArg, target, data); + poolClear(&tempPool); + return 1; +} + +static int +reportComment(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + XML_Char *data; + if (!commentHandler) { + if (defaultHandler) + reportDefault(parser, enc, start, end); + return 1; + } + data = poolStoreString(&tempPool, + enc, + start + enc->minBytesPerChar * 4, + end - enc->minBytesPerChar * 3); + if (!data) + return 0; + normalizeLines(data); + commentHandler(handlerArg, data); + poolClear(&tempPool); + return 1; +} + +static void +reportDefault(XML_Parser parser, const ENCODING *enc, + const char *s, const char *end) +{ + if (MUST_CONVERT(enc, s)) { + const char **eventPP; + const char **eventEndPP; + if (enc == encoding) { + eventPP = &eventPtr; + eventEndPP = &eventEndPtr; + } + else { + eventPP = &(openInternalEntities->internalEventPtr); + eventEndPP = &(openInternalEntities->internalEventEndPtr); + } + do { + ICHAR *dataPtr = (ICHAR *)dataBuf; + XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd); + *eventEndPP = s; + defaultHandler(handlerArg, dataBuf, (int)(dataPtr - (ICHAR *)dataBuf)); + *eventPP = s; + } while (s != end); + } + else + defaultHandler(handlerArg, (XML_Char *)s, (int)((XML_Char *)end - (XML_Char *)s)); +} + + +static int +defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, + XML_Bool isId, const XML_Char *value, XML_Parser parser) +{ + DEFAULT_ATTRIBUTE *att; + if (value || isId) { + /* The handling of default attributes gets messed up if we have + a default which duplicates a non-default. */ + int i; + for (i = 0; i < type->nDefaultAtts; i++) + if (attId == type->defaultAtts[i].id) + return 1; + if (isId && !type->idAtt && !attId->xmlns) + type->idAtt = attId; + } + if (type->nDefaultAtts == type->allocDefaultAtts) { + if (type->allocDefaultAtts == 0) { + type->allocDefaultAtts = 8; + type->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(type->allocDefaultAtts + * sizeof(DEFAULT_ATTRIBUTE)); + if (!type->defaultAtts) + return 0; + } + else { + DEFAULT_ATTRIBUTE *temp; + int count = type->allocDefaultAtts * 2; + temp = (DEFAULT_ATTRIBUTE *) + REALLOC(type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); + if (temp == NULL) + return 0; + type->allocDefaultAtts = count; + type->defaultAtts = temp; + } + } + att = type->defaultAtts + type->nDefaultAtts; + att->id = attId; + att->value = value; + att->isCdata = isCdata; + if (!isCdata) + attId->maybeTokenized = XML_TRUE; + type->nDefaultAtts += 1; + return 1; +} + +static int +setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *name; + for (name = elementType->name; *name; name++) { + if (*name == XML_T(':')) { + PREFIX *prefix; + const XML_Char *s; + for (s = elementType->name; s != name; s++) { + if (!poolAppendChar(&dtd->pool, *s)) + return 0; + } + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return 0; + prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), + sizeof(PREFIX)); + if (!prefix) + return 0; + if (prefix->name == poolStart(&dtd->pool)) + poolFinish(&dtd->pool); + else + poolDiscard(&dtd->pool); + elementType->prefix = prefix; + + } + } + return 1; +} + +static ATTRIBUTE_ID * +getAttributeId(XML_Parser parser, const ENCODING *enc, + const char *start, const char *end) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + ATTRIBUTE_ID *id; + const XML_Char *name; + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return NULL; + name = poolStoreString(&dtd->pool, enc, start, end); + if (!name) + return NULL; + /* skip quotation mark - its storage will be re-used (like in name[-1]) */ + ++name; + id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); + if (!id) + return NULL; + if (id->name != name) + poolDiscard(&dtd->pool); + else { + poolFinish(&dtd->pool); + if (!ns) + ; + else if (name[0] == XML_T('x') + && name[1] == XML_T('m') + && name[2] == XML_T('l') + && name[3] == XML_T('n') + && name[4] == XML_T('s') + && (name[5] == XML_T('\0') || name[5] == XML_T(':'))) { + if (name[5] == XML_T('\0')) + id->prefix = &dtd->defaultPrefix; + else + id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX)); + id->xmlns = XML_TRUE; + } + else { + int i; + for (i = 0; name[i]; i++) { + /* attributes without prefix are *not* in the default namespace */ + if (name[i] == XML_T(':')) { + int j; + for (j = 0; j < i; j++) { + if (!poolAppendChar(&dtd->pool, name[j])) + return NULL; + } + if (!poolAppendChar(&dtd->pool, XML_T('\0'))) + return NULL; + id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool), + sizeof(PREFIX)); + if (id->prefix->name == poolStart(&dtd->pool)) + poolFinish(&dtd->pool); + else + poolDiscard(&dtd->pool); + break; + } + } + } + } + return id; +} + +#define CONTEXT_SEP XML_T('\f') + +static const XML_Char * +getContext(XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + HASH_TABLE_ITER iter; + XML_Bool needSep = XML_FALSE; + + if (dtd->defaultPrefix.binding) { + int i; + int len; + if (!poolAppendChar(&tempPool, XML_T('='))) + return NULL; + len = dtd->defaultPrefix.binding->uriLen; + if (namespaceSeparator) + len--; + for (i = 0; i < len; i++) + if (!poolAppendChar(&tempPool, dtd->defaultPrefix.binding->uri[i])) + return NULL; + needSep = XML_TRUE; + } + + hashTableIterInit(&iter, &(dtd->prefixes)); + for (;;) { + int i; + int len; + const XML_Char *s; + PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter); + if (!prefix) + break; + if (!prefix->binding) + continue; + if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) + return NULL; + for (s = prefix->name; *s; s++) + if (!poolAppendChar(&tempPool, *s)) + return NULL; + if (!poolAppendChar(&tempPool, XML_T('='))) + return NULL; + len = prefix->binding->uriLen; + if (namespaceSeparator) + len--; + for (i = 0; i < len; i++) + if (!poolAppendChar(&tempPool, prefix->binding->uri[i])) + return NULL; + needSep = XML_TRUE; + } + + + hashTableIterInit(&iter, &(dtd->generalEntities)); + for (;;) { + const XML_Char *s; + ENTITY *e = (ENTITY *)hashTableIterNext(&iter); + if (!e) + break; + if (!e->open) + continue; + if (needSep && !poolAppendChar(&tempPool, CONTEXT_SEP)) + return NULL; + for (s = e->name; *s; s++) + if (!poolAppendChar(&tempPool, *s)) + return 0; + needSep = XML_TRUE; + } + + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return NULL; + return tempPool.start; +} + +static XML_Bool +setContext(XML_Parser parser, const XML_Char *context) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *s = context; + + while (*context != XML_T('\0')) { + if (*s == CONTEXT_SEP || *s == XML_T('\0')) { + ENTITY *e; + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0); + if (e) + e->open = XML_TRUE; + if (*s != XML_T('\0')) + s++; + context = s; + poolDiscard(&tempPool); + } + else if (*s == XML_T('=')) { + PREFIX *prefix; + if (poolLength(&tempPool) == 0) + prefix = &dtd->defaultPrefix; + else { + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool), + sizeof(PREFIX)); + if (!prefix) + return XML_FALSE; + if (prefix->name == poolStart(&tempPool)) { + prefix->name = poolCopyString(&dtd->pool, prefix->name); + if (!prefix->name) + return XML_FALSE; + } + poolDiscard(&tempPool); + } + for (context = s + 1; + *context != CONTEXT_SEP && *context != XML_T('\0'); + context++) + if (!poolAppendChar(&tempPool, *context)) + return XML_FALSE; + if (!poolAppendChar(&tempPool, XML_T('\0'))) + return XML_FALSE; + if (addBinding(parser, prefix, NULL, poolStart(&tempPool), + &inheritedBindings) != XML_ERROR_NONE) + return XML_FALSE; + poolDiscard(&tempPool); + if (*context != XML_T('\0')) + ++context; + s = context; + } + else { + if (!poolAppendChar(&tempPool, *s)) + return XML_FALSE; + s++; + } + } + return XML_TRUE; +} + +static void FASTCALL +normalizePublicId(XML_Char *publicId) +{ + XML_Char *p = publicId; + XML_Char *s; + for (s = publicId; *s; s++) { + switch (*s) { + case 0x20: + case 0xD: + case 0xA: + if (p != publicId && p[-1] != 0x20) + *p++ = 0x20; + break; + default: + *p++ = *s; + } + } + if (p != publicId && p[-1] == 0x20) + --p; + *p = XML_T('\0'); +} + +static DTD * +dtdCreate(const XML_Memory_Handling_Suite *ms) +{ + DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); + if (p == NULL) + return p; + poolInit(&(p->pool), ms); + poolInit(&(p->entityValuePool), ms); + hashTableInit(&(p->generalEntities), ms); + hashTableInit(&(p->elementTypes), ms); + hashTableInit(&(p->attributeIds), ms); + hashTableInit(&(p->prefixes), ms); +#ifdef XML_DTD + p->paramEntityRead = XML_FALSE; + hashTableInit(&(p->paramEntities), ms); +#endif /* XML_DTD */ + p->defaultPrefix.name = NULL; + p->defaultPrefix.binding = NULL; + + p->in_eldecl = XML_FALSE; + p->scaffIndex = NULL; + p->scaffold = NULL; + p->scaffLevel = 0; + p->scaffSize = 0; + p->scaffCount = 0; + p->contentStringLen = 0; + + p->keepProcessing = XML_TRUE; + p->hasParamEntityRefs = XML_FALSE; + p->standalone = XML_FALSE; + return p; +} + +static void +dtdReset(DTD *p, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + hashTableIterInit(&iter, &(p->elementTypes)); + for (;;) { + ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!e) + break; + if (e->allocDefaultAtts != 0) + ms->free_fcn(e->defaultAtts); + } + hashTableClear(&(p->generalEntities)); +#ifdef XML_DTD + p->paramEntityRead = XML_FALSE; + hashTableClear(&(p->paramEntities)); +#endif /* XML_DTD */ + hashTableClear(&(p->elementTypes)); + hashTableClear(&(p->attributeIds)); + hashTableClear(&(p->prefixes)); + poolClear(&(p->pool)); + poolClear(&(p->entityValuePool)); + p->defaultPrefix.name = NULL; + p->defaultPrefix.binding = NULL; + + p->in_eldecl = XML_FALSE; + + ms->free_fcn(p->scaffIndex); + p->scaffIndex = NULL; + ms->free_fcn(p->scaffold); + p->scaffold = NULL; + + p->scaffLevel = 0; + p->scaffSize = 0; + p->scaffCount = 0; + p->contentStringLen = 0; + + p->keepProcessing = XML_TRUE; + p->hasParamEntityRefs = XML_FALSE; + p->standalone = XML_FALSE; +} + +static void +dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + hashTableIterInit(&iter, &(p->elementTypes)); + for (;;) { + ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!e) + break; + if (e->allocDefaultAtts != 0) + ms->free_fcn(e->defaultAtts); + } + hashTableDestroy(&(p->generalEntities)); +#ifdef XML_DTD + hashTableDestroy(&(p->paramEntities)); +#endif /* XML_DTD */ + hashTableDestroy(&(p->elementTypes)); + hashTableDestroy(&(p->attributeIds)); + hashTableDestroy(&(p->prefixes)); + poolDestroy(&(p->pool)); + poolDestroy(&(p->entityValuePool)); + if (isDocEntity) { + ms->free_fcn(p->scaffIndex); + ms->free_fcn(p->scaffold); + } + ms->free_fcn(p); +} + +/* Do a deep copy of the DTD. Return 0 for out of memory, non-zero otherwise. + The new DTD has already been initialized. +*/ +static int +dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms) +{ + HASH_TABLE_ITER iter; + + /* Copy the prefix table. */ + + hashTableIterInit(&iter, &(oldDtd->prefixes)); + for (;;) { + const XML_Char *name; + const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter); + if (!oldP) + break; + name = poolCopyString(&(newDtd->pool), oldP->name); + if (!name) + return 0; + if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX))) + return 0; + } + + hashTableIterInit(&iter, &(oldDtd->attributeIds)); + + /* Copy the attribute id table. */ + + for (;;) { + ATTRIBUTE_ID *newA; + const XML_Char *name; + const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter); + + if (!oldA) + break; + /* Remember to allocate the scratch byte before the name. */ + if (!poolAppendChar(&(newDtd->pool), XML_T('\0'))) + return 0; + name = poolCopyString(&(newDtd->pool), oldA->name); + if (!name) + return 0; + ++name; + newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, + sizeof(ATTRIBUTE_ID)); + if (!newA) + return 0; + newA->maybeTokenized = oldA->maybeTokenized; + if (oldA->prefix) { + newA->xmlns = oldA->xmlns; + if (oldA->prefix == &oldDtd->defaultPrefix) + newA->prefix = &newDtd->defaultPrefix; + else + newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), + oldA->prefix->name, 0); + } + } + + /* Copy the element type table. */ + + hashTableIterInit(&iter, &(oldDtd->elementTypes)); + + for (;;) { + int i; + ELEMENT_TYPE *newE; + const XML_Char *name; + const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter); + if (!oldE) + break; + name = poolCopyString(&(newDtd->pool), oldE->name); + if (!name) + return 0; + newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, + sizeof(ELEMENT_TYPE)); + if (!newE) + return 0; + if (oldE->nDefaultAtts) { + newE->defaultAtts = (DEFAULT_ATTRIBUTE *) + ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); + if (!newE->defaultAtts) { + ms->free_fcn(newE); + return 0; + } + } + if (oldE->idAtt) + newE->idAtt = (ATTRIBUTE_ID *) + lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); + newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; + if (oldE->prefix) + newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), + oldE->prefix->name, 0); + for (i = 0; i < newE->nDefaultAtts; i++) { + newE->defaultAtts[i].id = (ATTRIBUTE_ID *) + lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); + newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; + if (oldE->defaultAtts[i].value) { + newE->defaultAtts[i].value + = poolCopyString(&(newDtd->pool), oldE->defaultAtts[i].value); + if (!newE->defaultAtts[i].value) + return 0; + } + else + newE->defaultAtts[i].value = NULL; + } + } + + /* Copy the entity tables. */ + if (!copyEntityTable(&(newDtd->generalEntities), + &(newDtd->pool), + &(oldDtd->generalEntities))) + return 0; + +#ifdef XML_DTD + if (!copyEntityTable(&(newDtd->paramEntities), + &(newDtd->pool), + &(oldDtd->paramEntities))) + return 0; + newDtd->paramEntityRead = oldDtd->paramEntityRead; +#endif /* XML_DTD */ + + newDtd->keepProcessing = oldDtd->keepProcessing; + newDtd->hasParamEntityRefs = oldDtd->hasParamEntityRefs; + newDtd->standalone = oldDtd->standalone; + + /* Don't want deep copying for scaffolding */ + newDtd->in_eldecl = oldDtd->in_eldecl; + newDtd->scaffold = oldDtd->scaffold; + newDtd->contentStringLen = oldDtd->contentStringLen; + newDtd->scaffSize = oldDtd->scaffSize; + newDtd->scaffLevel = oldDtd->scaffLevel; + newDtd->scaffIndex = oldDtd->scaffIndex; + + return 1; +} /* End dtdCopy */ + +static int +copyEntityTable(HASH_TABLE *newTable, + STRING_POOL *newPool, + const HASH_TABLE *oldTable) +{ + HASH_TABLE_ITER iter; + const XML_Char *cachedOldBase = NULL; + const XML_Char *cachedNewBase = NULL; + + hashTableIterInit(&iter, oldTable); + + for (;;) { + ENTITY *newE; + const XML_Char *name; + const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter); + if (!oldE) + break; + name = poolCopyString(newPool, oldE->name); + if (!name) + return 0; + newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY)); + if (!newE) + return 0; + if (oldE->systemId) { + const XML_Char *tem = poolCopyString(newPool, oldE->systemId); + if (!tem) + return 0; + newE->systemId = tem; + if (oldE->base) { + if (oldE->base == cachedOldBase) + newE->base = cachedNewBase; + else { + cachedOldBase = oldE->base; + tem = poolCopyString(newPool, cachedOldBase); + if (!tem) + return 0; + cachedNewBase = newE->base = tem; + } + } + if (oldE->publicId) { + tem = poolCopyString(newPool, oldE->publicId); + if (!tem) + return 0; + newE->publicId = tem; + } + } + else { + const XML_Char *tem = poolCopyStringN(newPool, oldE->textPtr, + oldE->textLen); + if (!tem) + return 0; + newE->textPtr = tem; + newE->textLen = oldE->textLen; + } + if (oldE->notation) { + const XML_Char *tem = poolCopyString(newPool, oldE->notation); + if (!tem) + return 0; + newE->notation = tem; + } + newE->is_param = oldE->is_param; + newE->is_internal = oldE->is_internal; + } + return 1; +} + +#define INIT_POWER 6 + +static XML_Bool FASTCALL +keyeq(KEY s1, KEY s2) +{ + for (; *s1 == *s2; s1++, s2++) + if (*s1 == 0) + return XML_TRUE; + return XML_FALSE; +} + +static unsigned long FASTCALL +hash(KEY s) +{ + unsigned long h = 0; + while (*s) + h = CHAR_HASH(h, *s++); + return h; +} + +static NAMED * +lookup(HASH_TABLE *table, KEY name, size_t createSize) +{ + size_t i; + if (table->size == 0) { + size_t tsize; + if (!createSize) + return NULL; + table->power = INIT_POWER; + /* table->size is a power of 2 */ + table->size = (size_t)1 << INIT_POWER; + tsize = table->size * sizeof(NAMED *); + table->v = (NAMED **)table->mem->malloc_fcn(tsize); + if (!table->v) { + table->size = 0; + return NULL; + } + memset(table->v, 0, tsize); + i = hash(name) & ((unsigned long)table->size - 1); + } + else { + unsigned long h = hash(name); + unsigned long mask = (unsigned long)table->size - 1; + unsigned char step = 0; + i = h & mask; + while (table->v[i]) { + if (keyeq(name, table->v[i]->name)) + return table->v[i]; + if (!step) + step = PROBE_STEP(h, mask, table->power); + i < step ? (i += table->size - step) : (i -= step); + } + if (!createSize) + return NULL; + + /* check for overflow (table is half full) */ + if (table->used >> (table->power - 1)) { + unsigned char newPower = table->power + 1; + size_t newSize = (size_t)1 << newPower; + unsigned long newMask = (unsigned long)newSize - 1; + size_t tsize = newSize * sizeof(NAMED *); + NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); + if (!newV) + return NULL; + memset(newV, 0, tsize); + for (i = 0; i < table->size; i++) + if (table->v[i]) { + unsigned long newHash = hash(table->v[i]->name); + size_t j = newHash & newMask; + step = 0; + while (newV[j]) { + if (!step) + step = PROBE_STEP(newHash, newMask, newPower); + j < step ? (j += newSize - step) : (j -= step); + } + newV[j] = table->v[i]; + } + table->mem->free_fcn(table->v); + table->v = newV; + table->power = newPower; + table->size = newSize; + i = h & newMask; + step = 0; + while (table->v[i]) { + if (!step) + step = PROBE_STEP(h, newMask, newPower); + i < step ? (i += newSize - step) : (i -= step); + } + } + } + table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); + if (!table->v[i]) + return NULL; + memset(table->v[i], 0, createSize); + table->v[i]->name = name; + (table->used)++; + return table->v[i]; +} + +static void FASTCALL +hashTableClear(HASH_TABLE *table) +{ + size_t i; + for (i = 0; i < table->size; i++) { + table->mem->free_fcn(table->v[i]); + table->v[i] = NULL; + } + table->used = 0; +} + +static void FASTCALL +hashTableDestroy(HASH_TABLE *table) +{ + size_t i; + for (i = 0; i < table->size; i++) + table->mem->free_fcn(table->v[i]); + table->mem->free_fcn(table->v); +} + +static void FASTCALL +hashTableInit(HASH_TABLE *p, const XML_Memory_Handling_Suite *ms) +{ + p->power = 0; + p->size = 0; + p->used = 0; + p->v = NULL; + p->mem = ms; +} + +static void FASTCALL +hashTableIterInit(HASH_TABLE_ITER *iter, const HASH_TABLE *table) +{ + iter->p = table->v; + iter->end = iter->p + table->size; +} + +static NAMED * FASTCALL +hashTableIterNext(HASH_TABLE_ITER *iter) +{ + while (iter->p != iter->end) { + NAMED *tem = *(iter->p)++; + if (tem) + return tem; + } + return NULL; +} + +static void FASTCALL +poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms) +{ + pool->blocks = NULL; + pool->freeBlocks = NULL; + pool->start = NULL; + pool->ptr = NULL; + pool->end = NULL; + pool->mem = ms; +} + +static void FASTCALL +poolClear(STRING_POOL *pool) +{ + if (!pool->freeBlocks) + pool->freeBlocks = pool->blocks; + else { + BLOCK *p = pool->blocks; + while (p) { + BLOCK *tem = p->next; + p->next = pool->freeBlocks; + pool->freeBlocks = p; + p = tem; + } + } + pool->blocks = NULL; + pool->start = NULL; + pool->ptr = NULL; + pool->end = NULL; +} + +static void FASTCALL +poolDestroy(STRING_POOL *pool) +{ + BLOCK *p = pool->blocks; + while (p) { + BLOCK *tem = p->next; + pool->mem->free_fcn(p); + p = tem; + } + p = pool->freeBlocks; + while (p) { + BLOCK *tem = p->next; + pool->mem->free_fcn(p); + p = tem; + } +} + +static XML_Char * +poolAppend(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end) +{ + if (!pool->ptr && !poolGrow(pool)) + return NULL; + for (;;) { + XmlConvert(enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); + if (ptr == end) + break; + if (!poolGrow(pool)) + return NULL; + } + return pool->start; +} + +static const XML_Char * FASTCALL +poolCopyString(STRING_POOL *pool, const XML_Char *s) +{ + do { + if (!poolAppendChar(pool, *s)) + return NULL; + } while (*s++); + s = pool->start; + poolFinish(pool); + return s; +} + +static const XML_Char * +poolCopyStringN(STRING_POOL *pool, const XML_Char *s, int n) +{ + if (!pool->ptr && !poolGrow(pool)) + return NULL; + for (; n > 0; --n, s++) { + if (!poolAppendChar(pool, *s)) + return NULL; + } + s = pool->start; + poolFinish(pool); + return s; +} + +static const XML_Char * FASTCALL +poolAppendString(STRING_POOL *pool, const XML_Char *s) +{ + while (*s) { + if (!poolAppendChar(pool, *s)) + return NULL; + s++; + } + return pool->start; +} + +static XML_Char * +poolStoreString(STRING_POOL *pool, const ENCODING *enc, + const char *ptr, const char *end) +{ + if (!poolAppend(pool, enc, ptr, end)) + return NULL; + if (pool->ptr == pool->end && !poolGrow(pool)) + return NULL; + *(pool->ptr)++ = 0; + return pool->start; +} + +static XML_Bool FASTCALL +poolGrow(STRING_POOL *pool) +{ + if (pool->freeBlocks) { + if (pool->start == 0) { + pool->blocks = pool->freeBlocks; + pool->freeBlocks = pool->freeBlocks->next; + pool->blocks->next = NULL; + pool->start = pool->blocks->s; + pool->end = pool->start + pool->blocks->size; + pool->ptr = pool->start; + return XML_TRUE; + } + if (pool->end - pool->start < pool->freeBlocks->size) { + BLOCK *tem = pool->freeBlocks->next; + pool->freeBlocks->next = pool->blocks; + pool->blocks = pool->freeBlocks; + pool->freeBlocks = tem; + memcpy(pool->blocks->s, pool->start, + (pool->end - pool->start) * sizeof(XML_Char)); + pool->ptr = pool->blocks->s + (pool->ptr - pool->start); + pool->start = pool->blocks->s; + pool->end = pool->start + pool->blocks->size; + return XML_TRUE; + } + } + if (pool->blocks && pool->start == pool->blocks->s) { + int blockSize = (int)(pool->end - pool->start)*2; + pool->blocks = (BLOCK *) + pool->mem->realloc_fcn(pool->blocks, + (offsetof(BLOCK, s) + + blockSize * sizeof(XML_Char))); + if (pool->blocks == NULL) + return XML_FALSE; + pool->blocks->size = blockSize; + pool->ptr = pool->blocks->s + (pool->ptr - pool->start); + pool->start = pool->blocks->s; + pool->end = pool->start + blockSize; + } + else { + BLOCK *tem; + int blockSize = (int)(pool->end - pool->start); + if (blockSize < INIT_BLOCK_SIZE) + blockSize = INIT_BLOCK_SIZE; + else + blockSize *= 2; + tem = (BLOCK *)pool->mem->malloc_fcn(offsetof(BLOCK, s) + + blockSize * sizeof(XML_Char)); + if (!tem) + return XML_FALSE; + tem->size = blockSize; + tem->next = pool->blocks; + pool->blocks = tem; + if (pool->ptr != pool->start) + memcpy(tem->s, pool->start, + (pool->ptr - pool->start) * sizeof(XML_Char)); + pool->ptr = tem->s + (pool->ptr - pool->start); + pool->start = tem->s; + pool->end = tem->s + blockSize; + } + return XML_TRUE; +} + +static int FASTCALL +nextScaffoldPart(XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + CONTENT_SCAFFOLD * me; + int next; + + if (!dtd->scaffIndex) { + dtd->scaffIndex = (int *)MALLOC(groupSize * sizeof(int)); + if (!dtd->scaffIndex) + return -1; + dtd->scaffIndex[0] = 0; + } + + if (dtd->scaffCount >= dtd->scaffSize) { + CONTENT_SCAFFOLD *temp; + if (dtd->scaffold) { + temp = (CONTENT_SCAFFOLD *) + REALLOC(dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); + if (temp == NULL) + return -1; + dtd->scaffSize *= 2; + } + else { + temp = (CONTENT_SCAFFOLD *)MALLOC(INIT_SCAFFOLD_ELEMENTS + * sizeof(CONTENT_SCAFFOLD)); + if (temp == NULL) + return -1; + dtd->scaffSize = INIT_SCAFFOLD_ELEMENTS; + } + dtd->scaffold = temp; + } + next = dtd->scaffCount++; + me = &dtd->scaffold[next]; + if (dtd->scaffLevel) { + CONTENT_SCAFFOLD *parent = &dtd->scaffold[dtd->scaffIndex[dtd->scaffLevel-1]]; + if (parent->lastchild) { + dtd->scaffold[parent->lastchild].nextsib = next; + } + if (!parent->childcnt) + parent->firstchild = next; + parent->lastchild = next; + parent->childcnt++; + } + me->firstchild = me->lastchild = me->childcnt = me->nextsib = 0; + return next; +} + +static void +build_node(XML_Parser parser, + int src_node, + XML_Content *dest, + XML_Content **contpos, + XML_Char **strpos) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + dest->type = dtd->scaffold[src_node].type; + dest->quant = dtd->scaffold[src_node].quant; + if (dest->type == XML_CTYPE_NAME) { + const XML_Char *src; + dest->name = *strpos; + src = dtd->scaffold[src_node].name; + for (;;) { + *(*strpos)++ = *src; + if (!*src) + break; + src++; + } + dest->numchildren = 0; + dest->children = NULL; + } + else { + unsigned int i; + int cn; + dest->numchildren = dtd->scaffold[src_node].childcnt; + dest->children = *contpos; + *contpos += dest->numchildren; + for (i = 0, cn = dtd->scaffold[src_node].firstchild; + i < dest->numchildren; + i++, cn = dtd->scaffold[cn].nextsib) { + build_node(parser, cn, &(dest->children[i]), contpos, strpos); + } + dest->name = NULL; + } +} + +static XML_Content * +build_model (XML_Parser parser) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + XML_Content *ret; + XML_Content *cpos; + XML_Char * str; + int allocsize = (dtd->scaffCount * sizeof(XML_Content) + + (dtd->contentStringLen * sizeof(XML_Char))); + + ret = (XML_Content *)MALLOC(allocsize); + if (!ret) + return NULL; + + str = (XML_Char *) (&ret[dtd->scaffCount]); + cpos = &ret[1]; + + build_node(parser, 0, ret, &cpos, &str); + return ret; +} + +static ELEMENT_TYPE * +getElementType(XML_Parser parser, + const ENCODING *enc, + const char *ptr, + const char *end) +{ + DTD * const dtd = _dtd; /* save one level of indirection */ + const XML_Char *name = poolStoreString(&dtd->pool, enc, ptr, end); + ELEMENT_TYPE *ret; + + if (!name) + return NULL; + ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE)); + if (!ret) + return NULL; + if (ret->name != name) + poolDiscard(&dtd->pool); + else { + poolFinish(&dtd->pool); + if (!setElementTypePrefix(parser, ret)) + return NULL; + } + return ret; +} diff --git a/libxsde/xsde/c/expat/xmlrole.c b/libxsde/xsde/c/expat/xmlrole.c new file mode 100644 index 0000000..f1bc407 --- /dev/null +++ b/libxsde/xsde/c/expat/xmlrole.c @@ -0,0 +1,1466 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include <stddef.h> + +#include "config.h" + +#include "expat_external.h" +#include "internal.h" +#include "xmlrole.h" +#include "ascii.h" + +/* Doesn't check: + + that ,| are not mixed in a model group + content of literals + +*/ + +static const char KW_ANY[] = { + ASCII_A, ASCII_N, ASCII_Y, '\0' }; +static const char KW_ATTLIST[] = { + ASCII_A, ASCII_T, ASCII_T, ASCII_L, ASCII_I, ASCII_S, ASCII_T, '\0' }; +static const char KW_CDATA[] = { + ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_DOCTYPE[] = { + ASCII_D, ASCII_O, ASCII_C, ASCII_T, ASCII_Y, ASCII_P, ASCII_E, '\0' }; +static const char KW_ELEMENT[] = { + ASCII_E, ASCII_L, ASCII_E, ASCII_M, ASCII_E, ASCII_N, ASCII_T, '\0' }; +static const char KW_EMPTY[] = { + ASCII_E, ASCII_M, ASCII_P, ASCII_T, ASCII_Y, '\0' }; +static const char KW_ENTITIES[] = { + ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_I, ASCII_E, ASCII_S, + '\0' }; +static const char KW_ENTITY[] = { + ASCII_E, ASCII_N, ASCII_T, ASCII_I, ASCII_T, ASCII_Y, '\0' }; +static const char KW_FIXED[] = { + ASCII_F, ASCII_I, ASCII_X, ASCII_E, ASCII_D, '\0' }; +static const char KW_ID[] = { + ASCII_I, ASCII_D, '\0' }; +static const char KW_IDREF[] = { + ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, '\0' }; +static const char KW_IDREFS[] = { + ASCII_I, ASCII_D, ASCII_R, ASCII_E, ASCII_F, ASCII_S, '\0' }; +static const char KW_IGNORE[] = { + ASCII_I, ASCII_G, ASCII_N, ASCII_O, ASCII_R, ASCII_E, '\0' }; +static const char KW_IMPLIED[] = { + ASCII_I, ASCII_M, ASCII_P, ASCII_L, ASCII_I, ASCII_E, ASCII_D, '\0' }; +static const char KW_INCLUDE[] = { + ASCII_I, ASCII_N, ASCII_C, ASCII_L, ASCII_U, ASCII_D, ASCII_E, '\0' }; +static const char KW_NDATA[] = { + ASCII_N, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_NMTOKEN[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, '\0' }; +static const char KW_NMTOKENS[] = { + ASCII_N, ASCII_M, ASCII_T, ASCII_O, ASCII_K, ASCII_E, ASCII_N, ASCII_S, + '\0' }; +static const char KW_NOTATION[] = + { ASCII_N, ASCII_O, ASCII_T, ASCII_A, ASCII_T, ASCII_I, ASCII_O, ASCII_N, + '\0' }; +static const char KW_PCDATA[] = { + ASCII_P, ASCII_C, ASCII_D, ASCII_A, ASCII_T, ASCII_A, '\0' }; +static const char KW_PUBLIC[] = { + ASCII_P, ASCII_U, ASCII_B, ASCII_L, ASCII_I, ASCII_C, '\0' }; +static const char KW_REQUIRED[] = { + ASCII_R, ASCII_E, ASCII_Q, ASCII_U, ASCII_I, ASCII_R, ASCII_E, ASCII_D, + '\0' }; +static const char KW_SYSTEM[] = { + ASCII_S, ASCII_Y, ASCII_S, ASCII_T, ASCII_E, ASCII_M, '\0' }; + +#ifndef MIN_BYTES_PER_CHAR +#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar) +#endif + +#ifdef XML_DTD +#define setTopLevel(state) \ + ((state)->handler = ((state)->documentEntity \ + ? internalSubset \ + : externalSubset1)) +#else /* not XML_DTD */ +#define setTopLevel(state) ((state)->handler = internalSubset) +#endif /* not XML_DTD */ + +typedef int PTRCALL PROLOG_HANDLER(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc); + +static PROLOG_HANDLER + prolog0, prolog1, prolog2, + doctype0, doctype1, doctype2, doctype3, doctype4, doctype5, + internalSubset, + entity0, entity1, entity2, entity3, entity4, entity5, entity6, + entity7, entity8, entity9, entity10, + notation0, notation1, notation2, notation3, notation4, + attlist0, attlist1, attlist2, attlist3, attlist4, attlist5, attlist6, + attlist7, attlist8, attlist9, + element0, element1, element2, element3, element4, element5, element6, + element7, +#ifdef XML_DTD + externalSubset0, externalSubset1, + condSect0, condSect1, condSect2, +#endif /* XML_DTD */ + declClose, + error; + +static int FASTCALL common(PROLOG_STATE *state, int tok); + +static int PTRCALL +prolog0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + state->handler = prolog1; + return XML_ROLE_NONE; + case XML_TOK_XML_DECL: + state->handler = prolog1; + return XML_ROLE_XML_DECL; + case XML_TOK_PI: + state->handler = prolog1; + return XML_ROLE_PI; + case XML_TOK_COMMENT: + state->handler = prolog1; + return XML_ROLE_COMMENT; + case XML_TOK_BOM: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (!XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_DOCTYPE)) + break; + state->handler = doctype0; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +prolog1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_BOM: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (!XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_DOCTYPE)) + break; + state->handler = doctype0; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +prolog2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_INSTANCE_START: + state->handler = error; + return XML_ROLE_INSTANCE_START; + } + return common(state, tok); +} + +static int PTRCALL +doctype0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = doctype1; + return XML_ROLE_DOCTYPE_NAME; + } + return common(state, tok); +} + +static int PTRCALL +doctype1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = internalSubset; + return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = doctype3; + return XML_ROLE_DOCTYPE_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = doctype2; + return XML_ROLE_DOCTYPE_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +doctype2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_LITERAL: + state->handler = doctype3; + return XML_ROLE_DOCTYPE_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +doctype3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_LITERAL: + state->handler = doctype4; + return XML_ROLE_DOCTYPE_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +doctype4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = internalSubset; + return XML_ROLE_DOCTYPE_INTERNAL_SUBSET; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + } + return common(state, tok); +} + +static int PTRCALL +doctype5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_DECL_CLOSE: + state->handler = prolog2; + return XML_ROLE_DOCTYPE_CLOSE; + } + return common(state, tok); +} + +static int PTRCALL +internalSubset(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_DECL_OPEN: + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ENTITY)) { + state->handler = entity0; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ATTLIST)) { + state->handler = attlist0; + return XML_ROLE_ATTLIST_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_ELEMENT)) { + state->handler = element0; + return XML_ROLE_ELEMENT_NONE; + } + if (XmlNameMatchesAscii(enc, + ptr + 2 * MIN_BYTES_PER_CHAR(enc), + end, + KW_NOTATION)) { + state->handler = notation0; + return XML_ROLE_NOTATION_NONE; + } + break; + case XML_TOK_PI: + return XML_ROLE_PI; + case XML_TOK_COMMENT: + return XML_ROLE_COMMENT; + case XML_TOK_PARAM_ENTITY_REF: + return XML_ROLE_PARAM_ENTITY_REF; + case XML_TOK_CLOSE_BRACKET: + state->handler = doctype5; + return XML_ROLE_DOCTYPE_NONE; + case XML_TOK_NONE: + return XML_ROLE_NONE; + } + return common(state, tok); +} + +#ifdef XML_DTD + +static int PTRCALL +externalSubset0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + state->handler = externalSubset1; + if (tok == XML_TOK_XML_DECL) + return XML_ROLE_TEXT_DECL; + return externalSubset1(state, tok, ptr, end, enc); +} + +static int PTRCALL +externalSubset1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_COND_SECT_OPEN: + state->handler = condSect0; + return XML_ROLE_NONE; + case XML_TOK_COND_SECT_CLOSE: + if (state->includeLevel == 0) + break; + state->includeLevel -= 1; + return XML_ROLE_NONE; + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_CLOSE_BRACKET: + break; + case XML_TOK_NONE: + if (state->includeLevel) + break; + return XML_ROLE_NONE; + default: + return internalSubset(state, tok, ptr, end, enc); + } + return common(state, tok); +} + +#endif /* XML_DTD */ + +static int PTRCALL +entity0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_PERCENT: + state->handler = entity1; + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = entity2; + return XML_ROLE_GENERAL_ENTITY_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = entity7; + return XML_ROLE_PARAM_ENTITY_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = entity4; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = entity3; + return XML_ROLE_ENTITY_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +entity3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity4; + return XML_ROLE_ENTITY_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity5; + return XML_ROLE_ENTITY_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ENTITY_COMPLETE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_NDATA)) { + state->handler = entity6; + return XML_ROLE_ENTITY_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +entity6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_NOTATION_NAME; + } + return common(state, tok); +} + +static int PTRCALL +entity7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = entity9; + return XML_ROLE_ENTITY_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = entity8; + return XML_ROLE_ENTITY_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_ENTITY_NONE; + return XML_ROLE_ENTITY_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +entity8(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity9; + return XML_ROLE_ENTITY_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity9(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_LITERAL: + state->handler = entity10; + return XML_ROLE_ENTITY_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +entity10(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ENTITY_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ENTITY_COMPLETE; + } + return common(state, tok); +} + +static int PTRCALL +notation0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_NAME: + state->handler = notation1; + return XML_ROLE_NOTATION_NAME; + } + return common(state, tok); +} + +static int PTRCALL +notation1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_SYSTEM)) { + state->handler = notation3; + return XML_ROLE_NOTATION_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_PUBLIC)) { + state->handler = notation2; + return XML_ROLE_NOTATION_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +notation2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = notation4; + return XML_ROLE_NOTATION_PUBLIC_ID; + } + return common(state, tok); +} + +static int PTRCALL +notation3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_NOTATION_NONE; + return XML_ROLE_NOTATION_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +notation4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NOTATION_NONE; + case XML_TOK_LITERAL: + state->handler = declClose; + state->role_none = XML_ROLE_NOTATION_NONE; + return XML_ROLE_NOTATION_SYSTEM_ID; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_NOTATION_NO_SYSTEM_ID; + } + return common(state, tok); +} + +static int PTRCALL +attlist0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist1; + return XML_ROLE_ATTLIST_ELEMENT_NAME; + } + return common(state, tok); +} + +static int PTRCALL +attlist1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist2; + return XML_ROLE_ATTRIBUTE_NAME; + } + return common(state, tok); +} + +static int PTRCALL +attlist2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + { + static const char * const types[] = { + KW_CDATA, + KW_ID, + KW_IDREF, + KW_IDREFS, + KW_ENTITY, + KW_ENTITIES, + KW_NMTOKEN, + KW_NMTOKENS, + }; + int i; + for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++) + if (XmlNameMatchesAscii(enc, ptr, end, types[i])) { + state->handler = attlist8; + return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i; + } + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_NOTATION)) { + state->handler = attlist5; + return XML_ROLE_ATTLIST_NONE; + } + break; + case XML_TOK_OPEN_PAREN: + state->handler = attlist3; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NMTOKEN: + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = attlist4; + return XML_ROLE_ATTRIBUTE_ENUM_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = attlist8; + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OR: + state->handler = attlist3; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OPEN_PAREN: + state->handler = attlist6; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +static int PTRCALL +attlist6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_NAME: + state->handler = attlist7; + return XML_ROLE_ATTRIBUTE_NOTATION_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = attlist8; + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_OR: + state->handler = attlist6; + return XML_ROLE_ATTLIST_NONE; + } + return common(state, tok); +} + +/* default value */ +static int PTRCALL +attlist8(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_POUND_NAME: + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_IMPLIED)) { + state->handler = attlist1; + return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE; + } + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_REQUIRED)) { + state->handler = attlist1; + return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE; + } + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_FIXED)) { + state->handler = attlist9; + return XML_ROLE_ATTLIST_NONE; + } + break; + case XML_TOK_LITERAL: + state->handler = attlist1; + return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +attlist9(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ATTLIST_NONE; + case XML_TOK_LITERAL: + state->handler = attlist1; + return XML_ROLE_FIXED_ATTRIBUTE_VALUE; + } + return common(state, tok); +} + +static int PTRCALL +element0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element1; + return XML_ROLE_ELEMENT_NAME; + } + return common(state, tok); +} + +static int PTRCALL +element1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_EMPTY)) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_CONTENT_EMPTY; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_ANY)) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_CONTENT_ANY; + } + break; + case XML_TOK_OPEN_PAREN: + state->handler = element2; + state->level = 1; + return XML_ROLE_GROUP_OPEN; + } + return common(state, tok); +} + +static int PTRCALL +element2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_POUND_NAME: + if (XmlNameMatchesAscii(enc, + ptr + MIN_BYTES_PER_CHAR(enc), + end, + KW_PCDATA)) { + state->handler = element3; + return XML_ROLE_CONTENT_PCDATA; + } + break; + case XML_TOK_OPEN_PAREN: + state->level = 2; + state->handler = element6; + return XML_ROLE_GROUP_OPEN; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT; + case XML_TOK_NAME_QUESTION: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_OPT; + case XML_TOK_NAME_ASTERISK: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_REP; + case XML_TOK_NAME_PLUS: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_PLUS; + } + return common(state, tok); +} + +static int PTRCALL +element3(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_OR: + state->handler = element4; + return XML_ROLE_ELEMENT_NONE; + } + return common(state, tok); +} + +static int PTRCALL +element4(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element5; + return XML_ROLE_CONTENT_ELEMENT; + } + return common(state, tok); +} + +static int PTRCALL +element5(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_OR: + state->handler = element4; + return XML_ROLE_ELEMENT_NONE; + } + return common(state, tok); +} + +static int PTRCALL +element6(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_OPEN_PAREN: + state->level += 1; + return XML_ROLE_GROUP_OPEN; + case XML_TOK_NAME: + case XML_TOK_PREFIXED_NAME: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT; + case XML_TOK_NAME_QUESTION: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_OPT; + case XML_TOK_NAME_ASTERISK: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_REP; + case XML_TOK_NAME_PLUS: + state->handler = element7; + return XML_ROLE_CONTENT_ELEMENT_PLUS; + } + return common(state, tok); +} + +static int PTRCALL +element7(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_ELEMENT_NONE; + case XML_TOK_CLOSE_PAREN: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE; + case XML_TOK_CLOSE_PAREN_ASTERISK: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_REP; + case XML_TOK_CLOSE_PAREN_QUESTION: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_OPT; + case XML_TOK_CLOSE_PAREN_PLUS: + state->level -= 1; + if (state->level == 0) { + state->handler = declClose; + state->role_none = XML_ROLE_ELEMENT_NONE; + } + return XML_ROLE_GROUP_CLOSE_PLUS; + case XML_TOK_COMMA: + state->handler = element6; + return XML_ROLE_GROUP_SEQUENCE; + case XML_TOK_OR: + state->handler = element6; + return XML_ROLE_GROUP_CHOICE; + } + return common(state, tok); +} + +#ifdef XML_DTD + +static int PTRCALL +condSect0(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_NAME: + if (XmlNameMatchesAscii(enc, ptr, end, KW_INCLUDE)) { + state->handler = condSect1; + return XML_ROLE_NONE; + } + if (XmlNameMatchesAscii(enc, ptr, end, KW_IGNORE)) { + state->handler = condSect2; + return XML_ROLE_NONE; + } + break; + } + return common(state, tok); +} + +static int PTRCALL +condSect1(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = externalSubset1; + state->includeLevel += 1; + return XML_ROLE_NONE; + } + return common(state, tok); +} + +static int PTRCALL +condSect2(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return XML_ROLE_NONE; + case XML_TOK_OPEN_BRACKET: + state->handler = externalSubset1; + return XML_ROLE_IGNORE_SECT; + } + return common(state, tok); +} + +#endif /* XML_DTD */ + +static int PTRCALL +declClose(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + switch (tok) { + case XML_TOK_PROLOG_S: + return state->role_none; + case XML_TOK_DECL_CLOSE: + setTopLevel(state); + return state->role_none; + } + return common(state, tok); +} + +static int PTRCALL +error(PROLOG_STATE *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc) +{ + UNUSED(state); + UNUSED(tok); + UNUSED(ptr); + UNUSED(end); + UNUSED(enc); + + return XML_ROLE_NONE; +} + +static int FASTCALL +common(PROLOG_STATE *state, int tok) +{ +#ifdef XML_DTD + if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF) + return XML_ROLE_INNER_PARAM_ENTITY_REF; +#endif + state->handler = error; + return XML_ROLE_ERROR; +} + +void +XmlPrologStateInit(PROLOG_STATE *state) +{ + state->handler = prolog0; +#ifdef XML_DTD + state->documentEntity = 1; + state->includeLevel = 0; + state->inEntityValue = 0; +#endif /* XML_DTD */ +} + +#ifdef XML_DTD + +void +XmlPrologStateInitExternalEntity(PROLOG_STATE *state) +{ + state->handler = externalSubset0; + state->documentEntity = 0; + state->includeLevel = 0; +} + +#endif /* XML_DTD */ diff --git a/libxsde/xsde/c/expat/xmlrole.h b/libxsde/xsde/c/expat/xmlrole.h new file mode 100644 index 0000000..4dd9f06 --- /dev/null +++ b/libxsde/xsde/c/expat/xmlrole.h @@ -0,0 +1,114 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef XmlRole_INCLUDED +#define XmlRole_INCLUDED 1 + +#ifdef __VMS +/* 0 1 2 3 0 1 2 3 + 1234567890123456789012345678901 1234567890123456789012345678901 */ +#define XmlPrologStateInitExternalEntity XmlPrologStateInitExternalEnt +#endif + +#include "xmltok.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + XML_ROLE_ERROR = -1, + XML_ROLE_NONE = 0, + XML_ROLE_XML_DECL, + XML_ROLE_INSTANCE_START, + XML_ROLE_DOCTYPE_NONE, + XML_ROLE_DOCTYPE_NAME, + XML_ROLE_DOCTYPE_SYSTEM_ID, + XML_ROLE_DOCTYPE_PUBLIC_ID, + XML_ROLE_DOCTYPE_INTERNAL_SUBSET, + XML_ROLE_DOCTYPE_CLOSE, + XML_ROLE_GENERAL_ENTITY_NAME, + XML_ROLE_PARAM_ENTITY_NAME, + XML_ROLE_ENTITY_NONE, + XML_ROLE_ENTITY_VALUE, + XML_ROLE_ENTITY_SYSTEM_ID, + XML_ROLE_ENTITY_PUBLIC_ID, + XML_ROLE_ENTITY_COMPLETE, + XML_ROLE_ENTITY_NOTATION_NAME, + XML_ROLE_NOTATION_NONE, + XML_ROLE_NOTATION_NAME, + XML_ROLE_NOTATION_SYSTEM_ID, + XML_ROLE_NOTATION_NO_SYSTEM_ID, + XML_ROLE_NOTATION_PUBLIC_ID, + XML_ROLE_ATTRIBUTE_NAME, + XML_ROLE_ATTRIBUTE_TYPE_CDATA, + XML_ROLE_ATTRIBUTE_TYPE_ID, + XML_ROLE_ATTRIBUTE_TYPE_IDREF, + XML_ROLE_ATTRIBUTE_TYPE_IDREFS, + XML_ROLE_ATTRIBUTE_TYPE_ENTITY, + XML_ROLE_ATTRIBUTE_TYPE_ENTITIES, + XML_ROLE_ATTRIBUTE_TYPE_NMTOKEN, + XML_ROLE_ATTRIBUTE_TYPE_NMTOKENS, + XML_ROLE_ATTRIBUTE_ENUM_VALUE, + XML_ROLE_ATTRIBUTE_NOTATION_VALUE, + XML_ROLE_ATTLIST_NONE, + XML_ROLE_ATTLIST_ELEMENT_NAME, + XML_ROLE_IMPLIED_ATTRIBUTE_VALUE, + XML_ROLE_REQUIRED_ATTRIBUTE_VALUE, + XML_ROLE_DEFAULT_ATTRIBUTE_VALUE, + XML_ROLE_FIXED_ATTRIBUTE_VALUE, + XML_ROLE_ELEMENT_NONE, + XML_ROLE_ELEMENT_NAME, + XML_ROLE_CONTENT_ANY, + XML_ROLE_CONTENT_EMPTY, + XML_ROLE_CONTENT_PCDATA, + XML_ROLE_GROUP_OPEN, + XML_ROLE_GROUP_CLOSE, + XML_ROLE_GROUP_CLOSE_REP, + XML_ROLE_GROUP_CLOSE_OPT, + XML_ROLE_GROUP_CLOSE_PLUS, + XML_ROLE_GROUP_CHOICE, + XML_ROLE_GROUP_SEQUENCE, + XML_ROLE_CONTENT_ELEMENT, + XML_ROLE_CONTENT_ELEMENT_REP, + XML_ROLE_CONTENT_ELEMENT_OPT, + XML_ROLE_CONTENT_ELEMENT_PLUS, + XML_ROLE_PI, + XML_ROLE_COMMENT, +#ifdef XML_DTD + XML_ROLE_TEXT_DECL, + XML_ROLE_IGNORE_SECT, + XML_ROLE_INNER_PARAM_ENTITY_REF, +#endif /* XML_DTD */ + XML_ROLE_PARAM_ENTITY_REF +}; + +typedef struct prolog_state { + int (PTRCALL *handler) (struct prolog_state *state, + int tok, + const char *ptr, + const char *end, + const ENCODING *enc); + unsigned level; + int role_none; +#ifdef XML_DTD + unsigned includeLevel; + int documentEntity; + int inEntityValue; +#endif /* XML_DTD */ +} PROLOG_STATE; + +void XmlPrologStateInit(PROLOG_STATE *); +#ifdef XML_DTD +void XmlPrologStateInitExternalEntity(PROLOG_STATE *); +#endif /* XML_DTD */ + +#define XmlTokenRole(state, tok, ptr, end, enc) \ + (((state)->handler)(state, tok, ptr, end, enc)) + +#ifdef __cplusplus +} +#endif + +#endif /* not XmlRole_INCLUDED */ diff --git a/libxsde/xsde/c/expat/xmltok.c b/libxsde/xsde/c/expat/xmltok.c new file mode 100644 index 0000000..77ab2e9 --- /dev/null +++ b/libxsde/xsde/c/expat/xmltok.c @@ -0,0 +1,1671 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#include <stddef.h> + +#include "config.h" + +#include "expat_external.h" +#include "internal.h" +#include "xmltok.h" +#include "nametab.h" + +#ifdef XML_DTD +#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok) +#else +#define IGNORE_SECTION_TOK_VTABLE /* as nothing */ +#endif + +#define VTABLE1 \ + { PREFIX(prologTok), PREFIX(contentTok), \ + PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \ + { PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \ + PREFIX(sameName), \ + PREFIX(nameMatchesAscii), \ + PREFIX(nameLength), \ + PREFIX(skipS), \ + PREFIX(getAtts), \ + PREFIX(charRefNumber), \ + PREFIX(predefinedEntityName), \ + PREFIX(updatePosition), \ + PREFIX(isPublicId) + +#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) + +#define UCS2_GET_NAMING(pages, hi, lo) \ + (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1 << ((lo) & 0x1F))) + +/* A 2 byte UTF-8 representation splits the characters 11 bits between + the bottom 5 and 6 bits of the bytes. We need 8 bits to index into + pages, 3 bits to add to that index and 5 bits to generate the mask. +*/ +#define UTF8_GET_NAMING2(pages, byte) \ + (namingBitmap[((pages)[(((byte)[0]) >> 2) & 7] << 3) \ + + ((((byte)[0]) & 3) << 1) \ + + ((((byte)[1]) >> 5) & 1)] \ + & (1 << (((byte)[1]) & 0x1F))) + +/* A 3 byte UTF-8 representation splits the characters 16 bits between + the bottom 4, 6 and 6 bits of the bytes. We need 8 bits to index + into pages, 3 bits to add to that index and 5 bits to generate the + mask. +*/ +#define UTF8_GET_NAMING3(pages, byte) \ + (namingBitmap[((pages)[((((byte)[0]) & 0xF) << 4) \ + + ((((byte)[1]) >> 2) & 0xF)] \ + << 3) \ + + ((((byte)[1]) & 3) << 1) \ + + ((((byte)[2]) >> 5) & 1)] \ + & (1 << (((byte)[2]) & 0x1F))) + +#define UTF8_GET_NAMING(pages, p, n) \ + ((n) == 2 \ + ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ + : ((n) == 3 \ + ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) \ + : 0)) + +/* Detection of invalid UTF-8 sequences is based on Table 3.1B + of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/ + with the additional restriction of not allowing the Unicode + code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE). + Implementation details: + (A & 0x80) == 0 means A < 0x80 + and + (A & 0xC0) == 0xC0 means A > 0xBF +*/ + +#define UTF8_INVALID2(p) \ + ((*p) < 0xC2 || ((p)[1] & 0x80) == 0 || ((p)[1] & 0xC0) == 0xC0) + +#define UTF8_INVALID3(p) \ + (((p)[2] & 0x80) == 0 \ + || \ + ((*p) == 0xEF && (p)[1] == 0xBF \ + ? \ + (p)[2] > 0xBD \ + : \ + ((p)[2] & 0xC0) == 0xC0) \ + || \ + ((*p) == 0xE0 \ + ? \ + (p)[1] < 0xA0 || ((p)[1] & 0xC0) == 0xC0 \ + : \ + ((p)[1] & 0x80) == 0 \ + || \ + ((*p) == 0xED ? (p)[1] > 0x9F : ((p)[1] & 0xC0) == 0xC0))) + +#define UTF8_INVALID4(p) \ + (((p)[3] & 0x80) == 0 || ((p)[3] & 0xC0) == 0xC0 \ + || \ + ((p)[2] & 0x80) == 0 || ((p)[2] & 0xC0) == 0xC0 \ + || \ + ((*p) == 0xF0 \ + ? \ + (p)[1] < 0x90 || ((p)[1] & 0xC0) == 0xC0 \ + : \ + ((p)[1] & 0x80) == 0 \ + || \ + ((*p) == 0xF4 ? (p)[1] > 0x8F : ((p)[1] & 0xC0) == 0xC0))) + +static int PTRFASTCALL +isNever(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + UNUSED(p); + + return 0; +} + +static int PTRFASTCALL +utf8_isName2(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_GET_NAMING2(namePages, (const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isName3(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_GET_NAMING3(namePages, (const unsigned char *)p); +} + +#define utf8_isName4 isNever + +static int PTRFASTCALL +utf8_isNmstrt2(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_GET_NAMING2(nmstrtPages, (const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isNmstrt3(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_GET_NAMING3(nmstrtPages, (const unsigned char *)p); +} + +#define utf8_isNmstrt4 isNever + +static int PTRFASTCALL +utf8_isInvalid2(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_INVALID2((const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isInvalid3(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_INVALID3((const unsigned char *)p); +} + +static int PTRFASTCALL +utf8_isInvalid4(const ENCODING *enc, const char *p) +{ + UNUSED(enc); + + return UTF8_INVALID4((const unsigned char *)p); +} + +struct normal_encoding { + ENCODING enc; + unsigned char type[256]; +#ifdef XML_MIN_SIZE + int (PTRFASTCALL *byteType)(const ENCODING *, const char *); + int (PTRFASTCALL *isNameMin)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrtMin)(const ENCODING *, const char *); + int (PTRFASTCALL *byteToAscii)(const ENCODING *, const char *); + int (PTRCALL *charMatches)(const ENCODING *, const char *, int); +#endif /* XML_MIN_SIZE */ + int (PTRFASTCALL *isName2)(const ENCODING *, const char *); + int (PTRFASTCALL *isName3)(const ENCODING *, const char *); + int (PTRFASTCALL *isName4)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt2)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt3)(const ENCODING *, const char *); + int (PTRFASTCALL *isNmstrt4)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid2)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid3)(const ENCODING *, const char *); + int (PTRFASTCALL *isInvalid4)(const ENCODING *, const char *); +}; + +#define AS_NORMAL_ENCODING(enc) ((const struct normal_encoding *) (enc)) + +#ifdef XML_MIN_SIZE + +#define STANDARD_VTABLE(E) \ + E ## byteType, \ + E ## isNameMin, \ + E ## isNmstrtMin, \ + E ## byteToAscii, \ + E ## charMatches, + +#define ZERO_VTABLE /* as nothing */ + +#else + +#define STANDARD_VTABLE(E) /* as nothing */ + +#define ZERO_VTABLE \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0 + +#endif + +#define NORMAL_VTABLE(E) \ + E ## isName2, \ + E ## isName3, \ + E ## isName4, \ + E ## isNmstrt2, \ + E ## isNmstrt3, \ + E ## isNmstrt4, \ + E ## isInvalid2, \ + E ## isInvalid3, \ + E ## isInvalid4 + +static int FASTCALL checkCharRefNumber(int); + +#include "xmltok_impl.h" +#include "ascii.h" + +#ifdef XML_MIN_SIZE +#define sb_isNameMin isNever +#define sb_isNmstrtMin isNever +#endif + +#ifdef XML_MIN_SIZE +#define MINBPC(enc) ((enc)->minBytesPerChar) +#else +/* minimum bytes per character */ +#define MINBPC(enc) 1 +#endif + +#define SB_BYTE_TYPE(enc, p) \ + (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) + +#ifdef XML_MIN_SIZE +static int PTRFASTCALL +sb_byteType(const ENCODING *enc, const char *p) +{ + return SB_BYTE_TYPE(enc, p); +} +#define BYTE_TYPE(enc, p) \ + (AS_NORMAL_ENCODING(enc)->byteType(enc, p)) +#else +#define BYTE_TYPE(enc, p) SB_BYTE_TYPE(enc, p) +#endif + +#ifdef XML_MIN_SIZE +#define BYTE_TO_ASCII(enc, p) \ + (AS_NORMAL_ENCODING(enc)->byteToAscii(enc, p)) +static int PTRFASTCALL +sb_byteToAscii(const ENCODING *enc, const char *p) +{ + return *p; +} +#else +#define BYTE_TO_ASCII(enc, p) (*(p)) +#endif + +#define IS_NAME_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isName ## n(enc, p)) +#define IS_NMSTRT_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isNmstrt ## n(enc, p)) +#define IS_INVALID_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isInvalid ## n(enc, p)) + +#ifdef XML_MIN_SIZE +#define IS_NAME_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNameMin(enc, p)) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) \ + (AS_NORMAL_ENCODING(enc)->isNmstrtMin(enc, p)) +#else +#define IS_NAME_CHAR_MINBPC(enc, p) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) (0) +#endif + +#ifdef XML_MIN_SIZE +#define CHAR_MATCHES(enc, p, c) \ + (AS_NORMAL_ENCODING(enc)->charMatches(enc, p, c)) +static int PTRCALL +sb_charMatches(const ENCODING *enc, const char *p, int c) +{ + return *p == c; +} +#else +/* c is an ASCII character */ +#define CHAR_MATCHES(enc, p, c) (*(p) == c) +#endif + +#define PREFIX(ident) normal_ ## ident +#include "xmltok_impl.c" + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +enum { /* UTF8_cvalN is value of masked first byte of N byte sequence */ + UTF8_cval1 = 0x00, + UTF8_cval2 = 0xc0, + UTF8_cval3 = 0xe0, + UTF8_cval4 = 0xf0 +}; + +static void PTRCALL +utf8_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + char *to; + const char *from; + + UNUSED(enc); + + if (fromLim - *fromP > toLim - *toP) { + /* Avoid copying partial characters. */ + for (fromLim = *fromP + (toLim - *toP); fromLim > *fromP; fromLim--) + if (((unsigned char)fromLim[-1] & 0xc0) != 0x80) + break; + } + for (to = *toP, from = *fromP; from != fromLim; from++, to++) + *to = *from; + *fromP = from; + *toP = to; +} + +static void PTRCALL +utf8_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + unsigned short *to = *toP; + const char *from = *fromP; + while (from != fromLim && to != toLim) { + switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { + case BT_LEAD2: + *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f)); + from += 2; + break; + case BT_LEAD3: + *to++ = (unsigned short)(((from[0] & 0xf) << 12) + | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f)); + from += 3; + break; + case BT_LEAD4: + { + unsigned long n; + if (to + 1 == toLim) + goto after; + n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12) + | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f); + n -= 0x10000; + to[0] = (unsigned short)((n >> 10) | 0xD800); + to[1] = (unsigned short)((n & 0x3FF) | 0xDC00); + to += 2; + from += 4; + } + break; + default: + *to++ = *from++; + break; + } + } +after: + *fromP = from; + *toP = to; +} + +#ifdef XML_NS +static const struct normal_encoding utf8_encoding_ns = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#include "asciitab.h" +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; +#endif + +static const struct normal_encoding utf8_encoding = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +#ifdef XML_NS + +static const struct normal_encoding internal_utf8_encoding_ns = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#include "iasciitab.h" +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +#endif + +static const struct normal_encoding internal_utf8_encoding = { + { VTABLE1, utf8_toUtf8, utf8_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "utf8tab.h" + }, + STANDARD_VTABLE(sb_) NORMAL_VTABLE(utf8_) +}; + +static void PTRCALL +latin1_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + UNUSED(enc); + + for (;;) { + unsigned char c; + if (*fromP == fromLim) + break; + c = (unsigned char)**fromP; + if (c & 0x80) { + if (toLim - *toP < 2) + break; + *(*toP)++ = (char)((c >> 6) | UTF8_cval2); + *(*toP)++ = (char)((c & 0x3f) | 0x80); + (*fromP)++; + } + else { + if (*toP == toLim) + break; + *(*toP)++ = *(*fromP)++; + } + } +} + +static void PTRCALL +latin1_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + UNUSED(enc); + + while (*fromP != fromLim && *toP != toLim) + *(*toP)++ = (unsigned char)*(*fromP)++; +} + +#ifdef XML_NS + +static const struct normal_encoding latin1_encoding_ns = { + { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) ZERO_VTABLE +}; + +#endif + +static const struct normal_encoding latin1_encoding = { + { VTABLE1, latin1_toUtf8, latin1_toUtf16, 1, 0, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(sb_) ZERO_VTABLE +}; + +static void PTRCALL +ascii_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + UNUSED(enc); + + while (*fromP != fromLim && *toP != toLim) + *(*toP)++ = *(*fromP)++; +} + +#ifdef XML_NS + +static const struct normal_encoding ascii_encoding_ns = { + { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, + { +#include "asciitab.h" +/* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) ZERO_VTABLE +}; + +#endif + +static const struct normal_encoding ascii_encoding = { + { VTABLE1, ascii_toUtf8, latin1_toUtf16, 1, 1, 0 }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +/* BT_NONXML == 0 */ + }, + STANDARD_VTABLE(sb_) ZERO_VTABLE +}; + +static int PTRFASTCALL +unicode_byte_type(char hi, char lo) +{ + switch ((unsigned char)hi) { + case 0xD8: case 0xD9: case 0xDA: case 0xDB: + return BT_LEAD4; + case 0xDC: case 0xDD: case 0xDE: case 0xDF: + return BT_TRAIL; + case 0xFF: + switch ((unsigned char)lo) { + case 0xFF: + case 0xFE: + return BT_NONXML; + } + break; + } + return BT_NONASCII; +} + +#define DEFINE_UTF16_TO_UTF8(E) \ +static void PTRCALL \ +E ## toUtf8(const ENCODING *enc, \ + const char **fromP, const char *fromLim, \ + char **toP, const char *toLim) \ +{ \ + const char *from; \ + UNUSED(enc); \ + for (from = *fromP; from != fromLim; from += 2) { \ + int plane; \ + unsigned char lo2; \ + unsigned char lo = GET_LO(from); \ + unsigned char hi = GET_HI(from); \ + switch (hi) { \ + case 0: \ + if (lo < 0x80) { \ + if (*toP == toLim) { \ + *fromP = from; \ + return; \ + } \ + *(*toP)++ = lo; \ + break; \ + } \ + /* fall through */ \ + case 0x1: case 0x2: case 0x3: \ + case 0x4: case 0x5: case 0x6: case 0x7: \ + if (toLim - *toP < 2) { \ + *fromP = from; \ + return; \ + } \ + *(*toP)++ = ((lo >> 6) | (hi << 2) | UTF8_cval2); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + default: \ + if (toLim - *toP < 3) { \ + *fromP = from; \ + return; \ + } \ + /* 16 bits divided 4, 6, 6 amongst 3 bytes */ \ + *(*toP)++ = ((hi >> 4) | UTF8_cval3); \ + *(*toP)++ = (((hi & 0xf) << 2) | (lo >> 6) | 0x80); \ + *(*toP)++ = ((lo & 0x3f) | 0x80); \ + break; \ + case 0xD8: case 0xD9: case 0xDA: case 0xDB: \ + if (toLim - *toP < 4) { \ + *fromP = from; \ + return; \ + } \ + plane = (((hi & 0x3) << 2) | ((lo >> 6) & 0x3)) + 1; \ + *(*toP)++ = ((plane >> 2) | UTF8_cval4); \ + *(*toP)++ = (((lo >> 2) & 0xF) | ((plane & 0x3) << 4) | 0x80); \ + from += 2; \ + lo2 = GET_LO(from); \ + *(*toP)++ = (((lo & 0x3) << 4) \ + | ((GET_HI(from) & 0x3) << 2) \ + | (lo2 >> 6) \ + | 0x80); \ + *(*toP)++ = ((lo2 & 0x3f) | 0x80); \ + break; \ + } \ + } \ + *fromP = from; \ +} + +#define DEFINE_UTF16_TO_UTF16(E) \ +static void PTRCALL \ +E ## toUtf16(const ENCODING *enc, \ + const char **fromP, const char *fromLim, \ + unsigned short **toP, const unsigned short *toLim) \ +{ \ + UNUSED(enc); \ + /* Avoid copying first half only of surrogate */ \ + if (fromLim - *fromP > ((toLim - *toP) << 1) \ + && (GET_HI(fromLim - 2) & 0xF8) == 0xD8) \ + fromLim -= 2; \ + for (; *fromP != fromLim && *toP != toLim; *fromP += 2) \ + *(*toP)++ = (GET_HI(*fromP) << 8) | GET_LO(*fromP); \ +} + +#define SET2(ptr, ch) \ + (((ptr)[0] = ((ch) & 0xff)), ((ptr)[1] = ((ch) >> 8))) +#define GET_LO(ptr) ((unsigned char)(ptr)[0]) +#define GET_HI(ptr) ((unsigned char)(ptr)[1]) + +DEFINE_UTF16_TO_UTF8(little2_) +DEFINE_UTF16_TO_UTF16(little2_) + +#undef SET2 +#undef GET_LO +#undef GET_HI + +#define SET2(ptr, ch) \ + (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch) & 0xFF))) +#define GET_LO(ptr) ((unsigned char)(ptr)[1]) +#define GET_HI(ptr) ((unsigned char)(ptr)[0]) + +DEFINE_UTF16_TO_UTF8(big2_) +DEFINE_UTF16_TO_UTF16(big2_) + +#undef SET2 +#undef GET_LO +#undef GET_HI + +#define LITTLE2_BYTE_TYPE(enc, p) \ + ((p)[1] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ + : unicode_byte_type((p)[1], (p)[0])) +#define LITTLE2_BYTE_TO_ASCII(enc, p) ((p)[1] == 0 ? (p)[0] : -1) +#define LITTLE2_CHAR_MATCHES(enc, p, c) ((p)[1] == 0 && (p)[0] == c) +#define LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0]) +#define LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[1], (unsigned char)p[0]) + +#ifdef XML_MIN_SIZE + +static int PTRFASTCALL +little2_byteType(const ENCODING *enc, const char *p) +{ + return LITTLE2_BYTE_TYPE(enc, p); +} + +static int PTRFASTCALL +little2_byteToAscii(const ENCODING *enc, const char *p) +{ + return LITTLE2_BYTE_TO_ASCII(enc, p); +} + +static int PTRCALL +little2_charMatches(const ENCODING *enc, const char *p, int c) +{ + return LITTLE2_CHAR_MATCHES(enc, p, c); +} + +static int PTRFASTCALL +little2_isNameMin(const ENCODING *enc, const char *p) +{ + return LITTLE2_IS_NAME_CHAR_MINBPC(enc, p); +} + +static int PTRFASTCALL +little2_isNmstrtMin(const ENCODING *enc, const char *p) +{ + return LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p); +} + +#undef VTABLE +#define VTABLE VTABLE1, little2_toUtf8, little2_toUtf16 + +#else /* not XML_MIN_SIZE */ + +#undef PREFIX +#define PREFIX(ident) little2_ ## ident +#define MINBPC(enc) 2 +/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ +#define BYTE_TYPE(enc, p) LITTLE2_BYTE_TYPE(enc, p) +#define BYTE_TO_ASCII(enc, p) LITTLE2_BYTE_TO_ASCII(enc, p) +#define CHAR_MATCHES(enc, p, c) LITTLE2_CHAR_MATCHES(enc, p, c) +#define IS_NAME_CHAR(enc, p, n) 0 +#define IS_NAME_CHAR_MINBPC(enc, p) LITTLE2_IS_NAME_CHAR_MINBPC(enc, p) +#define IS_NMSTRT_CHAR(enc, p, n) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(enc, p) + +#include "xmltok_impl.c" + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +#endif /* not XML_MIN_SIZE */ + +#ifdef XML_NS + +static const struct normal_encoding little2_encoding_ns = { + { VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) ZERO_VTABLE +}; + +#endif + +static const struct normal_encoding little2_encoding = { + { VTABLE, 2, 0, +#if BYTEORDER == 1234 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) ZERO_VTABLE +}; + +#if BYTEORDER != 4321 + +#ifdef XML_NS + +static const struct normal_encoding internal_little2_encoding_ns = { + { VTABLE, 2, 0, 1 }, + { +#include "iasciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) ZERO_VTABLE +}; + +#endif + +static const struct normal_encoding internal_little2_encoding = { + { VTABLE, 2, 0, 1 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(little2_) ZERO_VTABLE +}; + +#endif + + +#define BIG2_BYTE_TYPE(enc, p) \ + ((p)[0] == 0 \ + ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ + : unicode_byte_type((p)[0], (p)[1])) +#define BIG2_BYTE_TO_ASCII(enc, p) ((p)[0] == 0 ? (p)[1] : -1) +#define BIG2_CHAR_MATCHES(enc, p, c) ((p)[0] == 0 && (p)[1] == c) +#define BIG2_IS_NAME_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) +#define BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) \ + UCS2_GET_NAMING(nmstrtPages, (unsigned char)p[0], (unsigned char)p[1]) + +#ifdef XML_MIN_SIZE + +static int PTRFASTCALL +big2_byteType(const ENCODING *enc, const char *p) +{ + return BIG2_BYTE_TYPE(enc, p); +} + +static int PTRFASTCALL +big2_byteToAscii(const ENCODING *enc, const char *p) +{ + return BIG2_BYTE_TO_ASCII(enc, p); +} + +static int PTRCALL +big2_charMatches(const ENCODING *enc, const char *p, int c) +{ + return BIG2_CHAR_MATCHES(enc, p, c); +} + +static int PTRFASTCALL +big2_isNameMin(const ENCODING *enc, const char *p) +{ + return BIG2_IS_NAME_CHAR_MINBPC(enc, p); +} + +static int PTRFASTCALL +big2_isNmstrtMin(const ENCODING *enc, const char *p) +{ + return BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p); +} + +#undef VTABLE +#define VTABLE VTABLE1, big2_toUtf8, big2_toUtf16 + +#else /* not XML_MIN_SIZE */ + +#undef PREFIX +#define PREFIX(ident) big2_ ## ident +#define MINBPC(enc) 2 +/* CHAR_MATCHES is guaranteed to have MINBPC bytes available. */ +#define BYTE_TYPE(enc, p) BIG2_BYTE_TYPE(enc, p) +#define BYTE_TO_ASCII(enc, p) BIG2_BYTE_TO_ASCII(enc, p) +#define CHAR_MATCHES(enc, p, c) BIG2_CHAR_MATCHES(enc, p, c) +#define IS_NAME_CHAR(enc, p, n) 0 +#define IS_NAME_CHAR_MINBPC(enc, p) BIG2_IS_NAME_CHAR_MINBPC(enc, p) +#define IS_NMSTRT_CHAR(enc, p, n) (0) +#define IS_NMSTRT_CHAR_MINBPC(enc, p) BIG2_IS_NMSTRT_CHAR_MINBPC(enc, p) + +#include "xmltok_impl.c" + +#undef MINBPC +#undef BYTE_TYPE +#undef BYTE_TO_ASCII +#undef CHAR_MATCHES +#undef IS_NAME_CHAR +#undef IS_NAME_CHAR_MINBPC +#undef IS_NMSTRT_CHAR +#undef IS_NMSTRT_CHAR_MINBPC +#undef IS_INVALID_CHAR + +#endif /* not XML_MIN_SIZE */ + +#ifdef XML_NS + +static const struct normal_encoding big2_encoding_ns = { + { VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#include "asciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) ZERO_VTABLE +}; + +#endif + +static const struct normal_encoding big2_encoding = { + { VTABLE, 2, 0, +#if BYTEORDER == 4321 + 1 +#else + 0 +#endif + }, + { +#define BT_COLON BT_NMSTRT +#include "asciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) ZERO_VTABLE +}; + +#if BYTEORDER != 1234 + +#ifdef XML_NS + +static const struct normal_encoding internal_big2_encoding_ns = { + { VTABLE, 2, 0, 1 }, + { +#include "iasciitab.h" +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) ZERO_VTABLE +}; + +#endif + +static const struct normal_encoding internal_big2_encoding = { + { VTABLE, 2, 0, 1 }, + { +#define BT_COLON BT_NMSTRT +#include "iasciitab.h" +#undef BT_COLON +#include "latin1tab.h" + }, + STANDARD_VTABLE(big2_) ZERO_VTABLE +}; + +#endif + +#undef PREFIX + +static int FASTCALL +streqci(const char *s1, const char *s2) +{ + for (;;) { + char c1 = *s1++; + char c2 = *s2++; + if (ASCII_a <= c1 && c1 <= ASCII_z) + c1 += ASCII_A - ASCII_a; + if (ASCII_a <= c2 && c2 <= ASCII_z) + c2 += ASCII_A - ASCII_a; + if (c1 != c2) + return 0; + if (!c1) + break; + } + return 1; +} + +static void PTRCALL +initUpdatePosition(const ENCODING *enc, const char *ptr, + const char *end, POSITION *pos) +{ + UNUSED(enc); + normal_updatePosition(&utf8_encoding.enc, ptr, end, pos); +} + +static int +toAscii(const ENCODING *enc, const char *ptr, const char *end) +{ + char buf[1]; + char *p = buf; + XmlUtf8Convert(enc, &ptr, end, &p, p + 1); + if (p == buf) + return -1; + else + return buf[0]; +} + +static int FASTCALL +isSpace(int c) +{ + switch (c) { + case 0x20: + case 0xD: + case 0xA: + case 0x9: + return 1; + } + return 0; +} + +/* Return 1 if there's just optional white space or there's an S + followed by name=val. +*/ +static int +parsePseudoAttribute(const ENCODING *enc, + const char *ptr, + const char *end, + const char **namePtr, + const char **nameEndPtr, + const char **valPtr, + const char **nextTokPtr) +{ + int c; + char open; + if (ptr == end) { + *namePtr = NULL; + return 1; + } + if (!isSpace(toAscii(enc, ptr, end))) { + *nextTokPtr = ptr; + return 0; + } + do { + ptr += enc->minBytesPerChar; + } while (isSpace(toAscii(enc, ptr, end))); + if (ptr == end) { + *namePtr = NULL; + return 1; + } + *namePtr = ptr; + for (;;) { + c = toAscii(enc, ptr, end); + if (c == -1) { + *nextTokPtr = ptr; + return 0; + } + if (c == ASCII_EQUALS) { + *nameEndPtr = ptr; + break; + } + if (isSpace(c)) { + *nameEndPtr = ptr; + do { + ptr += enc->minBytesPerChar; + } while (isSpace(c = toAscii(enc, ptr, end))); + if (c != ASCII_EQUALS) { + *nextTokPtr = ptr; + return 0; + } + break; + } + ptr += enc->minBytesPerChar; + } + if (ptr == *namePtr) { + *nextTokPtr = ptr; + return 0; + } + ptr += enc->minBytesPerChar; + c = toAscii(enc, ptr, end); + while (isSpace(c)) { + ptr += enc->minBytesPerChar; + c = toAscii(enc, ptr, end); + } + if (c != ASCII_QUOT && c != ASCII_APOS) { + *nextTokPtr = ptr; + return 0; + } + open = (char)c; + ptr += enc->minBytesPerChar; + *valPtr = ptr; + for (;; ptr += enc->minBytesPerChar) { + c = toAscii(enc, ptr, end); + if (c == open) + break; + if (!(ASCII_a <= c && c <= ASCII_z) + && !(ASCII_A <= c && c <= ASCII_Z) + && !(ASCII_0 <= c && c <= ASCII_9) + && c != ASCII_PERIOD + && c != ASCII_MINUS + && c != ASCII_UNDERSCORE) { + *nextTokPtr = ptr; + return 0; + } + } + *nextTokPtr = ptr + enc->minBytesPerChar; + return 1; +} + +static const char KW_version[] = { + ASCII_v, ASCII_e, ASCII_r, ASCII_s, ASCII_i, ASCII_o, ASCII_n, '\0' +}; + +static const char KW_encoding[] = { + ASCII_e, ASCII_n, ASCII_c, ASCII_o, ASCII_d, ASCII_i, ASCII_n, ASCII_g, '\0' +}; + +static const char KW_standalone[] = { + ASCII_s, ASCII_t, ASCII_a, ASCII_n, ASCII_d, ASCII_a, ASCII_l, ASCII_o, + ASCII_n, ASCII_e, '\0' +}; + +static const char KW_yes[] = { + ASCII_y, ASCII_e, ASCII_s, '\0' +}; + +static const char KW_no[] = { + ASCII_n, ASCII_o, '\0' +}; + +static int +doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *, + const char *, + const char *), + int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingName, + const ENCODING **encoding, + int *standalone) +{ + const char *val = NULL; + const char *name = NULL; + const char *nameEnd = NULL; + ptr += 5 * enc->minBytesPerChar; + end -= 2 * enc->minBytesPerChar; + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) + || !name) { + *badPtr = ptr; + return 0; + } + if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_version)) { + if (!isGeneralTextEntity) { + *badPtr = name; + return 0; + } + } + else { + if (versionPtr) + *versionPtr = val; + if (versionEndPtr) + *versionEndPtr = ptr; + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + *badPtr = ptr; + return 0; + } + if (!name) { + if (isGeneralTextEntity) { + /* a TextDecl must have an EncodingDecl */ + *badPtr = ptr; + return 0; + } + return 1; + } + } + if (XmlNameMatchesAscii(enc, name, nameEnd, KW_encoding)) { + int c = toAscii(enc, val, end); + if (!(ASCII_a <= c && c <= ASCII_z) && !(ASCII_A <= c && c <= ASCII_Z)) { + *badPtr = val; + return 0; + } + if (encodingName) + *encodingName = val; + if (encoding) + *encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar); + if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) { + *badPtr = ptr; + return 0; + } + if (!name) + return 1; + } + if (!XmlNameMatchesAscii(enc, name, nameEnd, KW_standalone) + || isGeneralTextEntity) { + *badPtr = name; + return 0; + } + if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_yes)) { + if (standalone) + *standalone = 1; + } + else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_no)) { + if (standalone) + *standalone = 0; + } + else { + *badPtr = val; + return 0; + } + while (isSpace(toAscii(enc, ptr, end))) + ptr += enc->minBytesPerChar; + if (ptr != end) { + *badPtr = ptr; + return 0; + } + return 1; +} + +static int FASTCALL +checkCharRefNumber(int result) +{ + switch (result >> 8) { + case 0xD8: case 0xD9: case 0xDA: case 0xDB: + case 0xDC: case 0xDD: case 0xDE: case 0xDF: + return -1; + case 0: + if (latin1_encoding.type[result] == BT_NONXML) + return -1; + break; + case 0xFF: + if (result == 0xFFFE || result == 0xFFFF) + return -1; + break; + } + return result; +} + +int FASTCALL +XmlUtf8Encode(int c, char *buf) +{ + enum { + /* minN is minimum legal resulting value for N byte sequence */ + min2 = 0x80, + min3 = 0x800, + min4 = 0x10000 + }; + + if (c < 0) + return 0; + if (c < min2) { + buf[0] = (char)(c | UTF8_cval1); + return 1; + } + if (c < min3) { + buf[0] = (char)((c >> 6) | UTF8_cval2); + buf[1] = (char)((c & 0x3f) | 0x80); + return 2; + } + if (c < min4) { + buf[0] = (char)((c >> 12) | UTF8_cval3); + buf[1] = (char)(((c >> 6) & 0x3f) | 0x80); + buf[2] = (char)((c & 0x3f) | 0x80); + return 3; + } + if (c < 0x110000) { + buf[0] = (char)((c >> 18) | UTF8_cval4); + buf[1] = (char)(((c >> 12) & 0x3f) | 0x80); + buf[2] = (char)(((c >> 6) & 0x3f) | 0x80); + buf[3] = (char)((c & 0x3f) | 0x80); + return 4; + } + return 0; +} + +int FASTCALL +XmlUtf16Encode(int charNum, unsigned short *buf) +{ + if (charNum < 0) + return 0; + if (charNum < 0x10000) { + buf[0] = (unsigned short)charNum; + return 1; + } + if (charNum < 0x110000) { + charNum -= 0x10000; + buf[0] = (unsigned short)((charNum >> 10) + 0xD800); + buf[1] = (unsigned short)((charNum & 0x3FF) + 0xDC00); + return 2; + } + return 0; +} + +struct unknown_encoding { + struct normal_encoding normal; + CONVERTER convert; + void *userData; + unsigned short utf16[256]; + char utf8[256][4]; +}; + +#define AS_UNKNOWN_ENCODING(enc) ((const struct unknown_encoding *) (enc)) + +int +XmlSizeOfUnknownEncoding(void) +{ + return sizeof(struct unknown_encoding); +} + +static int PTRFASTCALL +unknown_isName(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + if (c & ~0xFFFF) + return 0; + return UCS2_GET_NAMING(namePages, c >> 8, c & 0xFF); +} + +static int PTRFASTCALL +unknown_isNmstrt(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + if (c & ~0xFFFF) + return 0; + return UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xFF); +} + +static int PTRFASTCALL +unknown_isInvalid(const ENCODING *enc, const char *p) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + int c = uenc->convert(uenc->userData, p); + return (c & ~0xFFFF) || checkCharRefNumber(c) < 0; +} + +static void PTRCALL +unknown_toUtf8(const ENCODING *enc, + const char **fromP, const char *fromLim, + char **toP, const char *toLim) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + char buf[XML_UTF8_ENCODE_MAX]; + for (;;) { + const char *utf8; + int n; + if (*fromP == fromLim) + break; + utf8 = uenc->utf8[(unsigned char)**fromP]; + n = *utf8++; + if (n == 0) { + int c = uenc->convert(uenc->userData, *fromP); + n = XmlUtf8Encode(c, buf); + if (n > toLim - *toP) + break; + utf8 = buf; + *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] + - (BT_LEAD2 - 2)); + } + else { + if (n > toLim - *toP) + break; + (*fromP)++; + } + do { + *(*toP)++ = *utf8++; + } while (--n != 0); + } +} + +static void PTRCALL +unknown_toUtf16(const ENCODING *enc, + const char **fromP, const char *fromLim, + unsigned short **toP, const unsigned short *toLim) +{ + const struct unknown_encoding *uenc = AS_UNKNOWN_ENCODING(enc); + while (*fromP != fromLim && *toP != toLim) { + unsigned short c = uenc->utf16[(unsigned char)**fromP]; + if (c == 0) { + c = (unsigned short) + uenc->convert(uenc->userData, *fromP); + *fromP += (AS_NORMAL_ENCODING(enc)->type[(unsigned char)**fromP] + - (BT_LEAD2 - 2)); + } + else + (*fromP)++; + *(*toP)++ = c; + } +} + +ENCODING * +XmlInitUnknownEncoding(void *mem, + int *table, + CONVERTER convert, + void *userData) +{ + int i; + struct unknown_encoding *e = (struct unknown_encoding *)mem; + for (i = 0; i < (int)sizeof(struct normal_encoding); i++) + ((char *)mem)[i] = ((char *)&latin1_encoding)[i]; + for (i = 0; i < 128; i++) + if (latin1_encoding.type[i] != BT_OTHER + && latin1_encoding.type[i] != BT_NONXML + && table[i] != i) + return 0; + for (i = 0; i < 256; i++) { + int c = table[i]; + if (c == -1) { + e->normal.type[i] = BT_MALFORM; + /* This shouldn't really get used. */ + e->utf16[i] = 0xFFFF; + e->utf8[i][0] = 1; + e->utf8[i][1] = 0; + } + else if (c < 0) { + if (c < -4) + return 0; + e->normal.type[i] = (unsigned char)(BT_LEAD2 - (c + 2)); + e->utf8[i][0] = 0; + e->utf16[i] = 0; + } + else if (c < 0x80) { + if (latin1_encoding.type[c] != BT_OTHER + && latin1_encoding.type[c] != BT_NONXML + && c != i) + return 0; + e->normal.type[i] = latin1_encoding.type[c]; + e->utf8[i][0] = 1; + e->utf8[i][1] = (char)c; + e->utf16[i] = (unsigned short)(c == 0 ? 0xFFFF : c); + } + else if (checkCharRefNumber(c) < 0) { + e->normal.type[i] = BT_NONXML; + /* This shouldn't really get used. */ + e->utf16[i] = 0xFFFF; + e->utf8[i][0] = 1; + e->utf8[i][1] = 0; + } + else { + if (c > 0xFFFF) + return 0; + if (UCS2_GET_NAMING(nmstrtPages, c >> 8, c & 0xff)) + e->normal.type[i] = BT_NMSTRT; + else if (UCS2_GET_NAMING(namePages, c >> 8, c & 0xff)) + e->normal.type[i] = BT_NAME; + else + e->normal.type[i] = BT_OTHER; + e->utf8[i][0] = (char)XmlUtf8Encode(c, e->utf8[i] + 1); + e->utf16[i] = (unsigned short)c; + } + } + e->userData = userData; + e->convert = convert; + if (convert) { + e->normal.isName2 = unknown_isName; + e->normal.isName3 = unknown_isName; + e->normal.isName4 = unknown_isName; + e->normal.isNmstrt2 = unknown_isNmstrt; + e->normal.isNmstrt3 = unknown_isNmstrt; + e->normal.isNmstrt4 = unknown_isNmstrt; + e->normal.isInvalid2 = unknown_isInvalid; + e->normal.isInvalid3 = unknown_isInvalid; + e->normal.isInvalid4 = unknown_isInvalid; + } + e->normal.enc.utf8Convert = unknown_toUtf8; + e->normal.enc.utf16Convert = unknown_toUtf16; + return &(e->normal.enc); +} + +/* If this enumeration is changed, getEncodingIndex and encodings +must also be changed. */ +enum { + UNKNOWN_ENC = -1, + ISO_8859_1_ENC = 0, + US_ASCII_ENC, + UTF_8_ENC, + UTF_16_ENC, + UTF_16BE_ENC, + UTF_16LE_ENC, + /* must match encodingNames up to here */ + NO_ENC +}; + +static const char KW_ISO_8859_1[] = { + ASCII_I, ASCII_S, ASCII_O, ASCII_MINUS, ASCII_8, ASCII_8, ASCII_5, ASCII_9, + ASCII_MINUS, ASCII_1, '\0' +}; +static const char KW_US_ASCII[] = { + ASCII_U, ASCII_S, ASCII_MINUS, ASCII_A, ASCII_S, ASCII_C, ASCII_I, ASCII_I, + '\0' +}; +static const char KW_UTF_8[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_8, '\0' +}; +static const char KW_UTF_16[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, '\0' +}; +static const char KW_UTF_16BE[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_B, ASCII_E, + '\0' +}; +static const char KW_UTF_16LE[] = { + ASCII_U, ASCII_T, ASCII_F, ASCII_MINUS, ASCII_1, ASCII_6, ASCII_L, ASCII_E, + '\0' +}; + +static int FASTCALL +getEncodingIndex(const char *name) +{ + static const char * const encodingNames[] = { + KW_ISO_8859_1, + KW_US_ASCII, + KW_UTF_8, + KW_UTF_16, + KW_UTF_16BE, + KW_UTF_16LE, + }; + int i; + if (name == NULL) + return NO_ENC; + for (i = 0; i < (int)(sizeof(encodingNames)/sizeof(encodingNames[0])); i++) + if (streqci(name, encodingNames[i])) + return i; + return UNKNOWN_ENC; +} + +/* For binary compatibility, we store the index of the encoding + specified at initialization in the isUtf16 member. +*/ + +#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16) +#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i) + +/* This is what detects the encoding. encodingTable maps from + encoding indices to encodings; INIT_ENC_INDEX(enc) is the index of + the external (protocol) specified encoding; state is + XML_CONTENT_STATE if we're parsing an external text entity, and + XML_PROLOG_STATE otherwise. +*/ + + +static int +initScan(const ENCODING * const *encodingTable, + const INIT_ENCODING *enc, + int state, + const char *ptr, + const char *end, + const char **nextTokPtr) +{ + const ENCODING **encPtr; + + if (ptr == end) + return XML_TOK_NONE; + encPtr = enc->encPtr; + if (ptr + 1 == end) { + /* only a single byte available for auto-detection */ +#ifndef XML_DTD /* FIXME */ + /* a well-formed document entity must have more than one byte */ + if (state != XML_CONTENT_STATE) + return XML_TOK_PARTIAL; +#endif + /* so we're parsing an external text entity... */ + /* if UTF-16 was externally specified, then we need at least 2 bytes */ + switch (INIT_ENC_INDEX(enc)) { + case UTF_16_ENC: + case UTF_16LE_ENC: + case UTF_16BE_ENC: + return XML_TOK_PARTIAL; + } + switch ((unsigned char)*ptr) { + case 0xFE: + case 0xFF: + case 0xEF: /* possibly first byte of UTF-8 BOM */ + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + /* fall through */ + case 0x00: + case 0x3C: + return XML_TOK_PARTIAL; + } + } + else { + switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) { + case 0xFEFF: + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + *nextTokPtr = ptr + 2; + *encPtr = encodingTable[UTF_16BE_ENC]; + return XML_TOK_BOM; + /* 00 3C is handled in the default case */ + case 0x3C00: + if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC + || INIT_ENC_INDEX(enc) == UTF_16_ENC) + && state == XML_CONTENT_STATE) + break; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + case 0xFFFE: + if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC + && state == XML_CONTENT_STATE) + break; + *nextTokPtr = ptr + 2; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XML_TOK_BOM; + case 0xEFBB: + /* Maybe a UTF-8 BOM (EF BB BF) */ + /* If there's an explicitly specified (external) encoding + of ISO-8859-1 or some flavour of UTF-16 + and this is an external text entity, + don't look for the BOM, + because it might be a legal data. + */ + if (state == XML_CONTENT_STATE) { + int e = INIT_ENC_INDEX(enc); + if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC + || e == UTF_16LE_ENC || e == UTF_16_ENC) + break; + } + if (ptr + 2 == end) + return XML_TOK_PARTIAL; + if ((unsigned char)ptr[2] == 0xBF) { + *nextTokPtr = ptr + 3; + *encPtr = encodingTable[UTF_8_ENC]; + return XML_TOK_BOM; + } + break; + default: + if (ptr[0] == '\0') { + /* 0 isn't a legal data character. Furthermore a document + entity can only start with ASCII characters. So the only + way this can fail to be big-endian UTF-16 if it it's an + external parsed general entity that's labelled as + UTF-16LE. + */ + if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC) + break; + *encPtr = encodingTable[UTF_16BE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + } + else if (ptr[1] == '\0') { + /* We could recover here in the case: + - parsing an external entity + - second byte is 0 + - no externally specified encoding + - no encoding declaration + by assuming UTF-16LE. But we don't, because this would mean when + presented just with a single byte, we couldn't reliably determine + whether we needed further bytes. + */ + if (state == XML_CONTENT_STATE) + break; + *encPtr = encodingTable[UTF_16LE_ENC]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); + } + break; + } + } + *encPtr = encodingTable[INIT_ENC_INDEX(enc)]; + return XmlTok(*encPtr, state, ptr, end, nextTokPtr); +} + + +#define NS(x) x +#define ns(x) x +#include "xmltok_ns.c" +#undef NS +#undef ns + +#ifdef XML_NS + +#define NS(x) x ## NS +#define ns(x) x ## _ns + +#include "xmltok_ns.c" + +#undef NS +#undef ns + +ENCODING * +XmlInitUnknownEncodingNS(void *mem, + int *table, + CONVERTER convert, + void *userData) +{ + ENCODING *enc = XmlInitUnknownEncoding(mem, table, convert, userData); + if (enc) + ((struct normal_encoding *)enc)->type[ASCII_COLON] = BT_COLON; + return enc; +} + +#endif /* XML_NS */ diff --git a/libxsde/xsde/c/expat/xmltok.h b/libxsde/xsde/c/expat/xmltok.h new file mode 100644 index 0000000..ca867aa --- /dev/null +++ b/libxsde/xsde/c/expat/xmltok.h @@ -0,0 +1,316 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef XmlTok_INCLUDED +#define XmlTok_INCLUDED 1 + +#ifdef __cplusplus +extern "C" { +#endif + +/* The following token may be returned by XmlContentTok */ +#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be + start of illegal ]]> sequence */ +/* The following tokens may be returned by both XmlPrologTok and + XmlContentTok. +*/ +#define XML_TOK_NONE -4 /* The string to be scanned is empty */ +#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; + might be part of CRLF sequence */ +#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ +#define XML_TOK_PARTIAL -1 /* only part of a token */ +#define XML_TOK_INVALID 0 + +/* The following tokens are returned by XmlContentTok; some are also + returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. +*/ +#define XML_TOK_START_TAG_WITH_ATTS 1 +#define XML_TOK_START_TAG_NO_ATTS 2 +#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */ +#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 +#define XML_TOK_END_TAG 5 +#define XML_TOK_DATA_CHARS 6 +#define XML_TOK_DATA_NEWLINE 7 +#define XML_TOK_CDATA_SECT_OPEN 8 +#define XML_TOK_ENTITY_REF 9 +#define XML_TOK_CHAR_REF 10 /* numeric character reference */ + +/* The following tokens may be returned by both XmlPrologTok and + XmlContentTok. +*/ +#define XML_TOK_PI 11 /* processing instruction */ +#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ +#define XML_TOK_COMMENT 13 +#define XML_TOK_BOM 14 /* Byte order mark */ + +/* The following tokens are returned only by XmlPrologTok */ +#define XML_TOK_PROLOG_S 15 +#define XML_TOK_DECL_OPEN 16 /* <!foo */ +#define XML_TOK_DECL_CLOSE 17 /* > */ +#define XML_TOK_NAME 18 +#define XML_TOK_NMTOKEN 19 +#define XML_TOK_POUND_NAME 20 /* #name */ +#define XML_TOK_OR 21 /* | */ +#define XML_TOK_PERCENT 22 +#define XML_TOK_OPEN_PAREN 23 +#define XML_TOK_CLOSE_PAREN 24 +#define XML_TOK_OPEN_BRACKET 25 +#define XML_TOK_CLOSE_BRACKET 26 +#define XML_TOK_LITERAL 27 +#define XML_TOK_PARAM_ENTITY_REF 28 +#define XML_TOK_INSTANCE_START 29 + +/* The following occur only in element type declarations */ +#define XML_TOK_NAME_QUESTION 30 /* name? */ +#define XML_TOK_NAME_ASTERISK 31 /* name* */ +#define XML_TOK_NAME_PLUS 32 /* name+ */ +#define XML_TOK_COND_SECT_OPEN 33 /* <![ */ +#define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */ +#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ +#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ +#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ +#define XML_TOK_COMMA 38 + +/* The following token is returned only by XmlAttributeValueTok */ +#define XML_TOK_ATTRIBUTE_VALUE_S 39 + +/* The following token is returned only by XmlCdataSectionTok */ +#define XML_TOK_CDATA_SECT_CLOSE 40 + +/* With namespace processing this is returned by XmlPrologTok for a + name with a colon. +*/ +#define XML_TOK_PREFIXED_NAME 41 + +#ifdef XML_DTD +#define XML_TOK_IGNORE_SECT 42 +#endif /* XML_DTD */ + +#ifdef XML_DTD +#define XML_N_STATES 4 +#else /* not XML_DTD */ +#define XML_N_STATES 3 +#endif /* not XML_DTD */ + +#define XML_PROLOG_STATE 0 +#define XML_CONTENT_STATE 1 +#define XML_CDATA_SECTION_STATE 2 +#ifdef XML_DTD +#define XML_IGNORE_SECTION_STATE 3 +#endif /* XML_DTD */ + +#define XML_N_LITERAL_TYPES 2 +#define XML_ATTRIBUTE_VALUE_LITERAL 0 +#define XML_ENTITY_VALUE_LITERAL 1 + +/* The size of the buffer passed to XmlUtf8Encode must be at least this. */ +#define XML_UTF8_ENCODE_MAX 4 +/* The size of the buffer passed to XmlUtf16Encode must be at least this. */ +#define XML_UTF16_ENCODE_MAX 2 + +typedef struct position { + /* first line and first column are 0 not 1 */ + XML_Size lineNumber; + XML_Size columnNumber; +} POSITION; + +typedef struct { + const char *name; + const char *valuePtr; + const char *valueEnd; + char normalized; +} ATTRIBUTE; + +struct encoding; +typedef struct encoding ENCODING; + +typedef int (PTRCALL *SCANNER)(const ENCODING *, + const char *, + const char *, + const char **); + +struct encoding { + SCANNER scanners[XML_N_STATES]; + SCANNER literalScanners[XML_N_LITERAL_TYPES]; + int (PTRCALL *sameName)(const ENCODING *, + const char *, + const char *); + int (PTRCALL *nameMatchesAscii)(const ENCODING *, + const char *, + const char *, + const char *); + int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); + const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); + int (PTRCALL *getAtts)(const ENCODING *enc, + const char *ptr, + int attsMax, + ATTRIBUTE *atts); + int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); + int (PTRCALL *predefinedEntityName)(const ENCODING *, + const char *, + const char *); + void (PTRCALL *updatePosition)(const ENCODING *, + const char *ptr, + const char *end, + POSITION *); + int (PTRCALL *isPublicId)(const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr); + void (PTRCALL *utf8Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + char **toP, + const char *toLim); + void (PTRCALL *utf16Convert)(const ENCODING *enc, + const char **fromP, + const char *fromLim, + unsigned short **toP, + const unsigned short *toLim); + int minBytesPerChar; + char isUtf8; + char isUtf16; +}; + +/* Scan the string starting at ptr until the end of the next complete + token, but do not scan past eptr. Return an integer giving the + type of token. + + Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. + + Return XML_TOK_PARTIAL when the string does not contain a complete + token; nextTokPtr will not be set. + + Return XML_TOK_INVALID when the string does not start a valid + token; nextTokPtr will be set to point to the character which made + the token invalid. + + Otherwise the string starts with a valid token; nextTokPtr will be + set to point to the character following the end of that token. + + Each data character counts as a single token, but adjacent data + characters may be returned together. Similarly for characters in + the prolog outside literals, comments and processing instructions. +*/ + + +#define XmlTok(enc, state, ptr, end, nextTokPtr) \ + (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) + +#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) + +#define XmlContentTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) + +#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) + +#ifdef XML_DTD + +#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ + XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) + +#endif /* XML_DTD */ + +/* This is used for performing a 2nd-level tokenization on the content + of a literal that has already been returned by XmlTok. +*/ +#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ + (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) + +#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) + +#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ + XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) + +#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) + +#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ + (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) + +#define XmlNameLength(enc, ptr) \ + (((enc)->nameLength)(enc, ptr)) + +#define XmlSkipS(enc, ptr) \ + (((enc)->skipS)(enc, ptr)) + +#define XmlGetAttributes(enc, ptr, attsMax, atts) \ + (((enc)->getAtts)(enc, ptr, attsMax, atts)) + +#define XmlCharRefNumber(enc, ptr) \ + (((enc)->charRefNumber)(enc, ptr)) + +#define XmlPredefinedEntityName(enc, ptr, end) \ + (((enc)->predefinedEntityName)(enc, ptr, end)) + +#define XmlUpdatePosition(enc, ptr, end, pos) \ + (((enc)->updatePosition)(enc, ptr, end, pos)) + +#define XmlIsPublicId(enc, ptr, end, badPtr) \ + (((enc)->isPublicId)(enc, ptr, end, badPtr)) + +#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ + (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) + +#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ + (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) + +typedef struct { + ENCODING initEnc; + const ENCODING **encPtr; +} INIT_ENCODING; + +int XmlParseXmlDecl(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, + int *standalonePtr); + +int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); +const ENCODING *XmlGetUtf8InternalEncoding(void); +const ENCODING *XmlGetUtf16InternalEncoding(void); +int FASTCALL XmlUtf8Encode(int charNumber, char *buf); +int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); +int XmlSizeOfUnknownEncoding(void); + + +typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); + +ENCODING * +XmlInitUnknownEncoding(void *mem, + int *table, + CONVERTER convert, + void *userData); + +int XmlParseXmlDeclNS(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingNamePtr, + const ENCODING **namedEncodingPtr, + int *standalonePtr); + +int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); +const ENCODING *XmlGetUtf8InternalEncodingNS(void); +const ENCODING *XmlGetUtf16InternalEncodingNS(void); +ENCODING * +XmlInitUnknownEncodingNS(void *mem, + int *table, + CONVERTER convert, + void *userData); +#ifdef __cplusplus +} +#endif + +#endif /* not XmlTok_INCLUDED */ diff --git a/libxsde/xsde/c/expat/xmltok_impl.c b/libxsde/xsde/c/expat/xmltok_impl.c new file mode 100644 index 0000000..b0d23c8 --- /dev/null +++ b/libxsde/xsde/c/expat/xmltok_impl.c @@ -0,0 +1,1792 @@ +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd + See the file COPYING for copying permission. +*/ + +#ifndef IS_INVALID_CHAR +#define IS_INVALID_CHAR(enc, ptr, n) (0) +#endif + +#define INVALID_LEAD_CASE(n, ptr, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_INVALID_CHAR(enc, ptr, n)) { \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define INVALID_CASES(ptr, nextTokPtr) \ + INVALID_LEAD_CASE(2, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(3, ptr, nextTokPtr) \ + INVALID_LEAD_CASE(4, ptr, nextTokPtr) \ + case BT_NONXML: \ + case BT_MALFORM: \ + case BT_TRAIL: \ + *(nextTokPtr) = (ptr); \ + return XML_TOK_INVALID; + +#define CHECK_NAME_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (!IS_NAME_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (!IS_NAME_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + case BT_NMSTRT: \ + case BT_HEX: \ + case BT_DIGIT: \ + case BT_NAME: \ + case BT_MINUS: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NAME_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NAME_CASE(4, enc, ptr, end, nextTokPtr) + +#define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (!IS_NMSTRT_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + ptr += n; \ + break; + +#define CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) \ + case BT_NONASCII: \ + if (!IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ + case BT_NMSTRT: \ + case BT_HEX: \ + ptr += MINBPC(enc); \ + break; \ + CHECK_NMSTRT_CASE(2, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(3, enc, ptr, end, nextTokPtr) \ + CHECK_NMSTRT_CASE(4, enc, ptr, end, nextTokPtr) + +#ifndef PREFIX +#define PREFIX(ident) ident +#endif + +/* ptr points to character following "<!-" */ + +static int PTRCALL +PREFIX(scanComment)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + if (ptr != end) { + if (!CHAR_MATCHES(enc, ptr, ASCII_MINUS)) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + ptr += MINBPC(enc); + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + INVALID_CASES(ptr, nextTokPtr) + case BT_MINUS: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_MINUS)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_COMMENT; + } + break; + default: + ptr += MINBPC(enc); + break; + } + } + } + return XML_TOK_PARTIAL; +} + +/* ptr points to character following "<!" */ + +static int PTRCALL +PREFIX(scanDecl)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + case BT_MINUS: + return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_LSQB: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_COND_SECT_OPEN; + case BT_NMSTRT: + case BT_HEX: + ptr += MINBPC(enc); + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_PERCNT: + if (ptr + MINBPC(enc) == end) + return XML_TOK_PARTIAL; + /* don't allow <!ENTITY% foo "whatever"> */ + switch (BYTE_TYPE(enc, ptr + MINBPC(enc))) { + case BT_S: case BT_CR: case BT_LF: case BT_PERCNT: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + /* fall through */ + case BT_S: case BT_CR: case BT_LF: + *nextTokPtr = ptr; + return XML_TOK_DECL_OPEN; + case BT_NMSTRT: + case BT_HEX: + ptr += MINBPC(enc); + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(checkPiTarget)(const ENCODING *enc, const char *ptr, + const char *end, int *tokPtr) +{ + int upper = 0; + + UNUSED(enc); + + *tokPtr = XML_TOK_PI; + if (end - ptr != MINBPC(enc)*3) + return 1; + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_x: + break; + case ASCII_X: + upper = 1; + break; + default: + return 1; + } + ptr += MINBPC(enc); + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_m: + break; + case ASCII_M: + upper = 1; + break; + default: + return 1; + } + ptr += MINBPC(enc); + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_l: + break; + case ASCII_L: + upper = 1; + break; + default: + return 1; + } + if (upper) + return 0; + *tokPtr = XML_TOK_XML_DECL; + return 1; +} + +/* ptr points to character following "<?" */ + +static int PTRCALL +PREFIX(scanPi)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + int tok; + const char *target = ptr; + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_S: case BT_CR: case BT_LF: + if (!PREFIX(checkPiTarget)(enc, target, ptr, &tok)) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + ptr += MINBPC(enc); + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + INVALID_CASES(ptr, nextTokPtr) + case BT_QUEST: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { + *nextTokPtr = ptr + MINBPC(enc); + return tok; + } + break; + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; + case BT_QUEST: + if (!PREFIX(checkPiTarget)(enc, target, ptr, &tok)) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { + *nextTokPtr = ptr + MINBPC(enc); + return tok; + } + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(scanCdataSection)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + static const char CDATA_LSQB[] = { ASCII_C, ASCII_D, ASCII_A, + ASCII_T, ASCII_A, ASCII_LSQB }; + int i; + + UNUSED(enc); + + /* CDATA[ */ + if (end - ptr < 6 * MINBPC(enc)) + return XML_TOK_PARTIAL; + for (i = 0; i < 6; i++, ptr += MINBPC(enc)) { + if (!CHAR_MATCHES(enc, ptr, CDATA_LSQB[i])) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + *nextTokPtr = ptr; + return XML_TOK_CDATA_SECT_OPEN; +} + +static int PTRCALL +PREFIX(cdataSectionTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_NONE; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + break; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr -= MINBPC(enc); + break; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CDATA_SECT_CLOSE; + case BT_CR: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + case BT_LF: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + INVALID_CASES(ptr, nextTokPtr) + default: + ptr += MINBPC(enc); + break; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONXML: + case BT_MALFORM: + case BT_TRAIL: + case BT_CR: + case BT_LF: + case BT_RSQB: + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +/* ptr points to character following "</" */ + +static int PTRCALL +PREFIX(scanEndTag)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_S: case BT_CR: case BT_LF: + for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_CR: case BT_LF: + break; + case BT_GT: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_END_TAG; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +#ifdef XML_NS + case BT_COLON: + /* no need to check qname syntax here, + since end-tag must match exactly */ + ptr += MINBPC(enc); + break; +#endif + case BT_GT: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_END_TAG; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +/* ptr points to character following "&#X" */ + +static int PTRCALL +PREFIX(scanHexCharRef)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + if (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + case BT_HEX: + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + case BT_HEX: + break; + case BT_SEMI: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CHAR_REF; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + } + return XML_TOK_PARTIAL; +} + +/* ptr points to character following "&#" */ + +static int PTRCALL +PREFIX(scanCharRef)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + if (ptr != end) { + if (CHAR_MATCHES(enc, ptr, ASCII_x)) + return PREFIX(scanHexCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + for (ptr += MINBPC(enc); ptr != end; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + break; + case BT_SEMI: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CHAR_REF; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + } + return XML_TOK_PARTIAL; +} + +/* ptr points to character following "&" */ + +static int PTRCALL +PREFIX(scanRef)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_NUM: + return PREFIX(scanCharRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_SEMI: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_ENTITY_REF; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +/* ptr points to character following first character of attribute name */ + +static int PTRCALL +PREFIX(scanAtts)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ +#ifdef XML_NS + int hadColon = 0; +#endif + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) +#ifdef XML_NS + case BT_COLON: + if (hadColon) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + hadColon = 1; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + break; +#endif + case BT_S: case BT_CR: case BT_LF: + for (;;) { + int t; + + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + t = BYTE_TYPE(enc, ptr); + if (t == BT_EQUALS) + break; + switch (t) { + case BT_S: + case BT_LF: + case BT_CR: + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + /* fall through */ + case BT_EQUALS: + { + int open; +#ifdef XML_NS + hadColon = 0; +#endif + for (;;) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + open = BYTE_TYPE(enc, ptr); + if (open == BT_QUOT || open == BT_APOS) + break; + switch (open) { + case BT_S: + case BT_LF: + case BT_CR: + break; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + ptr += MINBPC(enc); + /* in attribute value */ + for (;;) { + int t; + if (ptr == end) + return XML_TOK_PARTIAL; + t = BYTE_TYPE(enc, ptr); + if (t == open) + break; + switch (t) { + INVALID_CASES(ptr, nextTokPtr) + case BT_AMP: + { + int tok = PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, &ptr); + if (tok <= 0) { + if (tok == XML_TOK_INVALID) + *nextTokPtr = ptr; + return tok; + } + break; + } + case BT_LT: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + default: + ptr += MINBPC(enc); + break; + } + } + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: + case BT_CR: + case BT_LF: + break; + case BT_SOL: + goto sol; + case BT_GT: + goto gt; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + /* ptr points to closing quote */ + for (;;) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_S: case BT_CR: case BT_LF: + continue; + case BT_GT: + gt: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_START_TAG_WITH_ATTS; + case BT_SOL: + sol: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_EMPTY_ELEMENT_WITH_ATTS; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + break; + } + break; + } + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +/* ptr points to character following "<" */ + +static int PTRCALL +PREFIX(scanLt)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ +#ifdef XML_NS + int hadColon; +#endif + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_EXCL: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + case BT_MINUS: + return PREFIX(scanComment)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_LSQB: + return PREFIX(scanCdataSection)(enc, ptr + MINBPC(enc), + end, nextTokPtr); + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_QUEST: + return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_SOL: + return PREFIX(scanEndTag)(enc, ptr + MINBPC(enc), end, nextTokPtr); + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } +#ifdef XML_NS + hadColon = 0; +#endif + /* we have a start-tag */ + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) +#ifdef XML_NS + case BT_COLON: + if (hadColon) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + hadColon = 1; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + break; +#endif + case BT_S: case BT_CR: case BT_LF: + { + ptr += MINBPC(enc); + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_GT: + goto gt; + case BT_SOL: + goto sol; + case BT_S: case BT_CR: case BT_LF: + ptr += MINBPC(enc); + continue; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + return PREFIX(scanAtts)(enc, ptr, end, nextTokPtr); + } + return XML_TOK_PARTIAL; + } + case BT_GT: + gt: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_START_TAG_NO_ATTS; + case BT_SOL: + sol: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_EMPTY_ELEMENT_NO_ATTS; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(contentTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_NONE; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_LT: + return PREFIX(scanLt)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_AMP: + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_CR: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + case BT_LF: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_RSQB; + if (!CHAR_MATCHES(enc, ptr, ASCII_RSQB)) + break; + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_RSQB; + if (!CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr -= MINBPC(enc); + break; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + INVALID_CASES(ptr, nextTokPtr) + default: + ptr += MINBPC(enc); + break; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n || IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_DATA_CHARS; \ + } \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_RSQB: + if (ptr + MINBPC(enc) != end) { + if (!CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_RSQB)) { + ptr += MINBPC(enc); + break; + } + if (ptr + 2*MINBPC(enc) != end) { + if (!CHAR_MATCHES(enc, ptr + 2*MINBPC(enc), ASCII_GT)) { + ptr += MINBPC(enc); + break; + } + *nextTokPtr = ptr + 2*MINBPC(enc); + return XML_TOK_INVALID; + } + } + /* fall through */ + case BT_AMP: + case BT_LT: + case BT_NONXML: + case BT_MALFORM: + case BT_TRAIL: + case BT_CR: + case BT_LF: + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +/* ptr points to character following "%" */ + +static int PTRCALL +PREFIX(scanPercent)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return -XML_TOK_PERCENT; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + case BT_S: case BT_LF: case BT_CR: case BT_PERCNT: + *nextTokPtr = ptr; + return XML_TOK_PERCENT; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_SEMI: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_PARAM_ENTITY_REF; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NMSTRT_CASES(enc, ptr, end, nextTokPtr) + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_CR: case BT_LF: case BT_S: + case BT_RPAR: case BT_GT: case BT_PERCNT: case BT_VERBAR: + *nextTokPtr = ptr; + return XML_TOK_POUND_NAME; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return -XML_TOK_POUND_NAME; +} + +static int PTRCALL +PREFIX(scanLit)(int open, const ENCODING *enc, + const char *ptr, const char *end, + const char **nextTokPtr) +{ + while (ptr != end) { + int t = BYTE_TYPE(enc, ptr); + switch (t) { + INVALID_CASES(ptr, nextTokPtr) + case BT_QUOT: + case BT_APOS: + ptr += MINBPC(enc); + if (t != open) + break; + if (ptr == end) + return -XML_TOK_LITERAL; + *nextTokPtr = ptr; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_CR: case BT_LF: + case BT_GT: case BT_PERCNT: case BT_LSQB: + return XML_TOK_LITERAL; + default: + return XML_TOK_INVALID; + } + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; +} + +static int PTRCALL +PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + int tok; + if (ptr == end) + return XML_TOK_NONE; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + if (n == 0) + return XML_TOK_PARTIAL; + end = ptr + n; + } + } + switch (BYTE_TYPE(enc, ptr)) { + case BT_QUOT: + return PREFIX(scanLit)(BT_QUOT, enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_APOS: + return PREFIX(scanLit)(BT_APOS, enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_LT: + { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_PARTIAL; + switch (BYTE_TYPE(enc, ptr)) { + case BT_EXCL: + return PREFIX(scanDecl)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_QUEST: + return PREFIX(scanPi)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_NMSTRT: + case BT_HEX: + case BT_NONASCII: + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + *nextTokPtr = ptr - MINBPC(enc); + return XML_TOK_INSTANCE_START; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + case BT_CR: + if (ptr + MINBPC(enc) == end) { + *nextTokPtr = end; + /* indicate that this might be part of a CR/LF pair */ + return -XML_TOK_PROLOG_S; + } + /* fall through */ + case BT_S: case BT_LF: + for (;;) { + ptr += MINBPC(enc); + if (ptr == end) + break; + switch (BYTE_TYPE(enc, ptr)) { + case BT_S: case BT_LF: + break; + case BT_CR: + /* don't split CR/LF pair */ + if (ptr + MINBPC(enc) != end) + break; + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_PROLOG_S; + } + } + *nextTokPtr = ptr; + return XML_TOK_PROLOG_S; + case BT_PERCNT: + return PREFIX(scanPercent)(enc, ptr + MINBPC(enc), end, nextTokPtr); + case BT_COMMA: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_COMMA; + case BT_LSQB: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OPEN_BRACKET; + case BT_RSQB: + ptr += MINBPC(enc); + if (ptr == end) + return -XML_TOK_CLOSE_BRACKET; + if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { + if (ptr + MINBPC(enc) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_GT)) { + *nextTokPtr = ptr + 2*MINBPC(enc); + return XML_TOK_COND_SECT_CLOSE; + } + } + *nextTokPtr = ptr; + return XML_TOK_CLOSE_BRACKET; + case BT_LPAR: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OPEN_PAREN; + case BT_RPAR: + ptr += MINBPC(enc); + if (ptr == end) + return -XML_TOK_CLOSE_PAREN; + switch (BYTE_TYPE(enc, ptr)) { + case BT_AST: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_ASTERISK; + case BT_QUEST: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_QUESTION; + case BT_PLUS: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_CLOSE_PAREN_PLUS; + case BT_CR: case BT_LF: case BT_S: + case BT_GT: case BT_COMMA: case BT_VERBAR: + case BT_RPAR: + *nextTokPtr = ptr; + return XML_TOK_CLOSE_PAREN; + } + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_VERBAR: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_OR; + case BT_GT: + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DECL_CLOSE; + case BT_NUM: + return PREFIX(scanPoundName)(enc, ptr + MINBPC(enc), end, nextTokPtr); +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (end - ptr < n) \ + return XML_TOK_PARTIAL_CHAR; \ + if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NAME; \ + break; \ + } \ + if (IS_NAME_CHAR(enc, ptr, n)) { \ + ptr += n; \ + tok = XML_TOK_NMTOKEN; \ + break; \ + } \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NMSTRT: + case BT_HEX: + tok = XML_TOK_NAME; + ptr += MINBPC(enc); + break; + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: +#ifdef XML_NS + case BT_COLON: +#endif + tok = XML_TOK_NMTOKEN; + ptr += MINBPC(enc); + break; + case BT_NONASCII: + if (IS_NMSTRT_CHAR_MINBPC(enc, ptr)) { + ptr += MINBPC(enc); + tok = XML_TOK_NAME; + break; + } + if (IS_NAME_CHAR_MINBPC(enc, ptr)) { + ptr += MINBPC(enc); + tok = XML_TOK_NMTOKEN; + break; + } + /* fall through */ + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + case BT_GT: case BT_RPAR: case BT_COMMA: + case BT_VERBAR: case BT_LSQB: case BT_PERCNT: + case BT_S: case BT_CR: case BT_LF: + *nextTokPtr = ptr; + return tok; +#ifdef XML_NS + case BT_COLON: + ptr += MINBPC(enc); + switch (tok) { + case XML_TOK_NAME: + if (ptr == end) + return XML_TOK_PARTIAL; + tok = XML_TOK_PREFIXED_NAME; + switch (BYTE_TYPE(enc, ptr)) { + CHECK_NAME_CASES(enc, ptr, end, nextTokPtr) + default: + tok = XML_TOK_NMTOKEN; + break; + } + break; + case XML_TOK_PREFIXED_NAME: + tok = XML_TOK_NMTOKEN; + break; + } + break; +#endif + case BT_PLUS: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_PLUS; + case BT_AST: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_ASTERISK; + case BT_QUEST: + if (tok == XML_TOK_NMTOKEN) { + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_NAME_QUESTION; + default: + *nextTokPtr = ptr; + return XML_TOK_INVALID; + } + } + return -tok; +} + +static int PTRCALL +PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + const char *start; + if (ptr == end) + return XML_TOK_NONE; + start = ptr; + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_AMP: + if (ptr == start) + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_LT: + /* this is for inside entity references */ + *nextTokPtr = ptr; + return XML_TOK_INVALID; + case BT_LF: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_CR: + if (ptr == start) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_S: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_ATTRIBUTE_VALUE_S; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +static int PTRCALL +PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + const char *start; + if (ptr == end) + return XML_TOK_NONE; + start = ptr; + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_AMP: + if (ptr == start) + return PREFIX(scanRef)(enc, ptr + MINBPC(enc), end, nextTokPtr); + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_PERCNT: + if (ptr == start) { + int tok = PREFIX(scanPercent)(enc, ptr + MINBPC(enc), + end, nextTokPtr); + return (tok == XML_TOK_PERCENT) ? XML_TOK_INVALID : tok; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_LF: + if (ptr == start) { + *nextTokPtr = ptr + MINBPC(enc); + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + case BT_CR: + if (ptr == start) { + ptr += MINBPC(enc); + if (ptr == end) + return XML_TOK_TRAILING_CR; + if (BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + *nextTokPtr = ptr; + return XML_TOK_DATA_NEWLINE; + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; + default: + ptr += MINBPC(enc); + break; + } + } + *nextTokPtr = ptr; + return XML_TOK_DATA_CHARS; +} + +#ifdef XML_DTD + +static int PTRCALL +PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, + const char *end, const char **nextTokPtr) +{ + int level = 0; + if (MINBPC(enc) > 1) { + size_t n = end - ptr; + if (n & (MINBPC(enc) - 1)) { + n &= ~(MINBPC(enc) - 1); + end = ptr + n; + } + } + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { + INVALID_CASES(ptr, nextTokPtr) + case BT_LT: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_EXCL)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_LSQB)) { + ++level; + ptr += MINBPC(enc); + } + } + break; + case BT_RSQB: + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_RSQB)) { + if ((ptr += MINBPC(enc)) == end) + return XML_TOK_PARTIAL; + if (CHAR_MATCHES(enc, ptr, ASCII_GT)) { + ptr += MINBPC(enc); + if (level == 0) { + *nextTokPtr = ptr; + return XML_TOK_IGNORE_SECT; + } + --level; + } + } + break; + default: + ptr += MINBPC(enc); + break; + } + } + return XML_TOK_PARTIAL; +} + +#endif /* XML_DTD */ + +static int PTRCALL +PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end, + const char **badPtr) +{ + ptr += MINBPC(enc); + end -= MINBPC(enc); + for (; ptr != end; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_DIGIT: + case BT_HEX: + case BT_MINUS: + case BT_APOS: + case BT_LPAR: + case BT_RPAR: + case BT_PLUS: + case BT_COMMA: + case BT_SOL: + case BT_EQUALS: + case BT_QUEST: + case BT_CR: + case BT_LF: + case BT_SEMI: + case BT_EXCL: + case BT_AST: + case BT_PERCNT: + case BT_NUM: +#ifdef XML_NS + case BT_COLON: +#endif + break; + case BT_S: + if (CHAR_MATCHES(enc, ptr, ASCII_TAB)) { + *badPtr = ptr; + return 0; + } + break; + case BT_NAME: + case BT_NMSTRT: + if (!(BYTE_TO_ASCII(enc, ptr) & ~0x7f)) + break; + default: + switch (BYTE_TO_ASCII(enc, ptr)) { + case 0x24: /* $ */ + case 0x40: /* @ */ + break; + default: + *badPtr = ptr; + return 0; + } + break; + } + } + return 1; +} + +/* This must only be called for a well-formed start-tag or empty + element tag. Returns the number of attributes. Pointers to the + first attsMax attributes are stored in atts. +*/ + +static int PTRCALL +PREFIX(getAtts)(const ENCODING *enc, const char *ptr, + int attsMax, ATTRIBUTE *atts) +{ + enum { other, inName, inValue } state = inName; + int nAtts = 0; + int open = 0; /* defined when state == inValue; + initialization just to shut up compilers */ + + for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { + switch (BYTE_TYPE(enc, ptr)) { +#define START_NAME \ + if (state == other) { \ + if (nAtts < attsMax) { \ + atts[nAtts].name = ptr; \ + atts[nAtts].normalized = 1; \ + } \ + state = inName; \ + } +#define LEAD_CASE(n) \ + case BT_LEAD ## n: START_NAME ptr += (n - MINBPC(enc)); break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONASCII: + case BT_NMSTRT: + case BT_HEX: + START_NAME + break; +#undef START_NAME + case BT_QUOT: + if (state != inValue) { + if (nAtts < attsMax) + atts[nAtts].valuePtr = ptr + MINBPC(enc); + state = inValue; + open = BT_QUOT; + } + else if (open == BT_QUOT) { + state = other; + if (nAtts < attsMax) + atts[nAtts].valueEnd = ptr; + nAtts++; + } + break; + case BT_APOS: + if (state != inValue) { + if (nAtts < attsMax) + atts[nAtts].valuePtr = ptr + MINBPC(enc); + state = inValue; + open = BT_APOS; + } + else if (open == BT_APOS) { + state = other; + if (nAtts < attsMax) + atts[nAtts].valueEnd = ptr; + nAtts++; + } + break; + case BT_AMP: + if (nAtts < attsMax) + atts[nAtts].normalized = 0; + break; + case BT_S: + if (state == inName) + state = other; + else if (state == inValue + && nAtts < attsMax + && atts[nAtts].normalized + && (ptr == atts[nAtts].valuePtr + || BYTE_TO_ASCII(enc, ptr) != ASCII_SPACE + || BYTE_TO_ASCII(enc, ptr + MINBPC(enc)) == ASCII_SPACE + || BYTE_TYPE(enc, ptr + MINBPC(enc)) == open)) + atts[nAtts].normalized = 0; + break; + case BT_CR: case BT_LF: + /* This case ensures that the first attribute name is counted + Apart from that we could just change state on the quote. */ + if (state == inName) + state = other; + else if (state == inValue && nAtts < attsMax) + atts[nAtts].normalized = 0; + break; + case BT_GT: + case BT_SOL: + if (state != inValue) + return nAtts; + break; + default: + break; + } + } + /* not reached */ +} + +static int PTRFASTCALL +PREFIX(charRefNumber)(const ENCODING *enc, const char *ptr) +{ + int result = 0; + + UNUSED(enc); + + /* skip &# */ + ptr += 2*MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_x)) { + for (ptr += MINBPC(enc); + !CHAR_MATCHES(enc, ptr, ASCII_SEMI); + ptr += MINBPC(enc)) { + int c = BYTE_TO_ASCII(enc, ptr); + switch (c) { + case ASCII_0: case ASCII_1: case ASCII_2: case ASCII_3: case ASCII_4: + case ASCII_5: case ASCII_6: case ASCII_7: case ASCII_8: case ASCII_9: + result <<= 4; + result |= (c - ASCII_0); + break; + case ASCII_A: case ASCII_B: case ASCII_C: + case ASCII_D: case ASCII_E: case ASCII_F: + result <<= 4; + result += 10 + (c - ASCII_A); + break; + case ASCII_a: case ASCII_b: case ASCII_c: + case ASCII_d: case ASCII_e: case ASCII_f: + result <<= 4; + result += 10 + (c - ASCII_a); + break; + } + if (result >= 0x110000) + return -1; + } + } + else { + for (; !CHAR_MATCHES(enc, ptr, ASCII_SEMI); ptr += MINBPC(enc)) { + int c = BYTE_TO_ASCII(enc, ptr); + result *= 10; + result += (c - ASCII_0); + if (result >= 0x110000) + return -1; + } + } + return checkCharRefNumber(result); +} + +static int PTRCALL +PREFIX(predefinedEntityName)(const ENCODING *enc, const char *ptr, + const char *end) +{ + UNUSED(enc); + + switch ((end - ptr)/MINBPC(enc)) { + case 2: + if (CHAR_MATCHES(enc, ptr + MINBPC(enc), ASCII_t)) { + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_l: + return ASCII_LT; + case ASCII_g: + return ASCII_GT; + } + } + break; + case 3: + if (CHAR_MATCHES(enc, ptr, ASCII_a)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_m)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_p)) + return ASCII_AMP; + } + } + break; + case 4: + switch (BYTE_TO_ASCII(enc, ptr)) { + case ASCII_q: + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_u)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_o)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_t)) + return ASCII_QUOT; + } + } + break; + case ASCII_a: + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_p)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_o)) { + ptr += MINBPC(enc); + if (CHAR_MATCHES(enc, ptr, ASCII_s)) + return ASCII_APOS; + } + } + break; + } + } + return 0; +} + +static int PTRCALL +PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2) +{ + for (;;) { + switch (BYTE_TYPE(enc, ptr1)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + if (*ptr1++ != *ptr2++) \ + return 0; + LEAD_CASE(4) LEAD_CASE(3) LEAD_CASE(2) +#undef LEAD_CASE + /* fall through */ + if (*ptr1++ != *ptr2++) + return 0; + break; + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 1) { + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 2) { + if (*ptr2++ != *ptr1++) + return 0; + if (MINBPC(enc) > 3) { + if (*ptr2++ != *ptr1++) + return 0; + } + } + } + break; + default: + if (MINBPC(enc) == 1 && *ptr1 == *ptr2) + return 1; + switch (BYTE_TYPE(enc, ptr2)) { + case BT_LEAD2: + case BT_LEAD3: + case BT_LEAD4: + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + return 0; + default: + return 1; + } + } + } + /* not reached */ +} + +static int PTRCALL +PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, + const char *end1, const char *ptr2) +{ + UNUSED(enc); + + for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) { + if (ptr1 == end1) + return 0; + if (!CHAR_MATCHES(enc, ptr1, *ptr2)) + return 0; + } + return ptr1 == end1; +} + +static int PTRFASTCALL +PREFIX(nameLength)(const ENCODING *enc, const char *ptr) +{ + const char *start = ptr; + for (;;) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: ptr += n; break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_NONASCII: + case BT_NMSTRT: +#ifdef XML_NS + case BT_COLON: +#endif + case BT_HEX: + case BT_DIGIT: + case BT_NAME: + case BT_MINUS: + ptr += MINBPC(enc); + break; + default: + return (int)(ptr - start); + } + } +} + +static const char * PTRFASTCALL +PREFIX(skipS)(const ENCODING *enc, const char *ptr) +{ + for (;;) { + switch (BYTE_TYPE(enc, ptr)) { + case BT_LF: + case BT_CR: + case BT_S: + ptr += MINBPC(enc); + break; + default: + return ptr; + } + } +} + +static void PTRCALL +PREFIX(updatePosition)(const ENCODING *enc, + const char *ptr, + const char *end, + POSITION *pos) +{ + while (ptr != end) { + switch (BYTE_TYPE(enc, ptr)) { +#define LEAD_CASE(n) \ + case BT_LEAD ## n: \ + ptr += n; \ + break; + LEAD_CASE(2) LEAD_CASE(3) LEAD_CASE(4) +#undef LEAD_CASE + case BT_LF: + pos->columnNumber = (XML_Size)-1; + pos->lineNumber++; + ptr += MINBPC(enc); + break; + case BT_CR: + pos->lineNumber++; + ptr += MINBPC(enc); + if (ptr != end && BYTE_TYPE(enc, ptr) == BT_LF) + ptr += MINBPC(enc); + pos->columnNumber = (XML_Size)-1; + break; + default: + ptr += MINBPC(enc); + break; + } + pos->columnNumber++; + } +} + +#undef DO_LEAD_CASE +#undef MULTIBYTE_CASES +#undef INVALID_CASES +#undef CHECK_NAME_CASE +#undef CHECK_NAME_CASES +#undef CHECK_NMSTRT_CASE +#undef CHECK_NMSTRT_CASES + diff --git a/libxsde/xsde/c/expat/xmltok_impl.h b/libxsde/xsde/c/expat/xmltok_impl.h new file mode 100644 index 0000000..da0ea60 --- /dev/null +++ b/libxsde/xsde/c/expat/xmltok_impl.h @@ -0,0 +1,46 @@ +/* +Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd +See the file COPYING for copying permission. +*/ + +enum { + BT_NONXML, + BT_MALFORM, + BT_LT, + BT_AMP, + BT_RSQB, + BT_LEAD2, + BT_LEAD3, + BT_LEAD4, + BT_TRAIL, + BT_CR, + BT_LF, + BT_GT, + BT_QUOT, + BT_APOS, + BT_EQUALS, + BT_QUEST, + BT_EXCL, + BT_SOL, + BT_SEMI, + BT_NUM, + BT_LSQB, + BT_S, + BT_NMSTRT, + BT_COLON, + BT_HEX, + BT_DIGIT, + BT_NAME, + BT_MINUS, + BT_OTHER, /* known not to be a name or name start character */ + BT_NONASCII, /* might be a name or name start character */ + BT_PERCNT, + BT_LPAR, + BT_RPAR, + BT_AST, + BT_PLUS, + BT_COMMA, + BT_VERBAR +}; + +#include <stddef.h> diff --git a/libxsde/xsde/c/expat/xmltok_ns.c b/libxsde/xsde/c/expat/xmltok_ns.c new file mode 100644 index 0000000..d2f8938 --- /dev/null +++ b/libxsde/xsde/c/expat/xmltok_ns.c @@ -0,0 +1,106 @@ +const ENCODING * +NS(XmlGetUtf8InternalEncoding)(void) +{ + return &ns(internal_utf8_encoding).enc; +} + +const ENCODING * +NS(XmlGetUtf16InternalEncoding)(void) +{ +#if BYTEORDER == 1234 + return &ns(internal_little2_encoding).enc; +#elif BYTEORDER == 4321 + return &ns(internal_big2_encoding).enc; +#else + const short n = 1; + return (*(const char *)&n + ? &ns(internal_little2_encoding).enc + : &ns(internal_big2_encoding).enc); +#endif +} + +static const ENCODING * const NS(encodings)[] = { + &ns(latin1_encoding).enc, + &ns(ascii_encoding).enc, + &ns(utf8_encoding).enc, + &ns(big2_encoding).enc, + &ns(big2_encoding).enc, + &ns(little2_encoding).enc, + &ns(utf8_encoding).enc /* NO_ENC */ +}; + +static int PTRCALL +NS(initScanProlog)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + return initScan(NS(encodings), (const INIT_ENCODING *)enc, + XML_PROLOG_STATE, ptr, end, nextTokPtr); +} + +static int PTRCALL +NS(initScanContent)(const ENCODING *enc, const char *ptr, const char *end, + const char **nextTokPtr) +{ + return initScan(NS(encodings), (const INIT_ENCODING *)enc, + XML_CONTENT_STATE, ptr, end, nextTokPtr); +} + +int +NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, + const char *name) +{ + int i = getEncodingIndex(name); + if (i == UNKNOWN_ENC) + return 0; + SET_INIT_ENC_INDEX(p, i); + p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog); + p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent); + p->initEnc.updatePosition = initUpdatePosition; + p->encPtr = encPtr; + *encPtr = &(p->initEnc); + return 1; +} + +static const ENCODING * +NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) +{ +#define ENCODING_MAX 128 + char buf[ENCODING_MAX]; + char *p = buf; + int i; + XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); + if (ptr != end) + return 0; + *p = 0; + if (streqci(buf, KW_UTF_16) && enc->minBytesPerChar == 2) + return enc; + i = getEncodingIndex(buf); + if (i == UNKNOWN_ENC) + return 0; + return NS(encodings)[i]; +} + +int +NS(XmlParseXmlDecl)(int isGeneralTextEntity, + const ENCODING *enc, + const char *ptr, + const char *end, + const char **badPtr, + const char **versionPtr, + const char **versionEndPtr, + const char **encodingName, + const ENCODING **encoding, + int *standalone) +{ + return doParseXmlDecl(NS(findEncoding), + isGeneralTextEntity, + enc, + ptr, + end, + badPtr, + versionPtr, + versionEndPtr, + encodingName, + encoding, + standalone); +} diff --git a/libxsde/xsde/c/genx/COPYING b/libxsde/xsde/c/genx/COPYING new file mode 100644 index 0000000..e9b23f6 --- /dev/null +++ b/libxsde/xsde/c/genx/COPYING @@ -0,0 +1,39 @@ +Copyright (c) 2007-2009 Code Synthesis Tools CC. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Original Version: + +Copyright (c) Tim Bray and Sun Microsystems, 2004. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/libxsde/xsde/c/genx/char-props.c b/libxsde/xsde/c/genx/char-props.c new file mode 100644 index 0000000..a4fb16a --- /dev/null +++ b/libxsde/xsde/c/genx/char-props.c @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2007-2009 Code Synthesis Tools CC. + * Copyright (c) 2004 by Tim Bray and Sun Microsystems. + * + * For copying permission, see the accompanying COPYING file. + */ + +/* + * Construct character-properties tables for genx. + * Quite likely there's a better way. + * This version is generated semi-automatically from the source code of the + * XML specification via emacs global replace and keyboard macros + */ +#include "genx.h" + +static void charProp(char * p, int c, int prop) +{ + p[c] |= prop; +} + +static void rangeProp(char * p, int start, int end, int prop) +{ + int i; + for (i = start; i <= end; i++) + p[i] |= prop; +} + +void genxSetCharProps(char * p) +{ + int i; + + for (i = 0; i <= 0xffff; i++) + p[i] = 0; + + /* per XML 1.0 */ + charProp(p, 0x9, GENX_XML_CHAR); + charProp(p, 0xa, GENX_XML_CHAR); + charProp(p, 0xd, GENX_XML_CHAR); + rangeProp(p, 0x20, 0xd7ff, GENX_XML_CHAR); + rangeProp(p, 0xe000, 0xfffd, GENX_XML_CHAR); + + /* Letter ::= BaseChar | Ideographic */ + rangeProp(p, 0x0041, 0x005A, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0061, 0x007A, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x00C0, 0x00D6, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x00D8, 0x00F6, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x00F8, 0x00FF, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0100, 0x0131, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0134, 0x013E, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0141, 0x0148, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x014A, 0x017E, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0180, 0x01C3, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x01CD, 0x01F0, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x01F4, 0x01F5, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x01FA, 0x0217, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0250, 0x02A8, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x02BB, 0x02C1, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0386, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0388, 0x038A, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x038C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x038E, 0x03A1, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x03A3, 0x03CE, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x03D0, 0x03D6, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x03DA, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x03DC, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x03DE, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x03E0, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x03E2, 0x03F3, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0401, 0x040C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x040E, 0x044F, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0451, 0x045C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x045E, 0x0481, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0490, 0x04C4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x04C7, 0x04C8, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x04CB, 0x04CC, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x04D0, 0x04EB, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x04EE, 0x04F5, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x04F8, 0x04F9, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0531, 0x0556, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0559, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0561, 0x0586, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x05D0, 0x05EA, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x05F0, 0x05F2, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0621, 0x063A, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0641, 0x064A, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0671, 0x06B7, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x06BA, 0x06BE, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x06C0, 0x06CE, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x06D0, 0x06D3, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x06D5, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x06E5, 0x06E6, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0905, 0x0939, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x093D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0958, 0x0961, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0985, 0x098C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x098F, 0x0990, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0993, 0x09A8, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09AA, 0x09B0, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x09B2, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09B6, 0x09B9, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09DC, 0x09DD, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09DF, 0x09E1, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09F0, 0x09F1, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A05, 0x0A0A, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A0F, 0x0A10, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A13, 0x0A28, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A2A, 0x0A30, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A32, 0x0A33, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A35, 0x0A36, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A38, 0x0A39, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A59, 0x0A5C, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0A5E, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A72, 0x0A74, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A85, 0x0A8B, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0A8D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A8F, 0x0A91, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A93, 0x0AA8, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0AAA, 0x0AB0, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0AB2, 0x0AB3, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0AB5, 0x0AB9, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0ABD, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0AE0, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B05, 0x0B0C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B0F, 0x0B10, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B13, 0x0B28, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B2A, 0x0B30, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B32, 0x0B33, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B36, 0x0B39, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0B3D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B5C, 0x0B5D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B5F, 0x0B61, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B85, 0x0B8A, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B8E, 0x0B90, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B92, 0x0B95, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B99, 0x0B9A, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0B9C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B9E, 0x0B9F, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0BA3, 0x0BA4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0BA8, 0x0BAA, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0BAE, 0x0BB5, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0BB7, 0x0BB9, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C05, 0x0C0C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C0E, 0x0C10, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C12, 0x0C28, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C2A, 0x0C33, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C35, 0x0C39, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C60, 0x0C61, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C85, 0x0C8C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C8E, 0x0C90, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C92, 0x0CA8, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0CAA, 0x0CB3, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0CB5, 0x0CB9, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0CDE, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0CE0, 0x0CE1, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0D05, 0x0D0C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0D0E, 0x0D10, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0D12, 0x0D28, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0D2A, 0x0D39, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0D60, 0x0D61, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E01, 0x0E2E, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0E30, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E32, 0x0E33, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E40, 0x0E45, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E81, 0x0E82, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0E84, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E87, 0x0E88, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0E8A, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0E8D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E94, 0x0E97, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E99, 0x0E9F, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0EA1, 0x0EA3, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0EA5, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0EA7, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0EAA, 0x0EAB, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0EAD, 0x0EAE, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0EB0, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0EB2, 0x0EB3, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0EBD, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0EC0, 0x0EC4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0F40, 0x0F47, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0F49, 0x0F69, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x10A0, 0x10C5, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x10D0, 0x10F6, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1100, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1102, 0x1103, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1105, 0x1107, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1109, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x110B, 0x110C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x110E, 0x1112, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x113C, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x113E, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1140, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x114C, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x114E, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1150, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1154, 0x1155, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1159, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x115F, 0x1161, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1163, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1165, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1167, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1169, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x116D, 0x116E, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1172, 0x1173, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1175, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x119E, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x11A8, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x11AB, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x11AE, 0x11AF, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x11B7, 0x11B8, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x11BA, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x11BC, 0x11C2, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x11EB, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x11F0, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x11F9, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1E00, 0x1E9B, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1EA0, 0x1EF9, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F00, 0x1F15, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F18, 0x1F1D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F20, 0x1F45, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F48, 0x1F4D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F50, 0x1F57, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1F59, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1F5B, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1F5D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F5F, 0x1F7D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1F80, 0x1FB4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FB6, 0x1FBC, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x1FBE, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FC2, 0x1FC4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FC6, 0x1FCC, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FD0, 0x1FD3, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FD6, 0x1FDB, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FE0, 0x1FEC, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FF2, 0x1FF4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x1FF6, 0x1FFC, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x2126, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x212A, 0x212B, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x212E, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x2180, 0x2182, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x3041, 0x3094, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x30A1, 0x30FA, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x3105, 0x312C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0xAC00, 0xD7A3, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x4E00, 0x9FA5, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x3007, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x3021, 0x3029, GENX_LETTER|GENX_NAMECHAR); + + /* + * NameChar ::= + * Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender + */ + rangeProp(p, 0x0030, 0x0039, GENX_NAMECHAR); + rangeProp(p, 0x0660, 0x0669, GENX_NAMECHAR); + rangeProp(p, 0x06F0, 0x06F9, GENX_NAMECHAR); + rangeProp(p, 0x0966, 0x096F, GENX_NAMECHAR); + rangeProp(p, 0x09E6, 0x09EF, GENX_NAMECHAR); + rangeProp(p, 0x0A66, 0x0A6F, GENX_NAMECHAR); + rangeProp(p, 0x0AE6, 0x0AEF, GENX_NAMECHAR); + rangeProp(p, 0x0B66, 0x0B6F, GENX_NAMECHAR); + rangeProp(p, 0x0BE7, 0x0BEF, GENX_NAMECHAR); + rangeProp(p, 0x0C66, 0x0C6F, GENX_NAMECHAR); + rangeProp(p, 0x0CE6, 0x0CEF, GENX_NAMECHAR); + rangeProp(p, 0x0D66, 0x0D6F, GENX_NAMECHAR); + rangeProp(p, 0x0E50, 0x0E59, GENX_NAMECHAR); + rangeProp(p, 0x0ED0, 0x0ED9, GENX_NAMECHAR); + rangeProp(p, 0x0F20, 0x0F29, GENX_NAMECHAR); + + charProp(p, '.', GENX_NAMECHAR); + charProp(p, '-', GENX_NAMECHAR); + charProp(p, '_', GENX_NAMECHAR); + + rangeProp(p, 0x0300, 0x0345, GENX_NAMECHAR); + rangeProp(p, 0x0360, 0x0361, GENX_NAMECHAR); + rangeProp(p, 0x0483, 0x0486, GENX_NAMECHAR); + rangeProp(p, 0x0591, 0x05A1, GENX_NAMECHAR); + rangeProp(p, 0x05A3, 0x05B9, GENX_NAMECHAR); + rangeProp(p, 0x05BB, 0x05BD, GENX_NAMECHAR); + charProp(p, 0x05BF, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x05C1, 0x05C2, GENX_NAMECHAR); + charProp(p, 0x05C4, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x064B, 0x0652, GENX_NAMECHAR); + charProp(p, 0x0670, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x06D6, 0x06DC, GENX_NAMECHAR); + rangeProp(p, 0x06DD, 0x06DF, GENX_NAMECHAR); + rangeProp(p, 0x06E0, 0x06E4, GENX_NAMECHAR); + rangeProp(p, 0x06E7, 0x06E8, GENX_NAMECHAR); + rangeProp(p, 0x06EA, 0x06ED, GENX_NAMECHAR); + rangeProp(p, 0x0901, 0x0903, GENX_NAMECHAR); + charProp(p, 0x093C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x093E, 0x094C, GENX_NAMECHAR); + charProp(p, 0x094D, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0951, 0x0954, GENX_NAMECHAR); + rangeProp(p, 0x0962, 0x0963, GENX_NAMECHAR); + rangeProp(p, 0x0981, 0x0983, GENX_NAMECHAR); + charProp(p, 0x09BC, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x09BE, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x09BF, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09C0, 0x09C4, GENX_NAMECHAR); + rangeProp(p, 0x09C7, 0x09C8, GENX_NAMECHAR); + rangeProp(p, 0x09CB, 0x09CD, GENX_NAMECHAR); + charProp(p, 0x09D7, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x09E2, 0x09E3, GENX_NAMECHAR); + charProp(p, 0x0A02, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0A3C, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0A3E, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0A3F, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0A40, 0x0A42, GENX_NAMECHAR); + rangeProp(p, 0x0A47, 0x0A48, GENX_NAMECHAR); + rangeProp(p, 0x0A4B, 0x0A4D, GENX_NAMECHAR); + rangeProp(p, 0x0A70, 0x0A71, GENX_NAMECHAR); + rangeProp(p, 0x0A81, 0x0A83, GENX_NAMECHAR); + charProp(p, 0x0ABC, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0ABE, 0x0AC5, GENX_NAMECHAR); + rangeProp(p, 0x0AC7, 0x0AC9, GENX_NAMECHAR); + rangeProp(p, 0x0ACB, 0x0ACD, GENX_NAMECHAR); + rangeProp(p, 0x0B01, 0x0B03, GENX_NAMECHAR); + charProp(p, 0x0B3C, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0B3E, 0x0B43, GENX_NAMECHAR); + rangeProp(p, 0x0B47, 0x0B48, GENX_NAMECHAR); + rangeProp(p, 0x0B4B, 0x0B4D, GENX_NAMECHAR); + rangeProp(p, 0x0B56, 0x0B57, GENX_NAMECHAR); + rangeProp(p, 0x0B82, 0x0B83, GENX_NAMECHAR); + rangeProp(p, 0x0BBE, 0x0BC2, GENX_NAMECHAR); + rangeProp(p, 0x0BC6, 0x0BC8, GENX_NAMECHAR); + rangeProp(p, 0x0BCA, 0x0BCD, GENX_NAMECHAR); + charProp(p, 0x0BD7, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0C01, 0x0C03, GENX_NAMECHAR); + rangeProp(p, 0x0C3E, 0x0C44, GENX_NAMECHAR); + rangeProp(p, 0x0C46, 0x0C48, GENX_NAMECHAR); + rangeProp(p, 0x0C4A, 0x0C4D, GENX_NAMECHAR); + rangeProp(p, 0x0C55, 0x0C56, GENX_NAMECHAR); + rangeProp(p, 0x0C82, 0x0C83, GENX_NAMECHAR); + rangeProp(p, 0x0CBE, 0x0CC4, GENX_NAMECHAR); + rangeProp(p, 0x0CC6, 0x0CC8, GENX_NAMECHAR); + rangeProp(p, 0x0CCA, 0x0CCD, GENX_NAMECHAR); + rangeProp(p, 0x0CD5, 0x0CD6, GENX_NAMECHAR); + rangeProp(p, 0x0D02, 0x0D03, GENX_NAMECHAR); + rangeProp(p, 0x0D3E, 0x0D43, GENX_NAMECHAR); + rangeProp(p, 0x0D46, 0x0D48, GENX_NAMECHAR); + rangeProp(p, 0x0D4A, 0x0D4D, GENX_NAMECHAR); + charProp(p, 0x0D57, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0E31, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0E34, 0x0E3A, GENX_NAMECHAR); + rangeProp(p, 0x0E47, 0x0E4E, GENX_NAMECHAR); + charProp(p, 0x0EB1, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0EB4, 0x0EB9, GENX_NAMECHAR); + rangeProp(p, 0x0EBB, 0x0EBC, GENX_NAMECHAR); + rangeProp(p, 0x0EC8, 0x0ECD, GENX_NAMECHAR); + rangeProp(p, 0x0F18, 0x0F19, GENX_NAMECHAR); + charProp(p, 0x0F35, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0F37, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0F39, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0F3E, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0F3F, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0F71, 0x0F84, GENX_NAMECHAR); + rangeProp(p, 0x0F86, 0x0F8B, GENX_NAMECHAR); + rangeProp(p, 0x0F90, 0x0F95, GENX_NAMECHAR); + charProp(p, 0x0F97, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x0F99, 0x0FAD, GENX_NAMECHAR); + rangeProp(p, 0x0FB1, 0x0FB7, GENX_NAMECHAR); + charProp(p, 0x0FB9, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x20D0, 0x20DC, GENX_NAMECHAR); + charProp(p, 0x20E1, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x302A, 0x302F, GENX_NAMECHAR); + charProp(p, 0x3099, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x309A, GENX_LETTER|GENX_NAMECHAR); + + charProp(p, 0x00B7, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x02D0, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x02D1, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0387, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0640, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0E46, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x0EC6, GENX_LETTER|GENX_NAMECHAR); + charProp(p, 0x3005, GENX_LETTER|GENX_NAMECHAR); + rangeProp(p, 0x3031, 0x3035, GENX_NAMECHAR); + rangeProp(p, 0x309D, 0x309E, GENX_NAMECHAR); + rangeProp(p, 0x30FC, 0x30FE, GENX_NAMECHAR); +} diff --git a/libxsde/xsde/c/genx/genx.c b/libxsde/xsde/c/genx/genx.c new file mode 100644 index 0000000..1ce0527 --- /dev/null +++ b/libxsde/xsde/c/genx/genx.c @@ -0,0 +1,2118 @@ +/* + * Copyright (c) 2007-2009 Code Synthesis Tools CC. + * Copyright (c) 2004 by Tim Bray and Sun Microsystems. + * + * For copying permission, see the accompanying COPYING file. + */ + +#define GENX_VERSION "cs-1" + +#include <stdlib.h> +#include <string.h> + +#include "genx.h" + +#define Boolean int +#define True 1 +#define False 0 +#define STRLEN_XMLNS_COLON 6 + + +/******************************* + * writer state + */ +typedef enum +{ + SEQUENCE_NO_DOC, + SEQUENCE_PRE_DOC, + SEQUENCE_POST_DOC, + SEQUENCE_START_TAG, + SEQUENCE_ATTRIBUTES, + SEQUENCE_START_ATTR, + SEQUENCE_CONTENT +} writerSequence; + +/******************************* + * generic pointer list + */ +typedef struct +{ + genxWriter writer; + int count; + int space; + void * * pointers; +} plist; + +/******************************* + * text collector, for attribute values + */ +typedef struct +{ + utf8 buf; + int used; + int space; +} collector; + +/******************************* + * Structs with opaquely-exposed handles + */ + +/* + * This one's tricky, to handle stacking namespaces + * 'declaration' is the current attribute which would be used to + * declare the currently-effective prefix + * 'defDeclaration' is a appropriate declaration when this is being + * used with the default prefix as passed to genxDeclareNamespace + * baroque is true if this namespace has been used with more than one + * prefix, or is the default namespace but has been unset + */ +struct genxNamespace_rec +{ + genxWriter writer; + utf8 name; + int declCount; + Boolean baroque; + genxAttribute declaration; + genxAttribute defaultDecl; +}; + +struct genxElement_rec +{ + genxWriter writer; + utf8 type; + genxNamespace ns; +}; + +typedef enum +{ + ATTR_NSDECL, + ATTR_NAKED, + ATTR_PREFIXED +} attrType; + +struct genxAttribute_rec +{ + genxWriter writer; + utf8 name; + genxNamespace ns; + collector value; + int provided; /* provided for current element? */ + attrType atype; +}; + +/******************************* + * genx's sandbox + */ +struct genxWriter_rec +{ + FILE * file; + genxSender * sender; + genxStatus status; + writerSequence sequence; + char xmlChars[0x10000]; + void * userData; + int nextPrefix; + utf8 empty; + Boolean defaultNsDeclared; + genxAttribute xmlnsEquals; + genxElement nowStarting; + genxAttribute nowStartingAttr; + plist namespaces; + plist elements; + plist attributes; + plist prefixes; + plist stack; + struct genxAttribute_rec arec; + char * etext[100]; + void * (* alloc)(void * userData, int bytes); + void (* dealloc)(void * userData, void * data); +}; + +/******************************* + * Forward declarations + */ +static genxAttribute declareAttribute(genxWriter w, genxNamespace ns, + constUtf8 name, constUtf8 valuestr, + genxStatus * statusP); +static genxStatus addNamespace(genxNamespace ns, constUtf8 prefix); +static genxStatus unsetDefaultNamespace(genxWriter w); +static genxStatus addAttribute(genxAttribute a, constUtf8 valuestr); +void genxSetCharProps(char * p); + +/******************************* + * End of declarations + */ + +/******************************* + * private memory utilities + */ +static void * allocate(genxWriter w, int bytes) +{ + if (w->alloc) + return (void *) (*w->alloc)(w->userData, bytes); + else + return (void *) malloc(bytes); +} + +static void deallocate(genxWriter w, void * data) +{ + if (w->dealloc) + (*w->dealloc)(w->userData, data); + else if (w->alloc == NULL) + free(data); +} + +static utf8 copy(genxWriter w, constUtf8 from) +{ + utf8 temp; + + if ((temp = (utf8) allocate(w, strlen((const char *) from) + 1)) == NULL) + return NULL; + strcpy((char *) temp, (const char *) from); + return temp; +} + +static genxStatus initCollector(genxWriter w, collector * c) +{ + c->space = 100; + if ((c->buf = (utf8) allocate(w, c->space)) == NULL) + return GENX_ALLOC_FAILED; + c->used = 0; + return GENX_SUCCESS; +} + +static genxStatus growCollector(genxWriter w, collector * c, int size) +{ + utf8 newSpace; + + c->space = size * 2; + if ((newSpace = (utf8) allocate(w, c->space)) == NULL) + return GENX_ALLOC_FAILED; + + strncpy((char *) newSpace, (const char *) c->buf, c->used); + newSpace[c->used] = 0; + deallocate(w, c->buf); + c->buf = newSpace; + return GENX_SUCCESS; +} + +static void startCollect(collector * c) +{ + c->used = 0; +} +static void endCollect(collector * c) +{ + c->buf[c->used] = 0; +} + +static genxStatus collectString(genxWriter w, collector * c, constUtf8 string) +{ + int sl = strlen((const char *) string); + + if (sl >= c->space) + if ((w->status = growCollector(w, c, sl)) != GENX_SUCCESS) + return GENX_ALLOC_FAILED; + + strcpy((char *) c->buf, (const char *) string); + return GENX_SUCCESS; +} + +#define collectPiece(w,c,d,size) {if (((c)->used+(size))>=(c)->space){if (((w)->status=growCollector(w,c,(c)->used+(size)))!=GENX_SUCCESS) return (w)->status;}strncpy((char *)(c)->buf+(c)->used,d,size);(c)->used+=size;} + +/******************************* + * private list utilities + */ +static genxStatus initPlist(genxWriter w, plist * pl) +{ + pl->writer = w; + pl->count = 0; + pl->space = 10; + pl->pointers = (void * *) allocate(w, pl->space * sizeof(void *)); + if (pl->pointers == NULL) + return GENX_ALLOC_FAILED; + + return GENX_SUCCESS; +} + +/* + * make room in a plist + */ +static Boolean checkExpand(plist * pl) +{ + void * * newlist; + int i; + + if (pl->count < pl->space) + return True; + + pl->space *= 2; + newlist = (void * *) allocate(pl->writer, pl->space * sizeof(void *)); + if (newlist == NULL) + return False; + for (i = 0; i < pl->count; i++) + newlist[i] = pl->pointers[i]; + deallocate(pl->writer, pl->pointers); + pl->pointers = newlist; + + return True; +} + +/* + * stick something on the end of a plist + */ +static genxStatus listAppend(plist * pl, void * pointer) +{ + if (!checkExpand(pl)) + return GENX_ALLOC_FAILED; + + pl->pointers[pl->count++] = pointer; + return GENX_SUCCESS; +} + +/* + * insert in place, shuffling up + */ +static genxStatus listInsert(plist * pl, void * pointer, int at) +{ + int i; + + if (!checkExpand(pl)) + return GENX_ALLOC_FAILED; + + for (i = pl->count; i > at; i--) + pl->pointers[i] = pl->pointers[i - 1]; + pl->count++; + + pl->pointers[at] = pointer; + return GENX_SUCCESS; +} + +/******************************* + * list lookups + */ + +static genxNamespace findNamespace(plist * pl, constUtf8 uri) +{ + int i; + genxNamespace * nn = (genxNamespace *) pl->pointers; + + for (i = 0; i < pl->count; i++) + if (strcmp((char *) uri, (const char *) nn[i]->name) == 0) + return nn[i]; + + return NULL; +} + +static genxElement findElement(plist * pl, constUtf8 xmlns, constUtf8 type) +{ + int i; + genxElement * ee = (genxElement *) pl->pointers; + + for (i = 0; i < pl->count; i++) + { + if (xmlns == NULL) + { + if (ee[i]->ns == NULL && strcmp((const char *) type, + (const char *) ee[i]->type) == 0) + return ee[i]; + } + else + { + if (ee[i]->ns != NULL && + strcmp((const char *) xmlns, (const char *) ee[i]->ns->name) == 0 && + strcmp((const char *) type, (const char *) ee[i]->type) == 0) + return ee[i]; + } + } + + return NULL; +} + +/* + * store & intern a prefix, after giving it the + * "xmlns:" prefix. Don't allow storing the same one twice unless 'force' + * is set. + */ +static utf8 storePrefix(genxWriter w, constUtf8 prefix, Boolean force) +{ + int high, low; + utf8 * pp = (utf8 *) w->prefixes.pointers; + unsigned char buf[1024]; + + if (prefix[0] == 0) + prefix = (utf8) "xmlns"; + else + { + sprintf((char *) buf, "xmlns:%s", prefix); + prefix = buf; + } + + high = w->prefixes.count; low = -1; + while (high - low > 1) + { + int probe = (high + low) / 2; + if (strcmp((const char *) prefix, (const char *) pp[probe]) < 0) + high = probe; + else + low = probe; + } + + /* already there? */ + if (low != -1 && strcmp((const char *) prefix, (const char *) pp[low]) == 0) + { + if (force) + return pp[low]; + + w->status = GENX_DUPLICATE_PREFIX; + return NULL; + } + + /* copy & insert */ + if ((prefix = copy(w, prefix)) == NULL) + { + w->status = GENX_ALLOC_FAILED; + return NULL; + } + + w->status = listInsert(&w->prefixes, (void *) prefix, high); + if (w->status != GENX_SUCCESS) + return NULL; + + return (utf8) prefix; +} + +/******************************* + * UTF8 bit-banging + */ + +/* + * Retrieve the character pointed at, and advance the pointer; return -1 on + * error + */ +int genxNextUnicodeChar(constUtf8 * sp) +{ + utf8 s = (utf8) *sp; + int c; + + if (*s == 0) + return -1; + + if (*s < 0x80) + c = *s++; + + /* all this encoding sanity-checking taken from section 3.10 of Unicode 4 */ + else if (*s < 0xc2) + goto malformed; + + /* 2-byte encodings, first byte c2 .. df */ + else if (*s < 0xe0) + { + c = (*s++ & 0x1f) << 6; + + /* + * for this common idiom, if ((c & 0xc0) != 0x80) is slightly faster + * on MacOS (PPC) + */ + if (*s < 0x80 || *s > 0xbf) + goto malformed; + + c |= *s++ & 0x3f; + } + + /* 3-byte encodings, first byte e0 .. ef */ + else if (*s < 0xf0) + { + int b0 = *s; + c = (*s++ & 0x0f) << 12; + + if ((b0 == 0xe0 && (*s < 0xa0 || *s > 0xbf)) || + (b0 < 0xed && (*s < 0x80 || *s > 0xbf)) || + (b0 == 0xed && (*s < 0x80 || *s > 0x9f)) || + (b0 > 0xed && (*s < 0x80 || *s > 0xbf))) + goto malformed; + + c |= (*s++ & 0x3f) << 6; + + if (*s < 0x80 || *s > 0xbf) + goto malformed; + + c |= *s++ & 0x3f; + } + + /* 4-byte encodings, first byte f0 .. f4 */ + else if (*s < 0xf5) + { + int b0 = *s; + c = (*s++ & 0x07) << 18; + + if ((b0 == 0xf0 && (*s < 0x90 || *s > 0xbf)) || + (b0 < 0xf4 && (*s < 0x80 || *s > 0xbf)) || + (b0 >= 0xf4 && (*s < 0x80 || *s > 0x8f))) + goto malformed; + + c |= (*s++ & 0x3f) << 12; + + if (*s < 0x80 || *s > 0xbf) + goto malformed; + + c |= (*s++ & 0x3f) << 6; + + if (*s < 0x80 || *s > 0xbf) + goto malformed; + + c |= *s++ & 0x3f; + } + else + goto malformed; + + *sp = s; + return c; + + /* + * this is needed by scrubText, which wants to get the pointer moved + * past the problem area. + */ +malformed: + if (*s) + ++s; + *sp = s; + return -1; +} + +static Boolean isXMLChar(genxWriter w, int c) +{ + if (c < 0) + return False; + else if (c < 0x10000) + return (int) w->xmlChars[c]; + else + return (c <= 0x10ffff); +} + +static Boolean isLetter(genxWriter w, int c) +{ + if (c < 0 || c > 0xffff) + return False; + else + return w->xmlChars[c] & GENX_LETTER; +} + +static Boolean isNameChar(genxWriter w, int c) +{ + if (c < 0 || c > 0xffff) + return False; + else + return w->xmlChars[c] & GENX_NAMECHAR; +} + +/******************************* + * Constructors, setters/getters + */ + +/* + * Construct a new genxWriter + */ +genxWriter genxNew(void * (* alloc)(void * userData, int bytes), + void (* dealloc)(void * userData, void * data), + void * userData) +{ + genxWriter w; + genxNamespace xml; + + if (alloc) + w = (genxWriter) (*alloc)(userData, sizeof(struct genxWriter_rec)); + else + w = (genxWriter) malloc(sizeof(struct genxWriter_rec)); + + if (w == NULL) + return NULL; + + w->status = GENX_SUCCESS; + w->alloc = alloc; + w->dealloc = dealloc; + w->userData = userData; + w->sequence = SEQUENCE_NO_DOC; + + if (initPlist(w, &w->namespaces) != GENX_SUCCESS || + initPlist(w, &w->elements) != GENX_SUCCESS || + initPlist(w, &w->attributes) != GENX_SUCCESS || + initPlist(w, &w->prefixes) != GENX_SUCCESS || + initPlist(w, &w->stack) != GENX_SUCCESS) + return NULL; + + if ((w->status = initCollector(w, &w->arec.value)) != GENX_SUCCESS) + return NULL; + + if ((w->empty = copy(w, (utf8) "")) == NULL) + { + w->status = GENX_ALLOC_FAILED; + return NULL; + } + + w->xmlnsEquals = declareAttribute(w, NULL, (utf8) "xmlns", NULL, &w->status); + if (w->xmlnsEquals == NULL || w->status != GENX_SUCCESS) + return NULL; + w->defaultNsDeclared = False; + + w->nextPrefix = 1; + + genxSetCharProps(w->xmlChars); + + w->etext[GENX_SUCCESS] = "Success"; + w->etext[GENX_BAD_UTF8] = "Bad UTF8"; + w->etext[GENX_NON_XML_CHARACTER] = "Non XML Character"; + w->etext[GENX_BAD_NAME] = "Bad NAME"; + w->etext[GENX_ALLOC_FAILED] = "Memory allocation failed"; + w->etext[GENX_BAD_NAMESPACE_NAME] = "Bad namespace name"; + w->etext[GENX_INTERNAL_ERROR] = "Internal error"; + w->etext[GENX_DUPLICATE_PREFIX] = "Duplicate prefix"; + w->etext[GENX_SEQUENCE_ERROR] = "Call out of sequence"; + w->etext[GENX_NO_START_TAG] = "No Start-tag for EndElement call"; + w->etext[GENX_IO_ERROR] = "I/O error"; + w->etext[GENX_MISSING_VALUE] = "Missing attribute value"; + w->etext[GENX_MALFORMED_COMMENT] = "Malformed comment body"; + w->etext[GENX_MALFORMED_PI] = "?> in PI"; + w->etext[GENX_XML_PI_TARGET] = "Target of PI matches [xX][mM][lL]"; + w->etext[GENX_DUPLICATE_ATTRIBUTE] = + "Same attribute specified more than once"; + w->etext[GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE] = + "Attribute cannot be in default namespace"; + w->etext[GENX_DUPLICATE_NAMESPACE] = + "Declared namespace twice with different prefixes on one element."; + w->etext[GENX_BAD_DEFAULT_DECLARATION] = + "Declared a default namespace on an element which is in no namespace"; + + /* the xml: namespace is pre-wired */ + xml = genxDeclareNamespace(w, (utf8) "http://www.w3.org/XML/1998/namespace", + (utf8) "xml", &w->status); + if (xml == NULL) + return NULL; + xml->declCount = 1; + xml->declaration = xml->defaultDecl; + + return w; +} + +genxStatus genxReset (genxWriter w) +{ + int i; + + /* Clean up the stack. */ + w->stack.count = 0; + + /* Reset namespace declaration counts. The first entry is the pre-wired + xml namespace. */ + ((genxNamespace) w->namespaces.pointers[0])->declCount = 1; + + for (i = 1; i < w->namespaces.count; i++) + { + ((genxNamespace) w->namespaces.pointers[i])->declCount = 0; + ((genxNamespace) w->namespaces.pointers[i])->baroque = False; + } + + w->status = GENX_SUCCESS; + w->sequence = SEQUENCE_NO_DOC; + + return w->status; +} + + +/* + * get/set userData + */ +void genxSetUserData(genxWriter w, void * userData) +{ + w->userData = userData; +} +void * genxGetUserData(genxWriter w) +{ + return w->userData; +} + +/* + * get/set allocator + */ +void genxSetAlloc(genxWriter w, void * (* alloc)(void * userData, int bytes)) +{ + w->alloc = alloc; +} +void genxSetDealloc(genxWriter w, + void (* dealloc)(void * userData, void * data)) +{ + w->dealloc = dealloc; +} +void * (* genxGetAlloc(genxWriter w))(void * userData, int bytes) +{ + return w->alloc; +} +void (* genxGetDealloc(genxWriter w))(void * userData, void * data) +{ + return w->dealloc; +} + +/* + * Clean up + */ +void genxDispose(genxWriter w) +{ + int i; + genxNamespace * nn = (genxNamespace *) w->namespaces.pointers; + genxElement * ee = (genxElement *) w->elements.pointers; + genxAttribute * aa = (genxAttribute *) w->attributes.pointers; + utf8 * pp = (utf8 *) w->prefixes.pointers; + + for (i = 0; i < w->namespaces.count; i++) + { + deallocate(w, nn[i]->name); + deallocate(w, nn[i]); + } + + for (i = 0; i < w->elements.count; i++) + { + deallocate(w, ee[i]->type); + deallocate(w, ee[i]); + } + + for (i = 0; i < w->attributes.count; i++) + { + deallocate(w, aa[i]->name); + deallocate(w, aa[i]->value.buf); + deallocate(w, aa[i]); + } + + for(i = 0; i < w->prefixes.count; i++) + deallocate(w, pp[i]); + + deallocate(w, w->namespaces.pointers); + deallocate(w, w->elements.pointers); + deallocate(w, w->attributes.pointers); + deallocate(w, w->prefixes.pointers); + deallocate(w, w->stack.pointers); + + deallocate(w, w->arec.value.buf); + + deallocate(w, w->empty); + + /* how Oscar dealt with Igli */ + deallocate(w, w); +} + +/******************************* + * External utility routines + */ + +/* + * scan a buffer and report problems with UTF-8 encoding or non-XML characters + */ +genxStatus genxCheckText(genxWriter w, constUtf8 s) +{ + while (*s) + { + int c = genxNextUnicodeChar(&s); + if (c == -1) + return GENX_BAD_UTF8; + + if (!isXMLChar(w, c)) + return GENX_NON_XML_CHARACTER; + } + return GENX_SUCCESS; +} + +/* + * Purify some text + */ +int genxScrubText(genxWriter w, constUtf8 in, utf8 out) +{ + int problems = 0; + constUtf8 last = in; + + while (*in) + { + int c = genxNextUnicodeChar(&in); + if (c == -1) + { + problems++; + last = in; + continue; + } + + if (!isXMLChar(w, c)) + { + problems++; + last = in; + continue; + } + + while (last < in) + *out++ = *last++; + } + *out = 0; + return problems; +} + +/* + * check one character + */ +int genxCharClass(genxWriter w, int c) +{ + int ret = 0; + + if (isXMLChar(w, c)) + ret |= GENX_XML_CHAR; + if (isNameChar(w, c)) + ret |= GENX_NAMECHAR; + if (isLetter(w, c)) + ret |= GENX_LETTER; + return ret; +} + +static genxStatus checkNCName(genxWriter w, constUtf8 name) +{ + int c; + + if (name == NULL || *name == 0) + return GENX_BAD_NAME; + + c = genxNextUnicodeChar(&name); + if (!isLetter(w, c) && c != ':' && c != '_') + return GENX_BAD_NAME; + + while (*name) + { + c = genxNextUnicodeChar(&name); + if (c == -1) + return GENX_BAD_UTF8; + if (!isNameChar(w, c)) + return GENX_BAD_NAME; + } + return GENX_SUCCESS; +} + +char * genxGetErrorMessage(genxWriter w, genxStatus status) +{ + return w->etext[status]; +} +char * genxLastErrorMessage(genxWriter w) +{ + return w->etext[w->status]; +} + +/******************************* + * Declarations: namespace/element/attribute + */ + +/* + * DeclareNamespace - by far the most complex routine in Genx + */ +genxNamespace genxDeclareNamespace(genxWriter w, constUtf8 uri, + constUtf8 defaultPref, + genxStatus * statusP) +{ + genxNamespace ns; + genxAttribute defaultDecl; + unsigned char newPrefix[100]; + + if (uri == NULL || uri[0] == 0) + { + w->status = GENX_BAD_NAMESPACE_NAME; + goto busted; + } + + if ((w->status = genxCheckText(w, uri)) != GENX_SUCCESS) + goto busted; + + /* if a prefix is provided, it has to be an NCname */ + if (defaultPref != NULL && defaultPref[0] != 0 && + (w->status = checkNCName(w, defaultPref)) != GENX_SUCCESS) + goto busted; + + /* previously declared? */ + if ((ns = findNamespace(&w->namespaces, uri))) + { + /* just a lookup, really */ + if ((defaultPref == NULL) || + (defaultPref[0] == 0 && ns->defaultDecl == w->xmlnsEquals) || + (strcmp((const char *) ns->defaultDecl->name + STRLEN_XMLNS_COLON, + (const char *) defaultPref) == 0)) + { + w->status = *statusP = GENX_SUCCESS; + return ns; + } + } + + /* wasn't already declared */ + else + { + + /* make a default prefix if none provided */ + if (defaultPref == NULL) + { + sprintf((char *) newPrefix, "g%d", w->nextPrefix++); + defaultPref = newPrefix; + } + + ns = (genxNamespace) allocate(w, sizeof(struct genxNamespace_rec)); + if (ns == NULL) + { + w->status = GENX_ALLOC_FAILED; + goto busted; + } + ns->writer = w; + ns->baroque = False; + + if ((ns->name = copy(w, uri)) == NULL) + { + w->status = GENX_ALLOC_FAILED; + goto busted; + } + + if ((w->status = listAppend(&w->namespaces, ns)) != GENX_SUCCESS) + goto busted; + ns->defaultDecl = ns->declaration = NULL; + ns->declCount = 0; + } + + if (defaultPref[0] == 0) + { + if (w->defaultNsDeclared) + { + w->status = GENX_DUPLICATE_PREFIX; + goto busted; + } + defaultDecl = w->xmlnsEquals; + w->defaultNsDeclared = True; + } + else + { + /* this catches dupes too */ + if ((defaultPref = storePrefix(w, defaultPref, False)) == NULL) + goto busted; + + defaultDecl = declareAttribute(w, NULL, defaultPref, ns->name, statusP); + if (defaultDecl == NULL || *statusP != GENX_SUCCESS) + { + w->status = *statusP; + return NULL; + } + } + + if (ns->defaultDecl != NULL && defaultDecl != ns->defaultDecl) + ns->baroque = True; + ns->defaultDecl = defaultDecl; + + *statusP = GENX_SUCCESS; + return ns; + +busted: + *statusP = w->status; + return NULL; +} + +/* + * get namespace prefix + */ +utf8 genxGetNamespacePrefix(genxNamespace ns) +{ + if (ns->declaration == NULL) + return NULL; + + if (ns->declaration == ns->writer->xmlnsEquals) + return ns->writer->empty; + + return ns->declaration->name + STRLEN_XMLNS_COLON; +} + +/* + * DeclareElement - see genx.h for details + */ +genxElement genxDeclareElement(genxWriter w, + genxNamespace ns, constUtf8 type, + genxStatus * statusP) +{ + genxElement old; + genxElement el; + + if ((w->status = checkNCName(w, type)) != GENX_SUCCESS) + { + *statusP = w->status; + return NULL; + } + + /* already declared? */ + old = findElement(&w->elements, (ns == NULL) ? NULL : ns->name, type); + if (old) + return old; + + if ((el = (genxElement) allocate(w, sizeof(struct genxElement_rec))) == NULL) + { + w->status = *statusP = GENX_ALLOC_FAILED; + return NULL; + } + + el->writer = w; + el->ns = ns; + if ((el->type = copy(w, type)) == NULL) + { + w->status = *statusP = GENX_ALLOC_FAILED; + return NULL; + } + + if ((w->status = listAppend(&w->elements, el)) != GENX_SUCCESS) + { + *statusP = w->status; + return NULL; + } + + *statusP = GENX_SUCCESS; + return el; +} + +/* + * C14n ordering for attributes: + * - first, namespace declarations by the prefix being declared + * - second, unprefixed attributes by attr name + * - third, prefixed attrs by ns uri then local part + */ +static int orderAttributes(genxAttribute a1, genxAttribute a2) +{ + if (a1->atype == a2->atype) + { + if (a1->atype == ATTR_PREFIXED && a1->ns != a2->ns) + return strcmp((const char *) a1->ns->name, (const char *) a2->ns->name); + else + return strcmp((const char *) a1->name, (const char *) a2->name); + } + + else if (a1->atype == ATTR_NSDECL) + return -1; + + else if (a1->atype == ATTR_NAKED) + { + if (a2->atype == ATTR_NSDECL) + return 1; + else + return -1; + } + + else + return 1; +} + +/* + * internal declare-attribute. This one allows colonized values for + * names, so that you can declare xmlns:-type attributes + */ +static genxAttribute declareAttribute(genxWriter w, genxNamespace ns, + constUtf8 name, constUtf8 valuestr, + genxStatus * statusP) +{ + int high, low; + genxAttribute * aa = (genxAttribute *) w->attributes.pointers; + genxAttribute a; + + w->arec.ns = ns; + w->arec.name = (utf8) name; + + if (ns) + w->arec.atype = ATTR_PREFIXED; + else if (strncmp((const char *) name, "xmlns", STRLEN_XMLNS_COLON - 1) == 0) + w->arec.atype = ATTR_NSDECL; + else + w->arec.atype = ATTR_NAKED; + + if (ns && (ns->defaultDecl == w->xmlnsEquals)) + { + w->status = GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE; + goto busted; + } + + /* attribute list has to be kept sorted per c14n rules */ + high = w->attributes.count; low = -1; + while (high - low > 1) + { + int probe = (high + low) / 2; + if (orderAttributes(&w->arec, aa[probe]) < 0) + high = probe; + else + low = probe; + } + + /* if it was already there */ + if (low != -1 && orderAttributes(&w->arec, aa[low]) == 0) + return aa[low]; + + /* not there, build it */ + a = (genxAttribute) allocate(w, sizeof(struct genxAttribute_rec)); + if (a == NULL) + { + w->status = GENX_ALLOC_FAILED; + goto busted; + } + + a->writer = w; + a->ns = ns; + a->provided = False; + a->atype = w->arec.atype; + + if ((a->name = copy(w, name)) == NULL) + { + w->status = GENX_ALLOC_FAILED; + goto busted; + } + + if ((w->status = initCollector(w, &a->value)) != GENX_SUCCESS) + goto busted; + + if (valuestr) + if ((w->status = collectString(w, &a->value, valuestr)) != GENX_SUCCESS) + goto busted; + + w->status = listInsert(&w->attributes, a, high); + if (w->status != GENX_SUCCESS) + goto busted; + + *statusP = GENX_SUCCESS; + return a; + +busted: + *statusP = w->status; + return NULL; +} + +/* + * genxDeclareAttribute - see genx.h for details + */ +genxAttribute genxDeclareAttribute(genxWriter w, + genxNamespace ns, constUtf8 name, + genxStatus * statusP) +{ + if ((w->status = checkNCName(w, name)) != GENX_SUCCESS) + { + *statusP = w->status; + return NULL; + } + + return declareAttribute(w, ns, name, NULL, statusP); +} + +/******************************* + * I/O + */ +static genxStatus sendx(genxWriter w, constUtf8 s) +{ + if (w->sender) + return (*w->sender->send)(w->userData, s); + else + { + if (fputs((const char *) s, w->file) == -1) + return GENX_IO_ERROR; + else + return GENX_SUCCESS; + } +} + +static genxStatus sendxBounded(genxWriter w, constUtf8 start, constUtf8 end) +{ + if (w->sender) + return (*w->sender->sendBounded)(w->userData, start, end); + else + /* Looks like on VxWorks fwrite returns a signed type which causes warnings. */ + if ((unsigned) fwrite(start, 1, end - start, w->file) != (unsigned) (end - start)) + return GENX_IO_ERROR; + else + return GENX_SUCCESS; +} + +#define SendCheck(w,s) if ((w->status=sendx(w,(utf8)s))!=GENX_SUCCESS) return w->status; + +/******************************* + * XML writing routines. The semantics of the externally-facing ones are + * written up in genx.h. Commentary here is implementation notes and + * for internal routines. + */ + +/* + * Start a document + */ +genxStatus genxStartDocFile(genxWriter w, FILE * file) +{ + if (w->sequence != SEQUENCE_NO_DOC) + return w->status = GENX_SEQUENCE_ERROR; + + w->sequence = SEQUENCE_PRE_DOC; + w->file = file; + w->sender = NULL; + return GENX_SUCCESS; +} + +genxStatus genxStartDocSender(genxWriter w, genxSender * sender) +{ + if (w->sequence != SEQUENCE_NO_DOC) + return w->status = GENX_SEQUENCE_ERROR; + + w->sequence = SEQUENCE_PRE_DOC; + w->file = NULL; + w->sender = sender; + return GENX_SUCCESS; +} + +/* + * Write out the attributes we've been gathering up for an element. We save + * them until we've gathered them all so they can be writen in canonical + * order. + * Also, we end the start-tag. + * The trick here is that we keep the attribute list properly sorted as + * we build it, then as each attribute is added, we fill in its value and + * mark the fact that it's been added, in the "provided" field. + */ +static genxStatus writeStartTag(genxWriter w) +{ + int i; + genxAttribute * aa = (genxAttribute *) w->attributes.pointers; + genxElement e = w->nowStarting; + + /* + * make sure the right namespace decls are in effect; + * if they are these might create an error, so ignore it + */ + if (e->ns) + addNamespace(e->ns, NULL); + else + unsetDefaultNamespace(w); + w->status = GENX_SUCCESS; + + SendCheck(w, "<"); + if (e->ns && (e->ns->declaration != w->xmlnsEquals)) + { + SendCheck(w, e->ns->declaration->name + STRLEN_XMLNS_COLON); + SendCheck(w, ":"); + } + SendCheck(w, e->type); + + for (i = 0; i < w->attributes.count; i++) + { + if (aa[i]->provided) + { + if (aa[i]->ns && aa[i]->ns->baroque && + aa[i]->ns->declaration == w->xmlnsEquals) + return w->status = GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE; + + SendCheck(w, " "); + + if (aa[i]->ns) + { + SendCheck(w, aa[i]->ns->declaration->name + STRLEN_XMLNS_COLON) + SendCheck(w, ":"); + } + SendCheck(w, aa[i]->name); + SendCheck(w, "=\""); + SendCheck(w, aa[i]->value.buf); + SendCheck(w, "\""); + } + } + SendCheck(w, ">"); + return GENX_SUCCESS; +} + +/* + * internal clear-er; no sequence checking + */ +static genxStatus unsetDefaultNamespace(genxWriter w) +{ + int i; + Boolean found = False; + + /* don't put it in if not needed */ + i = w->stack.count - 1; + while (found == False && i > 0) + { + while (w->stack.pointers[i] != NULL) + { + genxAttribute decl = (genxAttribute) w->stack.pointers[i--]; + genxNamespace ns = (genxNamespace) w->stack.pointers[i--]; + + /* if already unset */ + if (ns == NULL) + return w->status = GENX_SUCCESS; + + /* + * the default namespace was declared. This namespace now + * becomes baroque + */ + if (decl == w->xmlnsEquals) + { + ns->baroque = True; + found = True; + break; + } + } + i -= 2; + } + + if (!found) + return GENX_SUCCESS; + + /* + * push a signal on the stack + */ + if ((w->status = listAppend(&w->stack, NULL)) != GENX_SUCCESS) + return w->status; + w->status = listAppend(&w->stack, w->xmlnsEquals); + if (w->status != GENX_SUCCESS) + return w->status; + + /* add the xmlns= attribute, it must be the first one */ + return addAttribute(w->xmlnsEquals, w->empty); +} + +/* + * clear the default namespace declaration + */ +genxStatus genxUnsetDefaultNamespace(genxWriter w) +{ + + /* can only do this while in start-tag mode */ + if (w->sequence != SEQUENCE_START_TAG) + return w->status = GENX_SEQUENCE_ERROR; + + return unsetDefaultNamespace(w); +} + +genxStatus genxStartElement(genxElement e) +{ + genxWriter w = e->writer; + int i; + + switch (w->sequence) + { + case SEQUENCE_NO_DOC: + case SEQUENCE_POST_DOC: + case SEQUENCE_START_ATTR: + return w->status = GENX_SEQUENCE_ERROR; + case SEQUENCE_START_TAG: + case SEQUENCE_ATTRIBUTES: + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + break; + case SEQUENCE_PRE_DOC: + case SEQUENCE_CONTENT: + break; + } + + w->sequence = SEQUENCE_START_TAG; + + /* clear provided attributes */ + for (i = 0; i < w->attributes.count; i++) + ((genxAttribute) w->attributes.pointers[i])->provided = 0; + + /* + * push the stack. We push a NULL after a pointer to this element + * because the stack will also contain pointers to the namespace + * attributes that got declared here, so we can keep track of what's + * in effect. I.e. a single stack entry consists logically of a pointer + * to an element object, a NULL, then zero or more pairs of pointers to + * namespace objects/declarations + */ + if ((w->status = listAppend(&w->stack, e)) != GENX_SUCCESS) + return w->status; + if ((w->status = listAppend(&w->stack, NULL)) != GENX_SUCCESS) + return w->status; + + w->nowStarting = e; + + return GENX_SUCCESS; +} + +/* + * internal namespace adder; no sequence checking + */ +static genxStatus addNamespace(genxNamespace ns, constUtf8 prefix) +{ + genxWriter w = ns->writer; + genxAttribute decl; + int i; + genxElement e; + + /* + * first, we'll find the declaring attribute + */ + if (prefix == NULL) + decl = ns->defaultDecl; + else + { + if (prefix[0] == 0) + decl = w->xmlnsEquals; + else + { + if ((prefix = storePrefix(w, prefix, True)) == NULL) + return w->status; + decl = declareAttribute(w, NULL, prefix, ns->name, &w->status); + if (decl == NULL || w->status != GENX_SUCCESS) + return w->status; + } + } + + if (decl != ns->defaultDecl) + ns->baroque = True; + + /* + * avoid doing anything if this namespace is already declared. If + * they've shown good taste we can do this cheaply + */ + if (!ns->baroque) + { + if (ns->declCount > 0) + return w->status = GENX_SUCCESS; + } + else + { + + /* + * First, we'll run all the way up the stack to see if there is + * another declaration for this namespace/prefix in scope, in which + * case it's a no-op; or, if there's another declaration for this + * prefix on another namespace, in which case we have to over-ride + */ + i = w->stack.count - 1; + while (i > 0) + { + while (w->stack.pointers[i] != NULL) + { + genxAttribute otherDecl = (genxAttribute) w->stack.pointers[i--]; + genxNamespace otherNs = (genxNamespace) w->stack.pointers[i--]; + + if (ns == otherNs) + { + if (decl == otherDecl) + return w->status = GENX_SUCCESS; + else + { + i = 0; + break; + } + } + else + { + /* different namespace, same prefix? */ + if (decl == otherDecl) + { + i = 0; + break; + } + } + } + i -= 2; + } + } + + /* + * If this namespace is already declared on + * this element (with different prefix/decl) which is an error. + */ + i = w->stack.count - 1; + while (w->stack.pointers[i] != NULL) + { + genxNamespace otherNs; + i--; /* don't need declaration */ + otherNs = (genxNamespace) w->stack.pointers[i--]; + + if (ns == otherNs) + return w->status = GENX_DUPLICATE_NAMESPACE; + } + + /* move pointer from NULL to element */ + --i; + + /* + * It's also an error if this is a default-namespace declaration and the + * element is in no namespace. + */ + e = (genxElement) w->stack.pointers[i]; + if (e->ns == NULL && decl == w->xmlnsEquals) + return w->status = GENX_BAD_DEFAULT_DECLARATION; + + if ((w->status = listAppend(&w->stack, ns)) != GENX_SUCCESS) + return w->status; + if ((w->status = listAppend(&w->stack, decl)) != GENX_SUCCESS) + return w->status; + + ns->declaration = decl; + ns->declCount++; + return addAttribute(decl, ns->name); +} + +/* + * Add a namespace declaration + */ +genxStatus genxAddNamespace(genxNamespace ns, constUtf8 prefix) +{ + if (ns->writer->sequence != SEQUENCE_START_TAG) + return ns->writer->status = GENX_SEQUENCE_ERROR; + + return addNamespace(ns, prefix); +} + +/* + * Private attribute-adding code + * most of the work here is normalizing the value, which is the same + * as regular normalization except for " is replaced by """ + */ +static genxStatus collectAttributeValue (genxWriter w, collector* value, + constUtf8 start, constUtf8 end) +{ + /* If end is NULL then the length of the value is unknown and + the value is 0-terminated. */ + + utf8 last = (utf8) start; + + while (*start && (end == NULL || start < end)) + { + int c = genxNextUnicodeChar(&start); + + if (c == -1) + return w->status = GENX_BAD_UTF8; + + if (!isXMLChar(w, c)) + return w->status = GENX_NON_XML_CHARACTER; + + switch(c) + { + case 9: + collectPiece(w, value, "	", 5); + break; + case 0xa: + collectPiece(w, value, "
", 5); + break; + case 0xd: + collectPiece(w, value, "
", 5); + break; + case '"': + collectPiece(w, value, """, 6); + break; + case '<': + collectPiece(w, value, "<", 4); + break; + case '&': + collectPiece(w, value, "&", 5); + break; + /* + case '>': + collectPiece(w, value, ">", 4); + break; + */ + default: + collectPiece(w, value, (const char *) last, start - last); + break; + } + last = (utf8) start; + } + + return GENX_SUCCESS; +} + +static genxStatus addAttribute(genxAttribute a, constUtf8 valuestr) +{ + genxWriter w = a->writer; + + /* if valuestr not provided, this is an xmlns with a pre-cooked value */ + if (valuestr) + { + startCollect(&a->value); + + if (collectAttributeValue (w, &a->value, valuestr, NULL) != GENX_SUCCESS) + return w->status; + + endCollect(&a->value); + } + + /* now add the namespace attribute; might fail if it's been hand-declared */ + if (a->ns) + addNamespace(a->ns, NULL); + + if (valuestr && a->provided) + return w->status = GENX_DUPLICATE_ATTRIBUTE; + a->provided = 1; + + return GENX_SUCCESS; +} + +/* + * public attribute adder. + * The only difference is that it doesn't allow a NULL value + */ +genxStatus genxAddAttribute(genxAttribute a, constUtf8 valuestr) +{ + if (a->writer->sequence != SEQUENCE_START_TAG && + a->writer->sequence != SEQUENCE_ATTRIBUTES) + return a->writer->status = GENX_SEQUENCE_ERROR; + a->writer->sequence = SEQUENCE_ATTRIBUTES; + + if (valuestr == NULL) + return a->writer->status = GENX_MISSING_VALUE; + + return addAttribute(a, valuestr); +} + +genxStatus genxStartAttribute(genxAttribute a) +{ + genxWriter w = a->writer; + + if (w->sequence != SEQUENCE_START_TAG && + w->sequence != SEQUENCE_ATTRIBUTES) + return w->status = GENX_SEQUENCE_ERROR; + + w->sequence = SEQUENCE_START_ATTR; + w->nowStartingAttr = a; + + startCollect(&a->value); + + return GENX_SUCCESS; +} + +genxStatus genxEndAttribute(genxWriter w) +{ + genxAttribute a; + + if (w->sequence != SEQUENCE_START_ATTR) + return w->status = GENX_SEQUENCE_ERROR; + + a = w->nowStartingAttr; + w->sequence = SEQUENCE_ATTRIBUTES; + + endCollect(&a->value); + + /* now add the namespace attribute; might fail if it's been hand-declared */ + if (a->ns) + addNamespace(a->ns, NULL); + + if (a->provided) + return w->status = GENX_DUPLICATE_ATTRIBUTE; + + a->provided = 1; + + return GENX_SUCCESS; +} + +genxStatus genxEndElement(genxWriter w) +{ + genxElement e; + int i; + + switch (w->sequence) + { + case SEQUENCE_NO_DOC: + case SEQUENCE_PRE_DOC: + case SEQUENCE_POST_DOC: + case SEQUENCE_START_ATTR: + return w->status = GENX_SEQUENCE_ERROR; + case SEQUENCE_START_TAG: + case SEQUENCE_ATTRIBUTES: + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + break; + case SEQUENCE_CONTENT: + break; + } + + /* + * first peek into the stack to find the right namespace declaration + * (if any) so we can properly prefix the end-tag. Have to do this + * before unwinding the stack because that might reset some xmlns + * prefixes to the context in the parent element + */ + for (i = w->stack.count - 1; w->stack.pointers[i] != NULL; i -= 2) + ; + e = (genxElement) w->stack.pointers[--i]; + + SendCheck(w, "</"); + if (e->ns && e->ns->declaration != w->xmlnsEquals) + { + SendCheck(w, e->ns->declaration->name + STRLEN_XMLNS_COLON); + SendCheck(w, ":"); + } + SendCheck(w, e->type); + SendCheck(w, ">"); + + /* + * pop zero or more namespace declarations, then a null, then the + * start-element declaration off the stack + */ + w->stack.count--; + while (w->stack.pointers[w->stack.count] != NULL) + { + genxNamespace ns = (genxNamespace) w->stack.pointers[--w->stack.count]; + w->stack.count--; /* don't need decl */ + + /* if not a fake unset-default namespace */ + if (ns) + { + /* + * if they've stupidly jammed in their own namespace-prefix + * declarations, we have to go looking to see if there's another + * one in effect + */ + if (ns->baroque) + { + i = w->stack.count; + while (i > 0) + { + while (w->stack.pointers[i] != NULL) + { + genxAttribute otherDecl = (genxAttribute) w->stack.pointers[i--]; + genxNamespace otherNs = (genxNamespace) w->stack.pointers[i--]; + + if (otherNs == ns) + { + ns->declaration = otherDecl; + i = 0; + break; + } + } + + /* skip NULL & element */ + i -= 2; + } + } + ns->declCount--; + if (ns->declCount == 0) + ns->baroque = False; + } + } + + /* pop the NULL */ + --w->stack.count; + if (w->stack.count < 0) + return w->status = GENX_NO_START_TAG; + + if (w->stack.count == 0) + w->sequence = SEQUENCE_POST_DOC; + else + w->sequence = SEQUENCE_CONTENT; + + return GENX_SUCCESS; +} + +/* + * Internal character-adder. It tries to keep the number of sendx() + * calls down by looking at each character but only doing the output + * when it has to escape something; ordinary text gets saved up in + * chunks the start of which is indicated by *breaker. + * c is the character, next points to the UTF8 representing the next + * lastsP indirectly points to the UTF8 representing the + * character, breakerP* indirectly points to the last place genx + * changed the UTF8, e.g. by escaping a '<' + */ +static genxStatus addChar(genxWriter w, int c, constUtf8 next, + constUtf8 * lastsP, constUtf8 * breakerP) +{ + if (c == -1) + return GENX_BAD_UTF8; + + if (!isXMLChar(w, c)) + return GENX_NON_XML_CHARACTER; + + switch(c) + { + case 0xd: + if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) + return w->status; + *breakerP = next; + sendx(w, (utf8) "
"); + break; + case '<': + if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) + return w->status; + *breakerP = next; + sendx(w, (utf8) "<"); + break; + case '&': + if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) + return w->status; + *breakerP = next; + sendx(w, (utf8) "&"); + break; + case '>': + if ((w->status = sendxBounded(w, *breakerP, *lastsP)) != GENX_SUCCESS) + return w->status; + *breakerP = next; + sendx(w, (utf8) ">"); + break; + default: + break; + } + *lastsP = next; + return GENX_SUCCESS; +} + +genxStatus genxAddText(genxWriter w, constUtf8 start) +{ + constUtf8 lasts = start; + constUtf8 breaker = start; + + if (w->sequence == SEQUENCE_START_TAG || + w->sequence == SEQUENCE_ATTRIBUTES) + { + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + w->sequence = SEQUENCE_CONTENT; + } + + if (w->sequence == SEQUENCE_CONTENT) + { + while (*start) + { + int c = genxNextUnicodeChar(&start); + + w->status = addChar(w, c, start, &lasts, &breaker); + if (w->status != GENX_SUCCESS) + return w->status; + } + return sendxBounded(w, breaker, (utf8) start); + } + else if (w->sequence == SEQUENCE_START_ATTR) + { + return collectAttributeValue (w, &w->nowStartingAttr->value, start, NULL); + } + else + return w->status = GENX_SEQUENCE_ERROR; +} + +genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end) +{ + constUtf8 lasts = start; + constUtf8 breaker = start; + + if (w->sequence == SEQUENCE_START_TAG || + w->sequence == SEQUENCE_ATTRIBUTES) + { + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + w->sequence = SEQUENCE_CONTENT; + } + + if (w->sequence == SEQUENCE_CONTENT) + { + while (start < end) + { + int c = genxNextUnicodeChar(&start); + + w->status = addChar(w, c, (utf8) start, &lasts, &breaker); + if (w->status != GENX_SUCCESS) + return w->status; + } + return sendxBounded(w, breaker, (utf8) start); + } + else if (w->sequence == SEQUENCE_START_ATTR) + { + return collectAttributeValue (w, &w->nowStartingAttr->value, start, end); + } + else + return w->status = GENX_SEQUENCE_ERROR; +} + +genxStatus genxAddCountedText(genxWriter w, constUtf8 start, int byteCount) +{ + utf8 end = (utf8) (start + byteCount); + + return genxAddBoundedText(w, start, end); +} + +genxStatus genxAddCharacter(genxWriter w, int c) +{ + unsigned char cUTF8[10]; + utf8 lasts, breaker, next; + + if (w->sequence == SEQUENCE_START_TAG || + w->sequence == SEQUENCE_ATTRIBUTES) + { + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + w->sequence = SEQUENCE_CONTENT; + } + + if (!isXMLChar(w, c)) + return w->status = GENX_NON_XML_CHARACTER; + + if (w->sequence == SEQUENCE_START_ATTR) + { + int done = 1; + collector* value = &w->nowStartingAttr->value; + + switch(c) + { + case 9: + collectPiece(w, value, "	", 5); + break; + case 0xa: + collectPiece(w, value, "
", 5); + break; + case 0xd: + collectPiece(w, value, "
", 5); + break; + case '"': + collectPiece(w, value, """, 6); + break; + case '<': + collectPiece(w, value, "<", 4); + break; + case '&': + collectPiece(w, value, "&", 5); + break; + /* + case '>': + collectPiece(w, value, ">", 4); + break; + */ + default: + done = 0; + break; + } + + if (done) + return GENX_SUCCESS; + } + + /* make UTF8 representation of character */ + lasts = breaker = next = cUTF8; + + if (c < 0x80) + *next++ = c; + else if (c < 0x800) + { + *next++ = 0xc0 | (c >> 6); + *next++ = 0x80 | (c & 0x3f); + } + else if (c < 0x10000) + { + *next++ = 0xe0 | (c >> 12); + *next++ = 0x80 | ((c & 0xfc0) >> 6); + *next++ = 0x80 | (c & 0x3f); + } + else + { + *next++ = 0xf0 | (c >> 18); + *next++ = 0x80 | ((c & 0x3f000) >> 12); + *next++ = 0x80 | ((c & 0xfc0) >> 6); + *next++ = 0x80 | (c & 0x3f); + } + *next = 0; + + if (w->sequence == SEQUENCE_CONTENT) + { + w->status = + addChar(w, c, next, (constUtf8 *) &lasts, (constUtf8 *) &breaker); + + if (w->status != GENX_SUCCESS) + return w->status; + + return sendxBounded(w, breaker, next); + } + else if (w->sequence == SEQUENCE_START_ATTR) + { + collectPiece(w, &w->nowStartingAttr->value, + (const char *) cUTF8, next - cUTF8); + return GENX_SUCCESS; + } + else + return w->status = GENX_SEQUENCE_ERROR; +} + +genxStatus genxEndDocument(genxWriter w) +{ + if (w->sequence != SEQUENCE_POST_DOC) + return w->status = GENX_SEQUENCE_ERROR; + + if (w->file) + fflush(w->file); + else + if ((w->status = (*w->sender->flush)(w->userData)) != GENX_SUCCESS) + return w->status; + + w->sequence = SEQUENCE_NO_DOC; + return GENX_SUCCESS; +} + +genxStatus genxComment(genxWriter w, constUtf8 text) +{ + int i; + + if (w->sequence == SEQUENCE_NO_DOC || + w->sequence == SEQUENCE_START_ATTR) + return w->status = GENX_SEQUENCE_ERROR; + + if ((w->status = genxCheckText(w, text)) != GENX_SUCCESS) + return w->status; + + /* no leading '-', no trailing '-', no '--' */ + if (text[0] == '-') + return w->status = GENX_MALFORMED_COMMENT; + for (i = 0; text[i]; i++) + if (text[i] == '-' && (text[i + 1] == '-' || text[i + 1] == 0)) + return w->status = GENX_MALFORMED_COMMENT; + + if (w->sequence == SEQUENCE_START_TAG || + w->sequence == SEQUENCE_ATTRIBUTES) + { + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + w->sequence = SEQUENCE_CONTENT; + } + + else if (w->sequence == SEQUENCE_POST_DOC) + if ((w->status = sendx(w, (utf8) "\n")) != GENX_SUCCESS) + return w->status; + + if ((w->status = sendx(w, (utf8) "<!--")) != GENX_SUCCESS) + return w->status; + if ((w->status = sendx(w, (utf8) text)) != GENX_SUCCESS) + return w->status; + if ((w->status = sendx(w, (utf8) "-->")) != GENX_SUCCESS) + return w->status; + + if (w->sequence == SEQUENCE_PRE_DOC) + if ((w->status = sendx(w, (utf8) "\n")) != GENX_SUCCESS) + return w->status; + + return GENX_SUCCESS; +} + +genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text) +{ + int i; + + if (w->sequence == SEQUENCE_NO_DOC || + w->sequence == SEQUENCE_START_ATTR) + return w->status = GENX_SEQUENCE_ERROR; + + if ((w->status = genxCheckText(w, target)) != GENX_SUCCESS) + return w->status; + if ((w->status = checkNCName(w, target)) != GENX_SUCCESS) + return w->status; + if ((strlen((const char *) target) >= 3) && + (target[0] == 'x' || target[0] == 'X') && + (target[1] == 'm' || target[1] == 'M') && + (target[2] == 'l' || target[2] == 'L') && + (target[3] == 0)) + return w->status = GENX_XML_PI_TARGET; + + if ((w->status = genxCheckText(w, text)) != GENX_SUCCESS) + return w->status; + + /* no ?> within */ + for (i = 1; text[i]; i++) + if (text[i] == '>' && text[i - 1] == '?') + return w->status = GENX_MALFORMED_PI; + + if (w->sequence == SEQUENCE_START_TAG || + w->sequence == SEQUENCE_ATTRIBUTES) + { + if ((w->status = writeStartTag(w)) != GENX_SUCCESS) + return w->status; + w->sequence = SEQUENCE_CONTENT; + } + + else if (w->sequence == SEQUENCE_POST_DOC) + if ((w->status = sendx(w, (utf8) "\n")) != GENX_SUCCESS) + return w->status; + + if ((w->status = sendx(w, (utf8) "<?")) != GENX_SUCCESS) + return w->status; + if ((w->status = sendx(w, target)) != GENX_SUCCESS) + return w->status; + if (text[0]) + { + if ((w->status = sendx(w, (utf8) " ")) != GENX_SUCCESS) + return w->status; + if ((w->status = sendx(w, text)) != GENX_SUCCESS) + return w->status; + } + if ((w->status = sendx(w, (utf8) "?>")) != GENX_SUCCESS) + return w->status; + + if (w->sequence == SEQUENCE_PRE_DOC) + if ((w->status = sendx(w, (utf8) "\n")) != GENX_SUCCESS) + return w->status; + + return GENX_SUCCESS; +} + +/******************************* + * Literal versions of the writing routines + */ +genxStatus genxStartElementLiteral(genxWriter w, + constUtf8 xmlns, constUtf8 type) +{ + genxNamespace ns = NULL; + genxElement e; + + if (xmlns) + { + ns = genxDeclareNamespace(w, xmlns, NULL, &w->status); + if (ns == NULL || w->status != GENX_SUCCESS) + return w->status; + } + e = genxDeclareElement(w, ns, type, &w->status); + if (e == NULL || w->status != GENX_SUCCESS) + return w->status; + + return genxStartElement(e); +} + +genxStatus genxAddAttributeLiteral(genxWriter w, constUtf8 xmlns, + constUtf8 name, constUtf8 value) +{ + genxNamespace ns = NULL; + genxAttribute a; + + if (xmlns) + { + ns = genxDeclareNamespace(w, xmlns, NULL, &w->status); + if (ns == NULL && w->status != GENX_SUCCESS) + return w->status; + } + + a = genxDeclareAttribute(w, ns, name, &w->status); + if (a == NULL || w->status != GENX_SUCCESS) + return w->status; + + return genxAddAttribute(a, value); +} + +genxStatus genxStartAttributeLiteral(genxWriter w, + constUtf8 xmlns, constUtf8 name) +{ + genxNamespace ns = NULL; + genxAttribute a; + + if (xmlns) + { + ns = genxDeclareNamespace(w, xmlns, NULL, &w->status); + if (ns == NULL && w->status != GENX_SUCCESS) + return w->status; + } + + a = genxDeclareAttribute(w, ns, name, &w->status); + if (a == NULL || w->status != GENX_SUCCESS) + return w->status; + + return genxStartAttribute(a); +} + +genxStatus genxAddNamespaceLiteral(genxWriter w, + constUtf8 uri, constUtf8 prefix) +{ + genxNamespace ns = genxDeclareNamespace(w, uri, prefix, &w->status); + if (ns == NULL && w->status != GENX_SUCCESS) + return w->status; + + return genxAddNamespace(ns, NULL); +} + +/* + * return version + */ +char * genxGetVersion() +{ + return GENX_VERSION; +} + diff --git a/libxsde/xsde/c/genx/genx.h b/libxsde/xsde/c/genx/genx.h new file mode 100644 index 0000000..da9f9b7 --- /dev/null +++ b/libxsde/xsde/c/genx/genx.h @@ -0,0 +1,322 @@ + +/* + * genx - C-callable library for generating XML documents + */ + +/* + * Copyright (c) 2007-2009 Code Synthesis Tools CC. + * Copyright (c) 2004 by Tim Bray and Sun Microsystems. + * + * For copying permission, see the accompanying COPYING file. + */ + +#ifndef GENX_H +#define GENX_H + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Note on error handling: genx routines mostly return + * GENX_SUCCESS (guaranteed to be zero) in normal circumstances, one of + * these other GENX_ values on a memory allocation or I/O failure or if the + * call would result in non-well-formed output. + * You can associate an error message with one of these codes explicitly + * or with the most recent error using genxGetErrorMessage() and + * genxLastErrorMessage(); see below. + */ +typedef enum +{ + GENX_SUCCESS = 0, + GENX_BAD_UTF8, + GENX_NON_XML_CHARACTER, + GENX_BAD_NAME, + GENX_ALLOC_FAILED, + GENX_BAD_NAMESPACE_NAME, + GENX_INTERNAL_ERROR, + GENX_DUPLICATE_PREFIX, + GENX_SEQUENCE_ERROR, + GENX_NO_START_TAG, + GENX_IO_ERROR, + GENX_MISSING_VALUE, + GENX_MALFORMED_COMMENT, + GENX_XML_PI_TARGET, + GENX_MALFORMED_PI, + GENX_DUPLICATE_ATTRIBUTE, + GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE, + GENX_DUPLICATE_NAMESPACE, + GENX_BAD_DEFAULT_DECLARATION +} genxStatus; + +/* character types */ +#define GENX_XML_CHAR 1 +#define GENX_LETTER 2 +#define GENX_NAMECHAR 4 + +/* a UTF-8 string */ +typedef unsigned char * utf8; +typedef const unsigned char * constUtf8; + +/* + * genx's own types + */ +typedef struct genxWriter_rec * genxWriter; +typedef struct genxNamespace_rec * genxNamespace; +typedef struct genxElement_rec * genxElement; +typedef struct genxAttribute_rec * genxAttribute; + +/* + * Constructors, set/get + */ + +/* + * Create a new writer. For generating multiple XML documents, it's most + * efficient to re-use the same genx object. However, you can only write + * one document at a time with a writer. + * Returns NULL if it fails, which can only be due to an allocation failure. + */ +genxWriter genxNew(void * (*alloc)(void * userData, int bytes), + void (* dealloc)(void * userData, void * data), + void * userData); + +/* + * Reset the writer object back into usable state after an error or + * interruption. + */ +genxStatus genxReset (genxWriter w); + +/* + * Dispose of a writer, freeing all associated memory + */ +void genxDispose(genxWriter w); + +/* + * Set/get + */ + +/* + * The userdata pointer will be passed to memory-allocation + * and I/O callbacks. If not set, genx will pass NULL + */ +void genxSetUserData(genxWriter w, void * userData); +void * genxGetUserData(genxWriter w); + +/* + * User-provided memory allocator, if desired. For example, if you were + * in an Apache module, you could arrange for genx to use ap_palloc by + * making the pool accessible via the userData call. + * The "dealloc" is to be used to free memory allocated with "alloc". If + * alloc is provided but dealloc is NULL, genx will not attempt to free + * the memory; this would be appropriate in an Apache context. + * If "alloc" is not provided, genx routines use malloc() to allocate memory + */ +void genxSetAlloc(genxWriter w, + void * (* alloc)(void * userData, int bytes)); +void genxSetDealloc(genxWriter w, + void (* dealloc)(void * userData, void * data)); +void * (* genxGetAlloc(genxWriter w))(void * userData, int bytes); +void (* genxGetDealloc(genxWriter w))(void * userData, void * data); + +/* + * Get the prefix associated with a namespace + */ +utf8 genxGetNamespacePrefix(genxNamespace ns); + +/* + * Declaration functions + */ + +/* + * Declare a namespace. The provided prefix is the default but can be + * overridden by genxAddNamespace. If no default prefiix is provided, + * genx will generate one of the form g-%d. + * On error, returns NULL and signals via statusp + */ +genxNamespace genxDeclareNamespace(genxWriter w, + constUtf8 uri, constUtf8 prefix, + genxStatus * statusP); + +/* + * Declare an element + * If something failed, returns NULL and sets the status code via statusP + */ +genxElement genxDeclareElement(genxWriter w, + genxNamespace ns, constUtf8 type, + genxStatus * statusP); + +/* + * Declare an attribute + */ +genxAttribute genxDeclareAttribute(genxWriter w, + genxNamespace ns, + constUtf8 name, genxStatus * statusP); + +/* + * Writing XML + */ + +/* + * Start a new document. + */ +genxStatus genxStartDocFile(genxWriter w, FILE * file); + +/* + * Caller-provided I/O package. + * First form is for a null-terminated string. + * for second, if you have s="abcdef" and want to send "abc", you'd call + * sendBounded(userData, s, s + 3) + */ +typedef struct +{ + genxStatus (* send)(void * userData, constUtf8 s); + genxStatus (* sendBounded)(void * userData, constUtf8 start, constUtf8 end); + genxStatus (* flush)(void * userData); +} genxSender; + +genxStatus genxStartDocSender(genxWriter w, genxSender * sender); + +/* + * End a document. Calls "flush" + */ +genxStatus genxEndDocument(genxWriter w); + +/* + * Write a comment + */ +genxStatus genxComment(genxWriter w, constUtf8 text); + +/* + * Write a PI + */ +genxStatus genxPI(genxWriter w, constUtf8 target, constUtf8 text); + +/* + * Start an element + */ +genxStatus genxStartElementLiteral(genxWriter w, + constUtf8 xmlns, constUtf8 type); + +/* + * Start a predeclared element + * - element must have been declared + */ +genxStatus genxStartElement(genxElement e); + +/* + * Write an attribute + */ +genxStatus genxAddAttributeLiteral(genxWriter w, constUtf8 xmlns, + constUtf8 name, constUtf8 value); + +/* + * Start an attribute + */ +genxStatus genxStartAttributeLiteral(genxWriter w, + constUtf8 xmlns, constUtf8 name); + +/* + * Write a predeclared attribute + */ +genxStatus genxAddAttribute(genxAttribute a, constUtf8 value); + +/* + * Start a predeclared attribute + */ +genxStatus genxStartAttribute(genxAttribute a); + +/* + * End an attribute + */ +genxStatus genxEndAttribute(genxWriter w); + +/* + * add a namespace declaration + */ +genxStatus genxAddNamespaceLiteral(genxWriter w, + constUtf8 uri, constUtf8 prefix); + +/* + * add a predefined namespace declaration + */ +genxStatus genxAddNamespace(genxNamespace ns, constUtf8 prefix); + +/* + * Clear default namespace declaration + */ +genxStatus genxUnsetDefaultNamespace(genxWriter w); + +/* + * Write an end tag + */ +genxStatus genxEndElement(genxWriter w); + +/* + * Write some text + * You can't write any text outside the root element, except with + * genxComment and genxPI + */ +genxStatus genxAddText(genxWriter w, constUtf8 start); +genxStatus genxAddCountedText(genxWriter w, constUtf8 start, int byteCount); +genxStatus genxAddBoundedText(genxWriter w, constUtf8 start, constUtf8 end); + +/* + * Write one character. The integer value is the Unicode character + * value, as usually expressed in U+XXXX notation. + */ +genxStatus genxAddCharacter(genxWriter w, int c); + +/* + * Utility routines + */ + +/* + * Return the Unicode character encoded by the UTF-8 pointed-to by the + * argument, and advance the argument past the encoding of the character. + * Returns -1 if the UTF-8 is malformed, in which case advances the + * argument to point at the first byte past the point past the malformed + * ones. + */ +int genxNextUnicodeChar(constUtf8 * sp); + +/* + * Scan a buffer allegedly full of UTF-8 encoded XML characters; return + * one of GENX_SUCCESS, GENX_BAD_UTF8, or GENX_NON_XML_CHARACTER + */ +genxStatus genxCheckText(genxWriter w, constUtf8 s); + +/* + * return character status, the OR of GENX_XML_CHAR, + * GENX_LETTER, and GENX_NAMECHAR + */ +int genxCharClass(genxWriter w, int c); + +/* + * Silently wipe any non-XML characters out of a chunk of text. + * If you call this on a string before you pass it addText or + * addAttribute, you will never get an error from genx unless + * (a) there's a bug in your software, e.g. a malformed element name, or + * (b) there's a memory allocation or I/O error + * The output can never be longer than the input. + * Returns true if any changes were made. + */ +int genxScrubText(genxWriter w, constUtf8 in, utf8 out); + +/* + * return error messages + */ +char * genxGetErrorMessage(genxWriter w, genxStatus status); +char * genxLastErrorMessage(genxWriter w); + +/* + * return version + */ +char * genxGetVersion(); + +#ifdef __cplusplus +} +#endif + +#endif /* GENX_H */ diff --git a/libxsde/xsde/cxx/buffer.cxx b/libxsde/xsde/cxx/buffer.cxx new file mode 100644 index 0000000..17bcd9e --- /dev/null +++ b/libxsde/xsde/cxx/buffer.cxx @@ -0,0 +1,145 @@ +// file : xsde/cxx/buffer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/buffer.hxx> + +namespace xsde +{ + namespace cxx + { + // c-tors + // + +#ifdef XSDE_EXCEPTIONS + buffer:: + buffer (size_t size) + : data_ (0), size_ (0), capacity_ (0) + { + capacity (size); + size_ = size; + } + + buffer:: + buffer (size_t size, size_t cap) + : data_ (0), size_ (0), capacity_ (0) + { + if (size > cap) + throw bounds (); + + capacity (cap); + size_ = size; + } + + buffer:: + buffer (const void* data, size_t size) + : data_ (0), size_ (0), capacity_ (0) + { + capacity (size); + size_ = size; + + if (size_) + memcpy (data_, data, size_); + } + + buffer:: + buffer (const void* data, size_t size, size_t cap) + : data_ (0), size_ (0), capacity_ (0) + { + if (size > cap) + throw bounds (); + + capacity (cap); + size_ = size; + + if (size_) + memcpy (data_, data, size_); + } + + buffer:: + buffer (void* data, size_t size, size_t cap, ownership_value) + : data_ (0), size_ (0), capacity_ (0) + { + if (size > cap) + throw bounds (); + + data_ = reinterpret_cast<char*> (data); + size_ = size; + capacity_ = cap; + } +#endif // XSDE_EXCEPTIONS + + // + // + +#ifdef XSDE_EXCEPTIONS + bool buffer:: + capacity (size_t capacity, bool copy) + { + if (size_ > capacity) + throw bounds (); + + if (capacity <= capacity_) + { + return false; // Do nothing if shrinking is requested. + } + else + { + char* data = reinterpret_cast<char*> (operator new (capacity)); + + if (copy && size_ > 0) + memcpy (data, data_, size_); + + if (data_) + operator delete (data_); + + data_ = data; + capacity_ = capacity; + + return true; + } + } +#else + buffer::error buffer:: + capacity (size_t capacity, bool copy, bool* moved) + { + if (size_ > capacity) + return error_bounds; + + if (capacity <= capacity_) + { + // Do nothing if shrinking is requested. + // + if (moved) + *moved = false; + } + else + { + char* data = reinterpret_cast<char*> (operator new (capacity)); + + if (data != 0) + { + if (copy && size_ > 0) + memcpy (data, data_, size_); + + if (data_) + operator delete (data_); + + data_ = data; + capacity_ = capacity; + + if (moved) + *moved = true; + } + else + return error_no_memory; + } + + return error_none; + } +#endif + } +} diff --git a/libxsde/xsde/cxx/buffer.hxx b/libxsde/xsde/cxx/buffer.hxx new file mode 100644 index 0000000..e219de3 --- /dev/null +++ b/libxsde/xsde/cxx/buffer.hxx @@ -0,0 +1,149 @@ +// file : xsde/cxx/buffer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_BUFFER_HXX +#define XSDE_CXX_BUFFER_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + // Binary buffer. Used for the base64Binary and hexBinary types. + // + class buffer + { + public: +#ifdef XSDE_EXCEPTIONS + class bounds {}; // Out of bounds exception. +#else + enum error + { + error_none, + error_bounds, + error_no_memory + }; +#endif + + public: + ~buffer (); + buffer (); + +#ifdef XSDE_EXCEPTIONS + explicit + buffer (size_t size); + buffer (size_t size, size_t capacity); + buffer (const void* data, size_t size); + buffer (const void* data, size_t size, size_t capacity); + + enum ownership_value { assume_ownership }; + + // This constructor assumes ownership of the memory passed. + // + buffer (void* data, size_t size, size_t capacity, ownership_value); +#endif + + private: + buffer (const buffer&); + + buffer& + operator= (const buffer&); + + public: +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + attach (void* data, size_t size, size_t capacity); + + void* + detach (); + + void + swap (buffer&); + + public: + size_t + capacity () const; + + // Returns true if the underlying buffer has moved. + // +#ifdef XSDE_EXCEPTIONS + bool + capacity (size_t); +#else + error + capacity (size_t); + + error + capacity (size_t, bool& moved); +#endif + + public: + size_t + size () const; + + // Returns true if the underlying buffer has moved. + // +#ifdef XSDE_EXCEPTIONS + bool + size (size_t); +#else + error + size (size_t); + + error + size (size_t, bool& moved); +#endif + + public: + const char* + data () const; + + char* + data (); + + const char* + begin () const; + + char* + begin (); + + const char* + end () const; + + char* + end (); + + private: +#ifdef XSDE_EXCEPTIONS + bool + capacity (size_t capacity, bool copy); +#else + error + capacity (size_t capacity, bool copy, bool* moved); +#endif + + private: + char* data_; + size_t size_; + size_t capacity_; + }; + + bool + operator== (const buffer&, const buffer&); + + bool + operator!= (const buffer&, const buffer&); + } +} + +#include <xsde/cxx/buffer.ixx> + +#endif // XSDE_CXX_BUFFER_HXX diff --git a/libxsde/xsde/cxx/buffer.ixx b/libxsde/xsde/cxx/buffer.ixx new file mode 100644 index 0000000..78f3633 --- /dev/null +++ b/libxsde/xsde/cxx/buffer.ixx @@ -0,0 +1,213 @@ +// file : xsde/cxx/buffer.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcmp + +namespace xsde +{ + namespace cxx + { + // c-tors & d-tor + // + inline buffer:: + ~buffer () + { + if (data_) + operator delete (data_); + } + + inline buffer:: + buffer () + : data_ (0), size_ (0), capacity_ (0) + { + } + +#ifndef XSDE_EXCEPTIONS + inline buffer::error buffer:: +#else + inline void buffer:: +#endif + attach (void* data, size_t size, size_t cap) + { + if (size > cap) + { +#ifdef XSDE_EXCEPTIONS + throw bounds (); +#else + return error_bounds; +#endif + } + + if (data_) + operator delete (data_); + + data_ = reinterpret_cast<char*> (data); + size_ = size; + capacity_ = cap; + +#ifndef XSDE_EXCEPTIONS + return error_none; +#endif + } + + inline void* buffer:: + detach () + { + void* r = data_; + + data_ = 0; + size_ = 0; + capacity_ = 0; + + return r; + } + + inline void buffer:: + swap (buffer& other) + { + char* d = data_; + size_t s = size_; + size_t c = capacity_; + + data_ = other.data_; + size_ = other.size_; + capacity_ = other.capacity_; + + other.data_ = d; + other.size_ = s; + other.capacity_ = c; + } + + // + // + inline size_t buffer:: + capacity () const + { + return capacity_; + } + +#ifdef XSDE_EXCEPTIONS + inline bool buffer:: + capacity (size_t cap) + { + return capacity (cap, true); + } +#else + inline buffer::error buffer:: + capacity (size_t cap) + { + return capacity (cap, true, 0); + } + + inline buffer::error buffer:: + capacity (size_t cap, bool& moved) + { + return capacity (cap, true, &moved); + } +#endif + + inline size_t buffer:: + size () const + { + return size_; + } + +#ifdef XSDE_EXCEPTIONS + inline bool buffer:: + size (size_t size) + { + bool r = false; + + if (size > capacity_) + r = capacity (size); + + size_ = size; + + return r; + } +#else + inline buffer::error buffer:: + size (size_t size) + { + error r = error_none; + + if (size > capacity_) + r = capacity (size); + + if (r == error_none) + size_ = size; + + return r; + } + + inline buffer::error buffer:: + size (size_t size, bool& moved) + { + error r = error_none; + moved = false; + + if (size > capacity_) + r = capacity (size, moved); + + if (r == error_none) + size_ = size; + + return r; + } +#endif + + // + // + inline const char* buffer:: + data () const + { + return data_; + } + + inline char* buffer:: + data () + { + return data_; + } + + inline const char* buffer:: + begin () const + { + return data_; + } + + inline char* buffer:: + begin () + { + return data_; + } + + inline const char* buffer:: + end () const + { + return data_ + size_; + } + + inline char* buffer:: + end () + { + return data_ + size_; + } + + inline bool + operator== (const buffer& x, const buffer& y) + { + return x.size () == y.size () && + memcmp (x.data (), y.data (), x.size ()) == 0; + } + + inline bool + operator!= (const buffer& x, const buffer& y) + { + return !(x == y); + } + } +} + diff --git a/libxsde/xsde/cxx/compilers/vc-6/post.hxx b/libxsde/xsde/cxx/compilers/vc-6/post.hxx new file mode 100644 index 0000000..a889512 --- /dev/null +++ b/libxsde/xsde/cxx/compilers/vc-6/post.hxx @@ -0,0 +1,6 @@ +// file : xsde/cxx/compilers/vc-6/post.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#pragma warning (pop) diff --git a/libxsde/xsde/cxx/compilers/vc-6/pre.hxx b/libxsde/xsde/cxx/compilers/vc-6/pre.hxx new file mode 100644 index 0000000..fc9d78e --- /dev/null +++ b/libxsde/xsde/cxx/compilers/vc-6/pre.hxx @@ -0,0 +1,33 @@ +// file : xsde/cxx/compilers/vc-6/pre.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/config.h> + +// These warnings had to be disabled "for good". +// +#pragma warning (disable:4505) // unreferenced local function has been removed + +#ifdef XSDE_REUSE_STYLE_MIXIN +#pragma warning (disable:4250) // inherits via dominance +#endif + + +// Push warning state. +// +#pragma warning (push, 3) + + +// Disabled warnings. +// +#pragma warning (disable:4355) // passing 'this' to a member +#pragma warning (disable:4584) // is already a base-class +#pragma warning (disable:4800) // forcing value to bool +#pragma warning (disable:4275) // non dll-interface base +#pragma warning (disable:4251) // base needs to have dll-interface + + +// Elevated warnings. +// +#pragma warning (2:4239) // standard doesn't allow this conversion diff --git a/libxsde/xsde/cxx/compilers/vc-7/post.hxx b/libxsde/xsde/cxx/compilers/vc-7/post.hxx new file mode 100644 index 0000000..867ae06 --- /dev/null +++ b/libxsde/xsde/cxx/compilers/vc-7/post.hxx @@ -0,0 +1,6 @@ +// file : xsde/cxx/compilers/vc-7/post.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#pragma warning (pop) diff --git a/libxsde/xsde/cxx/compilers/vc-7/pre.hxx b/libxsde/xsde/cxx/compilers/vc-7/pre.hxx new file mode 100644 index 0000000..d3678cf --- /dev/null +++ b/libxsde/xsde/cxx/compilers/vc-7/pre.hxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/compilers/vc-7/pre.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#if (_MSC_VER < 1310) +# error Microsoft Visual C++ 7.0 (.NET 2002) is not supported. +#endif + +#include <xsde/config.h> + +// These warnings had to be disabled "for good". +// +#pragma warning (disable:4505) // unreferenced local function has been + +#ifdef XSDE_REUSE_STYLE_MIXIN +#pragma warning (disable:4250) // inherits via dominance +#endif + + +// Push warning state. +// +#pragma warning (push, 3) + + +// Disabled warnings. +// +#pragma warning (disable:4355) // passing 'this' to a member +#pragma warning (disable:4584) // is already a base-class +#pragma warning (disable:4800) // forcing value to bool +#pragma warning (disable:4275) // non dll-interface base +#pragma warning (disable:4251) // base needs to have dll-interface + + +// Elevated warnings. +// +#pragma warning (2:4239) // standard doesn't allow this conversion diff --git a/libxsde/xsde/cxx/compilers/vc-8/post.hxx b/libxsde/xsde/cxx/compilers/vc-8/post.hxx new file mode 100644 index 0000000..eb93d5f --- /dev/null +++ b/libxsde/xsde/cxx/compilers/vc-8/post.hxx @@ -0,0 +1,6 @@ +// file : xsde/cxx/compilers/vc-8/post.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#pragma warning (pop) diff --git a/libxsde/xsde/cxx/compilers/vc-8/pre.hxx b/libxsde/xsde/cxx/compilers/vc-8/pre.hxx new file mode 100644 index 0000000..d9c4baf --- /dev/null +++ b/libxsde/xsde/cxx/compilers/vc-8/pre.hxx @@ -0,0 +1,30 @@ +// file : xsde/cxx/compilers/vc-8/pre.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/config.h> + +// These warnings had to be disabled "for good". +// +#ifdef XSDE_REUSE_STYLE_MIXIN +#pragma warning (disable:4250) // inherits via dominance +#endif + + +// Push warning state. +// +#pragma warning (push, 3) + + +// Disabled warnings. +// +#pragma warning (disable:4355) // passing 'this' to a member +#pragma warning (disable:4800) // forcing value to bool +#pragma warning (disable:4275) // non dll-interface base +#pragma warning (disable:4251) // base needs to have dll-interface + + +// Elevated warnings. +// +#pragma warning (2:4239) // standard doesn't allow this conversion diff --git a/libxsde/xsde/cxx/config.hxx b/libxsde/xsde/cxx/config.hxx new file mode 100644 index 0000000..359aaf2 --- /dev/null +++ b/libxsde/xsde/cxx/config.hxx @@ -0,0 +1,27 @@ +// file : xsde/cxx/config.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_CONFIG_HXX +#define XSDE_CXX_CONFIG_HXX + +#include <xsde/config.h> + +// Macro to suppress unused variable warning. +// +#define XSDE_UNUSED(x) (void)x + +// Using strtof appears to be highly non-portable. +// +#undef XSDE_STRTOF + +// The snprintf function on Win32 and WinCE is called _snprintf. +// +#ifdef XSDE_SNPRINTF +# if defined(XSDE_PLATFORM_WIN32) || defined(XSDE_PLATFORM_WINCE) +# define snprintf _snprintf +# endif +#endif + +#endif // XSDE_CXX_CONFIG_HXX diff --git a/libxsde/xsde/cxx/date-time.hxx b/libxsde/xsde/cxx/date-time.hxx new file mode 100644 index 0000000..2ec701d --- /dev/null +++ b/libxsde/xsde/cxx/date-time.hxx @@ -0,0 +1,415 @@ +// file : xsde/cxx/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_DATE_TIME_HXX +#define XSDE_CXX_DATE_TIME_HXX + +namespace xsde +{ + namespace cxx + { + // + // + class time_zone + { + public: + time_zone (); + time_zone (short hours, short minutes); + + // Returns true if time zone is specified. + // + bool + zone_present () const; + + // Resets the time zone to the 'not specified' state. + // + void + zone_reset (); + + short + zone_hours () const; + + void + zone_hours (short); + + short + zone_minutes () const; + + void + zone_minutes (short); + + private: + bool present_; + short hours_; + short minutes_; + }; + + bool + operator== (const time_zone&, const time_zone&); + + bool + operator!= (const time_zone&, const time_zone&); + + // + // + class gday: public time_zone + { + public: + gday (); + explicit + gday (unsigned short day); + gday (unsigned short day, short zone_hours, short zone_minutes); + + unsigned short + day () const; + + void + day (unsigned short); + + private: + unsigned short day_; + }; + + bool + operator== (const gday&, const gday&); + + bool + operator!= (const gday&, const gday&); + + // + // + class gmonth: public time_zone + { + public: + gmonth (); + explicit + gmonth (unsigned short month); + gmonth (unsigned short month, short zone_hours, short zone_minutes); + + unsigned short + month () const; + + void + month (unsigned short); + + private: + unsigned short month_; + }; + + bool + operator== (const gmonth&, const gmonth&); + + bool + operator!= (const gmonth&, const gmonth&); + + // + // + class gyear: public time_zone + { + public: + gyear (); + explicit + gyear (int year); + gyear (int year, short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + private: + int year_; + }; + + bool + operator== (const gyear&, const gyear&); + + bool + operator!= (const gyear&, const gyear&); + + // + // + class gmonth_day: public time_zone + { + public: + gmonth_day (); + gmonth_day (unsigned short month, unsigned short day); + gmonth_day (unsigned short month, unsigned short day, + short zone_hours, short zone_minutes); + + unsigned short + month () const; + + void + month (unsigned short); + + unsigned short + day () const; + + void + day (unsigned short); + + private: + unsigned short month_; + unsigned short day_; + }; + + bool + operator== (const gmonth_day&, const gmonth_day&); + + bool + operator!= (const gmonth_day&, const gmonth_day&); + + // + // + class gyear_month: public time_zone + { + public: + gyear_month (); + gyear_month (int year, unsigned short month); + gyear_month (int year, unsigned short month, + short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + unsigned short + month () const; + + void + month (unsigned short); + + private: + int year_; + unsigned short month_; + }; + + bool + operator== (const gyear_month&, const gyear_month&); + + bool + operator!= (const gyear_month&, const gyear_month&); + + // + // + class date: public time_zone + { + public: + date (); + date (int year, unsigned short month, unsigned short day); + date (int year, unsigned short month, unsigned short day, + short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + unsigned short + month () const; + + void + month (unsigned short); + + unsigned short + day () const; + + void + day (unsigned short); + + private: + int year_; + unsigned short month_; + unsigned short day_; + }; + + bool + operator== (const date&, const date&); + + bool + operator!= (const date&, const date&); + + // + // + class time: public time_zone + { + public: + time (); + time (unsigned short hours, unsigned short minutes, double seconds); + time (unsigned short hours, unsigned short minutes, double seconds, + short zone_hours, short zone_minutes); + + unsigned short + hours () const; + + void + hours (unsigned short); + + unsigned short + minutes () const; + + void + minutes (unsigned short); + + double + seconds () const; + + void + seconds (double); + + private: + unsigned short hours_; + unsigned short minutes_; + double seconds_; + }; + + bool + operator== (const time&, const time&); + + bool + operator!= (const time&, const time&); + + // + // + class date_time: public time_zone + { + public: + date_time (); + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds); + + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds, + short zone_hours, short zone_minutes); + + int + year () const; + + void + year (int); + + unsigned short + month () const; + + void + month (unsigned short); + + unsigned short + day () const; + + void + day (unsigned short); + + unsigned short + hours () const; + + void + hours (unsigned short); + + unsigned short + minutes () const; + + void + minutes (unsigned short); + + double + seconds () const; + + void + seconds (double); + + private: + int year_; + unsigned short month_; + unsigned short day_; + unsigned short hours_; + unsigned short minutes_; + double seconds_; + }; + + bool + operator== (const date_time&, const date_time&); + + bool + operator!= (const date_time&, const date_time&); + + // + // + class duration + { + public: + duration (); + duration (bool negative, + unsigned int years, unsigned int months, unsigned int days, + unsigned int hours, unsigned int minutes, double seconds); + + bool + negative () const; + + void + negative (bool); + + unsigned int + years () const; + + void + years (unsigned int); + + unsigned int + months () const; + + void + months (unsigned int); + + unsigned int + days () const; + + void + days (unsigned int); + + unsigned int + hours () const; + + void + hours (unsigned int); + + unsigned int + minutes () const; + + void + minutes (unsigned int); + + double + seconds () const; + + void + seconds (double); + + private: + bool negative_; + unsigned int years_; + unsigned int months_; + unsigned int days_; + unsigned int hours_; + unsigned int minutes_; + double seconds_; + }; + + bool + operator== (const duration&, const duration&); + + bool + operator!= (const duration&, const duration&); + } +} + +#include <xsde/cxx/date-time.ixx> + +#endif // XSDE_CXX_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/date-time.ixx b/libxsde/xsde/cxx/date-time.ixx new file mode 100644 index 0000000..d51d00c --- /dev/null +++ b/libxsde/xsde/cxx/date-time.ixx @@ -0,0 +1,725 @@ +// file : xsde/cxx/date-time.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + // time_zone + // + inline time_zone:: + time_zone () + : present_ (false) + { + } + + inline time_zone:: + time_zone (short h, short m) + : present_ (true), hours_ (h), minutes_ (m) + { + } + + inline bool time_zone:: + zone_present () const + { + return present_; + } + + inline void time_zone:: + zone_reset () + { + present_ = false; + } + + inline short time_zone:: + zone_hours () const + { + return hours_; + } + + inline void time_zone:: + zone_hours (short h) + { + hours_ = h; + present_ = true; + } + + inline short time_zone:: + zone_minutes () const + { + return minutes_; + } + + inline void time_zone:: + zone_minutes (short m) + { + minutes_ = m; + present_ = true; + } + + inline bool + operator== (const time_zone& x, const time_zone& y) + { + return x.zone_present () + ? y.zone_present () && + x.zone_hours () == y.zone_hours () && + x.zone_minutes () == y.zone_minutes () + : !y.zone_present (); + } + + inline bool + operator!= (const time_zone& x, const time_zone& y) + { + return !(x == y); + } + + // gday + // + inline gday:: + gday () + { + } + + inline gday:: + gday (unsigned short day) + : day_ (day) + { + } + + inline gday:: + gday (unsigned short day, short zone_h, short zone_m) + : time_zone (zone_h, zone_m), day_ (day) + { + } + + inline unsigned short gday:: + day () const + { + return day_; + } + + inline void gday:: + day (unsigned short day) + { + day_ = day; + } + + inline bool + operator== (const gday& x, const gday& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.day () == y.day () && xz == yz; + } + + inline bool + operator!= (const gday& x, const gday& y) + { + return !(x == y); + } + + // gmonth + // + inline gmonth:: + gmonth () + { + } + + inline gmonth:: + gmonth (unsigned short month) + : month_ (month) + { + } + + inline gmonth:: + gmonth (unsigned short month, short zone_h, short zone_m) + : time_zone (zone_h, zone_m), month_ (month) + { + } + + inline unsigned short gmonth:: + month () const + { + return month_; + } + + inline void gmonth:: + month (unsigned short month) + { + month_ = month; + } + + inline bool + operator== (const gmonth& x, const gmonth& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.month () == y.month () && xz == yz; + } + + inline bool + operator!= (const gmonth& x, const gmonth& y) + { + return !(x == y); + } + + // gyear + // + inline gyear:: + gyear () + { + } + + inline gyear:: + gyear (int year) + : year_ (year) + { + } + + inline gyear:: + gyear (int year, short zone_h, short zone_m) + : time_zone (zone_h, zone_m), year_ (year) + { + } + + inline int gyear:: + year () const + { + return year_; + } + + inline void gyear:: + year (int year) + { + year_ = year; + } + + inline bool + operator== (const gyear& x, const gyear& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && xz == yz; + } + + inline bool + operator!= (const gyear& x, const gyear& y) + { + return !(x == y); + } + + // gmonth_day + // + inline gmonth_day:: + gmonth_day () + { + } + + inline gmonth_day:: + gmonth_day (unsigned short month, unsigned short day) + : month_ (month), day_ (day) + { + } + + inline gmonth_day:: + gmonth_day (unsigned short month, unsigned short day, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), month_ (month), day_ (day) + { + } + + inline unsigned short gmonth_day:: + month () const + { + return month_; + } + + inline void gmonth_day:: + month (unsigned short month) + { + month_ = month; + } + + inline unsigned short gmonth_day:: + day () const + { + return day_; + } + + inline void gmonth_day:: + day (unsigned short day) + { + day_ = day; + } + + inline bool + operator== (const gmonth_day& x, const gmonth_day& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.month () == y.month () && + x.day () == y.day () && + xz == yz; + } + + inline bool + operator!= (const gmonth_day& x, const gmonth_day& y) + { + return !(x == y); + } + + // gyear_month + // + inline gyear_month:: + gyear_month () + { + } + + inline gyear_month:: + gyear_month (int year, unsigned short month) + : year_ (year), month_ (month) + { + } + + inline gyear_month:: + gyear_month (int year, unsigned short month, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), year_ (year), month_ (month) + { + } + + inline int gyear_month:: + year () const + { + return year_; + } + + inline void gyear_month:: + year (int year) + { + year_ = year; + } + + inline unsigned short gyear_month:: + month () const + { + return month_; + } + + inline void gyear_month:: + month (unsigned short month) + { + month_ = month; + } + + inline bool + operator== (const gyear_month& x, const gyear_month& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && + x.month () == y.month () && + xz == yz; + } + + inline bool + operator!= (const gyear_month& x, const gyear_month& y) + { + return !(x == y); + } + + // date + // + inline date:: + date () + { + } + + inline date:: + date (int year, unsigned short month, unsigned short day) + : year_ (year), month_ (month), day_ (day) + { + } + + inline date:: + date (int year, unsigned short month, unsigned short day, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), + year_ (year), month_ (month), day_ (day) + { + } + + inline int date:: + year () const + { + return year_; + } + + inline void date:: + year (int year) + { + year_ = year; + } + + inline unsigned short date:: + month () const + { + return month_; + } + + inline void date:: + month (unsigned short month) + { + month_ = month; + } + + inline unsigned short date:: + day () const + { + return day_; + } + + inline void date:: + day (unsigned short day) + { + day_ = day; + } + + inline bool + operator== (const date& x, const date& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && + x.month () == y.month () && + x.day () == y.day () && + xz == yz; + } + + inline bool + operator!= (const date& x, const date& y) + { + return !(x == y); + } + + // time + // + inline time:: + time () + { + } + + inline time:: + time (unsigned short hours, unsigned short minutes, double seconds) + : hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline time:: + time (unsigned short hours, unsigned short minutes, double seconds, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline unsigned short time:: + hours () const + { + return hours_; + } + + inline void time:: + hours (unsigned short hours) + { + hours_ = hours; + } + + inline unsigned short time:: + minutes () const + { + return minutes_; + } + + inline void time:: + minutes (unsigned short minutes) + { + minutes_ = minutes; + } + + inline double time:: + seconds () const + { + return seconds_; + } + + inline void time:: + seconds (double seconds) + { + seconds_ = seconds; + } + + inline bool + operator== (const time& x, const time& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.hours () == y.hours () && + x.minutes () == y.minutes () && + x.seconds () == y.seconds () && + xz == yz; + } + + inline bool + operator!= (const time& x, const time& y) + { + return !(x == y); + } + + // date_time + // + inline date_time:: + date_time () + { + } + + inline date_time:: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds) + : year_ (year), month_ (month), day_ (day), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline date_time:: + date_time (int year, unsigned short month, unsigned short day, + unsigned short hours, unsigned short minutes, double seconds, + short zone_h, short zone_m) + : time_zone (zone_h, zone_m), + year_ (year), month_ (month), day_ (day), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline int date_time:: + year () const + { + return year_; + } + + inline void date_time:: + year (int year) + { + year_ = year; + } + + inline unsigned short date_time:: + month () const + { + return month_; + } + + inline void date_time:: + month (unsigned short month) + { + month_ = month; + } + + inline unsigned short date_time:: + day () const + { + return day_; + } + + inline void date_time:: + day (unsigned short day) + { + day_ = day; + } + + inline unsigned short date_time:: + hours () const + { + return hours_; + } + + inline void date_time:: + hours (unsigned short hours) + { + hours_ = hours; + } + + inline unsigned short date_time:: + minutes () const + { + return minutes_; + } + + inline void date_time:: + minutes (unsigned short minutes) + { + minutes_ = minutes; + } + + inline double date_time:: + seconds () const + { + return seconds_; + } + + inline void date_time:: + seconds (double seconds) + { + seconds_ = seconds; + } + + inline bool + operator== (const date_time& x, const date_time& y) + { + const time_zone& xz = x; + const time_zone& yz = y; + + return x.year () == y.year () && + x.month () == y.month () && + x.day () == y.day () && + x.hours () == y.hours () && + x.minutes () == y.minutes () && + x.seconds () == y.seconds () && + xz == yz; + } + + inline bool + operator!= (const date_time& x, const date_time& y) + { + return !(x == y); + } + + // duration + // + inline duration:: + duration () + { + } + + inline duration:: + duration (bool negative, + unsigned int years, unsigned int months, unsigned int days, + unsigned int hours, unsigned int minutes, double seconds) + : negative_ (negative), + years_ (years), months_ (months), days_ (days), + hours_ (hours), minutes_ (minutes), seconds_ (seconds) + { + } + + inline bool duration:: + negative () const + { + return negative_; + } + + inline void duration:: + negative (bool negative) + { + negative_ = negative; + } + + inline unsigned int duration:: + years () const + { + return years_; + } + + inline void duration:: + years (unsigned int years) + { + years_ = years; + } + + inline unsigned int duration:: + months () const + { + return months_; + } + + inline void duration:: + months (unsigned int months) + { + months_ = months; + } + + inline unsigned int duration:: + days () const + { + return days_; + } + + inline void duration:: + days (unsigned int days) + { + days_ = days; + } + + inline unsigned int duration:: + hours () const + { + return hours_; + } + + inline void duration:: + hours (unsigned int hours) + { + hours_ = hours; + } + + inline unsigned int duration:: + minutes () const + { + return minutes_; + } + + inline void duration:: + minutes (unsigned int minutes) + { + minutes_ = minutes; + } + + inline double duration:: + seconds () const + { + return seconds_; + } + + inline void duration:: + seconds (double seconds) + { + seconds_ = seconds; + } + + inline bool + operator== (const duration& x, const duration& y) + { + return x.negative () == y.negative () && + x.years () == y.years () && + x.months () == y.months () && + x.days () == y.days () && + x.hours () == y.hours () && + x.minutes () == y.minutes () && + x.seconds () == y.seconds (); + } + + inline bool + operator!= (const duration& x, const duration& y) + { + return !(x == y); + } + } +} diff --git a/libxsde/xsde/cxx/errno.hxx b/libxsde/xsde/cxx/errno.hxx new file mode 100644 index 0000000..1669ec5 --- /dev/null +++ b/libxsde/xsde/cxx/errno.hxx @@ -0,0 +1,23 @@ +// file : xsde/cxx/errno.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_ERRNO_HXX +#define XSDE_CXX_ERRNO_HXX + +namespace xsde +{ + namespace cxx + { + int + get_errno (); + + void + set_errno (int); + } +} + +#include <xsde/cxx/errno.ixx> + +#endif // XSDE_CXX_ERRNO_HXX diff --git a/libxsde/xsde/cxx/errno.ixx b/libxsde/xsde/cxx/errno.ixx new file mode 100644 index 0000000..f817bbc --- /dev/null +++ b/libxsde/xsde/cxx/errno.ixx @@ -0,0 +1,44 @@ +// file : xsde/cxx/errno.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_PLATFORM_WINCE +# include <winbase.h> // Get/SetLastError +#else +# include <errno.h> +#endif + +namespace xsde +{ + namespace cxx + { +#ifdef XSDE_PLATFORM_WINCE + inline int + get_errno () + { + return static_cast<int> (GetLastError ()); + } + + inline void + set_errno (int e) + { + SetLastError (static_cast<DWORD> (e)); + } +#else + inline int + get_errno () + { + return errno; + } + + inline void + set_errno (int e) + { + errno = e; + } +#endif + } +} diff --git a/libxsde/xsde/cxx/exceptions.hxx b/libxsde/xsde/cxx/exceptions.hxx new file mode 100644 index 0000000..26ed4a9 --- /dev/null +++ b/libxsde/xsde/cxx/exceptions.hxx @@ -0,0 +1,21 @@ +// file : xsde/cxx/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_EXCEPTIONS_HXX +#define XSDE_CXX_EXCEPTIONS_HXX + +#include <exception> // std::exception + +namespace xsde +{ + namespace cxx + { + struct exception: std::exception + { + }; + } +} + +#endif // XSDE_CXX_EXCEPTIONS_HXX diff --git a/libxsde/xsde/cxx/hashmap.cxx b/libxsde/xsde/cxx/hashmap.cxx new file mode 100644 index 0000000..c5d9079 --- /dev/null +++ b/libxsde/xsde/cxx/hashmap.cxx @@ -0,0 +1,210 @@ +// file : xsde/cxx/hashmap.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memset, memcpy, strlen, strcmp, strncmp + +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + // const_iterator + // + hashmap_const_iterator:: + hashmap_const_iterator (const hashmap& map, size_t b) + : map_ (&map), bucket_ (b), element_ (0) + { + // Get it to the first actual element if any. + // + for (; bucket_ < map_->bcount_; ++bucket_) + { + hashmap::bucket* p = map_->buckets_[bucket_]; + if (p && p->size_) + break; + } + } + + const void* hashmap_const_iterator:: + operator* () const + { + typedef hashmap::bucket bucket; + typedef hashmap::element element; + + bucket* p = map_->buckets_[bucket_]; + const char* b = reinterpret_cast<const char*> (p) + sizeof (bucket); + b += element_ * (sizeof (element) + map_->esize_); + return b + sizeof (element); + } + + hashmap_const_iterator& hashmap_const_iterator:: + operator++ () + { + if (bucket_ < map_->bcount_) + { + hashmap::bucket* p = map_->buckets_[bucket_]; + + if (p->size_ > element_ + 1) + ++element_; + else + { + element_ = 0; + + for (++bucket_; bucket_ < map_->bcount_; ++bucket_) + { + p = map_->buckets_[bucket_]; + if (p && p->size_) + break; + } + } + } + + return *this; + } + + // hashmap + // + hashmap:: + ~hashmap () + { +#ifndef XSDE_EXCEPTIONS + if (buckets_ != 0) + { +#endif + for (size_t i = 0; i < bcount_; ++i) + { + if (buckets_[i]) + operator delete (buckets_[i]); + } + + delete[] buckets_; + +#ifndef XSDE_EXCEPTIONS + } +#endif + } + + + hashmap:: + hashmap (size_t bcount, size_t esize) + : esize_ (esize), ecount_ (0), bcount_ (bcount), buckets_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_ = error_none; +#endif + + buckets_ = new bucket*[bcount_]; + +#ifndef XSDE_EXCEPTIONS + if (buckets_ == 0) + { + error_ = error_no_memory; + return; + } +#endif + memset (buckets_, 0, sizeof (bucket*) * bcount_); + } + + void hashmap:: + insert (const char* key, void* value) + { + size_t h = hash (key); + bucket*& p = *(buckets_ + h % bcount_); + + if (p == 0) + { + // No elements in this bucket yet. Start with capacity for 2 + // elements. + // + p = static_cast<bucket*> ( + operator new (sizeof (bucket) + 2 * (sizeof (element) + esize_))); + +#ifndef XSDE_EXCEPTIONS + if (p == 0) + { + error_ = error_no_memory; + return; + } +#endif + p->size_ = 0; + p->capacity_ = 2; + } + + if (p->size_ == p->capacity_) + { + // No more space in this bucket. Create a bigger bucket. + // + size_t c = p->size_ * 2; + bucket* n = static_cast<bucket*> ( + operator new (sizeof (bucket) + c * (sizeof (element) + esize_))); + +#ifndef XSDE_EXCEPTIONS + if (n == 0) + { + error_ = error_no_memory; + return; + } +#endif + n->size_ = p->size_; + n->capacity_ = c; + + char* src = reinterpret_cast<char*> (p) + sizeof (bucket); + char* dst = reinterpret_cast<char*> (n) + sizeof (bucket); + + memcpy (dst, src, p->size_ * (sizeof (element) + esize_)); + + operator delete (p); + p = n; + } + + char* data = reinterpret_cast<char*> (p) + sizeof (bucket) + + p->size_ * (sizeof (element) + esize_); + + element* e = reinterpret_cast<element*> (data); + e->hash_ = h; + e->key_ = key; + + memcpy (data + sizeof (element), value, esize_); + + p->size_++; + ecount_++; + } + + const void* hashmap:: + find (const char* key) const + { + size_t h = hash (key); + const bucket* p = *(buckets_ + h % bcount_); + + if (p) + { + const char* b = reinterpret_cast<const char*> (p) + sizeof (bucket); + const char* e = b + p->size_ * (sizeof (element) + esize_); + + for (; b < e; b += sizeof (element) + esize_) + { + const element* e = reinterpret_cast<const element*> (b); + + if (e->hash_ == h && strcmp (e->key_, key) == 0) + return b + sizeof (element); + } + } + + return 0; + } + + size_t hashmap:: + max_bucket_size () const + { + size_t r = 0; + for (size_t i = 0; i < bcount_; ++i) + { + if (buckets_[i] != 0 && buckets_[i]->size_ > r) + r = buckets_[i]->size_; + } + return r; + } + } +} diff --git a/libxsde/xsde/cxx/hashmap.hxx b/libxsde/xsde/cxx/hashmap.hxx new file mode 100644 index 0000000..29c47e7 --- /dev/null +++ b/libxsde/xsde/cxx/hashmap.hxx @@ -0,0 +1,156 @@ +// file : xsde/cxx/hashmap.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HASHMAP_HXX +#define XSDE_CXX_HASHMAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + class hashmap; + + class hashmap_const_iterator + { + public: + hashmap_const_iterator (const hashmap& map, size_t bucket); + + // Forward iterator requirements. + // + const void* + operator* () const; + + hashmap_const_iterator& + operator++ (); + + hashmap_const_iterator + operator++ (int); + + friend bool + operator== (const hashmap_const_iterator& i, + const hashmap_const_iterator& j); + private: + const hashmap* map_; + size_t bucket_; + size_t element_; + }; + + bool + operator!= (const hashmap_const_iterator& i, + const hashmap_const_iterator& j); + + // Special-purpose, light-weight C-string to POD hashmap. Some of + // its characteristics: + // + // - number of buckets does not grow (no re-hashing) + // - removal of items is not supported + // - key and value (POD) are not deep-copied + // - empty bucket is cheap (1 pointer) + // + class hashmap + { + public: +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; + + error + _error () const; +#endif + + public: + ~hashmap (); + hashmap (size_t buckets, size_t element_size); + + private: + hashmap (hashmap&); + + hashmap& + operator= (hashmap&); + + public: + void + insert (const char* key, void* value); + + const void* + find (const char* key) const; + + public: + bool + empty () const; + + size_t + size () const; + + // Return the maximum number of elements in a single bucket. + // + size_t + max_bucket_size () const; + + public: + typedef hashmap_const_iterator const_iterator; + + const_iterator + begin () const; + + const_iterator + end () const; + + public: + static size_t + hash (const char*); + + static size_t + hash (const char*, size_t n); + + static size_t + hash (size_t hash, const char*); + + static size_t + hash (size_t hash, const char*, size_t n); + + protected: + struct bucket + { + size_t size_; + size_t capacity_; + }; + + struct element + { + size_t hash_; + const char* key_; + }; + + protected: + const bucket* + find (size_t hash) const; + + private: + friend class hashmap_const_iterator; + + size_t esize_; // element size + size_t ecount_; // element count + size_t bcount_; // bucket count + bucket** buckets_; + +#ifndef XSDE_EXCEPTIONS + protected: + error error_; +#endif + }; + } +} + +#include <xsde/cxx/hashmap.ixx> + +#endif // XSDE_CXX_HASHMAP_HXX diff --git a/libxsde/xsde/cxx/hashmap.ixx b/libxsde/xsde/cxx/hashmap.ixx new file mode 100644 index 0000000..a2d2a1b --- /dev/null +++ b/libxsde/xsde/cxx/hashmap.ixx @@ -0,0 +1,177 @@ +// file : xsde/cxx/hashmap.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + // const_iterator + // + inline hashmap_const_iterator hashmap_const_iterator:: + operator++ (int) + { + hashmap_const_iterator r (*this); + ++(*this); + return r; + } + + inline bool + operator== (const hashmap_const_iterator& i, + const hashmap_const_iterator& j) + { + return i.map_ == j.map_ && + i.bucket_ == j.bucket_ && + i.element_ == j.element_; + } + + inline bool + operator!= (const hashmap_const_iterator& i, + const hashmap_const_iterator& j) + { + return !(i == j); + } + + // hashmap + // + +#ifndef XSDE_EXCEPTIONS + inline hashmap::error hashmap:: + _error () const + { + return error_; + } +#endif + + inline bool hashmap:: + empty () const + { + return ecount_ == 0; + } + + inline size_t hashmap:: + size () const + { + return ecount_; + } + + inline const hashmap::bucket* hashmap:: + find (size_t h) const + { + return *(buckets_ + h % bcount_); + } + + inline hashmap::const_iterator hashmap:: + begin () const + { + return const_iterator (*this, ecount_ ? 0 : bcount_); + } + + inline hashmap::const_iterator hashmap:: + end () const + { + return const_iterator (*this, bcount_); + } + + // Fowler/Noll/Vo (FNV) hash (type FNV-1a) + // +#if XSDE_ARCH_WIDTH == 32 + inline size_t hashmap:: + hash (const char* s) + { + size_t r = static_cast<size_t> (2166136261UL); + for (; *s != 0; ++s) + { + r ^= static_cast<size_t> (*s); + r *= static_cast<size_t> (16777619UL); + } + return r; + } + + inline size_t hashmap:: + hash (const char* s, size_t n) + { + size_t r = static_cast<size_t> (2166136261UL); + for (; n > 0; --n) + { + r ^= static_cast<size_t> (*s++); + r *= static_cast<size_t> (16777619UL); + } + return r; + } + + inline size_t hashmap:: + hash (size_t h, const char* s) + { + for (; *s != 0; ++s) + { + h ^= static_cast<size_t> (*s); + h *= static_cast<size_t> (16777619UL); + } + return h; + } + + inline size_t hashmap:: + hash (size_t h, const char* s, size_t n) + { + for (; n > 0; --n) + { + h ^= static_cast<size_t> (*s++); + h *= static_cast<size_t> (16777619UL); + } + return h; + } + +#elif XSDE_ARCH_WIDTH == 64 + + inline size_t hashmap:: + hash (const char* s) + { + size_t r = static_cast<size_t> (14695981039346656037ULL); + for (; *s != 0; ++s) + { + r ^= static_cast<size_t> (*s); + r *= static_cast<size_t> (1099511628211ULL); + } + return r; + } + + inline size_t hashmap:: + hash (const char* s, size_t n) + { + size_t r = static_cast<size_t> (14695981039346656037ULL); + for (; n > 0; --n) + { + r ^= static_cast<size_t> (*s++); + r *= static_cast<size_t> (1099511628211ULL); + } + return r; + } + + inline size_t hashmap:: + hash (size_t h, const char* s) + { + for (; *s != 0; ++s) + { + h ^= static_cast<size_t> (*s); + h *= static_cast<size_t> (1099511628211ULL); + } + return h; + } + + inline size_t hashmap:: + hash (size_t h, const char* s, size_t n) + { + for (; n > 0; --n) + { + h ^= static_cast<size_t> (*s++); + h *= static_cast<size_t> (1099511628211ULL); + } + return h; + } +#else +#error there is no suitable hash function for this architecture width +#endif // XSDE_ARCH_WIDTH + } +} diff --git a/libxsde/xsde/cxx/hybrid/any-type.hxx b/libxsde/xsde/cxx/hybrid/any-type.hxx new file mode 100644 index 0000000..db512c2 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/any-type.hxx @@ -0,0 +1,26 @@ +// file : xsde/cxx/hybrid/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_ANY_TYPE_HXX +#define XSDE_CXX_HYBRID_ANY_TYPE_HXX + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + struct any_type + { + }; + + struct any_simple_type + { + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/hybrid/base.hxx b/libxsde/xsde/cxx/hybrid/base.hxx new file mode 100644 index 0000000..75753bc --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/base.hxx @@ -0,0 +1,370 @@ +// file : xsde/cxx/hybrid/base.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_BASE_HXX +#define XSDE_CXX_HYBRID_BASE_HXX + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // boolean + // + struct boolean_base + { + bool base_value () const {return x_;} + bool& base_value () {return x_;} + void base_value (bool x) {x_ = x;} + + operator const bool& () const {return x_;} + operator bool& () {return x_;} + + boolean_base& operator= (bool x) {x_ = x; return *this;} + + protected: + bool x_; + }; + + // byte + // + struct byte_base + { + signed char base_value () const {return x_;} + signed char& base_value () {return x_;} + void base_value (signed char x) {x_ = x;} + + operator const signed char& () const {return x_;} + operator signed char& () {return x_;} + + byte_base& operator= (signed char x) {x_ = x; return *this;} + + protected: + signed char x_; + }; + + // unsigned_byte + // + struct unsigned_byte_base + { + unsigned char base_value () const {return x_;} + unsigned char& base_value () {return x_;} + void base_value (unsigned char x) {x_ = x;} + + operator const unsigned char& () const {return x_;} + operator unsigned char& () {return x_;} + + unsigned_byte_base& + operator= (unsigned char x) {x_ = x; return *this;} + + protected: + unsigned char x_; + }; + + // short + // + struct short_base + { + short base_value () const {return x_;} + short& base_value () {return x_;} + void base_value (short x) {x_ = x;} + + operator const short& () const {return x_;} + operator short& () {return x_;} + + short_base& operator= (short x) {x_ = x; return *this;} + + protected: + short x_; + }; + + // unsigned_short + // + struct unsigned_short_base + { + unsigned short base_value () const {return x_;} + unsigned short& base_value () {return x_;} + void base_value (unsigned short x) {x_ = x;} + + operator const unsigned short& () const {return x_;} + operator unsigned short& () {return x_;} + + unsigned_short_base& + operator= (unsigned short x) {x_ = x; return *this;} + + protected: + unsigned short x_; + }; + + // int + // + struct int_base + { + int base_value () const {return x_;} + int& base_value () {return x_;} + void base_value (int x) {x_ = x;} + + operator const int& () const {return x_;} + operator int& () {return x_;} + + int_base& operator= (int x) {x_ = x; return *this;} + + protected: + int x_; + }; + + // unsigned_int + // + struct unsigned_int_base + { + unsigned int base_value () const {return x_;} + unsigned int& base_value () {return x_;} + void base_value (unsigned int x) {x_ = x;} + + operator const unsigned int& () const {return x_;} + operator unsigned int& () {return x_;} + + unsigned_int_base& operator= (unsigned int x) {x_ = x; return *this;} + + protected: + unsigned int x_; + }; + + // long + // +#ifdef XSDE_LONGLONG + struct long_base + { + long long base_value () const {return x_;} + long long& base_value () {return x_;} + void base_value (long long x) {x_ = x;} + + operator const long long& () const {return x_;} + operator long long& () {return x_;} + + long_base& operator= (long long x) {x_ = x; return *this;} + + protected: + long long x_; + }; +#else + struct long_base + { + long base_value () const {return x_;} + long& base_value () {return x_;} + void base_value (long x) {x_ = x;} + + operator const long& () const {return x_;} + operator long& () {return x_;} + + long_base& operator= (long x) {x_ = x; return *this;} + + protected: + long x_; + }; +#endif + + + // unsigned_long + // +#ifdef XSDE_LONGLONG + struct unsigned_long_base + { + unsigned long long base_value () const {return x_;} + unsigned long long& base_value () {return x_;} + void base_value (unsigned long long x) {x_ = x;} + + operator const unsigned long long& () const {return x_;} + operator unsigned long long& () {return x_;} + + unsigned_long_base& + operator= (unsigned long long x) {x_ = x; return *this;} + + protected: + unsigned long long x_; + }; +#else + struct unsigned_long_base + { + unsigned long base_value () const {return x_;} + unsigned long& base_value () {return x_;} + void base_value (unsigned long x) {x_ = x;} + + operator const unsigned long& () const {return x_;} + operator unsigned long& () {return x_;} + + unsigned_long_base& + operator= (unsigned long x) {x_ = x; return *this;} + + protected: + unsigned long x_; + }; +#endif + + // integer + // + struct integer_base + { + long base_value () const {return x_;} + long& base_value () {return x_;} + void base_value (long x) {x_ = x;} + + operator const long& () const {return x_;} + operator long& () {return x_;} + + integer_base& operator= (long x) {x_ = x; return *this;} + + protected: + long x_; + }; + + // negative_integer + // + struct negative_integer_base + { + long base_value () const {return x_;} + long& base_value () {return x_;} + void base_value (long x) {x_ = x;} + + operator const long& () const {return x_;} + operator long& () {return x_;} + + negative_integer_base& operator= (long x) {x_ = x; return *this;} + + protected: + long x_; + }; + + // non_positive_integer + // + struct non_positive_integer_base + { + long base_value () const {return x_;} + long& base_value () {return x_;} + void base_value (long x) {x_ = x;} + + operator const long& () const {return x_;} + operator long& () {return x_;} + + non_positive_integer_base& operator= (long x) {x_ = x; return *this;} + + protected: + long x_; + }; + + // positive_integer + // + struct positive_integer_base + { + unsigned long base_value () const {return x_;} + unsigned long& base_value () {return x_;} + void base_value (unsigned long x) {x_ = x;} + + operator const unsigned long& () const {return x_;} + operator unsigned long& () {return x_;} + + positive_integer_base& + operator= (unsigned long x) {x_ = x; return *this;} + + protected: + unsigned long x_; + }; + + // non_negative_integer + // + struct non_negative_integer_base + { + unsigned long base_value () const {return x_;} + unsigned long& base_value () {return x_;} + void base_value (unsigned long x) {x_ = x;} + + operator const unsigned long& () const {return x_;} + operator unsigned long& () {return x_;} + + non_negative_integer_base& + operator= (unsigned long x) {x_ = x; return *this;} + + protected: + unsigned long x_; + }; + + // float + // + struct float_base + { + float base_value () const {return x_;} + float& base_value () {return x_;} + void base_value (float x) {x_ = x;} + + operator const float& () const {return x_;} + operator float& () {return x_;} + + float_base& operator= (float x) {x_ = x; return *this;} + + protected: + float x_; + }; + + // double + // + struct double_base + { + double base_value () const {return x_;} + double& base_value () {return x_;} + void base_value (double x) {x_ = x;} + + operator const double& () const {return x_;} + operator double& () {return x_;} + + double_base& operator= (double x) {x_ = x; return *this;} + + protected: + double x_; + }; + + // decimal + // + struct decimal_base + { + double base_value () const {return x_;} + double& base_value () {return x_;} + void base_value (double x) {x_ = x;} + + operator const double& () const {return x_;} + operator double& () {return x_;} + + decimal_base& operator= (double x) {x_ = x; return *this;} + + protected: + double x_; + }; + + // string + // + struct string_base + { + string_base () : x_ (0) {} + ~string_base () {delete[] x_;} + + const char* base_value () const {return x_;} + char* base_value () {return x_;} + void base_value (char* x) {delete[] x_; x_ = x;} + + operator const char* () const {return x_;} + operator char* () {return x_;} + + string_base& operator= (char* x) {delete[] x_; x_ = x; return *this;} + + protected: + char* x_; + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_BASE_HXX diff --git a/libxsde/xsde/cxx/hybrid/sequence.cxx b/libxsde/xsde/cxx/hybrid/sequence.cxx new file mode 100644 index 0000000..da16e95 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/sequence.cxx @@ -0,0 +1,31 @@ +// file : xsde/cxx/hybrid/sequence.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/hybrid/sequence.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // + // data_seq + // + + void data_seq:: + clear () + { + if (destructor_) + { + for (size_t i = 0; i < size_; ++i) + destructor_ (static_cast<void**> (data_)[i], i); + } + + size_ = 0; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/sequence.hxx b/libxsde/xsde/cxx/hybrid/sequence.hxx new file mode 100644 index 0000000..d7f6dcb --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/sequence.hxx @@ -0,0 +1,921 @@ +// file : xsde/cxx/hybrid/sequence.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_SEQUENCE_HXX +#define XSDE_CXX_HYBRID_SEQUENCE_HXX + +#include <stddef.h> // size_t, ptrdiff_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/sequence-base.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/string-sequence.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // Sequence with fixed-length POD elements. + // + template <typename T> + class pod_seq: public sequence_base + { + public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef T* iterator; + typedef const T* const_iterator; + + public: + iterator + begin (); + + const_iterator + begin () const; + + iterator + end (); + + const_iterator + end () const; + + T& + front (); + + const T& + front () const; + + T& + back (); + + const T& + back () const; + + T& + operator[] (size_t); + + const T& + operator[] (size_t) const; + + public: + size_t + max_size () const; + + void + clear (); + + void + pop_back (); + + iterator + erase (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back (const T&); + +#ifndef XSDE_EXCEPTIONS + error + insert (iterator, const T&); + + error + insert (iterator, const T&, iterator& result); +#else + iterator + insert (iterator, const T&); +#endif + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + reserve (size_t); + + void + swap (pod_seq&); + }; + + // Sequence with fixed-length elements. + // + template <typename T> + class fix_seq: public sequence_base + { + public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef T* iterator; + typedef const T* const_iterator; + + public: + ~fix_seq (); + + public: + iterator + begin (); + + const_iterator + begin () const; + + iterator + end (); + + const_iterator + end () const; + + T& + front (); + + const T& + front () const; + + T& + back (); + + const T& + back () const; + + T& + operator[] (size_t); + + const T& + operator[] (size_t) const; + + public: + size_t + max_size () const; + + void + clear (); + + void + pop_back (); + + iterator + erase (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back (const T&); + +#ifndef XSDE_EXCEPTIONS + error + insert (iterator, const T&); + + error + insert (iterator, const T&, iterator& result); +#else + iterator + insert (iterator, const T&); +#endif + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + reserve (size_t); + + void + swap (fix_seq&); + + private: + static void + move_ (void* dst, void* src, size_t n); + + static void + move_forward_ (void* p, size_t n); + +#ifdef XSDE_EXCEPTIONS + static void + move_backward_ (void* p, size_t n, size_t& size); +#else + static void + move_backward_ (void* p, size_t n); +#endif + +#ifdef XSDE_EXCEPTIONS + struct guard + { + guard (T* p, size_t& n) : p_ (p), n_ (n) {} + + ~guard () + { + if (p_) + for (; n_ > 0; --n_) + p_[n_ - 1].~T (); + } + + void + release () { p_ = 0; } + + private: + T* p_; + size_t& n_; + }; +#endif + }; + + // Sequence with variable-length elements. + // + template <typename T> + class var_iterator + { + public: + typedef T value_type; + typedef T& reference; + typedef T* pointer; + + typedef ptrdiff_t difference_type; + + public: + var_iterator () + : i_ (0) + { + } + + explicit + var_iterator (T** i) + : i_ (i) + { + } + + public: + // Forward iterator requirements. + // + T& + operator* () const + { + return **i_; + } + + T* + operator-> () const + { + return *i_; + } + + var_iterator& + operator++ () + { + ++i_; + return *this; + } + + var_iterator + operator++ (int) + { + var_iterator r (*this); + ++i_; + return r; + } + + // Bidirectional iterator requirements. + // + var_iterator& + operator-- () + { + --i_; + return *this; + } + + var_iterator + operator-- (int) + { + var_iterator r (*this); + --i_; + return r; + } + + // Random access iterator requirements. + // + T& + operator[] (ptrdiff_t n) const + { + return *(i_[n]); + } + + var_iterator& + operator+= (ptrdiff_t n) + { + i_ += n; + return *this; + } + + var_iterator + operator+ (ptrdiff_t n) const + { + return var_iterator (i_ + n); + } + + var_iterator& + operator-= (ptrdiff_t n) + { + i_ -= n; + return *this; + } + + var_iterator + operator- (ptrdiff_t n) const + { + return var_iterator (i_ - n); + } + + public: + T** i_; + }; + + template <typename T> + class var_const_iterator + { + public: + typedef const T value_type; + typedef const T& reference; + typedef const T* pointer; + + typedef ptrdiff_t difference_type; + + public: + var_const_iterator () + : i_ (0) + { + } + + var_const_iterator (var_iterator<T> j) + : i_ (const_cast<const T**> (j.i_)) + { + } + + explicit + var_const_iterator (const T** i) + : i_ (i) + { + } + + var_const_iterator& + operator= (var_const_iterator j) + { + i_ = j.i_; + return *this; + } + + var_const_iterator& + operator= (var_iterator<T> j) + { + i_ = const_cast<const T**> (j.i_); + return *this; + } + + public: + // Forward iterator requirements. + // + const T& + operator* () const + { + return **i_; + } + + const T* + operator-> () const + { + return *i_; + } + + var_const_iterator& + operator++ () + { + ++i_; + return *this; + } + + var_const_iterator + operator++ (int) + { + var_const_iterator r (*this); + ++i_; + return r; + } + + // Bidirectional iterator requirements. + // + var_const_iterator& + operator-- () + { + --i_; + return *this; + } + + var_const_iterator + operator-- (int) + { + var_const_iterator r (*this); + --i_; + return r; + } + + // Random access iterator requirements. + // + const T& + operator[] (ptrdiff_t n) const + { + return *(i_[n]); + } + + var_const_iterator& + operator+= (ptrdiff_t n) + { + i_ += n; + return *this; + } + + var_const_iterator + operator+ (ptrdiff_t n) const + { + return var_const_iterator (i_ + n); + } + + var_const_iterator& + operator-= (ptrdiff_t n) + { + i_ -= n; + return *this; + } + + var_const_iterator + operator- (ptrdiff_t n) const + { + return var_const_iterator (i_ - n); + } + + public: + const T** i_; + }; + + // Forward iterator requirements. + // + template <typename T> + inline bool + operator== (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ == j.i_; + } + + template <typename T> + inline bool + operator== (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ == j.i_; + } + + template <typename T> + inline bool + operator== (var_iterator<T> i, var_const_iterator<T> j) + { + // eVC++ 4.0 needs the cast. + // + return const_cast<const T**> (i.i_) == j.i_; + } + + template <typename T> + inline bool + operator== (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ == const_cast<const T**> (j.i_); + } + + template <typename T> + inline bool + operator!= (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ != j.i_; + } + + template <typename T> + inline bool + operator!= (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ != j.i_; + } + + template <typename T> + inline bool + operator!= (var_iterator<T> i, var_const_iterator<T> j) + { + return const_cast<const T**> (i.i_) != j.i_; + } + + template <typename T> + inline bool + operator!= (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ != const_cast<const T**> (j.i_); + } + + // Random access iterator requirements + // + template <typename T> + inline bool + operator< (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ < j.i_; + } + + template <typename T> + inline bool + operator< (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ < j.i_; + } + + template <typename T> + inline bool + operator< (var_iterator<T> i, var_const_iterator<T> j) + { + return const_cast<const T**> (i.i_) < j.i_; + } + + template <typename T> + inline bool + operator< (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ < const_cast<const T**> (j.i_); + } + + template <typename T> + inline bool + operator> (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ > j.i_; + } + + template <typename T> + inline bool + operator> (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ > j.i_; + } + + template <typename T> + inline bool + operator> (var_iterator<T> i, var_const_iterator<T> j) + { + return const_cast<const T**> (i.i_) > j.i_; + } + + template <typename T> + inline bool + operator> (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ > const_cast<const T**> (j.i_); + } + + template <typename T> + inline bool + operator<= (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ <= j.i_; + } + + template <typename T> + inline bool + operator<= (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ <= j.i_; + } + + template <typename T> + inline bool + operator<= (var_iterator<T> i, var_const_iterator<T> j) + { + return const_cast<const T**> (i.i_) <= j.i_; + } + + template <typename T> + inline bool + operator<= (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ <= const_cast<const T**> (j.i_); + } + + template <typename T> + inline bool + operator>= (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ >= j.i_; + } + + template <typename T> + inline bool + operator>= (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ >= j.i_; + } + + template <typename T> + inline bool + operator>= (var_iterator<T> i, var_const_iterator<T> j) + { + return const_cast<const T**> (i.i_) >= j.i_; + } + + template <typename T> + inline bool + operator>= (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ >= const_cast<const T**> (j.i_); + } + + template <typename T> + inline ptrdiff_t + operator- (var_iterator<T> i, var_iterator<T> j) + { + return i.i_ - j.i_; + } + + template <typename T> + inline ptrdiff_t + operator- (var_const_iterator<T> i, var_const_iterator<T> j) + { + return i.i_ - j.i_; + } + + template <typename T> + inline ptrdiff_t + operator- (var_iterator<T> i, var_const_iterator<T> j) + { + return const_cast<const T**> (i.i_) - j.i_; + } + + template <typename T> + inline ptrdiff_t + operator- (var_const_iterator<T> i, var_iterator<T> j) + { + return i.i_ - const_cast<const T**> (j.i_); + } + + template <typename T> + inline var_iterator<T> + operator+ (ptrdiff_t n, var_iterator<T> i) + { + return var_iterator<T> (i.i_ + n); + } + + template <typename T> + inline var_iterator<T> + operator+ (ptrdiff_t n, var_const_iterator<T> i) + { + return var_const_iterator<T> (i.i_ + n); + } + + // + // + template <typename T> + class var_seq: public sequence_base + { + public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef var_iterator<T> iterator; + typedef var_const_iterator<T> const_iterator; + + public: + ~var_seq (); + + public: + iterator + begin (); + + const_iterator + begin () const; + + iterator + end (); + + const_iterator + end () const; + + T& + front (); + + const T& + front () const; + + T& + back (); + + const T& + back () const; + + T& + operator[] (size_t); + + const T& + operator[] (size_t) const; + + public: + size_t + max_size () const; + + void + clear (); + + void + pop_back (); + + iterator + erase (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back (T*); + +#ifndef XSDE_EXCEPTIONS + error + insert (iterator, T*); + + error + insert (iterator, T*, iterator& result); +#else + iterator + insert (iterator, T*); +#endif + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + reserve (size_t); + + void + swap (var_seq&); + +#ifdef XSDE_EXCEPTIONS + private: + struct guard + { + ~guard () { delete p_; } + guard (T* p) : p_ (p) {} + + void + release () { p_ = 0; } + + private: + T* p_; + }; +#endif + }; + + + // String sequence. + // + typedef string_sequence str_seq; + + + // Custom data sequence. + // + class data_seq: public sequence_base + { + public: + typedef void* value_type; + typedef void** pointer; + typedef const void** const_pointer; + typedef void* reference; + typedef const void* const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef void** iterator; + typedef const void* const* const_iterator; + + public: + ~data_seq (); + data_seq (); + + typedef void (*destroy_func) (void* data, size_t pos); + + void + destructor (destroy_func); + + public: + iterator + begin (); + + const_iterator + begin () const; + + iterator + end (); + + const_iterator + end () const; + + void* + front (); + + const void* + front () const; + + void* + back (); + + const void* + back () const; + + void* + operator[] (size_t); + + const void* + operator[] (size_t) const; + + public: + size_t + max_size () const; + + void + clear (); + + void + pop_back (); + + iterator + erase (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back (void*); + +#ifndef XSDE_EXCEPTIONS + error + insert (iterator, void*); + + error + insert (iterator, void*, iterator& result); +#else + iterator + insert (iterator, void*); +#endif + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + reserve (size_t); + + void + swap (data_seq&); + + private: + destroy_func destructor_; + }; + } + } +} + +#include <xsde/cxx/hybrid/sequence.ixx> +#include <xsde/cxx/hybrid/sequence.txx> + +#endif // XSDE_CXX_HYBRID_SEQUENCE_HXX diff --git a/libxsde/xsde/cxx/hybrid/sequence.ixx b/libxsde/xsde/cxx/hybrid/sequence.ixx new file mode 100644 index 0000000..c1566d2 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/sequence.ixx @@ -0,0 +1,881 @@ +// file : xsde/cxx/hybrid/sequence.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <new> // placement new + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // + // pod_seq + // + + template <typename T> + inline size_t pod_seq<T>:: + max_size () const + { + return size_t (-1) / sizeof (T); + } + + template <typename T> + inline void pod_seq<T>:: + swap (pod_seq& x) + { + swap_ (x); + } + + template <typename T> + inline T* pod_seq<T>:: + begin () + { + return static_cast<T*> (data_); + } + + template <typename T> + inline const T* pod_seq<T>:: + begin () const + { + // g++ 2.95 does not like static_cast here. + // + return (const T*) (data_); + } + + template <typename T> + inline T* pod_seq<T>:: + end () + { + return static_cast<T*> (data_) + size_; + } + + template <typename T> + inline const T* pod_seq<T>:: + end () const + { + return ((const T*) (data_)) + size_; + } + + template <typename T> + inline T& pod_seq<T>:: + front () + { + return *static_cast<T*> (data_); + } + + template <typename T> + inline const T& pod_seq<T>:: + front () const + { + return *((const T*) (data_)); + } + + template <typename T> + inline T& pod_seq<T>:: + back () + { + return static_cast<T*> (data_)[size_ - 1]; + } + + template <typename T> + inline const T& pod_seq<T>:: + back () const + { + return ((const T*) (data_))[size_ - 1]; + } + + template <typename T> + inline T& pod_seq<T>:: + operator[] (size_t i) + { + return static_cast<T*> (data_)[i]; + } + + template <typename T> + inline const T& pod_seq<T>:: + operator[] (size_t i) const + { + return ((const T*) (data_))[i]; + } + + template <typename T> + inline void pod_seq<T>:: + clear () + { + size_ = 0; + } + + template <typename T> + inline void pod_seq<T>:: + pop_back () + { + --size_; + } + + template <typename T> + inline T* pod_seq<T>:: + erase (T* i) + { + if (i != static_cast<T*> (data_) + (size_ - 1)) + erase_ (i, sizeof (T), 0); + else + --size_; + + return i; + } + +#ifdef XSDE_EXCEPTIONS + template <typename T> + inline void pod_seq<T>:: + push_back (const T& x) + { + if (capacity_ < size_ + 1) + grow_ (0, sizeof (T), 0); + + static_cast<T*> (data_)[size_++] = x; + } + + template <typename T> + inline T* pod_seq<T>:: + insert (T* i, const T& x) + { + T* p = static_cast<T*> (insert_ (i, sizeof (T), 0, 0)); + *p = x; + return p; + } + + template <typename T> + inline void pod_seq<T>:: + reserve (size_t n) + { + if (capacity_ < n) + grow_ (n, sizeof (T), 0); + } +#else + template <typename T> + inline sequence_base::error pod_seq<T>:: + push_back (const T& x) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (T), 0); + + if (r == error_none) + static_cast<T*> (data_)[size_++] = x; + + return r; + } + + template <typename T> + inline sequence_base::error pod_seq<T>:: + insert (T* i, const T& x) + { + T* p = static_cast<T*> (insert_ (i, sizeof (T), 0, 0)); + + if (p) + { + *p = x; + return error_none; + } + else + return error_no_memory; + } + + template <typename T> + inline sequence_base::error pod_seq<T>:: + insert (T* i, const T& x, T*& r) + { + T* p = static_cast<T*> (insert_ (i, sizeof (T), 0, 0)); + + if (p) + { + *p = x; + r = p; + return error_none; + } + else + return error_no_memory; + } + + template <typename T> + inline sequence_base::error pod_seq<T>:: + reserve (size_t n) + { + error r = error_none; + if (capacity_ < n) + r = grow_ (n, sizeof (T), 0); + return r; + } +#endif + + // + // fix_seq + // + + template <typename T> + inline fix_seq<T>:: + ~fix_seq () + { + clear (); + } + + template <typename T> + inline size_t fix_seq<T>:: + max_size () const + { + return size_t (-1) / sizeof (T); + } + + template <typename T> + inline void fix_seq<T>:: + swap (fix_seq& x) + { + swap_ (x); + } + + template <typename T> + inline T* fix_seq<T>:: + begin () + { + return static_cast<T*> (data_); + } + + template <typename T> + inline const T* fix_seq<T>:: + begin () const + { + return (const T*) (data_); + } + + template <typename T> + inline T* fix_seq<T>:: + end () + { + return static_cast<T*> (data_) + size_; + } + + template <typename T> + inline const T* fix_seq<T>:: + end () const + { + return ((const T*) (data_)) + size_; + } + + template <typename T> + inline T& fix_seq<T>:: + front () + { + return *static_cast<T*> (data_); + } + + template <typename T> + inline const T& fix_seq<T>:: + front () const + { + return *((const T*) (data_)); + } + + template <typename T> + inline T& fix_seq<T>:: + back () + { + return static_cast<T*> (data_)[size_ - 1]; + } + + template <typename T> + inline const T& fix_seq<T>:: + back () const + { + return ((const T*) (data_))[size_ - 1]; + } + + template <typename T> + inline T& fix_seq<T>:: + operator[] (size_t i) + { + return static_cast<T*> (data_)[i]; + } + + template <typename T> + inline const T& fix_seq<T>:: + operator[] (size_t i) const + { + return ((const T*) (data_))[i]; + } + + template <typename T> + inline void fix_seq<T>:: + pop_back () + { + static_cast<T*> (data_)[size_ - 1].~T (); + --size_; + } + + template <typename T> + inline T* fix_seq<T>:: + erase (T* i) + { + if (i != static_cast<T*> (data_) + (size_ - 1)) + erase_ (i, sizeof (T), &move_forward_); + else + { + static_cast<T*> (data_)[size_ - 1].~T (); + --size_; + } + + return i; + } + +#ifdef XSDE_EXCEPTIONS + template <typename T> + inline void fix_seq<T>:: + push_back (const T& x) + { + if (capacity_ < size_ + 1) + grow_ (0, sizeof (T), &move_); + + new (static_cast<T*> (data_) + size_) T (x); + size_++; + } + + template <typename T> + inline T* fix_seq<T>:: + insert (T* i, const T& x) + { + T* p = static_cast<T*> ( + insert_ (i, sizeof (T), &move_, &move_backward_)); + *p = x; + return p; + } + + template <typename T> + inline void fix_seq<T>:: + reserve (size_t n) + { + if (capacity_ < n) + grow_ (n, sizeof (T), &move_); + } +#else + template <typename T> + inline sequence_base::error fix_seq<T>:: + push_back (const T& x) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (T), &move_); + + if (r == error_none) + { + new (static_cast<T*> (data_) + size_) T (x); + size_++; + } + + return r; + } + + template <typename T> + inline sequence_base::error fix_seq<T>:: + insert (T* i, const T& x) + { + T* p = static_cast<T*> ( + insert_ (i, sizeof (T), &move_, &move_backward_)); + + if (p) + { + *p = x; + return error_none; + } + else + return error_no_memory; + } + + template <typename T> + inline sequence_base::error fix_seq<T>:: + insert (T* i, const T& x, T*& r) + { + T* p = static_cast<T*> ( + insert_ (i, sizeof (T), &move_, &move_backward_)); + + if (p) + { + *p = x; + r = p; + return error_none; + } + else + return error_no_memory; + } + + template <typename T> + inline sequence_base::error fix_seq<T>:: + reserve (size_t n) + { + error r = error_none; + if (capacity_ < n) + r = grow_ (n, sizeof (T), &move_); + return r; + } +#endif + + // + // var_seq + // + + template <typename T> + inline var_seq<T>:: + ~var_seq () + { + clear (); + } + + template <typename T> + inline size_t var_seq<T>:: + max_size () const + { + return size_t (-1) / sizeof (T*); + } + + template <typename T> + inline void var_seq<T>:: + swap (var_seq& x) + { + swap_ (x); + } + + template <typename T> + inline var_iterator<T> var_seq<T>:: + begin () + { + return iterator (static_cast<T**> (data_)); + } + + template <typename T> + inline var_const_iterator<T> var_seq<T>:: + begin () const + { + return const_iterator ((const T**) (data_)); + } + + template <typename T> + inline var_iterator<T> var_seq<T>:: + end () + { + return iterator (static_cast<T**> (data_) + size_); + } + + template <typename T> + inline var_const_iterator<T> var_seq<T>:: + end () const + { + return const_iterator (((const T**) (data_)) + size_); + } + + template <typename T> + inline T& var_seq<T>:: + front () + { + return **static_cast<T**> (data_); + } + + template <typename T> + inline const T& var_seq<T>:: + front () const + { + // g++ 2.95 does not like static_cast here. + // + return **((const T* const*) (data_)); + } + + template <typename T> + inline T& var_seq<T>:: + back () + { + return *(static_cast<T**> (data_)[size_ - 1]); + } + + template <typename T> + inline const T& var_seq<T>:: + back () const + { + return *(((const T* const*) (data_))[size_ - 1]); + } + + template <typename T> + inline T& var_seq<T>:: + operator[] (size_t i) + { + return *(static_cast<T**> (data_)[i]); + } + + template <typename T> + inline const T& var_seq<T>:: + operator[] (size_t i) const + { + return *(((const T* const*) (data_))[i]); + } + + template <typename T> + inline void var_seq<T>:: + pop_back () + { + delete static_cast<T**> (data_)[size_ - 1]; + --size_; + } + + template <typename T> + inline var_iterator<T> var_seq<T>:: + erase (iterator i) + { + delete *i.i_; + + if (i.i_ != static_cast<T**> (data_) + (size_ - 1)) + erase_ (i.i_, sizeof (T*), 0); + else + --size_; + + return i; + } + +#ifdef XSDE_EXCEPTIONS + template <typename T> + inline void var_seq<T>:: + push_back (T* x) + { + guard g (x); + + if (capacity_ < size_ + 1) + grow_ (0, sizeof (T*), 0); + + static_cast<T**> (data_)[size_++] = x; + + g.release (); + } + + template <typename T> + inline var_iterator<T> var_seq<T>:: + insert (iterator i, T* x) + { + guard g (x); + T** p = static_cast<T**> (insert_ (i.i_, sizeof (T*), 0, 0)); + *p = x; + g.release (); + return iterator (p); + } + + template <typename T> + inline void var_seq<T>:: + reserve (size_t n) + { + if (capacity_ < n) + grow_ (n, sizeof (T*), 0); + } +#else + template <typename T> + inline sequence_base::error var_seq<T>:: + push_back (T* x) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (T*), 0); + + if (r == error_none) + static_cast<T**> (data_)[size_++] = x; + else + delete x; + + return r; + } + + template <typename T> + inline sequence_base::error var_seq<T>:: + insert (iterator i, T* x) + { + T** p = static_cast<T**> (insert_ (i.i_, sizeof (T*), 0, 0)); + + if (p) + { + *p = x; + return error_none; + } + else + { + delete x; + return error_no_memory; + } + } + + template <typename T> + inline sequence_base::error var_seq<T>:: + insert (iterator i, T* x, iterator& r) + { + T** p = static_cast<T**> (insert_ (i.i_, sizeof (T*), 0, 0)); + + if (p) + { + *p = x; + r.i_ = p; + return error_none; + } + else + { + delete x; + return error_no_memory; + } + } + + template <typename T> + inline sequence_base::error var_seq<T>:: + reserve (size_t n) + { + error r = error_none; + if (capacity_ < n) + r = grow_ (n, sizeof (T*), 0); + return r; + } +#endif + + // + // data_seq + // + + inline data_seq:: + ~data_seq () + { + clear (); + } + + inline data_seq:: + data_seq () + : destructor_ (0) + { + } + + inline void data_seq:: + destructor (data_seq::destroy_func d) + { + destructor_ = d; + } + + inline size_t data_seq:: + max_size () const + { + return size_t (-1) / sizeof (void*); + } + + inline void data_seq:: + swap (data_seq& x) + { + swap_ (x); + } + + inline data_seq::iterator data_seq:: + begin () + { + return static_cast<void**> (data_); + } + + inline data_seq::const_iterator data_seq:: + begin () const + { + // g++ 2.95 does not like static_cast here. + // + return (const void* const*) (data_); + } + + inline data_seq::iterator data_seq:: + end () + { + return static_cast<void**> (data_) + size_; + } + + inline data_seq::const_iterator data_seq:: + end () const + { + return ((const void* const*) (data_)) + size_; + } + + inline void* data_seq:: + front () + { + return *static_cast<void**> (data_); + } + + inline const void* data_seq:: + front () const + { + return *((const void* const*) (data_)); + } + + inline void* data_seq:: + back () + { + return static_cast<void**> (data_)[size_ - 1]; + } + + inline const void* data_seq:: + back () const + { + return ((const void* const*) (data_))[size_ - 1]; + } + + inline void* data_seq:: + operator[] (size_t i) + { + return static_cast<void**> (data_)[i]; + } + + inline const void* data_seq:: + operator[] (size_t i) const + { + return ((const void* const*) (data_))[i]; + } + + inline void data_seq:: + pop_back () + { + if (destructor_) + destructor_ (static_cast<void**> (data_)[size_ - 1], size_ - 1); + --size_; + } + + inline data_seq::iterator data_seq:: + erase (iterator i) + { + if (destructor_) + destructor_ (*i, i - static_cast<void**> (data_)); + + if (i != static_cast<void**> (data_) + (size_ - 1)) + erase_ (i, sizeof (void*), 0); + else + --size_; + + return i; + } + +#ifdef XSDE_EXCEPTIONS + namespace data_seq_bits + { + struct guard + { + ~guard () { if (p_ && d_) d_ (p_, i_); } + guard (data_seq::destroy_func d, void* p, size_t i) + : d_ (d), p_ (p), i_ (i) {} + + void + release () { p_ = 0; } + + private: + data_seq::destroy_func d_; + void* p_; + size_t i_; + }; + } + + inline void data_seq:: + push_back (void* x) + { + data_seq_bits::guard g (destructor_, x, size_); + + if (capacity_ < size_ + 1) + grow_ (0, sizeof (void*), 0); + + static_cast<void**> (data_)[size_++] = x; + + g.release (); + } + + inline data_seq::iterator data_seq:: + insert (iterator i, void* x) + { + data_seq_bits::guard g ( + destructor_, x, i - static_cast<void**> (data_)); + + void** p = static_cast<void**> (insert_ (i, sizeof (void*), 0, 0)); + *p = x; + g.release (); + return p; + } + + inline void data_seq:: + reserve (size_t n) + { + if (capacity_ < n) + grow_ (n, sizeof (void*), 0); + } +#else + inline sequence_base::error data_seq:: + push_back (void* x) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (void*), 0); + + if (r == error_none) + static_cast<void**> (data_)[size_++] = x; + else + { + if (destructor_) + destructor_ (x, size_); + } + + return r; + } + + inline sequence_base::error data_seq:: + insert (iterator i, void* x) + { + size_t pos = i - static_cast<void**> (data_); + void** p = static_cast<void**> (insert_ (i, sizeof (void*), 0, 0)); + + if (p) + { + *p = x; + return error_none; + } + else + { + if (destructor_) + destructor_ (x, pos); + return error_no_memory; + } + } + + inline sequence_base::error data_seq:: + insert (iterator i, void* x, iterator& r) + { + size_t pos = i - static_cast<void**> (data_); + void** p = static_cast<void**> (insert_ (i, sizeof (void*), 0, 0)); + + if (p) + { + *p = x; + r = p; + return error_none; + } + else + { + if (destructor_) + destructor_ (x, pos); + return error_no_memory; + } + } + + inline sequence_base::error data_seq:: + reserve (size_t n) + { + error r = error_none; + if (capacity_ < n) + r = grow_ (n, sizeof (void*), 0); + return r; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/sequence.txx b/libxsde/xsde/cxx/hybrid/sequence.txx new file mode 100644 index 0000000..12faa99 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/sequence.txx @@ -0,0 +1,133 @@ +// file : xsde/cxx/hybrid/sequence.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <new> // placement new + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + // + // fix_seq + // + + template <typename T> + void fix_seq<T>:: + clear () + { + for (size_t i = 0; i < size_; ++i) + static_cast<T*> (data_)[i].~T (); + + size_ = 0; + } + +#ifdef XSDE_EXCEPTIONS + template <typename T> + void fix_seq<T>:: + move_ (void* dst, void* src, size_t n) + { + T* d = static_cast<T*> (dst); + T* s = static_cast<T*> (src); + + // The copy c-tor can throw in which case we need to destroy + // whatever objects we already copied into d. + // + size_t i = 0; + guard g (d, i); + + for (; i < n; i++) + new (d + i) T (s[i]); + + g.release (); + + for (size_t j = 0; j < n; j++) + s[j].~T (); + } +#else + template <typename T> + void fix_seq<T>:: + move_ (void* dst, void* src, size_t n) + { + T* d = static_cast<T*> (dst); + T* s = static_cast<T*> (src); + + for (size_t i = 0; i < n; i++) + { + new (d + i) T (s[i]); + s[i].~T (); + } + } +#endif + + template <typename T> + void fix_seq<T>:: + move_forward_ (void* p, size_t n) + { + // We are moving a sequence of elements one position to the left. + // The tricky part is to make sure we are in at least destructable + // state if things turn bad. We assume that there is a valid + // element at position p. + // + T* d = static_cast<T*> (p); + + for (size_t i = 0; i < n; i++) + d[i] = d[i + 1]; + + d[n].~T (); + } + +#ifdef XSDE_EXCEPTIONS + template <typename T> + void fix_seq<T>:: + move_backward_ (void* p, size_t n, size_t& size) + { + // We are moving a sequence of elements one position to the right. + // The tricky part is to make sure we are in at least destructable + // state if things turn bad. + // + T* d = static_cast<T*> (p); + T* e = d + n; + + new (e) T; + size++; + + for (size_t i = n; i > 0; i--) + d[i] = d[i - 1]; + } +#else + template <typename T> + void fix_seq<T>:: + move_backward_ (void* p, size_t n) + { + // We are moving a sequence of elements one position to the right. + // + T* d = static_cast<T*> (p); + T* e = d + n; + + new (e) T; + + for (size_t i = n; i > 0; i--) + d[i] = d[i - 1]; + } +#endif + + // + // var_seq + // + + template <typename T> + void var_seq<T>:: + clear () + { + for (size_t i = 0; i < size_; ++i) + delete static_cast<T**> (data_)[i]; + + size_ = 0; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xml-schema.hxx b/libxsde/xsde/cxx/hybrid/xml-schema.hxx new file mode 100644 index 0000000..d4b7cdb --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xml-schema.hxx @@ -0,0 +1,23 @@ +// file : xsde/cxx/hybrid/xml-schema.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_XML_SCHEMA_HXX +#define XSDE_CXX_HYBRID_XML_SCHEMA_HXX + +#include <xsde/cxx/buffer.hxx> +#include <xsde/cxx/date-time.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/qname-stl.hxx> +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/qname.hxx> +# include <xsde/cxx/string-sequence.hxx> +#endif + +#include <xsde/cxx/hybrid/base.hxx> +#include <xsde/cxx/hybrid/any-type.hxx> + +#endif // XSDE_CXX_HYBRID_XML_SCHEMA_HXX diff --git a/libxsde/xsde/cxx/parser/context.cxx b/libxsde/xsde/cxx/parser/context.cxx new file mode 100644 index 0000000..264ffd5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/context.cxx @@ -0,0 +1,18 @@ +// file : xsde/cxx/parser/context.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/context.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + } + } +} diff --git a/libxsde/xsde/cxx/parser/context.hxx b/libxsde/xsde/cxx/parser/context.hxx new file mode 100644 index 0000000..2b79be9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/context.hxx @@ -0,0 +1,139 @@ +// file : xsde/cxx/parser/context.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_CONTEXT_HXX +#define XSDE_CXX_PARSER_CONTEXT_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/c/expat/expat.h> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/sys-error.hxx> +#endif + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace parser + { + struct parser_base; + + struct parser_state + { + parser_state (); + + // Depth is maintained only when we don't have a parser for a + // document fragment or if we are handling a wildcard in which + // case the any flag should be set. + // + parser_base* parser_; + size_t depth_; + bool any_; + }; + + class context + { + public: + context (XML_Parser xml_parser); + + public: + XML_Parser + xml_parser (); + + // Error handling via codes. + // + public: + + // Application error. + // +#ifndef XSDE_EXCEPTIONS + public: + int + app_error () const; + + void + app_error (int); +#endif + + // Schema error. + // +#ifdef XSDE_PARSER_VALIDATION + public: + typedef cxx::schema_error::value schema_error_t; + + schema_error_t + schema_error () const; + + void + schema_error (schema_error_t); +#endif + + // System error. + // +#ifndef XSDE_EXCEPTIONS + public: + typedef cxx::sys_error::value sys_error_t; + + sys_error_t + sys_error () const; + + void + sys_error (sys_error_t); +#endif + + // Implementation details. + // +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + public: + enum error_type_t + { + error_none = 0, + error_app, + error_schema, + error_sys + }; + + error_type_t + error_type () const; + + protected: + error_type_t error_type_; + + union + { +#ifndef XSDE_EXCEPTIONS + int app; +#endif +#ifdef XSDE_PARSER_VALIDATION + schema_error_t schema; +#endif +#ifndef XSDE_EXCEPTIONS + sys_error_t sys; +#endif + } error_code_; + +#endif // XSDE_PARSER_VALIDATION || !XSDE_EXCEPTIONS + + public: + parser_state current_; + + protected: + XML_Parser xml_parser_; + }; + } + } +} + +#include <xsde/cxx/parser/context.ixx> + +#endif // XSDE_CXX_PARSER_CONTEXT_HXX diff --git a/libxsde/xsde/cxx/parser/context.ixx b/libxsde/xsde/cxx/parser/context.ixx new file mode 100644 index 0000000..00093d6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/context.ixx @@ -0,0 +1,91 @@ +// file : xsde/cxx/parser/context.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // parser_state + // + inline parser_state:: + parser_state () + : parser_ (0), depth_ (0), any_ (false) + { + } + + // context + // + inline context:: + context (XML_Parser xml_parser) + : xml_parser_ (xml_parser) + { +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + error_type_ = error_none; +#endif + } + + inline XML_Parser context:: + xml_parser () + { + return xml_parser_; + } + + // + // +#ifndef XSDE_EXCEPTIONS + inline int context:: + app_error () const + { + return error_code_.app; + } + + inline void context:: + app_error (int e) + { + error_type_ = error_app; + error_code_.app = e; + } + + inline void context:: + sys_error (sys_error_t e) + { + error_type_ = error_sys; + error_code_.sys = e; + } + + inline context::sys_error_t context:: + sys_error () const + { + return error_code_.sys; + } +#endif + +#ifdef XSDE_PARSER_VALIDATION + inline context::schema_error_t context:: + schema_error () const + { + return error_code_.schema; + } + + inline void context:: + schema_error (schema_error_t e) + { + error_type_ = error_schema; + error_code_.schema = e; + } +#endif + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + inline context::error_type_t context:: + error_type () const + { + return error_type_; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/elements.cxx b/libxsde/xsde/cxx/parser/elements.cxx new file mode 100644 index 0000000..4273ab8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/elements.cxx @@ -0,0 +1,201 @@ +// file : xsde/cxx/parser/elements.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/parser/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // parser_base + // + parser_base:: + ~parser_base () + { + } + + void parser_base:: + pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->pre (); +#endif + } + + void parser_base:: + _pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_pre (); +#endif + } + + void parser_base:: + _post () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_post (); +#endif + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + +#ifdef XSDE_POLYMORPHIC + void parser_base:: + _start_any_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (impl_) + impl_->_start_any_element (ns, name, type); + } +#else + void parser_base:: + _start_any_element (const ro_string& ns, + const ro_string& name) + { + if (impl_) + impl_->_start_any_element (ns, name); + } +#endif + + void parser_base:: + _end_any_element (const ro_string& ns, + const ro_string& name) + { + if (impl_) + impl_->_end_any_element (ns, name); + } + + void parser_base:: + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + if (impl_) + impl_->_any_attribute (ns, name, value); + } + + void parser_base:: + _any_characters (const ro_string& s) + { + if (impl_) + impl_->_any_characters (s); + } +#else // !XSDE_REUSE_STYLE_TIEIN + +#ifdef XSDE_POLYMORPHIC + void parser_base:: + _start_any_element (const ro_string&, + const ro_string&, + const char*) + { + } +#else + void parser_base:: + _start_any_element (const ro_string&, + const ro_string&) + { + } +#endif + + void parser_base:: + _end_any_element (const ro_string&, + const ro_string&) + { + } + + void parser_base:: + _any_attribute (const ro_string&, + const ro_string&, + const ro_string&) + { + } + + void parser_base:: + _any_characters (const ro_string&) + { + } +#endif // XSDE_REUSE_STYLE_TIEIN + + + void parser_base:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + context_ = &c; + + previous_ = c.current_; + + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + } + + void parser_base:: + _post_impl () + { +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (!context_->error_type ()) +#endif + _post (); + + context_->current_ = previous_; + context_ = 0; + } + +#ifdef XSDE_POLYMORPHIC + const char* parser_base:: + _dynamic_type () const + { + return 0; + } +#endif + + void parser_base:: + _reset () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_reset (); +#endif + +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + context_ = 0; + + previous_.parser_ = 0; + previous_.depth_ = 0; + previous_.any_ = false; + } + +#if defined (XSDE_REUSE_STYLE_TIEIN) && !defined (XSDE_EXCEPTIONS) + const parser_base* parser_base:: + _ultimate_impl () const + { + const parser_base* p = impl_; + for (; p->impl_ != 0; p = p->impl_) /*noop*/; + return p; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/elements.hxx b/libxsde/xsde/cxx/parser/elements.hxx new file mode 100644 index 0000000..5ce1e09 --- /dev/null +++ b/libxsde/xsde/cxx/parser/elements.hxx @@ -0,0 +1,248 @@ +// file : xsde/cxx/parser/elements.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_ELEMENTS_HXX +#define XSDE_CXX_PARSER_ELEMENTS_HXX + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/sys-error.hxx> +# include <xsde/cxx/parser/error.hxx> +#endif + +#include <xsde/cxx/parser/context.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // pre() and post() are overridable pre/post callbacks, i.e., the + // derived parser can override them without calling the base version. + // _pre() and _post() are not overridable pre/post callbacks in the + // sense that the derived parser may override them but has to call + // the base version. The call sequence is as shown below: + // + // pre () + // _pre () + // _post () + // post () + // + struct parser_base + { + virtual + ~parser_base (); + + parser_base (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base (parser_base* impl, void*); +#endif + + public: + virtual void + pre (); + + virtual void + _pre (); + + // The type argument is a type name and namespace from the + // xsi:type attribute in the form "<name> <namespace>" with + // the space and namespace part absent if the type does not + // have a namespace or 0 if xsi:type is not present. + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) = 0; +#else + virtual void + _start_element (const ro_string& ns, + const ro_string& name) = 0; +#endif + + virtual void + _end_element (const ro_string& ns, + const ro_string& name) = 0; + + virtual void + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) = 0; + + virtual void + _characters (const ro_string&) = 0; + + virtual void + _post (); + + // The post() signature varies depending on the parser return + // type. + // + + public: + // The following functions are called when wildcard content is + // encountered. Override them to handle mixed content models, + // any/anyAttribute, and anyType/anySimpleType. By default + // these functions do nothing. + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_any_element (const ro_string& ns, + const ro_string& name, + const char* type); +#else + virtual void + _start_any_element (const ro_string& ns, + const ro_string& name); +#endif + + virtual void + _end_any_element (const ro_string& ns, + const ro_string& name); + + virtual void + _any_attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual void + _any_characters (const ro_string&); + + public: + // Implementation callbacks for _pre and _post. The _pre and _post + // callbacks should never be called directly. Instead, the *_impl + // versions should be used. By default _pre_impl and _post_impl + // simply call _pre and _post respectively. + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + +#ifdef XSDE_POLYMORPHIC + public: + // Dynamic type in the form "<name> <namespace>" with + // the space and namespace part absent if the type does + // not have a namespace. + // + virtual const char* + _dynamic_type () const; +#endif + + public: + context& + _context (); + + // Reset the parser state after an error. + // + virtual void + _reset (); + + // Error handling via codes. If the error is set while parser + // is in the context, the error is set in the context, instead + // of the parser. Since pre() and post() calls are not in + // context, the parser stores application and system errors + // locally for this case. + // + +#ifndef XSDE_EXCEPTIONS + public: + error + _error () const; + + // Set application error. + // + void + _app_error (int); + + int + _app_error () const; +#endif + + // Schema error. + // +#ifdef XSDE_PARSER_VALIDATION + public: + void + _schema_error (context::schema_error_t); +#endif + + // System error. + // +#ifndef XSDE_EXCEPTIONS + public: + context::sys_error_t + _sys_error () const; + + void + _sys_error (context::sys_error_t); +#endif + + // Implementation. + // + +#ifndef XSDE_EXCEPTIONS + public: + enum error_type_t + { + error_none = 0, + error_app, + error_sys + }; + + error_type_t + _error_type () const; + + void + _copy_error (context&) const; + + private: + error_type_t error_type_; + + union + { + int app; + context::sys_error_t sys; + } error_code_; +#endif + + protected: + bool resetting_; + context* context_; + +#ifdef XSDE_REUSE_STYLE_TIEIN + protected: + parser_base* parent_; + parser_base* impl_; + + void + _set_parent_chain (); + +#ifndef XSDE_EXCEPTIONS + const parser_base* + _ultimate_impl () const; +#endif +#endif + + protected: + parser_state previous_; + }; + } + } +} + +#include <xsde/cxx/parser/elements.ixx> + +#endif // XSDE_CXX_PARSER_ELEMENTS_HXX diff --git a/libxsde/xsde/cxx/parser/elements.ixx b/libxsde/xsde/cxx/parser/elements.ixx new file mode 100644 index 0000000..ef47209 --- /dev/null +++ b/libxsde/xsde/cxx/parser/elements.ixx @@ -0,0 +1,221 @@ +// file : xsde/cxx/parser/elements.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + inline parser_base:: + parser_base () + : resetting_ (false), context_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + parent_ = 0; + impl_ = 0; +#endif + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline parser_base:: + parser_base (parser_base* impl, void*) + : resetting_ (false), context_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + parent_ = 0; + impl_ = impl; + } +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline void parser_base:: + _set_parent_chain () + { + if (impl_ && impl_->parent_ == 0) + { + for (parser_base* p = impl_; p != 0; p = p->impl_) + p->parent_ = this; + } + } +#endif + + inline context& parser_base:: + _context () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + return *(parent_ ? parent_->context_ : context_); +#else + return *context_; +#endif + } + + // Error handling. + // +#ifndef XSDE_EXCEPTIONS + inline error parser_base:: + _error () const + { + // Unlike context, which is stored in the top-level + // parser, error state is stored in the "bottom-level" + // implementation. It is done this way since the error + // handling mechanism can be used in constructors which + // would otherwise require passing the pointer to parent + // parser to each implementation's c-tor. + // +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + switch (p->error_type_) + { + case error_sys: + { + return error (p->error_code_.sys); + } + case error_app: + { + return error (p->error_code_.app, 0, 0); + } + default: + { + return error (); + } + } + } + + inline void parser_base:: + _app_error (int e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base* p = parent_ ? parent_ : this; +#else + parser_base* p = this; +#endif + + if (p->context_ != 0) + { + p->context_->app_error (e); + } + else + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (!impl_) + p = this; + else + for (p = impl_; p->impl_ != 0; p = p->impl_) /*noop*/ ; +#endif + p->error_type_ = error_app; + p->error_code_.app = e; + } + } + + inline int parser_base:: + _app_error () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + return p->error_code_.app; + } + + inline void parser_base:: + _sys_error (context::sys_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base* p = parent_ ? parent_ : this; +#else + parser_base* p = this; +#endif + if (p->context_ != 0) + { + p->context_->sys_error (e); + } + else + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (!impl_) + p = this; + else + for (p = impl_; p->impl_ != 0; p = p->impl_) /*noop*/; +#endif + p->error_type_ = error_sys; + p->error_code_.sys = e; + } + } + + inline context::sys_error_t parser_base:: + _sys_error () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + return p->error_code_.sys; + } + + inline parser_base::error_type_t parser_base:: + _error_type () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + return p->error_type_; + } + + inline void parser_base:: + _copy_error (context& ctx) const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const parser_base* p = !impl_ ? this : _ultimate_impl (); +#else + const parser_base* p = this; +#endif + + switch (p->error_type_) + { + case error_app: + { + ctx.app_error (p->error_code_.app); + break; + } + case error_sys: + { + ctx.sys_error (p->error_code_.sys); + break; + } + default: + break; + } + } +#endif // XSDE_EXCEPTIONS + +#ifdef XSDE_PARSER_VALIDATION + inline void parser_base:: + _schema_error (context::schema_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + parser_base* p = parent_ ? parent_ : this; +#else + parser_base* p = this; +#endif + p->context_->schema_error (e); + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/error.cxx b/libxsde/xsde/cxx/parser/error.cxx new file mode 100644 index 0000000..94e2534 --- /dev/null +++ b/libxsde/xsde/cxx/parser/error.cxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/parser/error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + void error:: + true_ () + { + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/error.hxx b/libxsde/xsde/cxx/parser/error.hxx new file mode 100644 index 0000000..47ca489 --- /dev/null +++ b/libxsde/xsde/cxx/parser/error.hxx @@ -0,0 +1,135 @@ +// file : xsde/cxx/parser/error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_ERROR_HXX +#define XSDE_CXX_PARSER_ERROR_HXX + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/sys-error.hxx> + +#include <xsde/cxx/parser/expat/xml-error.hxx> + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace parser + { + using expat::xml_error; + + // This type is only used when C++ exceptions are not used. + // + struct error + { + enum error_type + { + none, + sys, + xml, + schema, + app + }; + + public: + error_type + type () const; + + + // Line and column are only available for xml, schema, and + // app errors. + // + unsigned long + line () const; + + unsigned long + column () const; + + + // Returns true if there is an error so that you can write + // if (p.error ()) or if (error e = p.error ()). + // + typedef void (error::*bool_convertible) (); + operator bool_convertible () const; + + + // sys + // + public: + error (sys_error); + + sys_error + sys_code () const; + + const char* + sys_text () const; + + + // xml + // + public: + error (xml_error, unsigned long line, unsigned long column); + + xml_error + xml_code () const; + + const char* + xml_text () const; + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + public: + error (schema_error::value, unsigned long line, unsigned long column); + + schema_error + schema_code () const; + + const char* + schema_text () const; +#endif + + // app + // + public: + error (int app_code, unsigned long line, unsigned long column); + + int + app_code () const; + + + public: + error (); + + private: + void + true_ (); + + private: + error_type type_; + unsigned long line_; + unsigned long column_; + + union + { + sys_error::value sys; + xml_error xml; +#ifdef XSDE_PARSER_VALIDATION + schema_error::value schema; +#endif + int app; + } code_; + }; + } + } +} + +#include <xsde/cxx/parser/error.ixx> + +#endif // XSDE_CXX_PARSER_ERROR_HXX diff --git a/libxsde/xsde/cxx/parser/error.ixx b/libxsde/xsde/cxx/parser/error.ixx new file mode 100644 index 0000000..dbb57bb --- /dev/null +++ b/libxsde/xsde/cxx/parser/error.ixx @@ -0,0 +1,143 @@ +// file : xsde/cxx/parser/error.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + inline + error::error_type error:: + type () const + { + return type_; + } + + inline + unsigned long error:: + line () const + { + return line_; + } + + inline + unsigned long error:: + column () const + { + return column_; + } + + inline + error:: + operator error::bool_convertible () const + { + return type_ != none ? &error::true_ : 0; + } + + // sys + // + + inline + error:: + error (sys_error e) + : type_ (sys), line_ (0), column_ (0) + { + code_.sys = e; + } + + inline + sys_error error:: + sys_code () const + { + return code_.sys; + } + + inline + const char* error:: + sys_text () const + { + return sys_error::text (code_.sys); + } + + // xml + // + + inline + error:: + error (xml_error e, unsigned long l, unsigned long c) + : type_ (xml), line_ (l), column_ (c) + { + code_.xml = e; + } + + inline + xml_error error:: + xml_code () const + { + return code_.xml; + } + + inline + const char* error:: + xml_text () const + { + return expat::xml_error_text (code_.xml); + } + + // schema + // + +#ifdef XSDE_PARSER_VALIDATION + inline + error:: + error (schema_error::value e, unsigned long l, unsigned long c) + : type_ (schema), line_ (l), column_ (c) + { + code_.schema = e; + } + + inline + schema_error error:: + schema_code () const + { + return code_.schema; + } + + inline + const char* error:: + schema_text () const + { + return schema_error::text (code_.schema); + } +#endif + + // app + // + + inline + error:: + error (int e, unsigned long l, unsigned long c) + : type_ (app), line_ (l), column_ (c) + { + code_.app = e; + } + + inline + int error:: + app_code () const + { + return code_.app; + } + + inline + error:: + error () + : type_ (none) + { + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/exceptions.cxx b/libxsde/xsde/cxx/parser/exceptions.cxx new file mode 100644 index 0000000..0046266 --- /dev/null +++ b/libxsde/xsde/cxx/parser/exceptions.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/exceptions.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_IOSTREAM +# include <iostream> +#endif + +#include <xsde/cxx/parser/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // exception + // + +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream& os, const exception& e) + { + return os << e.text (); + } +#endif + + + // xml + // + const char* xml:: + text () const + { + return expat::xml_error_text (code_); + } + + const char* xml:: + what () const throw () + { + return "xml error"; + } + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + const char* schema:: + text () const + { + return schema_error::text (code_); + } + + const char* schema:: + what () const throw () + { + return "schema error"; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/parser/exceptions.hxx b/libxsde/xsde/cxx/parser/exceptions.hxx new file mode 100644 index 0000000..d02eeb3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/exceptions.hxx @@ -0,0 +1,103 @@ +// file : xsde/cxx/parser/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_EXCEPTIONS_HXX +#define XSDE_CXX_PARSER_EXCEPTIONS_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/cxx/exceptions.hxx> // xsde::cxx::exception + +#ifdef XSDE_PARSER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +#include <xsde/cxx/parser/expat/xml-error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // exception + // + struct exception: xsde::cxx::exception + { + exception (unsigned long line, unsigned long column); + + unsigned long + line () const; + + unsigned long + column () const; + + virtual const char* + text () const = 0; + + private: + unsigned long line_; + unsigned long column_; + }; + +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream&, const exception&); +#endif + + + // xml + // + using expat::xml_error; + + struct xml: exception + { + xml (xml_error, unsigned long line, unsigned long column); + + xml_error + code () const; + + virtual const char* + text () const; + + virtual const char* + what () const throw (); + + private: + xml_error code_; + }; + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + struct schema: exception + { + schema (schema_error, unsigned long line, unsigned long column); + + schema_error + code () const; + + virtual const char* + text () const; + + virtual const char* + what () const throw (); + + private: + schema_error code_; + }; +#endif + } + } +} + +#include <xsde/cxx/parser/exceptions.ixx> + +#endif // XSDE_CXX_PARSER_EXCEPTIONS_HXX diff --git a/libxsde/xsde/cxx/parser/exceptions.ixx b/libxsde/xsde/cxx/parser/exceptions.ixx new file mode 100644 index 0000000..77ca9e5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/exceptions.ixx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/exceptions.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // exception + // + inline exception:: + exception (unsigned long line, unsigned long column) + : line_ (line), column_ (column) + { + } + + inline unsigned long exception:: + line () const + { + return line_; + } + + inline unsigned long exception:: + column () const + { + return column_; + } + + + // xml + // + inline xml:: + xml (xml_error code, unsigned long line, unsigned long column) + : exception (line, column), code_ (code) + { + } + + inline xml_error xml:: + code () const + { + return code_; + } + + + // schema + // +#ifdef XSDE_PARSER_VALIDATION + inline schema:: + schema (schema_error code, unsigned long line, unsigned long column) + : exception (line, column), code_ (code) + { + } + + inline schema_error schema:: + code () const + { + return code_; + } +#endif + } + } +} + diff --git a/libxsde/xsde/cxx/parser/expat/document.cxx b/libxsde/xsde/cxx/parser/expat/document.cxx new file mode 100644 index 0000000..0e30a2a --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/document.cxx @@ -0,0 +1,1044 @@ +// file : xsde/cxx/parser/expat/document.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <assert.h> +#include <string.h> // strchr, strlen + +#ifdef XSDE_EXCEPTIONS +# include <new> // std::bad_alloc +#endif + +#ifdef XSDE_IOSTREAM +# include <iostream> +# include <fstream> +#endif + +#ifdef XSDE_EXCEPTIONS +# include <xsde/cxx/parser/exceptions.hxx> +#endif + +#ifdef XSDE_POLYMORPHIC +# include <xsde/cxx/parser/substitution-map.hxx> +#endif + +#include <xsde/cxx/parser/expat/document.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { +#ifdef XSDE_POLYMORPHIC + static substitution_map_init substitution_map_init_; +#endif + + // document_pimpl + // + + document_pimpl:: + ~document_pimpl () + { + // Prevents auto-generation of this dtor. + } + +#ifdef XSDE_STL + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, const std::string& n, bool poly) +#else + document_pimpl (parser_base& p, const std::string& n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (0, n.c_str ()); + } + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, + const std::string& ns, + const std::string& n, + bool poly) +#else + document_pimpl (parser_base& p, + const std::string& ns, + const std::string& n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (ns.c_str (), n.c_str ()); + } + +#endif // XSDE_STL + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, const char* n, bool poly) +#else + document_pimpl (parser_base& p, const char* n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (0, n); + } + + document_pimpl:: +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base& p, + const char* ns, + const char* n, + bool poly) +#else + document_pimpl (parser_base& p, const char* ns, const char* n) +#endif + : first_ (true), xml_parser_ (0), context_ (0), parser_ (&p) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = poly; +#endif + init_root_name (ns, n); + } + + document_pimpl:: + document_pimpl () + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0) + { +#ifdef XSDE_POLYMORPHIC + polymorphic_ = false; +#endif + } + +#ifdef XSDE_POLYMORPHIC + document_pimpl:: + document_pimpl (const char* n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (0, n); + } + + document_pimpl:: + document_pimpl (const char* ns, const char* n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (ns, n); + } + +#ifdef XSDE_STL + document_pimpl:: + document_pimpl (const std::string& n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (0, n.c_str ()); + } + + document_pimpl:: + document_pimpl (const std::string& ns, const std::string& n) + : first_ (true), xml_parser_ (0), context_ (0), parser_ (0), + polymorphic_ (true) + { + init_root_name (ns.c_str (), n.c_str ()); + } +#endif // XSDE_STL +#endif // XSDE_POLYMORPHIC + + void document_pimpl:: + init_root_name (const char* ns, const char* name) + { +#ifdef XSDE_EXCEPTIONS + root_ns_.assign (ns ? ns : ""); + root_name_.assign (name); +#else + if (root_ns_.assign (ns ? ns : "") || root_name_.assign (name)) + error_ = error (sys_error::no_memory); +#endif + } + + // + // + parser_base* document_pimpl:: +#ifdef XSDE_POLYMORPHIC + start_root_element (const ro_string& ns, + const ro_string& name, + const char*) +#else + start_root_element (const ro_string& ns, const ro_string& name) +#endif + { + if (root_name_ == name && root_ns_ == ns) + { + return parser_; + } + else + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::unexpected_element); +#endif + return 0; + } + } + + void document_pimpl:: + end_root_element (const ro_string&, const ro_string&, parser_base*) + { + } + + void document_pimpl:: + reset () + { +#ifndef XSDE_EXCEPTIONS + error_ = error (); +#endif + first_ = true; + + if (parser_) + parser_->_reset (); + } + + // file + // + +#ifdef XSDE_IOSTREAM + void document_pimpl:: + parse (const char* file) + { + std::ifstream ifs; + +#ifdef XSDE_EXCEPTIONS + ifs.exceptions (std::ifstream::badbit | std::ifstream::failbit); +#endif + + ifs.open (file, std::ifstream::in | std::ifstream::binary); + +#ifndef XSDE_EXCEPTIONS + if (ifs.fail ()) + { + error_ = error (sys_error::open_failed); + return; + } +#endif + parse (ifs); + } + +#ifdef XSDE_STL + void document_pimpl:: + parse (const std::string& file) + { + parse (file.c_str ()); + } +#endif + + // istream + // + +#ifdef XSDE_EXCEPTIONS + namespace bits + { + struct stream_exception_controller + { + ~stream_exception_controller () + { + std::istream::iostate s = is_.rdstate (); + s &= ~std::istream::failbit; + + // If our error state (sans failbit) intersects with the + // exception state then that means we have an active + // exception and changing error/exception state will + // cause another to be thrown. + // + if (!(old_state_ & s)) + { + // Clear failbit if it was caused by eof. + // + if (is_.fail () && is_.eof ()) + is_.clear (s); + + is_.exceptions (old_state_); + } + } + + stream_exception_controller (std::istream& is) + : is_ (is), old_state_ (is_.exceptions ()) + { + is_.exceptions (old_state_ & ~std::istream::failbit); + } + + private: + stream_exception_controller (const stream_exception_controller&); + + stream_exception_controller& + operator= (const stream_exception_controller&); + + private: + std::istream& is_; + std::istream::iostate old_state_; + }; + } +#endif + + void document_pimpl:: + parse (std::istream& is) + { +#ifdef XSDE_EXCEPTIONS + // Temporarily unset the exception failbit. Also clear the + // fail bit when we reset the old state if it was caused + // by eof. + // + bits::stream_exception_controller sec (is); +#endif + + char buf[4096]; // Page size. + + do + { + is.read (buf, sizeof (buf)); + +#ifndef XSDE_EXCEPTIONS + if (is.bad () || (is.fail () && !is.eof ())) + { + error_ = error (sys_error::read_failed); + break; + } +#endif + parse (buf, is.gcount (), is.eof ()); + +#ifndef XSDE_EXCEPTIONS + if (error_) + break; +#endif + } while (!is.eof ()); + } +#endif // XSDE_IOSTREAM + + + void document_pimpl:: + parse (const void* data, size_t size, bool last) + { + // First call. + // + if (first_) + { + if (auto_xml_parser_ == 0) + { + auto_xml_parser_ = XML_ParserCreateNS (0, XML_Char (' ')); + + if (auto_xml_parser_ == 0) + { +#ifdef XSDE_EXCEPTIONS + throw std::bad_alloc (); +#else + error_ = error (sys_error::no_memory); + return; +#endif + } + } + else + XML_ParserReset (auto_xml_parser_, 0); + + parse_begin (auto_xml_parser_); + first_ = false; + } + + + if (XML_Parse (xml_parser_, + static_cast<const char*> (data), + static_cast<int> (size), + last) == XML_STATUS_ERROR || + last) + { + first_ = true; + parse_end (); + } + } + + + // XML_Parser + // + + void document_pimpl:: + parse_begin (XML_Parser parser) + { + context_ = context (parser); + + xml_parser_ = parser; + set (); + } + + void document_pimpl:: + parse_end () + { + XML_Error e (XML_GetErrorCode (xml_parser_)); + + if (e == XML_ERROR_NONE) + { + clear (); + xml_parser_ = 0; + } + else + { + unsigned long l = XML_GetCurrentLineNumber (xml_parser_); + unsigned long c = XML_GetCurrentColumnNumber (xml_parser_); + + clear (); + xml_parser_ = 0; + + // See if the parser was aborted. + // + if (e == XML_ERROR_ABORTED) + { + // Got to be either a system, schema, or application + // level error. + // +#if defined(XSDE_PARSER_VALIDATION) || !defined (XSDE_EXCEPTIONS) + switch (context_.error_type ()) + { +#ifndef XSDE_EXCEPTIONS + case context::error_sys: + { + error_ = error (context_.sys_error ()); + break; + } +#endif +#ifdef XSDE_PARSER_VALIDATION + case context::error_schema: + { +#ifdef XSDE_EXCEPTIONS + throw schema (context_.schema_error (), l, c); +#else + error_ = error (context_.schema_error (), l, c); + break; +#endif + } +#endif +#ifndef XSDE_EXCEPTIONS + case context::error_app: + { + error_ = error (context_.app_error (), l, c); + break; + } +#endif + default: + { + // Someone aborted the parser without setting an + // error. Oh well, let them sort this one out. + // + break; + } + } +#endif // XSDE_PARSER_VALIDATION || !XSDE_EXCEPTIONS + } + else if (e == XML_ERROR_NO_MEMORY) + { +#ifdef XSDE_EXCEPTIONS + throw std::bad_alloc (); +#else + error_ = error (sys_error::no_memory); +#endif + } + else + { +#ifdef XSDE_EXCEPTIONS + throw xml (e, l, c); +#else + error_ = error (e, l, c); +#endif + } + } + } + + + // + // + void document_pimpl:: + set () + { + assert (xml_parser_ != 0); + + XML_SetUserData(xml_parser_, this); + XML_SetStartElementHandler (xml_parser_, &start_element); + XML_SetEndElementHandler (xml_parser_, &end_element); + XML_SetCharacterDataHandler (xml_parser_, &characters); + +#ifdef XSDE_POLYMORPHIC + if (polymorphic_) + XML_SetNamespaceDeclHandler ( + xml_parser_, &start_namespace_decl, &end_namespace_decl); +#endif + } + + void document_pimpl:: + clear () + { + assert (xml_parser_ != 0); + + XML_SetUserData (xml_parser_, 0); + XML_SetStartElementHandler (xml_parser_, 0); + XML_SetEndElementHandler (xml_parser_, 0); + XML_SetCharacterDataHandler (xml_parser_, 0); + +#ifdef XSDE_POLYMORPHIC + if (polymorphic_) + XML_SetNamespaceDeclHandler (xml_parser_, 0, 0); +#endif + } + + + // Expat thunks. + // + + void XMLCALL document_pimpl:: + start_element (void* p, const XML_Char* name, const XML_Char** ats) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.start_element_ (name, ats); + } + + void XMLCALL document_pimpl:: + end_element (void* p, const XML_Char* name) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.end_element_ (name); + } + + void XMLCALL document_pimpl:: + characters (void* p, const XML_Char* s, int n) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.characters_ (s, static_cast<size_t> (n)); + } + +#ifdef XSDE_POLYMORPHIC + void XMLCALL document_pimpl:: + start_namespace_decl (void* p, + const XML_Char* prefix, + const XML_Char* ns) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.start_namespace_decl_ (prefix, ns); + } + + void XMLCALL document_pimpl:: + end_namespace_decl (void* p, const XML_Char* prefix) + { + document_pimpl& doc = *reinterpret_cast<document_pimpl*> (p); + doc.end_namespace_decl_ (prefix); + } +#endif // XSDE_POLYMORPHIC + + namespace bits + { + inline void + split_name (const XML_Char* s, + const char*& ns, size_t& ns_s, + const char*& name, size_t& name_s) + { + const char* p = strchr (s, ' '); + + if (p) + { + ns = s; + ns_s = p - s; + name = p + 1; + } + else + { + ns = s; + ns_s = 0; + name = s; + } + + name_s = strlen (name); + } + } + + void document_pimpl:: + start_element_ (const XML_Char* ns_name, const XML_Char** atts) + { + // Current Expat (2.0.0) has a (mis)-feature of a possibility of + // calling callbacks even after the non-resumable XML_StopParser + // call. The following code accounts for this. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + const char* ns_p; + const char* name_p; + size_t ns_s, name_s; + + bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + + parser_state& cur = context_.current_; + + { + const ro_string ns (ns_p, ns_s); + const ro_string name (name_p, name_s); + +#ifdef XSDE_POLYMORPHIC + const char* type = 0; + string type_holder; + + if (polymorphic_) + { + // Search for the xsi:type attribute. + // + const XML_Char** p = atts; // VC8 can't handle p (atts) + for (; *p != 0; p += 2) + { + bits::split_name (*p, ns_p, ns_s, name_p, name_s); + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + + if (name.compare ("type", 4) == 0 && + ns.compare ( + "http://www.w3.org/2001/XMLSchema-instance", 41) == 0) + break; + } + + if (*p != 0) + { + bool valid = true; + + // @@ Need proper QName validation. + // + // Get the qualified type name and try to resolve it. + // + ro_string qn (*(p + 1)); + + ro_string tp, tn; + size_t pos = qn.find (':'); + + if (pos != ro_string::npos) + { + tp.assign (qn.data (), pos); + tn.assign (qn.data () + pos + 1); + + if (tp.empty ()) + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::invalid_xsi_type); +#endif + valid = false; + } + } + else + tn.assign (qn.data (), qn.size ()); + + if (valid && tn.empty ()) + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::invalid_xsi_type); +#endif + valid = false; + } + + if (valid) + { + // Search our namespace declaration stack. Note that + // we need to do this even if prefix is empty. + // + const char* tns = 0; + + for (size_t i = 0; i < prefixes_.size (); ++i) + { + if (tp == prefixes_[i]) + { +#ifdef XSDE_STL + tns = prefix_namespaces_[i].c_str (); +#else + tns = prefix_namespaces_[i]; +#endif + break; + } + } + + if (!tp.empty () && tns == 0) + { + // The 'xml' prefix requires special handling. + // + if (tp.compare ("xml", 3) == 0) + tns = "http://www.w3.org/XML/1998/namespace"; + else + { +#ifdef XSDE_PARSER_VALIDATION + context_.schema_error (schema_error::invalid_xsi_type); +#endif + valid = false; + } + } + + // Construct the compound name. + // + if (valid) + { + if (tns) + { +#ifdef XSDE_EXCEPTIONS + type_holder.assign (tn.data (), tn.size ()); + type_holder.append (" ", 1); + type_holder.append (tns); +#else + if (type_holder.assign (tn.data (), tn.size ()) || + type_holder.append (" ", 1) || + type_holder.append (tns)) + { + context_.sys_error (sys_error::no_memory); + XML_StopParser (xml_parser_, false); + } +#endif + type = type_holder.data (); + } + else + { + // We know that tn is '\0'-terminated. + // + type = tn.data (); + } + } + } + +#ifdef XSDE_PARSER_VALIDATION + if (!valid) + { + XML_StopParser (xml_parser_, false); + return; + } +#endif + } + } +#endif // XSDE_POLYMORPHIC + + // Dispatch. + // + if (cur.depth_ > 0) + { + if (cur.any_) + { + // Handling content matched by a wildcard. + // + cur.depth_++; + +#ifdef XSDE_POLYMORPHIC + cur.parser_->_start_any_element (ns, name, type); +#else + cur.parser_->_start_any_element (ns, name); +#endif + } + else + { + // Ignoring content for which there is no parser. + // + cur.depth_++; + } + } + else if (cur.parser_) + { + // The "normal" case: call _start_element which will + // call pre() and _pre_impl() (which will push the + // new parser). + // +#ifdef XSDE_POLYMORPHIC + cur.parser_->_start_element (ns, name, type); +#else + cur.parser_->_start_element (ns, name); +#endif + } + else + { + // Root element. Assume the user will report errors via + // context. + // +#ifdef XSDE_POLYMORPHIC + parser_base* p = 0; + + if (polymorphic_ && (root_name_ != name || root_ns_ != ns)) + { + // See if we can translate this element into type using + // substitution map. + // + if (substitution_map_instance ().check ( + ns, + name, + root_ns_.size () ? root_ns_.data () : 0, + root_name_.data (), + type)) + { + ro_string ro_ns (root_ns_); + ro_string ro_name (root_name_); + p = start_root_element (ro_ns, ro_name, type); + } + else + p = start_root_element (ns, name, type); + } + else + p = start_root_element (ns, name, type); +#else + parser_base* p = start_root_element (ns, name); +#endif + +#ifndef XSDE_EXCEPTIONS + if (!context_.error_type ()) + { +#endif + if (p) + { + // pre() is called by the user. + // + p->_pre_impl (context_); + } + else + { + // Ignoring. + // + cur.depth_++; + } + +#ifndef XSDE_EXCEPTIONS + } +#endif + } + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + { + XML_StopParser (xml_parser_, false); + return; + } +#endif + } + + // Dispatch attributes if we are not ignoring. + // + if (cur.depth_ == 0 || cur.any_) + { + for (; *atts != 0; atts += 2) + { + bits::split_name (*atts, ns_p, ns_s, name_p, name_s); + + const ro_string ns (ns_p, ns_s), name (name_p, name_s); + const ro_string value (*(atts + 1)); + + if (!cur.any_) + cur.parser_->_attribute (ns, name, value); + else + cur.parser_->_any_attribute (ns, name, value); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + { + XML_StopParser (xml_parser_, false); + break; + } +#endif + } + } + } + + void document_pimpl:: + end_element_ (const XML_Char* ns_name) + { + // See the comment in start_element_ for what's going on here. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + const char* ns_p; + const char* name_p; + size_t ns_s, name_s; + + bits::split_name (ns_name, ns_p, ns_s, name_p, name_s); + + const ro_string ns (ns_p, ns_s); + const ro_string name (name_p, name_s); + + parser_state& cur = context_.current_; + + // @@ Error propagation. + // + if (cur.depth_ == 0) + { + // The "normal" case: call _post to pop the parser and then + // call _end_element on the "outer" parser which calls post(). + // + parser_base* p = cur.parser_; + cur.parser_->_post_impl (); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (!context_.error_type ()) + { +#endif + // This case is a bit complicated by the fact that we can be + // popped up into a wildcard. + // + if (cur.depth_ == 0) + { + if (cur.parser_) + cur.parser_->_end_element (ns, name); + else + { + // End of the root element. post() is called by the user. + // + end_root_element (ns, name, p); + } + } + else + { + // Handling content matched by a wildcard. + // + if (--cur.depth_ > 0) + cur.parser_->_end_any_element (ns, name); + else + { + cur.parser_->_end_element (ns, name); + cur.any_ = false; + } + } + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + } +#endif + } + else + { + if (cur.any_) + { + // Handling content matched by a wildcard. + // + if (--cur.depth_ > 0) + cur.parser_->_end_any_element (ns, name); + else + { + cur.parser_->_end_element (ns, name); + cur.any_ = false; + } + } + else + { + // Ignoring content for which there is no parser. + // + if (--cur.depth_ == 0) + { + if (cur.parser_) + cur.parser_->_end_element (ns, name); + else + { + // End of the root element for which there was + // no parser. + // + end_root_element (ns, name, 0); + } + } + } + } + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + XML_StopParser (xml_parser_, false); +#endif + } + + void document_pimpl:: + characters_ (const XML_Char* s, size_t n) + { + // See the comment in start_element_ for what's going on here. + // + { + XML_ParsingStatus s; + XML_GetParsingStatus (xml_parser_, &s); + if (s.parsing == XML_FINISHED) + return; + } + + // Dispatch characters if we are not ignoring. + // + parser_state& cur = context_.current_; + + if (n != 0 && (cur.depth_ == 0 || cur.any_)) + { + const ro_string str (s, n); + + if (!cur.any_) + cur.parser_->_characters (str); + else + cur.parser_->_any_characters (str); + +#if defined(XSDE_PARSER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (context_.error_type ()) + XML_StopParser (xml_parser_, false); +#endif + } + } + +#ifdef XSDE_POLYMORPHIC + void document_pimpl:: + start_namespace_decl_ (const XML_Char* p, const XML_Char* ns) + { + // prefix is 0 for default namespace + // namespace is 0 when unsetting default namespace + // + if (polymorphic_) + { +#if defined (XSDE_STL) + prefixes_.push_back (p ? p : ""); + prefix_namespaces_.push_back (ns ? ns : ""); +#else +#if defined (XSDE_EXCEPTIONS) + prefixes_.push_back_copy (p ? p : ""); + prefix_namespaces_.push_back_copy (ns ? ns : ""); +#else + if (prefixes_.push_back_copy (p ? p : "" ) || + prefix_namespaces_.push_back_copy (ns ? ns : "")) + { + context_.sys_error (sys_error::no_memory); + XML_StopParser (xml_parser_, false); + } +#endif +#endif + } + } + + void document_pimpl:: + end_namespace_decl_ (const XML_Char*) + { + // prefix is 0 for default namespace + // + if (polymorphic_) + { + // Here we assume the prefixes are removed in the reverse + // order of them being added. This appears to how every + // sensible implementation works. + // + prefixes_.pop_back (); + prefix_namespaces_.pop_back (); + } + } +#endif // XSDE_POLYMORPHIC + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/expat/document.hxx b/libxsde/xsde/cxx/parser/expat/document.hxx new file mode 100644 index 0000000..2f87686 --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/document.hxx @@ -0,0 +1,337 @@ +// file : xsde/cxx/parser/expat/document.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_EXPAT_DOCUMENT_HXX +#define XSDE_CXX_PARSER_EXPAT_DOCUMENT_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#ifdef XSDE_STL +# include <string> +#endif + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/c/expat/expat.h> + +// We only support UTF-8 expat for now. +// +#ifdef XML_UNICODE +#error UTF-16 expat (XML_UNICODE defined) is not supported +#endif + +#include <xsde/cxx/string.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/string-sequence.hxx> +#endif + +#include <xsde/cxx/parser/context.hxx> +#include <xsde/cxx/parser/elements.hxx> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/parser/error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + // Simple auto pointer for Expat's XML_Parser object. + // + struct parser_auto_ptr + { + ~parser_auto_ptr (); + + explicit + parser_auto_ptr (XML_Parser = 0); + + parser_auto_ptr& + operator= (XML_Parser); + + public: + operator XML_Parser () + { + return parser_; + } + + private: + parser_auto_ptr (const parser_auto_ptr&); + + parser_auto_ptr& + operator= (const parser_auto_ptr&); + + private: + XML_Parser parser_; + }; + + // + // + class document_pimpl + { + public: + virtual + ~document_pimpl (); + +#ifdef XSDE_POLYMORPHIC + document_pimpl (parser_base&, + const char* root_element_name, + bool polymorphic = false); + + document_pimpl (parser_base&, + const char* root_element_namespace, + const char* root_element_name, + bool polymorphic = false); + +#ifdef XSDE_STL + document_pimpl (parser_base&, + const std::string& root_element_name, + bool polymorphic = false); + + document_pimpl (parser_base&, + const std::string& root_element_namespace, + const std::string& root_element_name, + bool polymorphic = false); + +#endif // XSDE_STL + protected: + document_pimpl (); // Non-polymorphic parsing. + + document_pimpl (const char* root_element_name); + + document_pimpl (const char* root_element_namespace, + const char* root_element_name); + +#ifdef XSDE_STL + document_pimpl (const std::string& root_element_name); + + document_pimpl (const std::string& root_element_namespace, + const std::string& root_element_name); +#endif + + +#else // XSDE_POLYMORPHIC + + document_pimpl (parser_base&, + const char* root_element_name); + + document_pimpl (parser_base&, + const char* root_element_namespace, + const char* root_element_name); + +#ifdef XSDE_STL + document_pimpl (parser_base&, + const std::string& root_element_name); + + document_pimpl (parser_base&, + const std::string& root_element_namespace, + const std::string& root_element_name); +#endif + protected: + document_pimpl (); + +#endif // XSDE_POLYMORPHIC + + // This function is called to obtain the root element type parser. + // If the returned pointed is 0 then the whole document content + // is ignored. + // + // The type argument contains the type name and namespace if + // xsi:type attribute or an element that substitutes the root + // was specified and 0 otherwise. The type argument is in the + // form "<name> <namespace>" with the space and namespace part + // absent if the type does not have a namespace. + // + // +#ifdef XSDE_POLYMORPHIC + virtual parser_base* + start_root_element (const ro_string& ns, + const ro_string& name, + const char* type); +#else + virtual parser_base* + start_root_element (const ro_string& ns, const ro_string& name); +#endif + + + // This function is called to indicate the completion of document + // parsing. The parser argument contains the pointer returned by + // start_root_element. + // + virtual void + end_root_element (const ro_string& ns, + const ro_string& name, + parser_base* parser); + + public: + // If you override start_root_element() then you will most + // likely also want to override reset() in order to reset + // root element parser(s). + // + virtual void + reset (); + +#ifdef XSDE_IOSTREAM + public: + // Parse a local file. The file is accessed with std::ifstream + // in binary mode. The std::ios_base::failure exception is used + // to report io errors (badbit and failbit) if XSDE_EXCEPTIONS + // is defined. Otherwise error codes are used. + // + void + parse (const char* file); + +#ifdef XSDE_STL + void + parse (const std::string& file); +#endif + + // Parse std::istream. std::ios_base::failure exception is used + // to report io errors (badbit and failbit) if XSDE_EXCEPTIONS + // is defined. Otherwise error codes are used. + // + void + parse (std::istream&); +#endif + + public: + // Parse a chunk of input. You can call this function multiple + // times with the last call having the last argument true. + // + void + parse (const void* data, size_t size, bool last); + + public: + // Low-level Expat-specific parsing API. A typical use case + // would look like this (pseudo-code): + // + // XML_Parser xml_parser (XML_ParserCreateNS (0, ' ')); + // + // xxx_pimpl root; + // document_pimpl doc (root, "root"); + // + // root.pre (); + // doc.parse_begin (xml_parser); + // + // while (more_stuff_to_parse) + // { + // // Call XML_Parse or XML_ParseBuffer: + // // + // if (XML_Parse (...) != XML_STATUS_ERROR) + // break; + // } + // + // doc.parse_end (); + // result_type result (root.post_xxx ()); + // + // Notes: + // + // 1. If your XML instances use XML namespaces, XML_ParserCreateNS + // functions should be used to create the XML parser. Space + // (XML_Char (' ')) should be used as a separator (the second + // argument to XML_ParserCreateNS). + // + // 2. If XML_Parse or XML_ParseBuffer fail, call parse_end to + // determine the error which is indicated either via exception + // or set as an error code. + // + void + parse_begin (XML_Parser); + + void + parse_end (); + +#ifndef XSDE_EXCEPTIONS + public: + const error& + _error () const; +#endif + + protected: + void + set (); + + void + clear (); + + protected: + static void XMLCALL + start_element (void*, const XML_Char*, const XML_Char**); + + static void XMLCALL + end_element (void*, const XML_Char*); + + static void XMLCALL + characters (void*, const XML_Char*, int); + +#ifdef XSDE_POLYMORPHIC + static void XMLCALL + start_namespace_decl (void*, const XML_Char*, const XML_Char*); + + static void XMLCALL + end_namespace_decl (void*, const XML_Char*); +#endif + + protected: + void + start_element_ (const XML_Char* ns_name, const XML_Char** atts); + + void + end_element_ (const XML_Char* ns_name); + + void + characters_ (const XML_Char* s, size_t n); + +#ifdef XSDE_POLYMORPHIC + void + start_namespace_decl_ (const XML_Char* prefix, const XML_Char* ns); + + void + end_namespace_decl_ (const XML_Char* prefix); +#endif + + protected: + bool first_; + XML_Parser xml_parser_; + parser_auto_ptr auto_xml_parser_; + + context context_; + + parser_base* parser_; + string root_name_; + string root_ns_; + +#ifdef XSDE_POLYMORPHIC + bool polymorphic_; + string_sequence prefixes_; + string_sequence prefix_namespaces_; +#endif + +#ifndef XSDE_EXCEPTIONS + error error_; +#endif + + private: + void + init_root_name (const char* ns, const char* name); + }; + } + } + } +} + +#include <xsde/cxx/parser/expat/document.ixx> + +#endif // XSDE_CXX_PARSER_EXPAT_DOCUMENT_HXX diff --git a/libxsde/xsde/cxx/parser/expat/document.ixx b/libxsde/xsde/cxx/parser/expat/document.ixx new file mode 100644 index 0000000..0c3d34d --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/document.ixx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/expat/document.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + // parser_auto_ptr + // + inline parser_auto_ptr:: + ~parser_auto_ptr () + { + if (parser_ != 0) + XML_ParserFree (parser_); + } + + inline parser_auto_ptr:: + parser_auto_ptr (XML_Parser parser) + : parser_ (parser) + { + } + + inline parser_auto_ptr& parser_auto_ptr:: + operator= (XML_Parser parser) + { + if (parser_ != 0) + XML_ParserFree (parser_); + + parser_ = parser; + return *this; + } + + + // document_pimpl + // +#ifndef XSDE_EXCEPTIONS + inline const error& document_pimpl:: + _error () const + { + return error_; + } +#endif + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/expat/xml-error.cxx b/libxsde/xsde/cxx/parser/expat/xml-error.cxx new file mode 100644 index 0000000..a24059c --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/xml-error.cxx @@ -0,0 +1,25 @@ +// file : xsde/cxx/parser/expat/xml-error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/expat/xml-error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + const char* + xml_error_text (xml_error e) + { + return XML_ErrorString (e); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/expat/xml-error.hxx b/libxsde/xsde/cxx/parser/expat/xml-error.hxx new file mode 100644 index 0000000..4028590 --- /dev/null +++ b/libxsde/xsde/cxx/parser/expat/xml-error.hxx @@ -0,0 +1,28 @@ +// file : xsde/cxx/parser/expat/xml-error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_EXPAT_XML_ERROR_HXX +#define XSDE_CXX_PARSER_EXPAT_XML_ERROR_HXX + +#include <xsde/c/expat/expat.h> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace expat + { + typedef XML_Error xml_error; + + const char* + xml_error_text (xml_error); + } + } + } +} + +#endif // XSDE_CXX_PARSER_EXPAT_XML_ERROR_HXX diff --git a/libxsde/xsde/cxx/parser/map.cxx b/libxsde/xsde/cxx/parser/map.cxx new file mode 100644 index 0000000..b21c41e --- /dev/null +++ b/libxsde/xsde/cxx/parser/map.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/parser/map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // parser_map + // + parser_map:: + ~parser_map () + { + } + + // parser_map_impl + // + void parser_map_impl:: + reset () const + { + for (hashmap::const_iterator i (map_.begin ()), e (map_.end ()); + i != e; ++i) + { + parser_base* p = *static_cast<parser_base* const*> (*i); + p->_reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/map.hxx b/libxsde/xsde/cxx/parser/map.hxx new file mode 100644 index 0000000..400de27 --- /dev/null +++ b/libxsde/xsde/cxx/parser/map.hxx @@ -0,0 +1,87 @@ +// file : xsde/cxx/parser/map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_MAP_HXX +#define XSDE_CXX_PARSER_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/hashmap.hxx> + +#include <xsde/cxx/parser/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // Parser map. Used in the polymorphic document parsing. + // + class parser_map + { + public: + // The type argument is the type name and namespace from the + // xsi:type attribute or substitution group map in the form + // "<name> <namespace>" with the space and namespace part + // absent if the type does not have a namespace. + // + virtual parser_base* + find (const char* type) const = 0; + + // Reset the parsers this map contains. + // + virtual void + reset () const = 0; + + virtual + ~parser_map (); + }; + + // Default parser map implementation. + // + class parser_map_impl: public parser_map + { + public: +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; + + error + _error () const; +#endif + + public: + parser_map_impl (size_t buckets); + + void + insert (parser_base&); + + virtual parser_base* + find (const char* type) const; + + virtual void + reset () const; + + private: + parser_map_impl (const parser_map_impl&); + + parser_map_impl& + operator= (const parser_map_impl&); + + private: + hashmap map_; + }; + } + } +} + +#include <xsde/cxx/parser/map.ixx> + +#endif // XSDE_CXX_PARSER_MAP_HXX diff --git a/libxsde/xsde/cxx/parser/map.ixx b/libxsde/xsde/cxx/parser/map.ixx new file mode 100644 index 0000000..3a1f931 --- /dev/null +++ b/libxsde/xsde/cxx/parser/map.ixx @@ -0,0 +1,41 @@ +// file : xsde/cxx/parser/map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { +#ifndef XSDE_EXCEPTIONS + inline parser_map_impl::error parser_map_impl:: + _error () const + { + return map_._error () ? error_no_memory : error_none; + } +#endif + + inline parser_map_impl:: + parser_map_impl (size_t buckets) + : map_ (buckets, sizeof (parser_base*)) + { + } + + inline void parser_map_impl:: + insert (parser_base& p) + { + parser_base* tmp = &p; + map_.insert (p._dynamic_type (), &tmp); + } + + inline parser_base* parser_map_impl:: + find (const char* type) const + { + const void* p = map_.find (type); + return p ? *static_cast<parser_base* const*> (p) : 0; + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/any-type.hxx b/libxsde/xsde/cxx/parser/non-validating/any-type.hxx new file mode 100644 index 0000000..37e1d6f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/any-type.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/parser/non-validating/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_ANY_TYPE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_ANY_TYPE_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_pimpl: virtual any_type_pskel +#else + struct any_type_pimpl: any_type_pskel +#endif + { + }; + + // any_simple_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_simple_type_pimpl: virtual any_simple_type_pskel +#else + struct any_simple_type_pimpl: any_simple_type_pskel +#endif + { + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/base64-binary.cxx b/libxsde/xsde/cxx/parser/non-validating/base64-binary.cxx new file mode 100644 index 0000000..95588a2 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/base64-binary.cxx @@ -0,0 +1,241 @@ +// file : xsde/cxx/parser/non-validating/base64-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/base64-binary.hxx> + +static unsigned char +base64_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= 'A' && c <= 'Z') + r = static_cast<unsigned char> (c - 'A'); + else if (c >= 'a' && c <= 'z') + r = static_cast<unsigned char> (c - 'a' + 26); + else if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0' + 52); + else if (c == '+') + r = 62; + else if (c == '/') + r = 63; + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + base64_binary_pimpl:: + ~base64_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void base64_binary_pimpl:: + _reset () + { + base64_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + base64_binary_pimpl:: + base64_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void base64_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void base64_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + buffer* base64_binary_pimpl:: + post_base64_binary () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + const char* src = str_.data (); + + // Remove all whitespaces. + // + { + size_type j = 0; + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.truncate (size); + } + + // Our length should be a multiple of four. + // + size_type quad_count = size / 4; + size_type capacity = quad_count * 3 + 1; + +#ifdef XSDE_EXCEPTIONS + buf_->size (capacity); +#else + if (buf_->size (capacity)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + char* dst = buf_->data (); + + // Source and destination indexes. + // + size_type si = 0; + size_type di = 0; + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q = 0; q < quad_count - 1; ++q) + { + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + b3 = base64_decode (src[si++]); + b4 = base64_decode (src[si++]); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + + char e3 = src[si++]; + char e4 = src[si++]; + + if (e4 == '=') + { + if (e3 == '=') + { + // Two pads. Last 4 bits in b2 should be zero. + // + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = base64_decode (e3); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = base64_decode (e3); + b4 = base64_decode (e4); + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf_->size (di); + + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/base64-binary.hxx b/libxsde/xsde/cxx/parser/non-validating/base64-binary.hxx new file mode 100644 index 0000000..fef946b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/base64-binary.hxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/parser/non-validating/base64-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_BASE64_BINARY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_BASE64_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct base64_binary_pimpl: virtual base64_binary_pskel +#else + struct base64_binary_pimpl: base64_binary_pskel +#endif + { + ~base64_binary_pimpl (); + base64_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual buffer* + post_base64_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_BASE64_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/boolean.cxx b/libxsde/xsde/cxx/parser/non-validating/boolean.cxx new file mode 100644 index 0000000..af5ee41 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/boolean.cxx @@ -0,0 +1,80 @@ +// file : xsde/cxx/parser/non-validating/boolean.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/boolean.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void boolean_pimpl:: + _pre () + { + size_ = 0; + state_ = leading_ws; + } + + void boolean_pimpl:: + _characters (const ro_string& s) + { + ro_string tmp (s.data (), s.size ()); + + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((5 - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((5 - size_) >= size) + { + memcpy (str_ + size_, tmp.data (), size); + size_ += size; + } + + break; + } + case trailing_ws: + { + // We don't really care if it is not. + break; + } + } + } + + bool boolean_pimpl:: + post_boolean () + { + ro_string tmp (str_, size_); + trim_right (tmp); + + return (tmp == "1" || tmp == "true"); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/boolean.hxx b/libxsde/xsde/cxx/parser/non-validating/boolean.hxx new file mode 100644 index 0000000..eeb9068 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/boolean.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_BOOLEAN_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_BOOLEAN_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct boolean_pimpl: virtual boolean_pskel +#else + struct boolean_pimpl: boolean_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual bool + post_boolean (); + + protected: + // We only need strlen("false") + 1 characters to hold all valid + // and trimmed string representations of boolean. + // + char str_[6]; + size_t size_; + enum { leading_ws, literal, trailing_ws } state_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_BOOLEAN_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/byte.cxx b/libxsde/xsde/cxx/parser/non-validating/byte.cxx new file mode 100644 index 0000000..47fa839 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/byte.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void byte_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 4); + } + + signed char byte_pimpl:: + post_byte () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? static_cast<signed char> (-static_cast<short> (ul)) + : static_cast<signed char> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/byte.hxx b/libxsde/xsde/cxx/parser/non-validating/byte.hxx new file mode 100644 index 0000000..a6bbffc --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/byte.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_BYTE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_BYTE_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 8-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct byte_pimpl: virtual byte_pskel, number +#else + struct byte_pimpl: byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual signed char + post_byte (); + + protected: + // We only need strlen("0128") + 1 characters to hold all valid + // and trimmed string representations of signed byte. + // + char str_[5]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/date-time.cxx b/libxsde/xsde/cxx/parser/non-validating/date-time.cxx new file mode 100644 index 0000000..59d8c11 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date-time.cxx @@ -0,0 +1,154 @@ +// file : xsde/cxx/parser/non-validating/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/date-time.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void date_time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + date_time date_time_pimpl:: + post_date_time () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + int year = 0; + unsigned short month = 0; + unsigned short day = 0; + unsigned short hours = 0; + unsigned short minutes = 0; + double seconds = 0.0; + bool zone = false; + short zh, zm; + + if (n >= 19) + { + // Find the end of the year token. + // + ro_string::size_type yp = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (yp != ro_string::npos && (n - yp - 1) >= 14) + { + // Find the end of the seconds fragment. + // + ro_string::size_type sp = yp + 15; + for (; sp < n; ++sp) + { + char c = s[sp]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse it backwards so that we can truncate and reuse + // the string. + // + + // zone + // + if (sp < n) + { + bits::parse_time_zone (s + sp, n - sp, zh, zm); + zone = true; + } + + // seconds + // + str_.truncate (sp); + + seconds = strtod (s + yp + 13, 0); + + // minutes + // + minutes = 10 * (s[yp + 10] - '0') + (s[yp + 11] - '0'); + + // hours + // + hours = 10 * (s[yp + 7] - '0') + (s[yp + 8] - '0'); + + // day + // + day = 10 * (s[yp + 4] - '0') + (s[yp + 5] - '0'); + + // month + // + month = 10 * (s[yp + 1] - '0') + (s[yp + 2] - '0'); + + // year + // + str_.truncate (yp); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + + return zone + ? date_time (year, month, day, hours, minutes, seconds, zh, zm) + : date_time (year, month, day, hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/date-time.hxx b/libxsde/xsde/cxx/parser/non-validating/date-time.hxx new file mode 100644 index 0000000..bb329af --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date-time.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DATE_TIME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DATE_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_time_pimpl: virtual date_time_pskel +#else + struct date_time_pimpl: date_time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual date_time + post_date_time (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/date.cxx b/libxsde/xsde/cxx/parser/non-validating/date.cxx new file mode 100644 index 0000000..0364ac1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date.cxx @@ -0,0 +1,126 @@ +// file : xsde/cxx/parser/non-validating/date.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/date.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void date_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + date date_pimpl:: + post_date () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + int year = 0; + unsigned short month = 0; + unsigned short day = 0; + bool zone = false; + short zh, zm; + + if (n >= 10) + { + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos != ro_string::npos && (n - pos - 1) >= 5) + { + // Parse the month, day values and time zone first so that we + // can truncate and reuse the string. + // + + // month + // + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + + // day + // + day = 10 * (s[pos + 4] - '0') + (s[pos + 5] - '0'); + + // zone + // + if ((pos + 6) < n) + { + bits::parse_time_zone (s + pos + 6, n - pos - 6, zh, zm); + zone = true; + } + + // year + // + str_.truncate (pos); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + + return zone + ? date (year, month, day, zh, zm) + : date (year, month, day); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/date.hxx b/libxsde/xsde/cxx/parser/non-validating/date.hxx new file mode 100644 index 0000000..174de7d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/date.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/date.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DATE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DATE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_pimpl: virtual date_pskel +#else + struct date_pimpl: date_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual date + post_date (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DATE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/decimal.cxx b/libxsde/xsde/cxx/parser/non-validating/decimal.cxx new file mode 100644 index 0000000..401800b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/decimal.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/decimal.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/parser/non-validating/decimal.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void decimal_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void decimal_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 127); + } + + double decimal_pimpl:: + post_decimal () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + double r = strtod (str_, 0); + + if (sign_ == minus) + r = -r; + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/decimal.hxx b/libxsde/xsde/cxx/parser/non-validating/decimal.hxx new file mode 100644 index 0000000..fd1cf4e --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/decimal.hxx @@ -0,0 +1,46 @@ +// file : xsde/cxx/parser/non-validating/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DECIMAL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DECIMAL_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct decimal_pimpl: virtual decimal_pskel, number +#else + struct decimal_pimpl: decimal_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual double + post_decimal (); + + protected: + // Assume decimal values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DECIMAL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/double.cxx b/libxsde/xsde/cxx/parser/non-validating/double.cxx new file mode 100644 index 0000000..8c7ab9a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/double.cxx @@ -0,0 +1,62 @@ +// file : xsde/cxx/parser/non-validating/double.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/parser/non-validating/double.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void double_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void double_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 127); + } + + double double_pimpl:: + post_double () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + double r; + + if (tmp == "INF") + { + r = strtod (sign_ == minus ? "-INF" : "INF", 0); + } + else if (tmp == "NaN") + { + r = strtod ("NAN", 0); + } + else + { + r = strtod (str_, 0); + + if (sign_ == minus) + r = -r; + } + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/double.hxx b/libxsde/xsde/cxx/parser/non-validating/double.hxx new file mode 100644 index 0000000..1e5f299 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/double.hxx @@ -0,0 +1,46 @@ +// file : xsde/cxx/parser/non-validating/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DOUBLE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DOUBLE_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct double_pimpl: virtual double_pskel, number +#else + struct double_pimpl: double_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual double + post_double (); + + protected: + // Assume double values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DOUBLE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/duration.cxx b/libxsde/xsde/cxx/parser/non-validating/duration.cxx new file mode 100644 index 0000000..d7cbb3b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/duration.cxx @@ -0,0 +1,166 @@ +// file : xsde/cxx/parser/non-validating/duration.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/duration.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void duration_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + static ro_string::size_type + rfind_delim (const char* s, ro_string::size_type pos) + { + const char* p = s + pos; + for (; p >= s; --p) + { + if (*p == 'Y' || *p == 'D' || *p == 'M' || + *p == 'H' || *p == 'M' || *p == 'S' || + *p == 'T' || *p == 'P') + break; + } + + return p >= s ? p - s : ro_string::npos; + } + + duration duration_pimpl:: + post_duration () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + bool negative = false; + unsigned int years = 0; + unsigned int months = 0; + unsigned int days = 0; + unsigned int hours = 0; + unsigned int minutes = 0; + double seconds = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + + if (n >= 3 && s[s[0] == '-' ? 1 : 0] == 'P') + { + if (s[0] == '-') + negative = true; + + // Parse it backwards so that we can truncate and reuse + // the string. + // + ro_string::size_type pos = n - 1; + ro_string::size_type t_pos = tmp.find ('T'); + + if (s[pos] == 'S') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + seconds = strtod (s + pos + 1, 0); + } + + if (s[pos] == 'M' && t_pos != ro_string::npos && t_pos < pos) + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + minutes = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'H') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + hours = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'T') + pos = rfind_delim (s, pos - 1); + + if (s[pos] == 'D') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + days = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'M') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + months = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + + if (s[pos] == 'Y') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + years = + static_cast<unsigned int> (strtoul (s + pos + 1, 0, 10)); + } + } + + return duration ( + negative, years, months, days, hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/duration.hxx b/libxsde/xsde/cxx/parser/non-validating/duration.hxx new file mode 100644 index 0000000..ebbd210 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/duration.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/duration.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_DURATION_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_DURATION_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct duration_pimpl: virtual duration_pskel +#else + struct duration_pimpl: duration_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual duration + post_duration (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_DURATION_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/float.cxx b/libxsde/xsde/cxx/parser/non-validating/float.cxx new file mode 100644 index 0000000..9c90b32 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/float.cxx @@ -0,0 +1,76 @@ +// file : xsde/cxx/parser/non-validating/float.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtof, strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/float.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void float_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void float_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 127); + } + + float float_pimpl:: + post_float () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + float r; + + if (tmp == "INF") + { +#ifdef XSDE_STRTOF + r = strtof (sign_ == minus ? "-INF" : "INF", 0); +#else + r = static_cast<float> (strtod (sign_ == minus ? "-INF" : "INF", 0)); +#endif + } + else if (tmp == "NaN") + { +#ifdef XSDE_STRTOF + r = strtof ("NAN", 0); +#else + r = static_cast<float> (strtod ("NAN", 0)); +#endif + } + else + { +#ifdef XSDE_STRTOF + r = strtof (str_, 0); +#else + r = static_cast<float> (strtod (str_, 0)); +#endif + + if (sign_ == minus) + r = -r; + } + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/float.hxx b/libxsde/xsde/cxx/parser/non-validating/float.hxx new file mode 100644 index 0000000..cae4fa7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/float.hxx @@ -0,0 +1,46 @@ +// file : xsde/cxx/parser/non-validating/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_FLOAT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_FLOAT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct float_pimpl: virtual float_pskel, number +#else + struct float_pimpl: float_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual float + post_float (); + + protected: + // Assume float values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_FLOAT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gday.cxx b/libxsde/xsde/cxx/parser/non-validating/gday.cxx new file mode 100644 index 0000000..64c9cd9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gday.cxx @@ -0,0 +1,88 @@ +// file : xsde/cxx/parser/non-validating/gday.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gday.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gday_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gday gday_pimpl:: + post_gday () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gday := ---DD[Z|(+|-)HH:MM] + // + + unsigned short day = 0; + bool zone = false; + short zh, zm; + + if (n >= 5) + { + day = 10 * (s[3] - '0') + (s[4] - '0'); + + if (n > 5) + { + bits::parse_time_zone (s + 5, n - 5, zh, zm); + zone = true; + } + } + + return zone ? gday (day, zh, zm) : gday (day); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gday.hxx b/libxsde/xsde/cxx/parser/non-validating/gday.hxx new file mode 100644 index 0000000..7af0c19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gday.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gday.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GDAY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GDAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gday_pimpl: virtual gday_pskel +#else + struct gday_pimpl: gday_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gday + post_gday (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GDAY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth-day.cxx b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.cxx new file mode 100644 index 0000000..223b73f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.cxx @@ -0,0 +1,100 @@ +// file : xsde/cxx/parser/non-validating/gmonth-day.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gmonth-day.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gmonth_day_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + + unsigned short month = 0; + unsigned short day = 0; + bool zone = false; + short zh, zm; + + if (n >= 7) + { + // month + // + month = 10 * (s[2] - '0') + (s[3] - '0'); + + // day + // + day = 10 * (s[5] - '0') + (s[6] - '0'); + + // zone + // + if (n > 7) + { + bits::parse_time_zone (s + 7, n - 7, zh, zm); + zone = true; + + } + } + + return zone + ? gmonth_day (month, day, zh, zm) + : gmonth_day (month, day); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth-day.hxx b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.hxx new file mode 100644 index 0000000..75fb3fb --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth-day.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gmonth-day.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_DAY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_DAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_day_pimpl: virtual gmonth_day_pskel +#else + struct gmonth_day_pimpl: gmonth_day_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gmonth_day + post_gmonth_day (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_DAY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth.cxx b/libxsde/xsde/cxx/parser/non-validating/gmonth.cxx new file mode 100644 index 0000000..f203c70 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth.cxx @@ -0,0 +1,88 @@ +// file : xsde/cxx/parser/non-validating/gmonth.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gmonth.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gmonth_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gmonth gmonth_pimpl:: + post_gmonth () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + + unsigned short month = 0; + bool zone = false; + short zh, zm; + + if (n >= 4) + { + month = 10 * (s[2] - '0') + (s[3] - '0'); + + if (n > 4) + { + bits::parse_time_zone (s + 4, n - 4, zh, zm); + zone = true; + } + } + + return zone ? gmonth (month, zh, zm) : gmonth (month); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gmonth.hxx b/libxsde/xsde/cxx/parser/non-validating/gmonth.hxx new file mode 100644 index 0000000..dfa9b33 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gmonth.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gmonth.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_pimpl: virtual gmonth_pskel +#else + struct gmonth_pimpl: gmonth_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gmonth + post_gmonth (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GMONTH_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear-month.cxx b/libxsde/xsde/cxx/parser/non-validating/gyear-month.cxx new file mode 100644 index 0000000..4492246 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear-month.cxx @@ -0,0 +1,121 @@ +// file : xsde/cxx/parser/non-validating/gyear-month.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gyear-month.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gyear_month_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + int year = 0; + unsigned short month = 0; + bool zone = false; + short zh, zm; + + if (n >= 7) + { + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos != ro_string::npos && (n - pos - 1) >= 2) + { + // Parse the month value and time zone first so that we can + // truncate and reuse the string. + // + + // month + // + month = 10 * (s[pos + 1] - '0') + (s[pos + 2] - '0'); + + // zone + // + if ((pos + 3) < n) + { + bits::parse_time_zone (s + pos + 3, n - pos - 3, zh, zm); + zone = true; + } + + // year + // + str_.truncate (pos); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + + return zone + ? gyear_month (year, month, zh, zm) + : gyear_month (year, month); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear-month.hxx b/libxsde/xsde/cxx/parser/non-validating/gyear-month.hxx new file mode 100644 index 0000000..23b7378 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear-month.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gyear-month.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_MONTH_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_MONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_month_pimpl: virtual gyear_month_pskel +#else + struct gyear_month_pimpl: gyear_month_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gyear_month + post_gyear_month (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_MONTH_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear.cxx b/libxsde/xsde/cxx/parser/non-validating/gyear.cxx new file mode 100644 index 0000000..351ac4c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear.cxx @@ -0,0 +1,115 @@ +// file : xsde/cxx/parser/non-validating/gyear.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/gyear.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void gyear_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + gyear gyear_pimpl:: + post_gyear () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + int year = 0; + bool zone = false; + short zh, zm; + + if (n >= 4) + { + // Find the end of the year token. + // + ro_string::size_type pos = (s[0] == '-' ? 5 : 4); + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + bits::parse_time_zone (s + pos, n - pos, zh, zm); + zone = true; + } + + // Parse the year value. + // + str_.truncate (pos); + + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, 0, 10); + + year = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + return zone ? gyear (year, zh, zm) : gyear (year); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/gyear.hxx b/libxsde/xsde/cxx/parser/non-validating/gyear.hxx new file mode 100644 index 0000000..528b368 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/gyear.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/gyear.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_pimpl: virtual gyear_pskel +#else + struct gyear_pimpl: gyear_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual gyear + post_gyear (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_GYEAR_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/hex-binary.cxx b/libxsde/xsde/cxx/parser/non-validating/hex-binary.cxx new file mode 100644 index 0000000..a7cc8b4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/hex-binary.cxx @@ -0,0 +1,159 @@ +// file : xsde/cxx/parser/non-validating/hex-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/hex-binary.hxx> + +static unsigned char +hex_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0'); + else if (c >= 'A' && c <= 'F') + r = static_cast<unsigned char> (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + r = static_cast<unsigned char> (10 + (c - 'a')); + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + hex_binary_pimpl:: + ~hex_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void hex_binary_pimpl:: + _reset () + { + hex_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + hex_binary_pimpl:: + hex_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void hex_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void hex_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + buffer* hex_binary_pimpl:: + post_hex_binary () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + size_t n = size / 2; + +#ifdef XSDE_EXCEPTIONS + buf_->size (n); +#else + if (buf_->size (n)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + + if (n != 0) + { + const char* src = tmp.data (); + char* dst = buf_->data (); + size_t i = 0; + + for (; i < n; ++i) + { + unsigned char h = hex_decode (src[2 * i]); + unsigned char l = hex_decode (src[2 * i + 1]); + + if (h == 0xFF || l == 0xFF) + break; + + dst[i] = (h << 4) | l; + } + } + + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/hex-binary.hxx b/libxsde/xsde/cxx/parser/non-validating/hex-binary.hxx new file mode 100644 index 0000000..3b7a4b3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/hex-binary.hxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/parser/non-validating/hex-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_HEX_BINARY_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_HEX_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct hex_binary_pimpl: virtual hex_binary_pskel +#else + struct hex_binary_pimpl: hex_binary_pskel +#endif + { + ~hex_binary_pimpl (); + hex_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual buffer* + post_hex_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_HEX_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/id-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/id-stl.cxx new file mode 100644 index 0000000..15a611b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id-stl.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/id-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/id-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void id_pimpl:: + _pre () + { + str_.erase (); + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string id_pimpl:: + post_id () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/non-validating/id-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/id-stl.hxx new file mode 100644 index 0000000..5109ba1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/id-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_ID_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_ID_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_id (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_ID_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/id.cxx b/libxsde/xsde/cxx/parser/non-validating/id.cxx new file mode 100644 index 0000000..5230305 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/id.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/id.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void id_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* id_pimpl:: + post_id () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/id.hxx b/libxsde/xsde/cxx/parser/non-validating/id.hxx new file mode 100644 index 0000000..d762271 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/id.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/id.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_ID_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_ID_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_id (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_ID_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idref-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/idref-stl.cxx new file mode 100644 index 0000000..e3be5af --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/idref-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void idref_pimpl:: + _pre () + { + str_.erase (); + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string idref_pimpl:: + post_idref () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/idref-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/idref-stl.hxx new file mode 100644 index 0000000..e65375c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/idref-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREF_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREF_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_idref (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREF_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idref.cxx b/libxsde/xsde/cxx/parser/non-validating/idref.cxx new file mode 100644 index 0000000..f6ac060 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/idref.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void idref_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* idref_pimpl:: + post_idref () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/idref.hxx b/libxsde/xsde/cxx/parser/non-validating/idref.hxx new file mode 100644 index 0000000..b76318c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idref.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/idref.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREF_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREF_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_idref (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREF_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.cxx new file mode 100644 index 0000000..a62ea47 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.cxx @@ -0,0 +1,94 @@ +// file : xsde/cxx/parser/non-validating/idrefs-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/idrefs-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + seq_->push_back (parser_.post_idref ()); + } + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.hxx new file mode 100644 index 0000000..193b764 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs-stl.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/idrefs-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_STL_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs.cxx b/libxsde/xsde/cxx/parser/non-validating/idrefs.cxx new file mode 100644 index 0000000..15a6947 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs.cxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/parser/non-validating/idrefs.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/idrefs.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + +#ifdef XSDE_EXCEPTIONS + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + + // push_back() frees the string if it throws. + // + seq_->push_back (parser_.post_idref ()); + } +#else + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); + + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_idref (); + + if (!parser_._error_type ()) + { + // push_back() frees the string if it fails. + // + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); + } + } +#endif + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/non-validating/idrefs.hxx b/libxsde/xsde/cxx/parser/non-validating/idrefs.hxx new file mode 100644 index 0000000..f3d9b99 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/idrefs.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/idrefs.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_IDREFS_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/int.cxx b/libxsde/xsde/cxx/parser/non-validating/int.cxx new file mode 100644 index 0000000..86a9a8b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/int.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void int_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 11); + } + + int int_pimpl:: + post_int () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/int.hxx b/libxsde/xsde/cxx/parser/non-validating/int.hxx new file mode 100644 index 0000000..8543909 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/int.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_INT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_INT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 32-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct int_pimpl: virtual int_pskel, number +#else + struct int_pimpl: int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual int + post_int (); + + protected: + // We only need strlen("02147483648") + 1 characters to hold all + // valid and trimmed string representations of int. + // + char str_[12]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_INT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/integer.cxx b/libxsde/xsde/cxx/parser/non-validating/integer.cxx new file mode 100644 index 0000000..dbad0e6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/integer.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN, LONG_MAX + +#include <xsde/cxx/parser/non-validating/integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long integer_pimpl:: + post_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? (ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN : -static_cast<long> (ul)) + : static_cast<long> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/integer.hxx b/libxsde/xsde/cxx/parser/non-validating/integer.hxx new file mode 100644 index 0000000..94e1754 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/integer.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct integer_pimpl: virtual integer_pskel, number +#else + struct integer_pimpl: integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/language-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/language-stl.cxx new file mode 100644 index 0000000..80128ea --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/language-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/language-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void language_pimpl:: + _pre () + { + str_.erase (); + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string language_pimpl:: + post_language () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/language-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/language-stl.hxx new file mode 100644 index 0000000..01dda2d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/language-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_language (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/language.cxx b/libxsde/xsde/cxx/parser/non-validating/language.cxx new file mode 100644 index 0000000..bcf41b0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/language.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/language.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void language_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* language_pimpl:: + post_language () + { + ro_string tmp (str_); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/language.hxx b/libxsde/xsde/cxx/parser/non-validating/language.hxx new file mode 100644 index 0000000..cfefe25 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/language.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/language.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_language (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LANGUAGE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/long-long.cxx b/libxsde/xsde/cxx/parser/non-validating/long-long.cxx new file mode 100644 index 0000000..5501925 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long-long.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/parser/non-validating/long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long long long_pimpl:: + post_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long long ull = strtoull (str_, 0, 10); + + return (sign_ == minus) + ? (ull == 9223372036854775808ULL + ? (-9223372036854775807LL - 1) + : -static_cast<long long> (ull)) + : static_cast<long long> (ull); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/long-long.hxx b/libxsde/xsde/cxx/parser/non-validating/long-long.hxx new file mode 100644 index 0000000..44669d0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long-long.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LONG_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LONG_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 64-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/long.cxx b/libxsde/xsde/cxx/parser/non-validating/long.cxx new file mode 100644 index 0000000..e1a3beb --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long long_pimpl:: + post_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/long.hxx b/libxsde/xsde/cxx/parser/non-validating/long.hxx new file mode 100644 index 0000000..b51ecd0f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/long.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/name-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/name-stl.cxx new file mode 100644 index 0000000..65c3e0a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/name-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/name-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void name_pimpl:: + _pre () + { + str_.erase (); + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string name_pimpl:: + post_name () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/name-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/name-stl.hxx new file mode 100644 index 0000000..75bbf03 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/name-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NAME_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_name (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/name.cxx b/libxsde/xsde/cxx/parser/non-validating/name.cxx new file mode 100644 index 0000000..bbc7a2e --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/name.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/name.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void name_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* name_pimpl:: + post_name () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/name.hxx b/libxsde/xsde/cxx/parser/non-validating/name.hxx new file mode 100644 index 0000000..d10d34d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/name.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/name.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NAME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_name (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NAME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.cxx new file mode 100644 index 0000000..50f2df8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/ncname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/ncname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void ncname_pimpl:: + _pre () + { + str_.erase (); + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string ncname_pimpl:: + post_ncname () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.hxx new file mode 100644 index 0000000..a1a1c69 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/ncname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_ncname (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname.cxx b/libxsde/xsde/cxx/parser/non-validating/ncname.cxx new file mode 100644 index 0000000..0fffa19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void ncname_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* ncname_pimpl:: + post_ncname () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/ncname.hxx b/libxsde/xsde/cxx/parser/non-validating/ncname.hxx new file mode 100644 index 0000000..61a6a65 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/ncname.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_ncname (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NCNAME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/negative-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/negative-integer.cxx new file mode 100644 index 0000000..7121020 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/negative-integer.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/parser/non-validating/negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long negative_integer_pimpl:: + post_negative_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (ul == static_cast<unsigned long> (LONG_MIN)) + ? LONG_MIN : -static_cast<long> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/negative-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/negative-integer.hxx new file mode 100644 index 0000000..b7ee9e0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/negative-integer.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length negative integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct negative_integer_pimpl: virtual negative_integer_pskel, number +#else + struct negative_integer_pimpl: negative_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_negative_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.cxx new file mode 100644 index 0000000..ce9df4b --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/nmtoken-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void nmtoken_pimpl:: + _pre () + { + str_.erase (); + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string nmtoken_pimpl:: + post_nmtoken () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.hxx new file mode 100644 index 0000000..770bfba --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/nmtoken-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_nmtoken (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken.cxx new file mode 100644 index 0000000..63888c7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/nmtoken.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void nmtoken_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* nmtoken_pimpl:: + post_nmtoken () + { + ro_string tmp (str_.data (), str_.size ()); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtoken.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtoken.hxx new file mode 100644 index 0000000..a76eead --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtoken.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/nmtoken.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_nmtoken (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.cxx new file mode 100644 index 0000000..5b8186d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.cxx @@ -0,0 +1,90 @@ +// file : xsde/cxx/parser/non-validating/nmtokens-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/nmtokens-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + seq_->push_back (parser_.post_nmtoken ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.hxx new file mode 100644 index 0000000..8c90877 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens-stl.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/nmtokens-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_STL_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens.cxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens.cxx new file mode 100644 index 0000000..4cf41be --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens.cxx @@ -0,0 +1,129 @@ +// file : xsde/cxx/parser/non-validating/nmtokens.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/nmtokens.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + +#ifdef XSDE_EXCEPTIONS + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + parser_.pre (); + parser_._pre_impl (_context ()); + parser_._characters (s); + parser_._post_impl (); + + // push_back() frees the string if it throws. + // + seq_->push_back (parser_.post_nmtoken ()); + } +#else + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); + + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_nmtoken (); + + if (!parser_._error_type ()) + { + // push_back() frees the string if it fails. + // + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); + } + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/nmtokens.hxx b/libxsde/xsde/cxx/parser/non-validating/nmtokens.hxx new file mode 100644 index 0000000..f8b3a19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/nmtokens.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/non-validating/nmtokens.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/non-validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NMTOKENS_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.cxx new file mode 100644 index 0000000..463c6c6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/non-negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/non-negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void non_negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long non_negative_integer_pimpl:: + post_non_negative_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoul (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.hxx new file mode 100644 index 0000000..b7cf3f7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-negative-integer.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/non-negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length non-negative integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel, +#else + struct non_negative_integer_pimpl: non_negative_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long + post_non_negative_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.cxx new file mode 100644 index 0000000..c218a77 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/non-positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/parser/non-validating/non-positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void non_positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 20); + } + + long non_positive_integer_pimpl:: + post_non_positive_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + unsigned long ul = strtoul (str_, 0, 10); + + return (ul == static_cast<unsigned long> (LONG_MIN)) + ? LONG_MIN : -static_cast<long> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.hxx new file mode 100644 index 0000000..a6cefab --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/non-positive-integer.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/non-validating/non-positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length non-positive integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel, +#else + struct non_positive_integer_pimpl: non_positive_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual long + post_non_positive_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.cxx new file mode 100644 index 0000000..2b1ff1a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/normalized-string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/normalized-string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void normalized_string_pimpl:: + _pre () + { + str_.erase (); + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string normalized_string_pimpl:: + post_normalized_string () + { + std::string::size_type size = str_.size (); + + for (std::string::size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.hxx new file mode 100644 index 0000000..8544ac3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/normalized-string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_normalized_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string.cxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string.cxx new file mode 100644 index 0000000..b00b6c7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/non-validating/normalized-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/normalized-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void normalized_string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* normalized_string_pimpl:: + post_normalized_string () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + + for (size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/normalized-string.hxx b/libxsde/xsde/cxx/parser/non-validating/normalized-string.hxx new file mode 100644 index 0000000..8953729 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/normalized-string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/normalized-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_normalized_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NORMALIZED_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/number.cxx b/libxsde/xsde/cxx/parser/non-validating/number.cxx new file mode 100644 index 0000000..c271ab5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/number.cxx @@ -0,0 +1,127 @@ +// file : xsde/cxx/parser/non-validating/number.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/parser/non-validating/number.hxx> + +using xsde::cxx::ro_string; + +static bool +trim_leading_zeros (ro_string& s) +{ + ro_string::size_type size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size; + const char* of = f; + + while (f < l && *f == '0') + ++f; + + if (f != of) + { + s.assign ((f <= l ? f : 0), (f <= l ? l - f : 0)); + return true; + } + } + + return false; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void number:: + parse (const ro_string& s, char* str, size_t max) + { + ro_string tmp (s.data (), s.size ()); + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = sign; + else + break; + // Fall through. + } + case sign: + { + if (tmp[0] == '-') + sign_ = minus; + else if (tmp[0] == '+') + sign_ = plus; + + if (sign_ != none) + tmp.assign (tmp.data () + 1, --size); + + if (size != 0) + state_ = leading_zeros; + else + break; + + // Fall through. + } + case leading_zeros: + { + if (trim_leading_zeros (tmp)) + { + if (size_ == 0) + { + str[0] = '0'; + size_ = 1; + } + + size = tmp.size (); + } + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((max - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((max - size_) >= size) + { + memcpy (str + size_, tmp.data (), size); + size_ += size; + } + + break; + } + case trailing_ws: + { + // We don't really care if it is not. + break; + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/number.hxx b/libxsde/xsde/cxx/parser/non-validating/number.hxx new file mode 100644 index 0000000..793f9b9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/number.hxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/parser/non-validating/number.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_NUMBER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_NUMBER_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/ro-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + class number + { + protected: + void + parse (const ro_string&, char* str, size_t max); + + protected: + size_t size_; + enum {leading_ws, sign, leading_zeros, literal, trailing_ws} state_; + enum {none, plus, minus} sign_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_NUMBER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.cxx b/libxsde/xsde/cxx/parser/non-validating/parser.cxx new file mode 100644 index 0000000..21a15e7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/parser.cxx @@ -0,0 +1,473 @@ +// file : xsde/cxx/parser/non-validating/parser.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/parser/non-validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // empty_content + // + +#ifdef XSDE_POLYMORPHIC + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const char*) + { + return false; + } +#else + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&) + { + return false; + } +#endif + + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + // + // +#ifdef XSDE_POLYMORPHIC + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + _start_any_element (ns, name, type); + } +#else + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + _start_any_element (ns, name); + } +#endif + + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _end_any_element (ns, name); + } + + static const char + xmlns_namespace_[] = "http://www.w3.org/2000/xmlns/"; + + static const char + xsi_namespace_[] = "http://www.w3.org/2001/XMLSchema-instance"; + + static const char + type_[] = "type"; + + static const char + nil_[] = "nil"; + + static const char + schema_location_[] = "schemaLocation"; + + static const char + no_namespace_schema_location_[] = "noNamespaceSchemaLocation"; + + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + void empty_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _any_characters (s); + } + + + // simple_content + // + + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + void simple_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _any_characters (s); + } + + + // complex_content + // + +#ifdef XSDE_POLYMORPHIC + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + { + context& c = _context (); + + c.current_.any_ = true; + c.current_.depth_++; + + _start_any_element (ns, name, type); + } + } +#else + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + { + context& c = _context (); + + c.current_.any_ = true; + c.current_.depth_++; + + _start_any_element (ns, name); + } + } +#endif + + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _end_any_element (ns, name); + } + + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _any_attribute (ns, name, value); + } + + void complex_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _any_characters (s); + } + + void complex_content:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + if (depth_++ == 0) + context_ = &c; + +#ifdef XSDE_EXCEPTIONS + parser_stack_.push (c.current_); +#else + if (parser_stack_.push (c.current_)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + } + + void complex_content:: + _post_impl () + { +#ifndef XSDE_EXCEPTIONS + if (!context_->error_type ()) +#endif + _post (); + + context_->current_ = parser_stack_.top (); + parser_stack_.pop (); + + if (--depth_ == 0) + context_ = 0; + } + + void complex_content:: + _reset () + { + empty_content::_reset (); + + depth_ = 0; + parser_stack_.clear (); + } + + // list_base + // + + // Find first non-space character. + // + static ro_string::size_type + find_ns (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + (s[pos] == 0x20 || s[pos] == 0x0A || + s[pos] == 0x0D || s[pos] == 0x09)) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Find first space character. + // + static ro_string::size_type + find_s (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + s[pos] != 0x20 && s[pos] != 0x0A && + s[pos] != 0x0D && s[pos] != 0x09) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + void list_base:: + _pre_impl (context& c) + { + simple_content::_pre_impl (c); + +#ifdef XSDE_EXCEPTIONS + buf_.assign ("", 0); +#else + if (!c.error_type ()) + { + if (buf_.assign ("", 0)) + _sys_error (sys_error::no_memory); + } +#endif + } + + void list_base:: + _characters (const ro_string& s) + { + typedef ro_string::size_type size_type; + + const char* data = s.data (); + size_type size = s.size (); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == 0x20 || data[0] == 0x0A || + data[0] == 0x0D || data[0] == 0x09)) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + buf_.assign ("", 0); // Can't fail. + } + +#ifndef XSDE_EXCEPTIONS + context& ctx = _context (); +#endif + + // Traverse the data while logically collapsing spaces. + // + for (size_type i = find_ns (data, size, 0); i != ro_string::npos;) + { + size_type j = find_s (data, size, i); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string tmp (data + i, j - i); // Private copy ctor. + _xsde_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + string str; + str.swap (buf_); + +#ifdef XSDE_EXCEPTIONS + str.append (data + i, j - i); +#else + if (str.append (data + i, j - i)) + { + _sys_error (sys_error::no_memory); + break; + } +#endif + ro_string tmp (str); // Private copy ctor. + _xsde_parse_item (tmp); + } + +#ifndef XSDE_EXCEPTIONS + if (ctx.error_type ()) + break; +#endif + + i = find_ns (data, size, j); + } + else + { + // Last fragment, append it to buf_. + // +#ifdef XSDE_EXCEPTIONS + buf_.append (data + i, size - i); +#else + if (buf_.append (data + i, size - i)) + _sys_error (sys_error::no_memory); +#endif + break; + } + } + } + + void list_base:: + _xsde_parse_item (const ro_string&) + { + } + + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.hxx b/libxsde/xsde/cxx/parser/non-validating/parser.hxx new file mode 100644 index 0000000..6b9889a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/parser.hxx @@ -0,0 +1,196 @@ +// file : xsde/cxx/parser/non-validating/parser.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_PARSER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_PARSER_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/cxx/string.hxx> +#include <xsde/cxx/ro-string.hxx> + +#include <xsde/cxx/parser/elements.hxx> +#include <xsde/cxx/parser/state.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + struct empty_content: parser_base + { + // + // +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, + const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + empty_content (); + empty_content (empty_content* impl, void*); +#endif + }; + + + // + // + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + simple_content (); + simple_content (simple_content* impl, void*); +#endif + }; + + + // + // + struct complex_content: empty_content + { +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + + // + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + + // + // + virtual void + _reset (); + + // + // + complex_content (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + complex_content (complex_content* impl, void*); +#endif + protected: + size_t depth_; + parser_stack parser_stack_; + }; + + // Base for xsd:list. + // + struct list_base: simple_content + { + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _pre_impl (context&); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + list_base (); + list_base (list_base* impl, void*); +#endif + protected: + string buf_; + }; + } + } + } +} + +#include <xsde/cxx/parser/non-validating/parser.ixx> + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_PARSER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/parser.ixx b/libxsde/xsde/cxx/parser/non-validating/parser.ixx new file mode 100644 index 0000000..95f085d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/parser.ixx @@ -0,0 +1,77 @@ +// file : xsde/cxx/parser/non-validating/parser.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // empty_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline empty_content:: + empty_content () + { + } + + inline empty_content:: + empty_content (empty_content* impl, void*) + : parser_base (impl, 0) + { + } +#endif + + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline simple_content:: + simple_content () + { + } + + inline simple_content:: + simple_content (simple_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + + // complex_content + // + inline complex_content:: + complex_content () + : depth_ (0), parser_stack_ (previous_) + { + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline complex_content:: + complex_content (complex_content* impl, void*) + : empty_content (impl, 0), depth_ (0), parser_stack_ (previous_) + { + } +#endif + + // list_base + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline list_base:: + list_base () + { + } + + inline list_base:: + list_base (list_base* impl, void*) + : simple_content (impl, 0) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/positive-integer.cxx b/libxsde/xsde/cxx/parser/non-validating/positive-integer.cxx new file mode 100644 index 0000000..47f9852 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/positive-integer.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long positive_integer_pimpl:: + post_positive_integer () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoul (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/positive-integer.hxx b/libxsde/xsde/cxx/parser/non-validating/positive-integer.hxx new file mode 100644 index 0000000..fc326e4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/positive-integer.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Arbitrary-length positive integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct positive_integer_pimpl: virtual positive_integer_pskel, number +#else + struct positive_integer_pimpl: positive_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long + post_positive_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/qname-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/qname-stl.cxx new file mode 100644 index 0000000..746959a --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname-stl.cxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/non-validating/qname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/qname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void qname_pimpl:: + _pre () + { + str_.erase (); + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + qname qname_pimpl:: + post_qname () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + if (pos != ro_string::npos) + { + std::string prefix (tmp.data (), pos); + std::string name (tmp.data () + pos + 1, size - pos - 1); + return qname (prefix, name); + } + else + { + str_.resize (size); + return qname (str_); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/qname-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/qname-stl.hxx new file mode 100644 index 0000000..7671400 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_QNAME_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_QNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual qname + post_qname (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/qname.cxx b/libxsde/xsde/cxx/parser/non-validating/qname.cxx new file mode 100644 index 0000000..87f03e8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname.cxx @@ -0,0 +1,153 @@ +// file : xsde/cxx/parser/non-validating/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/qname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + qname_pimpl:: + ~qname_pimpl () + { + if (!base_) + delete qn_; + } + + void qname_pimpl:: + _reset () + { + qname_pskel::_reset (); + + if (!base_) + { + delete qn_; + qn_ = 0; + } + } + + qname_pimpl:: + qname_pimpl (bool base) + : base_ (base), qn_ (0) + { + } + + void qname_pimpl:: + pre_impl (qname* qn) + { + qn_ = qn; + } + + void qname_pimpl:: + _pre () + { + if (qn_ == 0) + { + qn_ = new qname (); + +#ifndef XSDE_EXCEPTIONS + if (qn_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + qname* qname_pimpl:: + post_qname () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + const char* s = tmp.data (); + + string prefix; + string name; + + if (pos != ro_string::npos) + { +#ifdef XSDE_EXCEPTIONS + prefix.assign (s, pos); + name.assign (s + pos + 1, size - pos - 1); +#else + if (prefix.assign (s, pos) || + name.assign (s + pos + 1, size - pos - 1)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + } + else + { +#ifdef XSDE_EXCEPTIONS + prefix.assign ("", 0); +#else + if (prefix.assign ("", 0)) + { + _sys_error (sys_error::no_memory); + return 0; + } +#endif + str_.truncate (size); + name.swap (str_); + } + + qn_->prefix (prefix.detach ()); + qn_->name (name.detach ()); + + qname* r = qn_; + qn_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/qname.hxx b/libxsde/xsde/cxx/parser/non-validating/qname.hxx new file mode 100644 index 0000000..257eaf4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/qname.hxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/parser/non-validating/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_QNAME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_QNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + ~qname_pimpl (); + qname_pimpl (bool base = false); + + void + pre_impl (qname*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual qname* + post_qname (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + qname* qn_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_QNAME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/short.cxx b/libxsde/xsde/cxx/parser/non-validating/short.cxx new file mode 100644 index 0000000..70f401d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/short.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void short_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 6); + } + + short short_pimpl:: + post_short () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + unsigned long ul = strtoul (str_, 0, 10); + + return (sign_ == minus) + ? static_cast<short> (-static_cast<int> (ul)) + : static_cast<short> (ul); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/short.hxx b/libxsde/xsde/cxx/parser/non-validating/short.hxx new file mode 100644 index 0000000..8417a94 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/short.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_SHORT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_SHORT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 16-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct short_pimpl: virtual short_pskel, number +#else + struct short_pimpl: short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual short + post_short (); + + protected: + // We only need strlen("032768") + 1 characters to hold all valid + // and trimmed string representations of short. + // + char str_[7]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/string-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/string-stl.cxx new file mode 100644 index 0000000..7864648 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/parser/non-validating/string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void string_pimpl:: + _pre () + { + str_.erase (); + } + + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string string_pimpl:: + post_string () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/string-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/string-stl.hxx new file mode 100644 index 0000000..aaab4ba --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_STRING_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/string.cxx b/libxsde/xsde/cxx/parser/non-validating/string.cxx new file mode 100644 index 0000000..9d5f083 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* string_pimpl:: + post_string () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/string.hxx b/libxsde/xsde/cxx/parser/non-validating/string.hxx new file mode 100644 index 0000000..de48551 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_STRING_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx b/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx new file mode 100644 index 0000000..3465045 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time-zone.cxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/non-validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + namespace bits + { + void + parse_time_zone (const char* s, size_t n, short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return; + } + else if (s[0] == 'Z') + { + h = 0; + m = 0; + } + else if (n == 6) + { + // Parse hours. + // + h = 10 * (s[1] - '0') + (s[2] - '0'); + + // Parse minutes. + // + m = 10 * (s[4] - '0') + (s[5] - '0'); + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/time-zone.hxx b/libxsde/xsde/cxx/parser/non-validating/time-zone.hxx new file mode 100644 index 0000000..9a3363c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time-zone.hxx @@ -0,0 +1,32 @@ +// file : xsde/cxx/parser/non-validating/time-zone.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TIME_ZONE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TIME_ZONE_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + namespace bits + { + void + parse_time_zone (const char* s, + size_t size, + short& hours, + short& minutes); + } + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TIME_ZONE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/time.cxx b/libxsde/xsde/cxx/parser/non-validating/time.cxx new file mode 100644 index 0000000..a2ad5d3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time.cxx @@ -0,0 +1,118 @@ +// file : xsde/cxx/parser/non-validating/time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/time.hxx> +#include <xsde/cxx/parser/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + time time_pimpl:: + post_time () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + unsigned short hours = 0; + unsigned short minutes = 0; + double seconds = 0.0; + bool zone = false; + short zh, zm; + + if (n >= 8) + { + // hours + // + hours = 10 * (s[0] - '0') + (s[1] - '0'); + + // minutes + // + minutes = 10 * (s[3] - '0') + (s[4] - '0'); + + // Find the end of the seconds fragment. + // + ro_string::size_type pos = 8; + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + bits::parse_time_zone (s + pos, n - pos, zh, zm); + zone = true; + } + + // seconds + // + str_.truncate (pos); + seconds = strtod (s + 6, 0); + } + + return zone + ? time (hours, minutes, seconds, zh, zm) + : time (hours, minutes, seconds); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/time.hxx b/libxsde/xsde/cxx/parser/non-validating/time.hxx new file mode 100644 index 0000000..7526414 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/time.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TIME_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct time_pimpl: virtual time_pskel +#else + struct time_pimpl: time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual time + post_time (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/token-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/token-stl.cxx new file mode 100644 index 0000000..e975ae3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token-stl.cxx @@ -0,0 +1,73 @@ +// file : xsde/cxx/parser/non-validating/token-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/token-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void token_pimpl:: + _pre () + { + str_.erase (); + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string token_pimpl:: + post_token () + { + std::string::size_type size = str_.size (); + std::string::size_type j = 0; + + bool subs = false; + + for (std::string::size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/token-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/token-stl.hxx new file mode 100644 index 0000000..0f3a288 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/token-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_token (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/token.cxx b/libxsde/xsde/cxx/parser/non-validating/token.cxx new file mode 100644 index 0000000..ffc1b4d --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token.cxx @@ -0,0 +1,94 @@ +// file : xsde/cxx/parser/non-validating/token.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/token.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void token_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* token_pimpl:: + post_token () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + size_type j = 0; + + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.truncate (j); + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/token.hxx b/libxsde/xsde/cxx/parser/non-validating/token.hxx new file mode 100644 index 0000000..22d9f59 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/token.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/token.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_token (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_TOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.cxx new file mode 100644 index 0000000..11e6dd5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 4); + } + + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + return static_cast<unsigned char> (strtoul (str_, 0, 10)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.hxx new file mode 100644 index 0000000..ed54cd0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-byte.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_BYTE_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_BYTE_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 8-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel, number +#else + struct unsigned_byte_pimpl: unsigned_byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned char + post_unsigned_byte (); + + protected: + // We only need strlen("0256") + 1 characters to hold all valid + // and trimmed string representations of unsigned byte. + // + char str_[5]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-int.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.cxx new file mode 100644 index 0000000..e14e091 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 11); + } + + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return static_cast<unsigned int> (strtoul (str_, 0, 10)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-int.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.hxx new file mode 100644 index 0000000..4cce2b0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-int.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_INT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_INT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 32-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_int_pimpl: virtual unsigned_int_pskel, number +#else + struct unsigned_int_pimpl: unsigned_int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned int + post_unsigned_int (); + + protected: + // We only need strlen("04294967295") + 1 characters to hold all + // valid and trimmed string representations of unsigned int. + // + char str_[12]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_INT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.cxx new file mode 100644 index 0000000..908066c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/parser/non-validating/unsigned-long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoull (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.hxx new file mode 100644 index 0000000..8957135 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long-long.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 64-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.cxx new file mode 100644 index 0000000..8f70812 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 21); + } + + unsigned long unsigned_long_pimpl:: + post_unsigned_long () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + str_[size] = '\0'; + + return strtoul (str_, 0, 10); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-long.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.hxx new file mode 100644 index 0000000..45c976f --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-long.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-short.cxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.cxx new file mode 100644 index 0000000..2044611 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/unsigned-short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/non-validating/unsigned-short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void unsigned_short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + parse (s, str_, 6); + } + + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + str_[size] = '\0'; + return static_cast<unsigned short> (strtoul (str_, 0, 10)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/unsigned-short.hxx b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.hxx new file mode 100644 index 0000000..26b97ce --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/unsigned-short.hxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/non-validating/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_SHORT_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_SHORT_HXX + +#include <xsde/cxx/parser/non-validating/number.hxx> +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // 16-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_short_pimpl: virtual unsigned_short_pskel, number +#else + struct unsigned_short_pimpl: unsigned_short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual unsigned short + post_unsigned_short (); + + protected: + // We only need strlen("065535") + 1 characters to hold all valid + // and trimmed string representations of unsigned short. + // + char str_[7]; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_UNSIGNED_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/uri-stl.cxx b/libxsde/xsde/cxx/parser/non-validating/uri-stl.cxx new file mode 100644 index 0000000..369f448 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri-stl.cxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/non-validating/uri-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/uri-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void uri_pimpl:: + _pre () + { + str_.erase (); + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string uri_pimpl:: + post_uri () + { + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/uri-stl.hxx b/libxsde/xsde/cxx/parser/non-validating/uri-stl.hxx new file mode 100644 index 0000000..351c513 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/uri-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_URI_STL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_URI_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_uri (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_URI_STL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/uri.cxx b/libxsde/xsde/cxx/parser/non-validating/uri.cxx new file mode 100644 index 0000000..2edb794 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/parser/non-validating/uri.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/non-validating/uri.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + void uri_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* uri_pimpl:: + post_uri () + { + ro_string tmp (str_); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/non-validating/uri.hxx b/libxsde/xsde/cxx/parser/non-validating/uri.hxx new file mode 100644 index 0000000..245c493 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/uri.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/non-validating/uri.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_URI_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_URI_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_uri (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_URI_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..e51cff0 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx @@ -0,0 +1,82 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +#include <xsde/cxx/parser/non-validating/any-type.hxx> +#include <xsde/cxx/parser/non-validating/boolean.hxx> +#include <xsde/cxx/parser/non-validating/byte.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/non-validating/byte.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/non-validating/short.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-short.hxx> +#include <xsde/cxx/parser/non-validating/int.hxx> +#include <xsde/cxx/parser/non-validating/unsigned-int.hxx> + +#ifdef XSDE_LONGLONG +# include <xsde/cxx/parser/non-validating/long-long.hxx> +# include <xsde/cxx/parser/non-validating/unsigned-long-long.hxx> +#else +# include <xsde/cxx/parser/non-validating/long.hxx> +# include <xsde/cxx/parser/non-validating/unsigned-long.hxx> +#endif + +#include <xsde/cxx/parser/non-validating/integer.hxx> +#include <xsde/cxx/parser/non-validating/negative-integer.hxx> +#include <xsde/cxx/parser/non-validating/non-positive-integer.hxx> +#include <xsde/cxx/parser/non-validating/positive-integer.hxx> +#include <xsde/cxx/parser/non-validating/non-negative-integer.hxx> +#include <xsde/cxx/parser/non-validating/float.hxx> +#include <xsde/cxx/parser/non-validating/double.hxx> +#include <xsde/cxx/parser/non-validating/decimal.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/parser/non-validating/string-stl.hxx> +# include <xsde/cxx/parser/non-validating/normalized-string-stl.hxx> +# include <xsde/cxx/parser/non-validating/token-stl.hxx> +# include <xsde/cxx/parser/non-validating/name-stl.hxx> +# include <xsde/cxx/parser/non-validating/nmtoken-stl.hxx> +# include <xsde/cxx/parser/non-validating/nmtokens-stl.hxx> +# include <xsde/cxx/parser/non-validating/ncname-stl.hxx> +# include <xsde/cxx/parser/non-validating/id-stl.hxx> +# include <xsde/cxx/parser/non-validating/idref-stl.hxx> +# include <xsde/cxx/parser/non-validating/idrefs-stl.hxx> +# include <xsde/cxx/parser/non-validating/language-stl.hxx> +# include <xsde/cxx/parser/non-validating/uri-stl.hxx> +# include <xsde/cxx/parser/non-validating/qname-stl.hxx> +#else +# include <xsde/cxx/parser/non-validating/string.hxx> +# include <xsde/cxx/parser/non-validating/normalized-string.hxx> +# include <xsde/cxx/parser/non-validating/token.hxx> +# include <xsde/cxx/parser/non-validating/name.hxx> +# include <xsde/cxx/parser/non-validating/nmtoken.hxx> +# include <xsde/cxx/parser/non-validating/nmtokens.hxx> +# include <xsde/cxx/parser/non-validating/ncname.hxx> +# include <xsde/cxx/parser/non-validating/id.hxx> +# include <xsde/cxx/parser/non-validating/idref.hxx> +# include <xsde/cxx/parser/non-validating/idrefs.hxx> +# include <xsde/cxx/parser/non-validating/language.hxx> +# include <xsde/cxx/parser/non-validating/uri.hxx> +# include <xsde/cxx/parser/non-validating/qname.hxx> +#endif + +#include <xsde/cxx/parser/non-validating/base64-binary.hxx> +#include <xsde/cxx/parser/non-validating/hex-binary.hxx> + +#include <xsde/cxx/parser/non-validating/gday.hxx> +#include <xsde/cxx/parser/non-validating/gmonth.hxx> +#include <xsde/cxx/parser/non-validating/gyear.hxx> +#include <xsde/cxx/parser/non-validating/gmonth-day.hxx> +#include <xsde/cxx/parser/non-validating/gyear-month.hxx> +#include <xsde/cxx/parser/non-validating/date.hxx> +#include <xsde/cxx/parser/non-validating/time.hxx> +#include <xsde/cxx/parser/non-validating/date-time.hxx> +#include <xsde/cxx/parser/non-validating/duration.hxx> + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PIMPL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.cxx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.cxx new file mode 100644 index 0000000..39138a1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.cxx @@ -0,0 +1,612 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pskel.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type and any_simple_type + // + // In non-validating case we can simply return false from *_impl + // functions which will result in calls to the corresponding + // _any_* callbacks. + // + // + +#ifdef XSDE_POLYMORPHIC + bool any_type_pskel:: + _start_element_impl (const ro_string&, + const ro_string&, + const char*) + { + return false; + } +#else + bool any_type_pskel:: + _start_element_impl (const ro_string&, const ro_string&) + { + return false; + } +#endif + + + bool any_type_pskel:: + _end_element_impl (const ro_string&, const ro_string&) + { + return false; + } + + bool any_type_pskel:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool any_type_pskel:: + _characters_impl (const ro_string&) + { + return false; + } + + void any_type_pskel:: + post_any_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_type_impl_) + any_type_impl_->post_any_type (); +#endif + } + + // any_simple_type + // + + bool any_simple_type_pskel:: + _characters_impl (const ro_string&) + { + return false; + } + + void any_simple_type_pskel:: + post_any_simple_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_simple_type_impl_) + any_simple_type_impl_->post_any_simple_type (); +#endif + } + + // static/dynamic_type function implementations. + // + +#ifdef XSDE_POLYMORPHIC + const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + const char* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif // XSDE_POLYMORPHIC + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.hxx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..0792936 --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.hxx @@ -0,0 +1,1388 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/parser/xml-schema.hxx> + +#include <xsde/cxx/parser/non-validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + + struct any_type_pskel: complex_content + { +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, + const ro_string&); +#endif + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_pskel (); + any_type_pskel (any_type_pskel* impl, void*); + + protected: + any_type_pskel* any_type_impl_; +#endif + }; + + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_simple_type_pskel (); + any_simple_type_pskel (any_simple_type_pskel* impl, void*); + + protected: + any_simple_type_pskel* any_simple_type_impl_; +#endif + }; + + + // Boolean. + // + + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + boolean_pskel (); + boolean_pskel (boolean_pskel* impl, void*); + + protected: + boolean_pskel* boolean_impl_; +#endif + }; + + + // 8-bit + // + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + byte_pskel (); + byte_pskel (byte_pskel* impl, void*); + + protected: + byte_pskel* byte_impl_; +#endif + }; + + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_byte_pskel (); + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*); + + protected: + unsigned_byte_pskel* unsigned_byte_impl_; +#endif + }; + + + // 16-bit + // + + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + short_pskel (); + short_pskel (short_pskel* impl, void*); + + protected: + short_pskel* short_impl_; +#endif + }; + + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_short_pskel (); + unsigned_short_pskel (unsigned_short_pskel* impl, void*); + + protected: + unsigned_short_pskel* unsigned_short_impl_; +#endif + }; + + + // 32-bit + // + + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + int_pskel (); + int_pskel (int_pskel* impl, void*); + + protected: + int_pskel* int_impl_; +#endif + }; + + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_int_pskel (); + unsigned_int_pskel (unsigned_int_pskel* impl, void*); + + protected: + unsigned_int_pskel* unsigned_int_impl_; +#endif + }; + + + // 64-bit + // +#ifdef XSDE_LONGLONG + + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; + +#else + + struct long_pskel: simple_content + { + virtual long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; +#endif + + + // Arbitrary-length integers. + // + + struct integer_pskel: simple_content + { + virtual long + post_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + integer_pskel (); + integer_pskel (integer_pskel* impl, void*); + + protected: + integer_pskel* integer_impl_; +#endif + }; + + struct negative_integer_pskel: simple_content + { + virtual long + post_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + negative_integer_pskel (); + negative_integer_pskel (negative_integer_pskel* impl, void*); + + protected: + negative_integer_pskel* negative_integer_impl_; +#endif + }; + + struct non_positive_integer_pskel: simple_content + { + virtual long + post_non_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_positive_integer_pskel (); + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*); + + protected: + non_positive_integer_pskel* non_positive_integer_impl_; +#endif + }; + + struct positive_integer_pskel: simple_content + { + virtual unsigned long + post_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + positive_integer_pskel (); + positive_integer_pskel (positive_integer_pskel* impl, void*); + + protected: + positive_integer_pskel* positive_integer_impl_; +#endif + }; + + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long + post_non_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_negative_integer_pskel (); + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*); + + protected: + non_negative_integer_pskel* non_negative_integer_impl_; +#endif + }; + + + // Floats. + // + + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + float_pskel (); + float_pskel (float_pskel* impl, void*); + + protected: + float_pskel* float_impl_; +#endif + }; + + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + double_pskel (); + double_pskel (double_pskel* impl, void*); + + protected: + double_pskel* double_impl_; +#endif + }; + + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + decimal_pskel (); + decimal_pskel (decimal_pskel* impl, void*); + + protected: + decimal_pskel* decimal_impl_; +#endif + }; + + + // String-based types. + // +#ifdef XSDE_STL + + struct string_pskel: simple_content + { + virtual std::string + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual std::string + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual std::string + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual std::string + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual std::string + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual std::string + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual std::string + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual std::string + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual std::string + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual std::string + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; + +#else // XSDE_STL + + // Note that in this case you are getting a C string that you + // have to delete with delete[]. + // + + struct string_pskel: simple_content + { + virtual char* + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual char* + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual char* + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual char* + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual char* + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual char* + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual char* + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual char* + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual char* + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual char* + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname* + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; +#endif // XSDE_STL + + + // base64Binary + // + struct base64_binary_pskel: simple_content + { + virtual buffer* + post_base64_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + base64_binary_pskel (); + base64_binary_pskel (base64_binary_pskel* impl, void*); + + protected: + base64_binary_pskel* base64_binary_impl_; +#endif + }; + + // hexBinary + // + struct hex_binary_pskel: simple_content + { + virtual buffer* + post_hex_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + hex_binary_pskel (); + hex_binary_pskel (hex_binary_pskel* impl, void*); + + protected: + hex_binary_pskel* hex_binary_impl_; +#endif + }; + + // Time and date types. + // + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gday_pskel (); + gday_pskel (gday_pskel* impl, void*); + + protected: + gday_pskel* gday_impl_; +#endif + }; + + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_pskel (); + gmonth_pskel (gmonth_pskel* impl, void*); + + protected: + gmonth_pskel* gmonth_impl_; +#endif + }; + + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_pskel (); + gyear_pskel (gyear_pskel* impl, void*); + + protected: + gyear_pskel* gyear_impl_; +#endif + }; + + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_day_pskel (); + gmonth_day_pskel (gmonth_day_pskel* impl, void*); + + protected: + gmonth_day_pskel* gmonth_day_impl_; +#endif + }; + + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_month_pskel (); + gyear_month_pskel (gyear_month_pskel* impl, void*); + + protected: + gyear_month_pskel* gyear_month_impl_; +#endif + }; + + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_pskel (); + date_pskel (date_pskel* impl, void*); + + protected: + date_pskel* date_impl_; +#endif + }; + + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + time_pskel (); + time_pskel (time_pskel* impl, void*); + + protected: + time_pskel* time_impl_; +#endif + }; + + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_time_pskel (); + date_time_pskel (date_time_pskel* impl, void*); + + protected: + date_time_pskel* date_time_impl_; +#endif + }; + + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + duration_pskel (); + duration_pskel (duration_pskel* impl, void*); + + protected: + duration_pskel* duration_impl_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/parser/non-validating/xml-schema-pskel.ixx> + +#endif // XSDE_CXX_PARSER_NON_VALIDATING_XML_SCHEMA_PSKEL_HXX diff --git a/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.ixx b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..220464c --- /dev/null +++ b/libxsde/xsde/cxx/parser/non-validating/xml-schema-pskel.ixx @@ -0,0 +1,704 @@ +// file : xsde/cxx/parser/non-validating/xml-schema-pskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace non_validating + { + // any_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_pskel:: + any_type_pskel () + : any_type_impl_ (0) + { + } + + inline any_type_pskel:: + any_type_pskel (any_type_pskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + + // any_simple_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_simple_type_pskel:: + any_simple_type_pskel () + : any_simple_type_impl_ (0) + { + } + + inline any_simple_type_pskel:: + any_simple_type_pskel (any_simple_type_pskel* impl, void*) + : simple_content (impl, 0), any_simple_type_impl_ (impl) + { + } +#endif + + // boolean_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline boolean_pskel:: + boolean_pskel () + : boolean_impl_ (0) + { + } + + inline boolean_pskel:: + boolean_pskel (boolean_pskel* impl, void*) + : simple_content (impl, 0), boolean_impl_ (impl) + { + } +#endif + + // byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline byte_pskel:: + byte_pskel () + : byte_impl_ (0) + { + } + + inline byte_pskel:: + byte_pskel (byte_pskel* impl, void*) + : simple_content (impl, 0), byte_impl_ (impl) + { + } +#endif + + // unsigned_byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_byte_pskel:: + unsigned_byte_pskel () + : unsigned_byte_impl_ (0) + { + } + + inline unsigned_byte_pskel:: + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*) + : simple_content (impl, 0), unsigned_byte_impl_ (impl) + { + } +#endif + + // short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline short_pskel:: + short_pskel () + : short_impl_ (0) + { + } + + inline short_pskel:: + short_pskel (short_pskel* impl, void*) + : simple_content (impl, 0), short_impl_ (impl) + { + } +#endif + + // unsigned_short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_short_pskel:: + unsigned_short_pskel () + : unsigned_short_impl_ (0) + { + } + + inline unsigned_short_pskel:: + unsigned_short_pskel (unsigned_short_pskel* impl, void*) + : simple_content (impl, 0), unsigned_short_impl_ (impl) + { + } +#endif + + // int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline int_pskel:: + int_pskel () + : int_impl_ (0) + { + } + + inline int_pskel:: + int_pskel (int_pskel* impl, void*) + : simple_content (impl, 0), int_impl_ (impl) + { + } +#endif + + // unsigned_int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_int_pskel:: + unsigned_int_pskel () + : unsigned_int_impl_ (0) + { + } + + inline unsigned_int_pskel:: + unsigned_int_pskel (unsigned_int_pskel* impl, void*) + : simple_content (impl, 0), unsigned_int_impl_ (impl) + { + } +#endif + + // long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline long_pskel:: + long_pskel () + : long_impl_ (0) + { + } + + inline long_pskel:: + long_pskel (long_pskel* impl, void*) + : simple_content (impl, 0), long_impl_ (impl) + { + } +#endif + + // unsigned_long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_long_pskel:: + unsigned_long_pskel () + : unsigned_long_impl_ (0) + { + } + + inline unsigned_long_pskel:: + unsigned_long_pskel (unsigned_long_pskel* impl, void*) + : simple_content (impl, 0), unsigned_long_impl_ (impl) + { + } +#endif + + // integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline integer_pskel:: + integer_pskel () + : integer_impl_ (0) + { + } + + inline integer_pskel:: + integer_pskel (integer_pskel* impl, void*) + : simple_content (impl, 0), integer_impl_ (impl) + { + } +#endif + + // negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline negative_integer_pskel:: + negative_integer_pskel () + : negative_integer_impl_ (0) + { + } + + inline negative_integer_pskel:: + negative_integer_pskel (negative_integer_pskel* impl, void*) + : simple_content (impl, 0), negative_integer_impl_ (impl) + { + } +#endif + + // non_positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_positive_integer_pskel:: + non_positive_integer_pskel () + : non_positive_integer_impl_ (0) + { + } + + inline non_positive_integer_pskel:: + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*) + : simple_content (impl, 0), non_positive_integer_impl_ (impl) + { + } +#endif + + // positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline positive_integer_pskel:: + positive_integer_pskel () + : positive_integer_impl_ (0) + { + } + + inline positive_integer_pskel:: + positive_integer_pskel (positive_integer_pskel* impl, void*) + : simple_content (impl, 0), positive_integer_impl_ (impl) + { + } +#endif + + // non_negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_negative_integer_pskel:: + non_negative_integer_pskel () + : non_negative_integer_impl_ (0) + { + } + + inline non_negative_integer_pskel:: + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*) + : simple_content (impl, 0), non_negative_integer_impl_ (impl) + { + } +#endif + + // float_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline float_pskel:: + float_pskel () + : float_impl_ (0) + { + } + + inline float_pskel:: + float_pskel (float_pskel* impl, void*) + : simple_content (impl, 0), float_impl_ (impl) + { + } +#endif + + // double_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline double_pskel:: + double_pskel () + : double_impl_ (0) + { + } + + inline double_pskel:: + double_pskel (double_pskel* impl, void*) + : simple_content (impl, 0), double_impl_ (impl) + { + } +#endif + + // decimal_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline decimal_pskel:: + decimal_pskel () + : decimal_impl_ (0) + { + } + + inline decimal_pskel:: + decimal_pskel (decimal_pskel* impl, void*) + : simple_content (impl, 0), decimal_impl_ (impl) + { + } +#endif + + // string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline string_pskel:: + string_pskel () + : string_impl_ (0) + { + } + + inline string_pskel:: + string_pskel (string_pskel* impl, void*) + : simple_content (impl, 0), string_impl_ (impl) + { + } +#endif + + // normalized_string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline normalized_string_pskel:: + normalized_string_pskel () + : normalized_string_impl_ (0) + { + } + + inline normalized_string_pskel:: + normalized_string_pskel (normalized_string_pskel* impl, void*) + : simple_content (impl, 0), normalized_string_impl_ (impl) + { + } +#endif + + // token_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline token_pskel:: + token_pskel () + : token_impl_ (0) + { + } + + inline token_pskel:: + token_pskel (token_pskel* impl, void*) + : simple_content (impl, 0), token_impl_ (impl) + { + } +#endif + + // name_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline name_pskel:: + name_pskel () + : name_impl_ (0) + { + } + + inline name_pskel:: + name_pskel (name_pskel* impl, void*) + : simple_content (impl, 0), name_impl_ (impl) + { + } +#endif + + // nmtoken_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtoken_pskel:: + nmtoken_pskel () + : nmtoken_impl_ (0) + { + } + + inline nmtoken_pskel:: + nmtoken_pskel (nmtoken_pskel* impl, void*) + : simple_content (impl, 0), nmtoken_impl_ (impl) + { + } +#endif + + // nmtokens_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtokens_pskel:: + nmtokens_pskel () + : nmtokens_impl_ (0) + { + } + + inline nmtokens_pskel:: + nmtokens_pskel (nmtokens_pskel* impl, void*) + : list_base (impl, 0), nmtokens_impl_ (impl) + { + } +#endif + + // ncname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline ncname_pskel:: + ncname_pskel () + : ncname_impl_ (0) + { + } + + inline ncname_pskel:: + ncname_pskel (ncname_pskel* impl, void*) + : simple_content (impl, 0), ncname_impl_ (impl) + { + } +#endif + + // id_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline id_pskel:: + id_pskel () + : id_impl_ (0) + { + } + + inline id_pskel:: + id_pskel (id_pskel* impl, void*) + : simple_content (impl, 0), id_impl_ (impl) + { + } +#endif + + // idref_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idref_pskel:: + idref_pskel () + : idref_impl_ (0) + { + } + + inline idref_pskel:: + idref_pskel (idref_pskel* impl, void*) + : simple_content (impl, 0), idref_impl_ (impl) + { + } +#endif + + // idrefs_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idrefs_pskel:: + idrefs_pskel () + : idrefs_impl_ (0) + { + } + + inline idrefs_pskel:: + idrefs_pskel (idrefs_pskel* impl, void*) + : list_base (impl, 0), idrefs_impl_ (impl) + { + } +#endif + + // language_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline language_pskel:: + language_pskel () + : language_impl_ (0) + { + } + + inline language_pskel:: + language_pskel (language_pskel* impl, void*) + : simple_content (impl, 0), language_impl_ (impl) + { + } +#endif + + // uri_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline uri_pskel:: + uri_pskel () + : uri_impl_ (0) + { + } + + inline uri_pskel:: + uri_pskel (uri_pskel* impl, void*) + : simple_content (impl, 0), uri_impl_ (impl) + { + } +#endif + + // qname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline qname_pskel:: + qname_pskel () + : qname_impl_ (0) + { + } + + inline qname_pskel:: + qname_pskel (qname_pskel* impl, void*) + : simple_content (impl, 0), qname_impl_ (impl) + { + } +#endif + + // base64_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline base64_binary_pskel:: + base64_binary_pskel () + : base64_binary_impl_ (0) + { + } + + inline base64_binary_pskel:: + base64_binary_pskel (base64_binary_pskel* impl, void*) + : simple_content (impl, 0), base64_binary_impl_ (impl) + { + } +#endif + + // hex_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline hex_binary_pskel:: + hex_binary_pskel () + : hex_binary_impl_ (0) + { + } + + inline hex_binary_pskel:: + hex_binary_pskel (hex_binary_pskel* impl, void*) + : simple_content (impl, 0), hex_binary_impl_ (impl) + { + } +#endif + + // gday_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gday_pskel:: + gday_pskel () + : gday_impl_ (0) + { + } + + inline gday_pskel:: + gday_pskel (gday_pskel* impl, void*) + : simple_content (impl, 0), gday_impl_ (impl) + { + } +#endif + + // gmonth_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_pskel:: + gmonth_pskel () + : gmonth_impl_ (0) + { + } + + inline gmonth_pskel:: + gmonth_pskel (gmonth_pskel* impl, void*) + : simple_content (impl, 0), gmonth_impl_ (impl) + { + } +#endif + + // gyear_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_pskel:: + gyear_pskel () + : gyear_impl_ (0) + { + } + + inline gyear_pskel:: + gyear_pskel (gyear_pskel* impl, void*) + : simple_content (impl, 0), gyear_impl_ (impl) + { + } +#endif + + // gmonth_day_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_day_pskel:: + gmonth_day_pskel () + : gmonth_day_impl_ (0) + { + } + + inline gmonth_day_pskel:: + gmonth_day_pskel (gmonth_day_pskel* impl, void*) + : simple_content (impl, 0), gmonth_day_impl_ (impl) + { + } +#endif + + // gyear_month_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_month_pskel:: + gyear_month_pskel () + : gyear_month_impl_ (0) + { + } + + inline gyear_month_pskel:: + gyear_month_pskel (gyear_month_pskel* impl, void*) + : simple_content (impl, 0), gyear_month_impl_ (impl) + { + } +#endif + + // date_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_pskel:: + date_pskel () + : date_impl_ (0) + { + } + + inline date_pskel:: + date_pskel (date_pskel* impl, void*) + : simple_content (impl, 0), date_impl_ (impl) + { + } +#endif + + // time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline time_pskel:: + time_pskel () + : time_impl_ (0) + { + } + + inline time_pskel:: + time_pskel (time_pskel* impl, void*) + : simple_content (impl, 0), time_impl_ (impl) + { + } +#endif + + // date_time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_time_pskel:: + date_time_pskel () + : date_time_impl_ (0) + { + } + + inline date_time_pskel:: + date_time_pskel (date_time_pskel* impl, void*) + : simple_content (impl, 0), date_time_impl_ (impl) + { + } +#endif + + // duration_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline duration_pskel:: + duration_pskel () + : duration_impl_ (0) + { + } + + inline duration_pskel:: + duration_pskel (duration_pskel* impl, void*) + : simple_content (impl, 0), duration_impl_ (impl) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/state.cxx b/libxsde/xsde/cxx/parser/state.cxx new file mode 100644 index 0000000..756190e --- /dev/null +++ b/libxsde/xsde/cxx/parser/state.cxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/parser/state.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/parser/state.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + stack::error stack:: + grow () + { + size_t c = capacity_ ? capacity_ * 2 : 8; + char* d = new char[c * el_size_]; + + if (d == 0) + return error_no_memory; + + if (size_ > 1) + memcpy (d, data_, (size_ - 1) * el_size_); + + delete[] data_; + + data_ = d; + capacity_ = c; + + return error_none; + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/state.hxx b/libxsde/xsde/cxx/parser/state.hxx new file mode 100644 index 0000000..11ace8d --- /dev/null +++ b/libxsde/xsde/cxx/parser/state.hxx @@ -0,0 +1,89 @@ +// file : xsde/cxx/parser/state.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_STATE_HXX +#define XSDE_CXX_PARSER_STATE_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // POD stack with pre-allocated first element. You may + // need to pad your elements to get the proper alignment. + // + struct stack + { + enum error + { + error_none, + error_no_memory + }; + + ~stack (); + stack (size_t element_size, void* first_element); + + public: + void + pop (); + + error + push (); + + void* + top (); + + size_t + element_size () const; + + void + clear (); + + private: + error + grow (); + + private: + size_t el_size_; + void* first_; + char* data_; + size_t size_; + size_t capacity_; + }; + + // Optimized state stack for non-recursive case (one element). + // + struct parser_stack + { + parser_stack (parser_state& first); + + stack::error + push (parser_state&); + + void + pop (); + + parser_state& + top (); + + void + clear (); + + private: + stack stack_; + }; + } + } +} + + +#include <xsde/cxx/parser/state.ixx> + +#endif // XSDE_CXX_PARSER_STATE_HXX diff --git a/libxsde/xsde/cxx/parser/state.ixx b/libxsde/xsde/cxx/parser/state.ixx new file mode 100644 index 0000000..6f9c4b7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/state.ixx @@ -0,0 +1,102 @@ +// file : xsde/cxx/parser/state.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + // stack + // + + inline stack:: + ~stack () + { + delete[] data_; + } + + inline stack:: + stack (size_t el_size, void* first_el) + : el_size_ (el_size), first_ (first_el), + data_ (0), size_ (0), capacity_ (0) + { + } + + inline void stack:: + pop () + { + --size_; + } + + inline stack::error stack:: + push () + { + if (size_ > capacity_) + if (error e = grow ()) + return e; + + ++size_; + + return error_none; + } + + inline void* stack:: + top () + { + return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_; + } + + inline size_t stack:: + element_size () const + { + return el_size_; + } + + inline void stack:: + clear () + { + size_ = 0; + } + + // parser_stack + // + inline parser_stack:: + parser_stack (parser_state& first) + : stack_ (sizeof (parser_state), &first) + { + } + + inline stack::error parser_stack:: + push (parser_state& s) + { + if (stack::error e = stack_.push ()) + return e; + + *static_cast<parser_state*> (stack_.top ()) = s; + return stack::error_none; + } + + inline void parser_stack:: + pop () + { + stack_.pop (); + } + + inline parser_state& parser_stack:: + top () + { + return *static_cast<parser_state*> (stack_.top ()); + } + + inline void parser_stack:: + clear () + { + stack_.clear (); + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/substitution-map-load.hxx b/libxsde/xsde/cxx/parser/substitution-map-load.hxx new file mode 100644 index 0000000..4efa2ad --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map-load.hxx @@ -0,0 +1,31 @@ +// file : xsde/cxx/parser/substitution-map-load.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_SUBSTITUTION_MAP_LOAD_HXX +#define XSDE_CXX_PARSER_SUBSTITUTION_MAP_LOAD_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + size_t + parser_smap_elements (); + + inline size_t + parser_smap_buckets () + { + return XSDE_PARSER_SMAP_BUCKETS; + } + } + } +} + +#endif // XSDE_CXX_PARSER_SUBSTITUTION_MAP_LOAD_HXX diff --git a/libxsde/xsde/cxx/parser/substitution-map.cxx b/libxsde/xsde/cxx/parser/substitution-map.cxx new file mode 100644 index 0000000..950d07d --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map.cxx @@ -0,0 +1,236 @@ +// file : xsde/cxx/parser/substitution-map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strlen, strcmp, strncmp + +#ifndef XSDE_EXCEPTIONS +# include <assert.h> // assert +# include <stdlib.h> // exit +#endif + +#include <xsde/cxx/parser/substitution-map.hxx> +#include <xsde/cxx/parser/substitution-map-load.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + substitution_map* substitution_map_init::map = 0; + size_t substitution_map_init::count = 0; + + bool substitution_map:: + check_ (const ro_string& ns, + const ro_string& name, + const char* root, + const char** type) const + { + bool r = false; + + if (const value* v = find_ (ns, name)) + { + if (strcmp (root, v->root_) == 0) + r = true; + else + r = check_ (v->root_, root); + + if (r && type != 0 && *type == 0) + *type = v->type_; + } + + return r; + } + + bool substitution_map:: + check_ (const ro_string& ns, + const ro_string& name, + const char* root_ns, + const char* root_name, + const char** type) const + { + bool r = false; + + if (const value* v = find_ (ns, name)) + { + if (root_ns == 0) + r = strcmp (v->root_, root_name) == 0; + else + { + size_t n = strlen (root_name); + + r = strncmp (v->root_, root_name, n) == 0 && v->root_[n] == ' ' && + strcmp (v->root_ + n + 1, root_ns) == 0; + } + + if (!r) + r = check_ (v->root_, root_ns, root_name); + + if (r && type != 0 && *type == 0) + *type = v->type_; + } + + return r; + } + + bool substitution_map:: + check_ (const char* member, const char* root) const + { + const value* v = static_cast<const value*> (find (member)); + + if (v == 0) + return false; + + return strcmp (root, v->root_) == 0 ? true : check_ (v->root_, root); + } + + bool substitution_map:: + check_ (const char* member, + const char* root_ns, + const char* root_name) const + { + const value* v = static_cast<const value*> (find (member)); + + if (v == 0) + return false; + + bool r; + + if (root_ns == 0) + r = strcmp (v->root_, root_name) == 0; + else + { + size_t n = strlen (root_name); + + r = strncmp (v->root_, root_name, n) == 0 && v->root_[n] == ' ' && + strcmp (v->root_ + n + 1, root_ns) == 0; + } + + return r ? true : check_ (v->root_, root_ns, root_name); + } + + const substitution_map::value* substitution_map:: + find_ (const ro_string& ns, const ro_string& name) const + { + bool q = !ns.empty (); + size_t h = hash (name.data (), name.size ()); + + if (q) + { + h = hash (h, " ", 1); + h = hash (h, ns.data (), ns.size ()); + } + + const bucket* p = find (h); + + if (p == 0) + return 0; + + // Search for the entry in the bucket. + // + const size_t el_size = sizeof (element) + sizeof (value); + const char* b = reinterpret_cast<const char*> (p) + sizeof (bucket); + const char* e = b + p->size_ * el_size; + + for (; b < e; b += el_size) + { + const element* e = reinterpret_cast<const element*> (b); + + if (e->hash_ == h) + { + if (!q) + { + if (strlen (e->key_) == name.size () && + strncmp (e->key_, name.data (), name.size ()) == 0) + break; + } + else + { + size_t n = name.size (); + + if (strncmp (e->key_, name.data (), n) == 0 && + e->key_[n] == ' ' && + strlen (e->key_ + n + 1) == ns.size () && + strncmp (e->key_ + n + 1, ns.data (), ns.size ()) == 0) + break; + } + } + } + + if (b == e) + return 0; + + return reinterpret_cast<const value*> (b + sizeof (element)); + } + + // substitution_map_init + // + substitution_map_init:: + substitution_map_init () + { + if (count == 0) + { + map = new substitution_map (XSDE_PARSER_SMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != substitution_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + substitution_map_init:: + ~substitution_map_init () + { + if (--count == 0) + delete map; + } + + // substitution_map_entry + // + substitution_map_entry:: + substitution_map_entry (const char* member, + const char* root, + const char* type) + { + substitution_map& m = substitution_map_instance (); + m.insert (member, root, type); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != substitution_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + parser_smap_elements () + { + return substitution_map_instance ().size (); + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/substitution-map.hxx b/libxsde/xsde/cxx/parser/substitution-map.hxx new file mode 100644 index 0000000..14586c1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map.hxx @@ -0,0 +1,115 @@ +// file : xsde/cxx/parser/substitution-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_SUBSTITUTION_MAP_HXX +#define XSDE_CXX_PARSER_SUBSTITUTION_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + struct substitution_map: hashmap + { + substitution_map (size_t buckets); + + void + insert (const char* member, + const char* root, + const char* type); + + // Check and have the type set if found. + // + bool + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root, + const char*& type) const; + + bool + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root_ns, // 0 if no namespace + const char* root_name, + const char*& type) const; + + // Check but don't care about the type. + // + bool + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root) const; + + private: + struct value + { + const char* root_; + const char* type_; + }; + + private: + bool + check_ (const ro_string& member_ns, + const ro_string& member_name, + const char* root, + const char** type) const; + + bool + check_ (const ro_string& member_ns, + const ro_string& member_name, + const char* root_ns, + const char* root_name, + const char** type) const; + + bool + check_ (const char* member, const char* root) const; + + bool + check_ (const char* member, + const char* root_ns, + const char* root_name) const; + + const value* + find_ (const ro_string& member_ns, + const ro_string& member_name) const; + }; + + + // Translation unit initializer. + // + struct substitution_map_init + { + static substitution_map* map; + static size_t count; + + substitution_map_init (); + ~substitution_map_init (); + }; + + substitution_map& + substitution_map_instance (); + + // Map entry initializer. + // + struct substitution_map_entry + { + substitution_map_entry (const char* member, + const char* root, + const char* type); + }; + } + } +} + +#include <xsde/cxx/parser/substitution-map.ixx> + +#endif // XSDE_CXX_PARSER_SUBSTITUTION_MAP_HXX diff --git a/libxsde/xsde/cxx/parser/substitution-map.ixx b/libxsde/xsde/cxx/parser/substitution-map.ixx new file mode 100644 index 0000000..a45b5d4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/substitution-map.ixx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/substitution-map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + inline substitution_map:: + substitution_map (size_t buckets) + : hashmap (buckets, sizeof (value)) + { + } + + inline void substitution_map:: + insert (const char* member, + const char* root, + const char* type) + { + value v; + v.root_ = root; + v.type_ = type; + hashmap::insert (member, &v); + } + + inline bool substitution_map:: + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root, + const char*& type) const + { + + return empty () + ? false + : check_ (member_ns, member_name, root, &type); + } + + inline bool substitution_map:: + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root_ns, + const char* root_name, + const char*& type) const + { + return empty () + ? false + : check_ (member_ns, member_name, root_ns, root_name, &type); + } + + inline bool substitution_map:: + check (const ro_string& member_ns, + const ro_string& member_name, + const char* root) const + { + + return empty () + ? false + : check_ (member_ns, member_name, root, 0); + } + + inline substitution_map& + substitution_map_instance () + { + return *substitution_map_init::map; + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/any-type.hxx b/libxsde/xsde/cxx/parser/validating/any-type.hxx new file mode 100644 index 0000000..6f183d4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/any-type.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/parser/validating/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_ANY_TYPE_HXX +#define XSDE_CXX_PARSER_VALIDATING_ANY_TYPE_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_pimpl: virtual any_type_pskel +#else + struct any_type_pimpl: any_type_pskel +#endif + { + }; + + // any_simple_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_simple_type_pimpl: virtual any_simple_type_pskel +#else + struct any_simple_type_pimpl: any_simple_type_pskel +#endif + { + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/base64-binary.cxx b/libxsde/xsde/cxx/parser/validating/base64-binary.cxx new file mode 100644 index 0000000..994c14b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/base64-binary.cxx @@ -0,0 +1,281 @@ +// file : xsde/cxx/parser/validating/base64-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/base64-binary.hxx> + +static unsigned char +base64_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= 'A' && c <= 'Z') + r = static_cast<unsigned char> (c - 'A'); + else if (c >= 'a' && c <= 'z') + r = static_cast<unsigned char> (c - 'a' + 26); + else if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0' + 52); + else if (c == '+') + r = 62; + else if (c == '/') + r = 63; + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + base64_binary_pimpl:: + ~base64_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void base64_binary_pimpl:: + _reset () + { + base64_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + base64_binary_pimpl:: + base64_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void base64_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void base64_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void base64_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void base64_binary_pimpl:: + _post () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + const char* src = str_.data (); + + // Remove all whitespaces. + // + { + size_type j = 0; + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + subs = false; + + str_[j++] = c; + } + } + + size = j; + str_.truncate (size); + } + + // Our length should be a multiple of four. + // + if (size == 0 || size % 4 != 0) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + size_type quad_count = size / 4; + size_type capacity = quad_count * 3 + 1; + +#ifdef XSDE_EXCEPTIONS + buf_->size (capacity); +#else + if (buf_->size (capacity)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + char* dst = buf_->data (); + + // Source and destination indexes. + // + size_type si = 0; + size_type di = 0; + + // Process all quads except the last one. + // + unsigned char b1, b2, b3, b4; + + for (size_type q = 0; q < quad_count - 1; ++q) + { + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + b3 = base64_decode (src[si++]); + b4 = base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF || b3 == 0xFF || b4 == 0xFF) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Process the last quad. The first two octets are always there. + // + b1 = base64_decode (src[si++]); + b2 = base64_decode (src[si++]); + + if (b1 == 0xFF || b2 == 0xFF) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + char e3 = src[si++]; + char e4 = src[si++]; + + if (e4 == '=') + { + if (e3 == '=') + { + // Two pads. Last 4 bits in b2 should be zero. + // + if ((b2 & 0x0F) != 0) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + } + else + { + // One pad. Last 2 bits in b3 should be zero. + // + b3 = base64_decode (e3); + + if (b3 == 0xFF || (b3 & 0x03) != 0) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + } + } + else + { + // No pads. + // + b3 = base64_decode (e3); + b4 = base64_decode (e4); + + if (b3 == 0xFF || b4 == 0xFF) + { + _schema_error (schema_error::invalid_base64_binary_value); + return; + } + + dst[di++] = (b1 << 2) | (b2 >> 4); + dst[di++] = (b2 << 4) | (b3 >> 2); + dst[di++] = (b3 << 6) | b4; + } + + // Set the real size. + // + buf_->size (di); + } + + buffer* base64_binary_pimpl:: + post_base64_binary () + { + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/base64-binary.hxx b/libxsde/xsde/cxx/parser/validating/base64-binary.hxx new file mode 100644 index 0000000..656bf9b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/base64-binary.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/validating/base64-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_BASE64_BINARY_HXX +#define XSDE_CXX_PARSER_VALIDATING_BASE64_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct base64_binary_pimpl: virtual base64_binary_pskel +#else + struct base64_binary_pimpl: base64_binary_pskel +#endif + { + ~base64_binary_pimpl (); + base64_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual buffer* + post_base64_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_BASE64_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/boolean.cxx b/libxsde/xsde/cxx/parser/validating/boolean.cxx new file mode 100644 index 0000000..80d88f8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/boolean.cxx @@ -0,0 +1,93 @@ +// file : xsde/cxx/parser/validating/boolean.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/boolean.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void boolean_pimpl:: + _pre () + { + size_ = 0; + state_ = leading_ws; + } + + void boolean_pimpl:: + _characters (const ro_string& s) + { + ro_string tmp (s.data (), s.size ()); + + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((5 - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((5 - size_) >= size) + { + memcpy (str_ + size_, tmp.data (), size); + size_ += size; + } + else + _schema_error (schema_error::invalid_boolean_value); + + break; + } + case trailing_ws: + { + if (trim_left (tmp) != 0) + _schema_error (schema_error::invalid_boolean_value); + } + } + } + + void boolean_pimpl:: + _post () + { + ro_string tmp (str_, size_); + trim_right (tmp); + + if (tmp == "1" || tmp == "true") + value_ = true; + else if (tmp == "0" || tmp == "false") + value_ = false; + else + _schema_error (schema_error::invalid_boolean_value); + } + + bool boolean_pimpl:: + post_boolean () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/boolean.hxx b/libxsde/xsde/cxx/parser/validating/boolean.hxx new file mode 100644 index 0000000..81c1e29 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/boolean.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/validating/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_BOOLEAN_HXX +#define XSDE_CXX_PARSER_VALIDATING_BOOLEAN_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct boolean_pimpl: virtual boolean_pskel +#else + struct boolean_pimpl: boolean_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual bool + post_boolean (); + + protected: + // We only need strlen("false") + 1 characters to hold all valid + // and trimmed string representations of boolean. + // + char str_[6]; + size_t size_; + enum { leading_ws, literal, trailing_ws } state_; + + bool value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_BOOLEAN_HXX diff --git a/libxsde/xsde/cxx/parser/validating/byte.cxx b/libxsde/xsde/cxx/parser/validating/byte.cxx new file mode 100644 index 0000000..a18c26a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/byte.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void byte_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 4)) + _schema_error (schema_error::invalid_byte_value); + } + + void byte_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || (neg && ul > 128) || (!neg && ul > 127)) + _schema_error (schema_error::invalid_byte_value); + + value_ = neg + ? static_cast<signed char> (-static_cast<short> (ul)) + : static_cast<signed char> (ul); + } + else + _schema_error (schema_error::invalid_byte_value); + } + + signed char byte_pimpl:: + post_byte () + { + return value_; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/byte.hxx b/libxsde/xsde/cxx/parser/validating/byte.hxx new file mode 100644 index 0000000..6a3abce --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/byte.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_BYTE_HXX +#define XSDE_CXX_PARSER_VALIDATING_BYTE_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 8-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct byte_pimpl: virtual byte_pskel, number +#else + struct byte_pimpl: byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual signed char + post_byte (); + + protected: + // We only need strlen("0128") + 1 characters to hold all valid + // and trimmed string representations of signed byte. + // + char str_[5]; + signed char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/date-time.cxx b/libxsde/xsde/cxx/parser/validating/date-time.cxx new file mode 100644 index 0000000..32f33a7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date-time.cxx @@ -0,0 +1,259 @@ +// file : xsde/cxx/parser/validating/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/date-time.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void date_time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void date_time_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date_time := [-]CCYY[N]*-MM-DDTHH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (n < 19 || (s[0] == '-' && n < 20)) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type yp = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (yp == ro_string::npos || (n - yp - 1) < 14 + || s[yp + 3] != '-' || s[yp + 6] != 'T' + || s[yp + 9] != ':' || s[yp + 12] != ':') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // Find the end of the seconds fragment. + // + ro_string::size_type sp = yp + 15; + for (; sp < n; ++sp) + { + char c = s[sp]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // At least one digit should follow the fraction point. + // + if ((sp - yp - 13) == 3) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // Parse it backwards so that we can truncate and reuse + // the string. + // + + // zone + // + if (sp < n) + { + if (!bits::parse_time_zone (s + sp, n - sp, zh_, zm_)) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // seconds + // + str_.truncate (sp); + + char* p; + set_errno (0); + seconds_ = strtod (s + yp + 13, &p); + + if (*p != '\0' || get_errno () != 0 || seconds_ >= 60.0) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // minutes + // + char d1 = s[yp + 10]; + char d2 = s[yp + 11]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // hours + // + d1 = s[yp + 7]; + d2 = s[yp + 8]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // day + // + d1 = s[yp + 4]; + d2 = s[yp + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // month + // + d1 = s[yp + 1]; + d2 = s[yp + 2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + // year + // + str_.truncate (yp); + + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + date_time date_time_pimpl:: + post_date_time () + { + return z_ + ? date_time (year_, month_, day_, hours_, + minutes_, seconds_, zh_, zm_) + : date_time (year_, month_, day_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/date-time.hxx b/libxsde/xsde/cxx/parser/validating/date-time.hxx new file mode 100644 index 0000000..dcbbaa9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date-time.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DATE_TIME_HXX +#define XSDE_CXX_PARSER_VALIDATING_DATE_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_time_pimpl: virtual date_time_pskel +#else + struct date_time_pimpl: date_time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date_time + post_date_time (); + + protected: + string str_; + int year_; + unsigned short month_, day_; + unsigned short hours_, minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/date.cxx b/libxsde/xsde/cxx/parser/validating/date.cxx new file mode 100644 index 0000000..9efc52f --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date.cxx @@ -0,0 +1,182 @@ +// file : xsde/cxx/parser/validating/date.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/date.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void date_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void date_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void date_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // date := [-]CCYY[N]*-MM-DD[Z|(+|-)HH:MM] + // + + if (n < 10 || (s[0] == '-' && n < 11)) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos == ro_string::npos || + (n - pos - 1) < 5 || + s[pos + 3] != '-') + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // Parse the month, day values and time zone first so that we + // can truncate and reuse the string. + // + + // month + // + char d1 = s[pos + 1]; + char d2 = s[pos + 2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // day + // + d1 = s[pos + 4]; + d2 = s[pos + 5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_date_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + // zone + // + if ((pos + 6) < n) + { + if (!bits::parse_time_zone (s + pos + 6, n - pos - 6, zh_, zm_)) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // year + // + str_.truncate (pos); + + char* p; + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_date_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + date date_pimpl:: + post_date () + { + return z_ + ? date (year_, month_, day_, zh_, zm_) + : date (year_, month_, day_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/date.hxx b/libxsde/xsde/cxx/parser/validating/date.hxx new file mode 100644 index 0000000..feb4738 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/date.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/date.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DATE_HXX +#define XSDE_CXX_PARSER_VALIDATING_DATE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_pimpl: virtual date_pskel +#else + struct date_pimpl: date_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual date + post_date (); + + protected: + string str_; + int year_; + unsigned short month_, day_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DATE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/decimal.cxx b/libxsde/xsde/cxx/parser/validating/decimal.cxx new file mode 100644 index 0000000..15aa4e9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/decimal.cxx @@ -0,0 +1,74 @@ +// file : xsde/cxx/parser/validating/decimal.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/decimal.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void decimal_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void decimal_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 127)) + _schema_error (schema_error::invalid_decimal_value); + } + + void decimal_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + if (tmp == "INF" || tmp == "NaN" || tmp == "NAN") + { + _schema_error (schema_error::invalid_decimal_value); + } + else + { + char* p; + set_errno (0); + value_ = strtod (str_, &p); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_decimal_value); + + if (sign_ == minus) + value_ = -value_; + } + } + else + _schema_error (schema_error::invalid_decimal_value); + } + + double decimal_pimpl:: + post_decimal () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/decimal.hxx b/libxsde/xsde/cxx/parser/validating/decimal.hxx new file mode 100644 index 0000000..0669ce6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/decimal.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DECIMAL_HXX +#define XSDE_CXX_PARSER_VALIDATING_DECIMAL_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct decimal_pimpl: virtual decimal_pskel, number +#else + struct decimal_pimpl: decimal_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_decimal (); + + protected: + // Assume decimal values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + double value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DECIMAL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/double.cxx b/libxsde/xsde/cxx/parser/validating/double.cxx new file mode 100644 index 0000000..947f983 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/double.cxx @@ -0,0 +1,99 @@ +// file : xsde/cxx/parser/validating/double.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/double.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void double_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void double_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 127)) + _schema_error (schema_error::invalid_double_value); + } + + void double_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + if (tmp == "INF") + { + switch (sign_) + { + case none: + { + value_ = strtod ("INF", 0); + break; + } + case plus: + { + _schema_error (schema_error::invalid_double_value); + break; + } + case minus: + { + value_ = strtod ("-INF", 0); + break; + } + } + } + else if (tmp == "NaN") + { + if (sign_ == none) + value_ = strtod ("NAN", 0); + else + _schema_error (schema_error::invalid_double_value); + + } + else + { + char* p; + set_errno (0); + value_ = strtod (str_, &p); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_double_value); + + if (sign_ == minus) + value_ = -value_; + } + } + else + _schema_error (schema_error::invalid_double_value); + } + + double double_pimpl:: + post_double () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/double.hxx b/libxsde/xsde/cxx/parser/validating/double.hxx new file mode 100644 index 0000000..afae038 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/double.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DOUBLE_HXX +#define XSDE_CXX_PARSER_VALIDATING_DOUBLE_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct double_pimpl: virtual double_pskel, number +#else + struct double_pimpl: double_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual double + post_double (); + + protected: + // Assume double values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + double value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DOUBLE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/duration.cxx b/libxsde/xsde/cxx/parser/validating/duration.cxx new file mode 100644 index 0000000..9d72609 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/duration.cxx @@ -0,0 +1,265 @@ +// file : xsde/cxx/parser/validating/duration.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul, strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/duration.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void duration_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void duration_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + static ro_string::size_type + rfind_delim (const char* s, ro_string::size_type pos) + { + const char* p = s + pos; + for (; p >= s; --p) + { + if (*p == 'Y' || *p == 'D' || *p == 'M' || + *p == 'H' || *p == 'M' || *p == 'S' || + *p == 'T' || *p == 'P') + break; + } + + return p >= s ? p - s : ro_string::npos; + } + + + void duration_pimpl:: + _post () + { + typedef ro_string::size_type size_type; + + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + size_type n = trim_right (tmp); + + negative_ = false; + years_ = 0; + months_ = 0; + days_ = 0; + hours_ = 0; + minutes_ = 0; + seconds_ = 0.0; + + // duration := [-]P[nY][nM][nD][TnHnMn[.n+]S] + // + + if (n < 3 || (s[0] == '-' && n < 4)) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + if (s[0] == '-') + negative_ = true; + + if (s[negative_ ? 1 : 0] != 'P') + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + // Parse it backwards so that we can truncate and reuse + // the string. + // + + bool need_t = false; + size_type pos = n - 1; + size_type t_pos = tmp.find ('T'); + + char* p; + unsigned long ul; + + if (s[pos] == 'S') + { + need_t = true; + + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + seconds_ = strtod (s + pos + 1, &p); + + if (*p != '\0' || get_errno () != 0 || seconds_ < 0.0) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + + if (s[pos] == 'M' && t_pos != ro_string::npos && t_pos < pos) + { + need_t = true; + + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + minutes_ = static_cast<unsigned int> (ul); + } + + if (s[pos] == 'H') + { + need_t = true; + + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + hours_ = static_cast<unsigned int> (ul); + } + + if (need_t) + { + if (s[pos] == 'T') + pos = rfind_delim (s, pos - 1); + else + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + else + { + if (s[pos] == 'T') + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + + if (s[pos] == 'D') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + days_ = static_cast<unsigned int> (ul); + } + + if (s[pos] == 'M') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + months_ = static_cast<unsigned int> (ul); + } + + if (s[pos] == 'Y') + { + str_.truncate (pos); + pos = rfind_delim (s, pos - 1); + + set_errno (0); + ul = strtoul (s + pos + 1, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + years_ = static_cast<unsigned int> (ul); + } + + // Something did not match or appeared in the wrong order. + // + if (pos != static_cast<size_type> (negative_ ? 1 : 0)) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + } + + duration duration_pimpl:: + post_duration () + { + return duration ( + negative_, years_, months_, days_, hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/duration.hxx b/libxsde/xsde/cxx/parser/validating/duration.hxx new file mode 100644 index 0000000..3ee53db --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/duration.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/duration.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_DURATION_HXX +#define XSDE_CXX_PARSER_VALIDATING_DURATION_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct duration_pimpl: virtual duration_pskel +#else + struct duration_pimpl: duration_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual duration + post_duration (); + + protected: + string str_; + bool negative_; + unsigned int years_, months_, days_; + unsigned int hours_, minutes_; + double seconds_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_DURATION_HXX diff --git a/libxsde/xsde/cxx/parser/validating/float.cxx b/libxsde/xsde/cxx/parser/validating/float.cxx new file mode 100644 index 0000000..7bbbcca --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/float.cxx @@ -0,0 +1,118 @@ +// file : xsde/cxx/parser/validating/float.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtof, strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/float.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void float_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void float_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 127)) + _schema_error (schema_error::invalid_float_value); + } + + void float_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + if (tmp == "INF") + { + switch (sign_) + { + case none: + { +#ifdef XSDE_STRTOF + value_ = strtof ("INF", 0); +#else + value_ = static_cast<float> (strtod ("INF", 0)); +#endif + break; + } + case plus: + { + _schema_error (schema_error::invalid_float_value); + break; + } + case minus: + { +#ifdef XSDE_STRTOF + value_ = strtof ("-INF", 0); +#else + value_ = static_cast<float> (strtod ("-INF", 0)); +#endif + break; + } + } + } + else if (tmp == "NaN") + { + if (sign_ == none) + { +#ifdef XSDE_STRTOF + value_ = strtof ("NAN", 0); +#else + value_ = static_cast<float> (strtod ("NAN", 0)); +#endif + } + else + _schema_error (schema_error::invalid_float_value); + + } + else + { + char* p; + set_errno (0); +#ifdef XSDE_STRTOF + value_ = strtof (str_, &p); +#else + value_ = static_cast<float> (strtod (str_, &p)); +#endif + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_float_value); + + if (sign_ == minus) + value_ = -value_; + } + } + else + _schema_error (schema_error::invalid_float_value); + } + + float float_pimpl:: + post_float () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/float.hxx b/libxsde/xsde/cxx/parser/validating/float.hxx new file mode 100644 index 0000000..2bb6e7d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/float.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_FLOAT_HXX +#define XSDE_CXX_PARSER_VALIDATING_FLOAT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct float_pimpl: virtual float_pskel, number +#else + struct float_pimpl: float_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual float + post_float (); + + protected: + // Assume float values (without leading and trailing whitespaces) + // cannot be longer than 127 characters. + // + char str_[128]; + float value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_FLOAT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gday.cxx b/libxsde/xsde/cxx/parser/validating/gday.cxx new file mode 100644 index 0000000..a743eee --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gday.cxx @@ -0,0 +1,112 @@ +// file : xsde/cxx/parser/validating/gday.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/gday.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gday_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gday_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gday_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gday := ---DD[Z|(+|-)HH:MM] + // + if (n < 5 || s[0] != '-' || s[1] != '-' || s[2] != '-') + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + char d1 = s[3]; + char d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + if (n > 5) + { + if (!bits::parse_time_zone (s + 5, n - 5, zh_, zm_)) + { + _schema_error (schema_error::invalid_gday_value); + return; + } + + z_ = true; + } + else + z_ = false; + } + + gday gday_pimpl:: + post_gday () + { + return z_ ? gday (day_, zh_, zm_) : gday (day_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gday.hxx b/libxsde/xsde/cxx/parser/validating/gday.hxx new file mode 100644 index 0000000..21f8fcd --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gday.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gday.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GDAY_HXX +#define XSDE_CXX_PARSER_VALIDATING_GDAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gday_pimpl: virtual gday_pskel +#else + struct gday_pimpl: gday_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gday + post_gday (); + + protected: + string str_; + unsigned short day_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GDAY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gmonth-day.cxx b/libxsde/xsde/cxx/parser/validating/gmonth-day.cxx new file mode 100644 index 0000000..3b4b4ea --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth-day.cxx @@ -0,0 +1,137 @@ +// file : xsde/cxx/parser/validating/gmonth-day.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/gmonth-day.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gmonth_day_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_day_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gmonth_day_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth_day := --MM-DD[Z|(+|-)HH:MM] + // + if (n < 7 || s[0] != '-' || s[1] != '-' || s[4] != '-') + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + // month + // + char d1 = s[2]; + char d2 = s[3]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + // day + // + d1 = s[5]; + d2 = s[6]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + day_ = 10 * (d1 - '0') + (d2 - '0'); + + if (day_ < 1 || day_ > 31) + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + // zone + // + if (n > 7) + { + if (!bits::parse_time_zone (s + 7, n - 7, zh_, zm_)) + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + + z_ = true; + } + else + z_ = false; + } + + gmonth_day gmonth_day_pimpl:: + post_gmonth_day () + { + return z_ + ? gmonth_day (month_, day_, zh_, zm_) + : gmonth_day (month_, day_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gmonth-day.hxx b/libxsde/xsde/cxx/parser/validating/gmonth-day.hxx new file mode 100644 index 0000000..7ec4d59 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth-day.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gmonth-day.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GMONTH_DAY_HXX +#define XSDE_CXX_PARSER_VALIDATING_GMONTH_DAY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_day_pimpl: virtual gmonth_day_pskel +#else + struct gmonth_day_pimpl: gmonth_day_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth_day + post_gmonth_day (); + + protected: + string str_; + unsigned short month_, day_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GMONTH_DAY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gmonth.cxx b/libxsde/xsde/cxx/parser/validating/gmonth.cxx new file mode 100644 index 0000000..a6f5fc1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth.cxx @@ -0,0 +1,112 @@ +// file : xsde/cxx/parser/validating/gmonth.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/gmonth.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gmonth_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gmonth_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gmonth_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gmonth := --MM[Z|(+|-)HH:MM] + // + if (n < 4 || s[0] != '-' || s[1] != '-') + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + char d1 = s[2]; + char d2 = s[3]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + if (n > 4) + { + if (!bits::parse_time_zone (s + 4, n - 4, zh_, zm_)) + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + + z_ = true; + } + else + z_ = false; + } + + gmonth gmonth_pimpl:: + post_gmonth () + { + return z_ ? gmonth (month_, zh_, zm_) : gmonth (month_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gmonth.hxx b/libxsde/xsde/cxx/parser/validating/gmonth.hxx new file mode 100644 index 0000000..cfd0e92 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gmonth.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gmonth.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GMONTH_HXX +#define XSDE_CXX_PARSER_VALIDATING_GMONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_pimpl: virtual gmonth_pskel +#else + struct gmonth_pimpl: gmonth_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gmonth + post_gmonth (); + + protected: + string str_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GMONTH_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gyear-month.cxx b/libxsde/xsde/cxx/parser/validating/gyear-month.cxx new file mode 100644 index 0000000..023b06c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear-month.cxx @@ -0,0 +1,161 @@ +// file : xsde/cxx/parser/validating/gyear-month.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/gyear-month.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gyear_month_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_month_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gyear_month_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear_month := [-]CCYY[N]*-MM[Z|(+|-)HH:MM] + // + + if (n < 7 || (s[0] == '-' && n < 8)) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type pos = tmp.find ('-', s[0] == '-' ? 5 : 4); + + if (pos == ro_string::npos || (n - pos - 1) < 2) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + // Parse the month value and time zone first so that we can + // truncate and reuse the string. + // + + // month + // + char d1 = s[pos + 1]; + char d2 = s[pos + 2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + month_ = 10 * (d1 - '0') + (d2 - '0'); + + if (month_ < 1 || month_ > 12) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + // zone + // + if ((pos + 3) < n) + { + if (!bits::parse_time_zone (s + pos + 3, n - pos - 3, zh_, zm_)) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // year + // + str_.truncate (pos); + + char* p; + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + gyear_month gyear_month_pimpl:: + post_gyear_month () + { + return z_ + ? gyear_month (year_, month_, zh_, zm_) + : gyear_month (year_, month_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gyear-month.hxx b/libxsde/xsde/cxx/parser/validating/gyear-month.hxx new file mode 100644 index 0000000..4e7933c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear-month.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/gyear-month.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GYEAR_MONTH_HXX +#define XSDE_CXX_PARSER_VALIDATING_GYEAR_MONTH_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_month_pimpl: virtual gyear_month_pskel +#else + struct gyear_month_pimpl: gyear_month_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear_month + post_gyear_month (); + + protected: + string str_; + int year_; + unsigned short month_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GYEAR_MONTH_HXX diff --git a/libxsde/xsde/cxx/parser/validating/gyear.cxx b/libxsde/xsde/cxx/parser/validating/gyear.cxx new file mode 100644 index 0000000..cbe87e1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear.cxx @@ -0,0 +1,138 @@ +// file : xsde/cxx/parser/validating/gyear.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/gyear.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void gyear_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void gyear_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void gyear_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // gyear := [-]CCYY[N]*[Z|(+|-)HH:MM] + // + + if (n < 4 || (s[0] == '-' && n < 5)) + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + + // Find the end of the year token. + // + ro_string::size_type pos = (s[0] == '-' ? 5 : 4); + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + if (!bits::parse_time_zone (s + pos, n - pos, zh_, zm_)) + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // Parse the year value. + // + str_.truncate (pos); + + char* p; + set_errno (0); + bool neg = (s[0] == '-'); + unsigned long ul = strtoul (neg ? s + 1 : s, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL) || + ul == 0) + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + + year_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + + gyear gyear_pimpl:: + post_gyear () + { + return z_ ? gyear (year_, zh_, zm_) : gyear (year_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/gyear.hxx b/libxsde/xsde/cxx/parser/validating/gyear.hxx new file mode 100644 index 0000000..557a6e4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/gyear.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/parser/validating/gyear.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_GYEAR_HXX +#define XSDE_CXX_PARSER_VALIDATING_GYEAR_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_pimpl: virtual gyear_pskel +#else + struct gyear_pimpl: gyear_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual gyear + post_gyear (); + + protected: + string str_; + int year_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_GYEAR_HXX diff --git a/libxsde/xsde/cxx/parser/validating/hex-binary.cxx b/libxsde/xsde/cxx/parser/validating/hex-binary.cxx new file mode 100644 index 0000000..5f5a02c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/hex-binary.cxx @@ -0,0 +1,172 @@ +// file : xsde/cxx/parser/validating/hex-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/hex-binary.hxx> + +static unsigned char +hex_decode (char c) +{ + unsigned char r = 0xFF; + + if (c >= '0' && c <= '9') + r = static_cast<unsigned char> (c - '0'); + else if (c >= 'A' && c <= 'F') + r = static_cast<unsigned char> (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + r = static_cast<unsigned char> (10 + (c - 'a')); + + return r; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + hex_binary_pimpl:: + ~hex_binary_pimpl () + { + if (!base_) + delete buf_; + } + + void hex_binary_pimpl:: + _reset () + { + hex_binary_pskel::_reset (); + + if (!base_) + { + delete buf_; + buf_ = 0; + } + } + + hex_binary_pimpl:: + hex_binary_pimpl (bool base) + : base_ (base), buf_ (0) + { + } + + void hex_binary_pimpl:: + pre_impl (buffer* b) + { + buf_ = b; + } + + void hex_binary_pimpl:: + _pre () + { + if (buf_ == 0) + { + buf_ = new buffer (); + +#ifndef XSDE_EXCEPTIONS + if (buf_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void hex_binary_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void hex_binary_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (size % 2 != 0) + { + _schema_error (schema_error::invalid_hex_binary_value); + return; + } + + size_t n = size / 2; + +#ifdef XSDE_EXCEPTIONS + buf_->size (n); +#else + if (buf_->size (n)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + + if (n != 0) + { + const char* src = tmp.data (); + char* dst = buf_->data (); + size_t i = 0; + + for (; i < n; ++i) + { + unsigned char h = hex_decode (src[2 * i]); + unsigned char l = hex_decode (src[2 * i + 1]); + + if (h == 0xFF || l == 0xFF) + break; + + dst[i] = (h << 4) | l; + } + + if (i != n) + _schema_error (schema_error::invalid_hex_binary_value); + } + } + + buffer* hex_binary_pimpl:: + post_hex_binary () + { + buffer* r = buf_; + buf_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/hex-binary.hxx b/libxsde/xsde/cxx/parser/validating/hex-binary.hxx new file mode 100644 index 0000000..4ba0e96 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/hex-binary.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/validating/hex-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_HEX_BINARY_HXX +#define XSDE_CXX_PARSER_VALIDATING_HEX_BINARY_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct hex_binary_pimpl: virtual hex_binary_pskel +#else + struct hex_binary_pimpl: hex_binary_pskel +#endif + { + ~hex_binary_pimpl (); + hex_binary_pimpl (bool base = false); + + void + pre_impl (buffer*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual buffer* + post_hex_binary (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + buffer* buf_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_HEX_BINARY_HXX diff --git a/libxsde/xsde/cxx/parser/validating/id-stl.cxx b/libxsde/xsde/cxx/parser/validating/id-stl.cxx new file mode 100644 index 0000000..84d487c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id-stl.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/id-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/id-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void id_pimpl:: + _pre () + { + str_.erase (); + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void id_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.resize (size); + else + _schema_error (schema_error::invalid_id_value); + } + + std::string id_pimpl:: + post_id () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/id-stl.hxx b/libxsde/xsde/cxx/parser/validating/id-stl.hxx new file mode 100644 index 0000000..8ded862 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/id-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_ID_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_ID_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_id (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_ID_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/id.cxx b/libxsde/xsde/cxx/parser/validating/id.cxx new file mode 100644 index 0000000..f5b1daf --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id.cxx @@ -0,0 +1,80 @@ +// file : xsde/cxx/parser/validating/id.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/id.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void id_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void id_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void id_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.truncate (size); + else + _schema_error (schema_error::invalid_id_value); + } + + char* id_pimpl:: + post_id () + { + return str_.detach (); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/id.hxx b/libxsde/xsde/cxx/parser/validating/id.hxx new file mode 100644 index 0000000..2b02290 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/id.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/id.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_ID_HXX +#define XSDE_CXX_PARSER_VALIDATING_ID_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_pimpl: virtual id_pskel +#else + struct id_pimpl: id_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_id (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_ID_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idref-stl.cxx b/libxsde/xsde/cxx/parser/validating/idref-stl.cxx new file mode 100644 index 0000000..a7a4f10 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref-stl.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/idref-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void idref_pimpl:: + _pre () + { + str_.erase (); + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void idref_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.resize (size); + else + _schema_error (schema_error::invalid_idref_value); + } + + std::string idref_pimpl:: + post_idref () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/idref-stl.hxx b/libxsde/xsde/cxx/parser/validating/idref-stl.hxx new file mode 100644 index 0000000..0382400 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/idref-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREF_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREF_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_idref (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREF_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idref.cxx b/libxsde/xsde/cxx/parser/validating/idref.cxx new file mode 100644 index 0000000..1e0b320 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/idref.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void idref_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void idref_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void idref_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.truncate (size); + else + _schema_error (schema_error::invalid_idref_value); + } + + char* idref_pimpl:: + post_idref () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/idref.hxx b/libxsde/xsde/cxx/parser/validating/idref.hxx new file mode 100644 index 0000000..bfbacb9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idref.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/idref.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREF_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREF_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_pimpl: virtual idref_pskel +#else + struct idref_pimpl: idref_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_idref (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREF_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idrefs-stl.cxx b/libxsde/xsde/cxx/parser/validating/idrefs-stl.cxx new file mode 100644 index 0000000..0451a43 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs-stl.cxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/parser/validating/idrefs-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/idrefs-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + void idrefs_pimpl:: + _post () + { + idrefs_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_idrefs_value); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + idref_pskel& p = parser_; + + p.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!p._error_type ()) + p._pre_impl (ctx); + else + p._copy_error (ctx); +#else + p._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + p._characters (s); + + if (!ctx.error_type ()) + p._post_impl (); + + if (!ctx.error_type ()) + { + const std::string& x = p.post_idref (); + +#ifndef XSDE_EXCEPTIONS + if (!p._error_type ()) + seq_->push_back (x); + else + p._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/validating/idrefs-stl.hxx b/libxsde/xsde/cxx/parser/validating/idrefs-stl.hxx new file mode 100644 index 0000000..44dfea8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs-stl.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/idrefs-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREFS_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREFS_STL_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREFS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/idrefs.cxx b/libxsde/xsde/cxx/parser/validating/idrefs.cxx new file mode 100644 index 0000000..f6072a5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs.cxx @@ -0,0 +1,136 @@ +// file : xsde/cxx/parser/validating/idrefs.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/pre.hxx> + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/idrefs.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + idrefs_pimpl:: + ~idrefs_pimpl () + { + if (!base_) + delete seq_; + } + + void idrefs_pimpl:: + _reset () + { + idrefs_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + idrefs_pimpl:: + idrefs_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void idrefs_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void idrefs_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + idrefs_pskel::_pre (); + } + + void idrefs_pimpl:: + _post () + { + idrefs_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_idrefs_value); + } + + string_sequence* idrefs_pimpl:: + post_idrefs () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void idrefs_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); +#else + parser_._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_idref (); + + // push_back() frees the string if it fails. + // +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + { + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} + +#include <xsde/cxx/post.hxx> diff --git a/libxsde/xsde/cxx/parser/validating/idrefs.hxx b/libxsde/xsde/cxx/parser/validating/idrefs.hxx new file mode 100644 index 0000000..f2415ff --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/idrefs.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/idrefs.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_IDREFS_HXX +#define XSDE_CXX_PARSER_VALIDATING_IDREFS_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_pimpl: virtual idrefs_pskel +#else + struct idrefs_pimpl: idrefs_pskel +#endif + { + ~idrefs_pimpl (); + idrefs_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_idrefs (); + + virtual void + _reset (); + + protected: + bool base_; + idref_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_IDREFS_HXX diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map-load.hxx b/libxsde/xsde/cxx/parser/validating/inheritance-map-load.hxx new file mode 100644 index 0000000..ad04019 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map-load.hxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/parser/validating/inheritance-map-load.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_LOAD_HXX +#define XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_LOAD_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + size_t + parser_imap_elements (); + + inline size_t + parser_imap_buckets () + { + return XSDE_PARSER_IMAP_BUCKETS; + } + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_LOAD_HXX + diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx new file mode 100644 index 0000000..491ec8d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.cxx @@ -0,0 +1,111 @@ +// file : xsde/cxx/parser/validating/inheritance-map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strcmp + +#ifndef XSDE_EXCEPTIONS +# include <assert.h> // assert +# include <stdlib.h> // exit +#endif + +#include <xsde/cxx/parser/validating/inheritance-map.hxx> +#include <xsde/cxx/parser/validating/inheritance-map-load.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + inheritance_map* inheritance_map_init::map = 0; + size_t inheritance_map_init::count = 0; + + bool inheritance_map:: + check (const char* derived, const char* base) const + { + if (strcmp (derived, base) == 0) + return true; + + const void* p = find (derived); + + if (p) + { + const char* b = *static_cast<const char* const*> (p); + return strcmp (base, b) == 0 ? true : check (b, base); + } + + return false; + } + + // inheritance_map_init + // + inheritance_map_init:: + inheritance_map_init () + { + if (count == 0) + { + map = new inheritance_map (XSDE_PARSER_IMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + inheritance_map_init:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + inheritance_map_entry:: + inheritance_map_entry (const char* derived, const char* base) + { + inheritance_map& m = inheritance_map_instance (); + m.insert (derived, base); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + parser_imap_elements () + { + return inheritance_map_instance ().size (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx b/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx new file mode 100644 index 0000000..6329545 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.hxx @@ -0,0 +1,63 @@ +// file : xsde/cxx/parser/validating/inheritance-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX +#define XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + struct inheritance_map: hashmap + { + inheritance_map (size_t buckets); + + void + insert (const char* derived, const char* base); + + bool + check (const char* derived, const char* base) const; + }; + + + // Translation unit initializer. + // + struct inheritance_map_init + { + static inheritance_map* map; + static size_t count; + + inheritance_map_init (); + ~inheritance_map_init (); + }; + + inline inheritance_map& + inheritance_map_instance (); + + // Map entry initializer. + // + struct inheritance_map_entry + { + inheritance_map_entry (const char* derived, const char* base); + }; + } + } + } +} + +#include <xsde/cxx/parser/validating/inheritance-map.ixx> + +#endif // XSDE_CXX_PARSER_VALIDATING_INHERITANCE_MAP_HXX + diff --git a/libxsde/xsde/cxx/parser/validating/inheritance-map.ixx b/libxsde/xsde/cxx/parser/validating/inheritance-map.ixx new file mode 100644 index 0000000..4f76685 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/inheritance-map.ixx @@ -0,0 +1,34 @@ +// file : xsde/cxx/parser/validating/inheritance-map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + inline inheritance_map:: + inheritance_map (size_t buckets) + : hashmap (buckets, sizeof (const char*)) + { + } + + inline void inheritance_map:: + insert (const char* derived, const char* base) + { + hashmap::insert (derived, &base); + } + + inline inheritance_map& + inheritance_map_instance () + { + return *inheritance_map_init::map; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/int.cxx b/libxsde/xsde/cxx/parser/validating/int.cxx new file mode 100644 index 0000000..bfbac40 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/int.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void int_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 11)) + _schema_error (schema_error::invalid_int_value); + } + + void int_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL)) + _schema_error (schema_error::invalid_int_value); + + value_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<int> (ul)) + : static_cast<int> (ul); + } + else + _schema_error (schema_error::invalid_int_value); + } + + int int_pimpl:: + post_int () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/int.hxx b/libxsde/xsde/cxx/parser/validating/int.hxx new file mode 100644 index 0000000..7172af7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/int.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INT_HXX +#define XSDE_CXX_PARSER_VALIDATING_INT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 32-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct int_pimpl: virtual int_pskel, number +#else + struct int_pimpl: int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual int + post_int (); + + protected: + // We only need strlen("02147483648") + 1 characters to hold all + // valid and trimmed string representations of int. + // + char str_[12]; + int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_INT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/integer.cxx b/libxsde/xsde/cxx/parser/validating/integer.cxx new file mode 100644 index 0000000..e3255e3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/integer.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN, LONG_MAX + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_integer_value); + } + + void integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > static_cast<unsigned long> (LONG_MIN)) || + (!neg && ul > LONG_MAX)) + _schema_error (schema_error::invalid_integer_value); + + value_ = neg + ? (ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN: -static_cast<long> (ul)) + : static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_integer_value); + } + + long integer_pimpl:: + post_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/integer.hxx b/libxsde/xsde/cxx/parser/validating/integer.hxx new file mode 100644 index 0000000..ec7c863 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/integer.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct integer_pimpl: virtual integer_pskel, number +#else + struct integer_pimpl: integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/language-stl.cxx b/libxsde/xsde/cxx/parser/validating/language-stl.cxx new file mode 100644 index 0000000..53e0e75 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language-stl.cxx @@ -0,0 +1,95 @@ +// file : xsde/cxx/parser/validating/language-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/language-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void language_pimpl:: + _pre () + { + str_.erase (); + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void language_pimpl:: + _post () + { + typedef ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size = trim_right (tmp); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + bool ok = true; + size_type i = 0; + + for (size_type tag = 0; ; ++tag) + { + size_type n = 0; + + for (; i < size && n < 8; ++n, ++i) + { + char c = tmp[i]; + + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (tag != 0 && c >= '0' && c <= '9'))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (i == size) + break; + + if (tmp[i++] != '-') + { + ok = false; + break; + } + } + + if (ok) + str_.resize (size); + else + _schema_error (schema_error::invalid_language_value); + } + + std::string language_pimpl:: + post_language () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/language-stl.hxx b/libxsde/xsde/cxx/parser/validating/language-stl.hxx new file mode 100644 index 0000000..8c0dfca --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/language-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LANGUAGE_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_LANGUAGE_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_language (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LANGUAGE_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/language.cxx b/libxsde/xsde/cxx/parser/validating/language.cxx new file mode 100644 index 0000000..177be73 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language.cxx @@ -0,0 +1,114 @@ +// file : xsde/cxx/parser/validating/language.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/language.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void language_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void language_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void language_pimpl:: + _post () + { + typedef ro_string::size_type size_type; + + ro_string tmp (str_); + size_type size = trim_right (tmp); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + bool ok = true; + size_type i = 0; + + for (size_type tag = 0; ; ++tag) + { + size_type n = 0; + + for (; i < size && n < 8; ++n, ++i) + { + char c = tmp[i]; + + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (tag != 0 && c >= '0' && c <= '9'))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (i == size) + break; + + if (tmp[i++] != '-') + { + ok = false; + break; + } + } + + if (ok) + str_.truncate (size); + else + _schema_error (schema_error::invalid_language_value); + } + + char* language_pimpl:: + post_language () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/language.hxx b/libxsde/xsde/cxx/parser/validating/language.hxx new file mode 100644 index 0000000..4321b00 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/language.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/language.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LANGUAGE_HXX +#define XSDE_CXX_PARSER_VALIDATING_LANGUAGE_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_pimpl: virtual language_pskel +#else + struct language_pimpl: language_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_language (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LANGUAGE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/long-long.cxx b/libxsde/xsde/cxx/parser/validating/long-long.cxx new file mode 100644 index 0000000..66fec5b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long-long.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_long_value); + } + + void long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long long ull = strtoull (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ull > 9223372036854775808ULL) || + (!neg && ull > 9223372036854775807ULL)) + _schema_error (schema_error::invalid_long_value); + + value_ = neg + ? (ull == 9223372036854775808ULL + ? (-9223372036854775807LL - 1) + : -static_cast<long long> (ull)) + : static_cast<long long> (ull); + } + else + _schema_error (schema_error::invalid_long_value); + } + + long long long_pimpl:: + post_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/long-long.hxx b/libxsde/xsde/cxx/parser/validating/long-long.hxx new file mode 100644 index 0000000..b7e830b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long-long.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LONG_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_LONG_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 64-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/long.cxx b/libxsde/xsde/cxx/parser/validating/long.cxx new file mode 100644 index 0000000..d1f24b4 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/parser/validating/long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_long_value); + } + + void long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || + get_errno () != 0 || + (neg && ul > 2147483648UL) || + (!neg && ul > 2147483647UL)) + _schema_error (schema_error::invalid_long_value); + + value_ = neg + ? (ul == 2147483648UL + ? (-2147483647 - 1) + : -static_cast<long> (ul)) + : static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_long_value); + } + + long long_pimpl:: + post_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/long.hxx b/libxsde/xsde/cxx/parser/validating/long.hxx new file mode 100644 index 0000000..f87c6c6 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/long.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_pimpl: virtual long_pskel, number +#else + struct long_pimpl: long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_long (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long long. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/name-stl.cxx b/libxsde/xsde/cxx/parser/validating/name-stl.cxx new file mode 100644 index 0000000..a691f94 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name-stl.cxx @@ -0,0 +1,86 @@ +// file : xsde/cxx/parser/validating/name-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/name-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void name_pimpl:: + _pre () + { + str_.erase (); + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void name_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + unsigned char c = static_cast<unsigned char> (str_[0]); + + ok = c >= 0x80 || (xml::char_table[c] & xml::name_first_char_mask); + + if (ok) + { + for (ro_string::size_type i = 1; i < size; ++i) + { + c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + } + + str_.resize (size); + + if (!ok) + _schema_error (schema_error::invalid_name_value); + } + + std::string name_pimpl:: + post_name () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/name-stl.hxx b/libxsde/xsde/cxx/parser/validating/name-stl.hxx new file mode 100644 index 0000000..d3d7e02 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/name-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NAME_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_name (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/name.cxx b/libxsde/xsde/cxx/parser/validating/name.cxx new file mode 100644 index 0000000..167aa47 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name.cxx @@ -0,0 +1,105 @@ +// file : xsde/cxx/parser/validating/name.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/name.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void name_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void name_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void name_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + unsigned char c = static_cast<unsigned char> (str_[0]); + + ok = c >= 0x80 || (xml::char_table[c] & xml::name_first_char_mask); + + if (ok) + { + for (ro_string::size_type i = 1; i < size; ++i) + { + c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + } + + str_.truncate (size); + + if (!ok) + _schema_error (schema_error::invalid_name_value); + } + + char* name_pimpl:: + post_name () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/name.hxx b/libxsde/xsde/cxx/parser/validating/name.hxx new file mode 100644 index 0000000..9f9046f --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/name.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/name.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NAME_HXX +#define XSDE_CXX_PARSER_VALIDATING_NAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_pimpl: virtual name_pskel +#else + struct name_pimpl: name_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_name (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NAME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/ncname-stl.cxx b/libxsde/xsde/cxx/parser/validating/ncname-stl.cxx new file mode 100644 index 0000000..50bea6f --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname-stl.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/ncname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/ncname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void ncname_pimpl:: + _pre () + { + str_.erase (); + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void ncname_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.resize (size); + else + _schema_error (schema_error::invalid_ncname_value); + } + + std::string ncname_pimpl:: + post_ncname () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/ncname-stl.hxx b/libxsde/xsde/cxx/parser/validating/ncname-stl.hxx new file mode 100644 index 0000000..6329c18 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/ncname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NCNAME_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NCNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_ncname (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NCNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/ncname.cxx b/libxsde/xsde/cxx/parser/validating/ncname.cxx new file mode 100644 index 0000000..c664014 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void ncname_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void ncname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void ncname_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + if (xml::valid_ncname (tmp.data (), size)) + str_.truncate (size); + else + _schema_error (schema_error::invalid_ncname_value); + } + + char* ncname_pimpl:: + post_ncname () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/ncname.hxx b/libxsde/xsde/cxx/parser/validating/ncname.hxx new file mode 100644 index 0000000..89a5521 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/ncname.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NCNAME_HXX +#define XSDE_CXX_PARSER_VALIDATING_NCNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_pimpl: virtual ncname_pskel +#else + struct ncname_pimpl: ncname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_ncname (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NCNAME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/negative-integer.cxx b/libxsde/xsde/cxx/parser/validating/negative-integer.cxx new file mode 100644 index 0000000..e5c78a8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/negative-integer.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void negative_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_negative_integer_value); + } + + void negative_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (sign_ == minus && size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + ul == 0 || + ul > static_cast<unsigned long> (LONG_MIN)) + _schema_error (schema_error::invalid_negative_integer_value); + + value_ = ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN : -static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_negative_integer_value); + } + + long negative_integer_pimpl:: + post_negative_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/negative-integer.hxx b/libxsde/xsde/cxx/parser/validating/negative-integer.hxx new file mode 100644 index 0000000..0839b03 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/negative-integer.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length negative integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct negative_integer_pimpl: virtual negative_integer_pskel, number +#else + struct negative_integer_pimpl: negative_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_negative_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken-stl.cxx b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.cxx new file mode 100644 index 0000000..0f7e987 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/nmtoken-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void nmtoken_pimpl:: + _pre () + { + str_.erase (); + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void nmtoken_pimpl:: + _post () + { + ro_string tmp (str_); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + for (ro_string::size_type i = 0; i < size; ++i) + { + unsigned char c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + + str_.resize (size); + + if (!ok) + _schema_error (schema_error::invalid_nmtoken_value); + } + + std::string nmtoken_pimpl:: + post_nmtoken () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken-stl.hxx b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.hxx new file mode 100644 index 0000000..5166018 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken-stl.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/nmtoken-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKEN_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual std::string + post_nmtoken (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken.cxx b/libxsde/xsde/cxx/parser/validating/nmtoken.cxx new file mode 100644 index 0000000..875b8e3 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken.cxx @@ -0,0 +1,98 @@ +// file : xsde/cxx/parser/validating/nmtoken.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/parser/validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void nmtoken_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void nmtoken_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void nmtoken_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + for (ro_string::size_type i = 0; i < size; ++i) + { + unsigned char c = static_cast<unsigned char> (str_[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + { + ok = false; + break; + } + } + } + + str_.truncate (size); + + if (!ok) + _schema_error (schema_error::invalid_nmtoken_value); + } + + char* nmtoken_pimpl:: + post_nmtoken () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtoken.hxx b/libxsde/xsde/cxx/parser/validating/nmtoken.hxx new file mode 100644 index 0000000..f4d322e --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtoken.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/parser/validating/nmtoken.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKEN_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_pimpl: virtual nmtoken_pskel +#else + struct nmtoken_pimpl: nmtoken_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual char* + post_nmtoken (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens-stl.cxx b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.cxx new file mode 100644 index 0000000..1c88132 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.cxx @@ -0,0 +1,127 @@ +// file : xsde/cxx/parser/validating/nmtokens-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/nmtokens-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + void nmtokens_pimpl:: + _post () + { + nmtokens_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_nmtokens_value); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); +#else + parser_._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + const std::string& x = parser_.post_nmtoken (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + seq_->push_back (x); + else + parser_._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens-stl.hxx b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.hxx new file mode 100644 index 0000000..6cbc464 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens-stl.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/nmtokens-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKENS_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKENS_STL_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKENS_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens.cxx b/libxsde/xsde/cxx/parser/validating/nmtokens.cxx new file mode 100644 index 0000000..074294d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens.cxx @@ -0,0 +1,132 @@ +// file : xsde/cxx/parser/validating/nmtokens.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/nmtokens.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + nmtokens_pimpl:: + ~nmtokens_pimpl () + { + if (!base_) + delete seq_; + } + + void nmtokens_pimpl:: + _reset () + { + nmtokens_pskel::_reset (); + + if (!base_) + { + delete seq_; + seq_ = 0; + } + + parser_._reset (); + } + + nmtokens_pimpl:: + nmtokens_pimpl (bool base) + : base_ (base), seq_ (0) + { + } + + void nmtokens_pimpl:: + pre_impl (string_sequence* seq) + { + seq_ = seq; + } + + void nmtokens_pimpl:: + _pre () + { + if (seq_ == 0) + { + seq_ = new string_sequence (); + +#ifndef XSDE_EXCEPTIONS + if (seq_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + + nmtokens_pskel::_pre (); + } + + void nmtokens_pimpl:: + _post () + { + nmtokens_pskel::_post (); + + // Should have at least one element. + // + if (!_context ().error_type () && seq_->size () < 1) + _schema_error (schema_error::invalid_nmtokens_value); + } + + string_sequence* nmtokens_pimpl:: + post_nmtokens () + { + string_sequence* r = seq_; + seq_ = 0; + return r; + } + + void nmtokens_pimpl:: + _xsde_parse_item (const ro_string& s) + { + context& ctx = _context (); + + parser_.pre (); + +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + parser_._pre_impl (ctx); + else + parser_._copy_error (ctx); +#else + parser_._pre_impl (ctx); +#endif + if (!ctx.error_type ()) + parser_._characters (s); + + if (!ctx.error_type ()) + parser_._post_impl (); + + if (!ctx.error_type ()) + { + char* x = parser_.post_nmtoken (); + + // push_back() frees the string if it fails. + // +#ifndef XSDE_EXCEPTIONS + if (!parser_._error_type ()) + { + if (seq_->push_back (x)) + _sys_error (sys_error::no_memory); + } + else + parser_._copy_error (ctx); +#else + seq_->push_back (x); +#endif + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/nmtokens.hxx b/libxsde/xsde/cxx/parser/validating/nmtokens.hxx new file mode 100644 index 0000000..f24161a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/nmtokens.hxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/parser/validating/nmtokens.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NMTOKENS_HXX +#define XSDE_CXX_PARSER_VALIDATING_NMTOKENS_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> +#include <xsde/cxx/parser/validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_pimpl: virtual nmtokens_pskel +#else + struct nmtokens_pimpl: nmtokens_pskel +#endif + { + ~nmtokens_pimpl (); + nmtokens_pimpl (bool base = false); + + void + pre_impl (string_sequence*); + + virtual void + _pre (); + + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _post (); + + virtual string_sequence* + post_nmtokens (); + + virtual void + _reset (); + + protected: + bool base_; + nmtoken_pimpl parser_; + string_sequence* seq_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NMTOKENS_HXX diff --git a/libxsde/xsde/cxx/parser/validating/non-negative-integer.cxx b/libxsde/xsde/cxx/parser/validating/non-negative-integer.cxx new file mode 100644 index 0000000..7333abf --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-negative-integer.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/non-negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/non-negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void non_negative_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_negative_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_non_negative_integer_value); + } + + void non_negative_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoul (str_, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (sign_ == minus && value_ != 0)) + _schema_error (schema_error::invalid_non_negative_integer_value); + } + else + _schema_error (schema_error::invalid_non_negative_integer_value); + } + + unsigned long non_negative_integer_pimpl:: + post_non_negative_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/non-negative-integer.hxx b/libxsde/xsde/cxx/parser/validating/non-negative-integer.hxx new file mode 100644 index 0000000..36dabf7 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-negative-integer.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/validating/non-negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NON_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NON_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length non-negative integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_negative_integer_pimpl: virtual non_negative_integer_pskel, +#else + struct non_negative_integer_pimpl: non_negative_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long + post_non_negative_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NON_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/non-positive-integer.cxx b/libxsde/xsde/cxx/parser/validating/non-positive-integer.cxx new file mode 100644 index 0000000..0560a34 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-positive-integer.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/non-positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul +#include <limits.h> // LONG_MIN + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/non-positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void non_positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void non_positive_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 20)) + _schema_error (schema_error::invalid_non_positive_integer_value); + } + + void non_positive_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || + get_errno () != 0 || + (sign_ != minus && ul != 0) || + ul > static_cast<unsigned long> (LONG_MIN)) + _schema_error (schema_error::invalid_non_positive_integer_value); + + value_ = ul == static_cast<unsigned long> (LONG_MIN) + ? LONG_MIN : -static_cast<long> (ul); + } + else + _schema_error (schema_error::invalid_non_positive_integer_value); + } + + long non_positive_integer_pimpl:: + post_non_positive_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/non-positive-integer.hxx b/libxsde/xsde/cxx/parser/validating/non-positive-integer.hxx new file mode 100644 index 0000000..f592289 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/non-positive-integer.hxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/parser/validating/non-positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NON_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NON_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length non-positive integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_positive_integer_pimpl: virtual non_positive_integer_pskel, +#else + struct non_positive_integer_pimpl: non_positive_integer_pskel, +#endif + number + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual long + post_non_positive_integer (); + + protected: + // We only need strlen("09223372036854775808") + 1 characters to + // hold all valid and trimmed string representations of long, + // assuming we are on a 64 bit machine. + // + char str_[21]; + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NON_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string-stl.cxx b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.cxx new file mode 100644 index 0000000..131b4a1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/validating/normalized-string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/normalized-string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void normalized_string_pimpl:: + _pre () + { + str_.erase (); + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string normalized_string_pimpl:: + post_normalized_string () + { + std::string::size_type size = str_.size (); + + for (std::string::size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string-stl.hxx b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.hxx new file mode 100644 index 0000000..02247d2 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/normalized-string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_normalized_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string.cxx b/libxsde/xsde/cxx/parser/validating/normalized-string.cxx new file mode 100644 index 0000000..634cf2e --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string.cxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/parser/validating/normalized-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/normalized-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void normalized_string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void normalized_string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* normalized_string_pimpl:: + post_normalized_string () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + + for (size_type i = 0; i < size; ++i) + { + char& c = str_[i]; + + if (c == 0x0A || c == 0x0D || c == 0x09) + c = 0x20; + } + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/normalized-string.hxx b/libxsde/xsde/cxx/parser/validating/normalized-string.hxx new file mode 100644 index 0000000..5446ceb --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/normalized-string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/normalized-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_HXX +#define XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_pimpl: virtual normalized_string_pskel +#else + struct normalized_string_pimpl: normalized_string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_normalized_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NORMALIZED_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/validating/number.cxx b/libxsde/xsde/cxx/parser/validating/number.cxx new file mode 100644 index 0000000..62b7d53 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/number.cxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/parser/validating/number.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy + +#include <xsde/cxx/parser/validating/number.hxx> + +using xsde::cxx::ro_string; + +static bool +trim_leading_zeros (ro_string& s) +{ + ro_string::size_type size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size; + const char* of = f; + + while (f < l && *f == '0') + ++f; + + if (f != of) + { + s.assign ((f <= l ? f : 0), (f <= l ? l - f : 0)); + return true; + } + } + + return false; +} + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + bool number:: + parse (const ro_string& s, char* str, size_t max) + { + bool r = true; + + ro_string tmp (s.data (), s.size ()); + size_t size = tmp.size (); + + switch (state_) + { + case leading_ws: + { + size = trim_left (tmp); + + if (size != 0) + state_ = sign; + else + break; + // Fall through. + } + case sign: + { + if (tmp[0] == '-') + sign_ = minus; + else if (tmp[0] == '+') + sign_ = plus; + + if (sign_ != none) + tmp.assign (tmp.data () + 1, --size); + + if (size != 0) + state_ = leading_zeros; + else + break; + + // Fall through. + } + case leading_zeros: + { + if (trim_leading_zeros (tmp)) + { + if (size_ == 0) + { + str[0] = '0'; + size_ = 1; + } + + size = tmp.size (); + } + + if (size != 0) + state_ = literal; + else + break; + // Fall through. + } + case literal: + { + // If this chunk is too long then it has to be the last so trim + // trailing ws. + // + if ((max - size_) < size) + { + size = trim_right (tmp); + state_ = trailing_ws; // It either had ws or is too large. + } + + if ((max - size_) >= size) + { + memcpy (str + size_, tmp.data (), size); + size_ += size; + } + else + r = false; + + break; + } + case trailing_ws: + { + if (trim_left (tmp) != 0) + r = false; + } + } + + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/number.hxx b/libxsde/xsde/cxx/parser/validating/number.hxx new file mode 100644 index 0000000..2cd9b62 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/number.hxx @@ -0,0 +1,37 @@ +// file : xsde/cxx/parser/validating/number.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_NUMBER_HXX +#define XSDE_CXX_PARSER_VALIDATING_NUMBER_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/ro-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + class number + { + protected: + bool + parse (const ro_string&, char* str, size_t max); + + protected: + size_t size_; + enum {leading_ws, sign, leading_zeros, literal, trailing_ws} state_; + enum {none, plus, minus} sign_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_NUMBER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/parser.cxx b/libxsde/xsde/cxx/parser/validating/parser.cxx new file mode 100644 index 0000000..119bf79 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/parser.cxx @@ -0,0 +1,633 @@ +// file : xsde/cxx/parser/validating/parser.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/parser/validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // empty_content + // + +#ifdef XSDE_POLYMORPHIC + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&, + const char*) + { + return false; + } +#else + bool empty_content:: + _start_element_impl (const ro_string&, + const ro_string&) + { + return false; + } +#endif + + bool empty_content:: + _end_element_impl (const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool empty_content:: + _characters_impl (const ro_string&) + { + return false; + } + + // + // +#ifdef XSDE_POLYMORPHIC + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + _schema_error (schema_error::unexpected_element); + } +#else + void empty_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } +#endif + + void empty_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } + + static const char + xmlns_namespace_[] = "http://www.w3.org/2000/xmlns/"; + + static const char + xsi_namespace_[] = "http://www.w3.org/2001/XMLSchema-instance"; + + static const char + type_[] = "type"; + + static const char + nil_[] = "nil"; + + static const char + schema_location_[] = "schemaLocation"; + + static const char + no_namespace_schema_location_[] = "noNamespaceSchemaLocation"; + + void empty_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _schema_error (schema_error::unexpected_attribute); + } + + void empty_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + _schema_error (schema_error::unexpected_characters); + } + + + // simple_content + // + + void simple_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _schema_error (schema_error::unexpected_attribute); + } + + void simple_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + ro_string::size_type end = s.size (); + for (ro_string::size_type i = 0; i < end; ++i) + { + char c = s[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + continue; + + _schema_error (schema_error::unexpected_characters); + break; + } + } + } + + void simple_content:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + context_ = &c; + + previous_ = c.current_; + + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + + if (!c.error_type ()) + _pre_a_validate (); + } + + void simple_content:: + _post_impl () + { + if (!context_->error_type ()) + _post_a_validate (); + + if (!context_->error_type ()) + _post (); + + context_->current_ = previous_; + context_ = 0; + } + + void simple_content:: + _pre_a_validate () + { + } + + void simple_content:: + _post_a_validate () + { + } + + bool simple_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Returns true on error. + // + if (_attribute_impl_phase_one (ns, name, value)) + return true; + + return _attribute_impl_phase_two (ns, name, value); + } + + bool simple_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool simple_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + + // complex_content + // + +#ifdef XSDE_POLYMORPHIC + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name, + const char* type) + { + if (!_start_element_impl (ns, name, type)) + _schema_error (schema_error::unexpected_element); + } +#else + void complex_content:: + _start_element (const ro_string& ns, + const ro_string& name) + { + if (!_start_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } +#endif + + void complex_content:: + _end_element (const ro_string& ns, + const ro_string& name) + { + if (!_end_element_impl (ns, name)) + _schema_error (schema_error::unexpected_element); + } + + void complex_content:: + _attribute (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Weed out special attributes: xsi:type, xsi:nil, + // xsi:schemaLocation and noNamespaceSchemaLocation. + // See section 3.2.7 in Structures for details. + // + if (ns == xsi_namespace_ && + (name == schema_location_ || + name == no_namespace_schema_location_ || + name == type_ || + name == nil_)) + return; + + // Also some parsers supply us with namespace-prefix + // mapping attributes. + // + if (ns == xmlns_namespace_) + return; + + if (!_attribute_impl (ns, name, value)) + _schema_error (schema_error::unexpected_attribute); + } + + void complex_content:: + _characters (const ro_string& s) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_characters (s); + else +#endif + if (!_characters_impl (s)) + { + // Mixed content is implemented in the generated code + // by overriding _characters_impl and forwarding to + // _any_characters. + // + + // Scan the string for any non-whitespace characters + // (Structures, section 3.4.4, clause 1.3). + // + ro_string::size_type end = s.size (); + for (ro_string::size_type i = 0; i < end; ++i) + { + char c = s[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + continue; + + _schema_error (schema_error::unexpected_characters); + break; + } + } + } + + void complex_content:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + if (depth_++ == 0) + context_ = &c; + +#ifdef XSDE_EXCEPTIONS + parser_stack_.push (c.current_); +#else + if (parser_stack_.push (c.current_)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + c.current_.parser_ = this; + c.current_.depth_ = 0; + c.current_.any_ = false; + + _pre (); + + if (!c.error_type ()) + _pre_a_validate (); + + if (!c.error_type ()) + _pre_e_validate (); + } + + void complex_content:: + _post_impl () + { + if (!context_->error_type ()) + _post_e_validate (); + + if (!context_->error_type ()) + _post_a_validate (); + + if (!context_->error_type ()) + _post (); + + context_->current_ = parser_stack_.top (); + parser_stack_.pop (); + + if (--depth_ == 0) + context_ = 0; + } + + void complex_content:: + _pre_e_validate () + { + } + + void complex_content:: + _post_e_validate () + { + } + + void complex_content:: + _pre_a_validate () + { + } + + void complex_content:: + _post_a_validate () + { + } + + bool complex_content:: + _attribute_impl (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + // Returns true on error. + // + if (_attribute_impl_phase_one (ns, name, value)) + return true; + + return _attribute_impl_phase_two (ns, name, value); + } + + bool complex_content:: + _attribute_impl_phase_one (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + bool complex_content:: + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&) + { + return false; + } + + void complex_content:: + _reset () + { + empty_content::_reset (); + + depth_ = 0; + parser_stack_.clear (); + } + + // list_base + // + + // Find first non-space character. + // + static ro_string::size_type + find_ns (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + (s[pos] == 0x20 || s[pos] == 0x0A || + s[pos] == 0x0D || s[pos] == 0x09)) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Find first space character. + // + static ro_string::size_type + find_s (const char* s, + ro_string::size_type size, + ro_string::size_type pos) + { + while (pos < size && + s[pos] != 0x20 && s[pos] != 0x0A && + s[pos] != 0x0D && s[pos] != 0x09) + ++pos; + + return pos < size ? pos : ro_string::npos; + } + + // Relevant XML Schema Part 2: Datatypes sections: 4.2.1.2, 4.3.6. + // + + void list_base:: + _pre_impl (context& c) + { + simple_content::_pre_impl (c); + + if (!c.error_type ()) + { +#ifdef XSDE_EXCEPTIONS + buf_.assign ("", 0); +#else + if (buf_.assign ("", 0)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + } + + void list_base:: + _characters (const ro_string& s) + { + typedef ro_string::size_type size_type; + + const char* data = s.data (); + size_type size = s.size (); + + // Handle the previous chunk if we start with a ws. + // + if (!buf_.empty () && + (data[0] == 0x20 || data[0] == 0x0A || + data[0] == 0x0D || data[0] == 0x09)) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + buf_.assign ("", 0); // Can't fail. + } + + context& ctx = _context (); + + // Traverse the data while logically collapsing spaces. + // + for (size_type i = find_ns (data, size, 0); i != ro_string::npos;) + { + size_type j = find_s (data, size, i); + + if (j != ro_string::npos) + { + if (buf_.empty ()) + { + ro_string tmp (data + i, j - i); // Private copy ctor. + _xsde_parse_item (tmp); + } + else + { + // Assemble the first item in str from buf_ and s. + // + string str; + str.swap (buf_); + +#ifdef XSDE_EXCEPTIONS + str.append (data + i, j - i); +#else + if (str.append (data + i, j - i)) + { + _sys_error (sys_error::no_memory); + break; + } +#endif + ro_string tmp (str); // Private copy ctor. + _xsde_parse_item (tmp); + } + + if (ctx.error_type ()) + break; + + i = find_ns (data, size, j); + } + else + { + // Last fragment, append it to buf_. + // +#ifdef XSDE_EXCEPTIONS + buf_.append (data + i, size - i); +#else + if (buf_.append (data + i, size - i)) + _sys_error (sys_error::no_memory); +#endif + break; + } + } + } + + void list_base:: + _xsde_parse_item (const ro_string&) + { + } + + void list_base:: + _post_impl () + { + // Handle the last item. + // + if (!buf_.empty ()) + { + ro_string tmp (buf_); // Private copy ctor. + _xsde_parse_item (tmp); + } + + simple_content::_post_impl (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/parser.hxx b/libxsde/xsde/cxx/parser/validating/parser.hxx new file mode 100644 index 0000000..246b7c9 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/parser.hxx @@ -0,0 +1,304 @@ +// file : xsde/cxx/parser/validating/parser.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_PARSER_HXX +#define XSDE_CXX_PARSER_VALIDATING_PARSER_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/cxx/string.hxx> +#include <xsde/cxx/ro-string.hxx> + +#include <xsde/cxx/parser/elements.hxx> +#include <xsde/cxx/parser/state.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // + // + struct empty_content: parser_base + { + +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, + const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, + const ro_string&); + + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + + // + // +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + empty_content (); + empty_content (empty_content* impl, void*); +#endif + }; + + + // + // + struct simple_content: empty_content + { + // + // + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + simple_content (); + simple_content (simple_content* impl, void*); +#endif + }; + + + // + // + struct complex_content: empty_content + { +#ifdef XSDE_POLYMORPHIC + virtual void + _start_element (const ro_string&, + const ro_string&, + const char*); +#else + virtual void + _start_element (const ro_string&, + const ro_string&); +#endif + + virtual void + _end_element (const ro_string&, + const ro_string&); + + virtual void + _attribute (const ro_string&, + const ro_string&, + const ro_string&); + + virtual void + _characters (const ro_string&); + + // + // + virtual bool + _attribute_impl (const ro_string&, + const ro_string&, + const ro_string&); + + // + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + + + // Implementation callbacks. + // + virtual void + _pre_e_validate (); + + virtual void + _post_e_validate (); + + virtual void + _pre_a_validate (); + + virtual void + _post_a_validate (); + + + // Attribute validation: during phase one we are searching for + // matching attributes (Structures, section 3.4.4, clause 2.1). + // During phase two we are searching for attribute wildcards + // (section 3.4.4, clause 2.2). Both phases run across + // inheritance hierarchy from derived to base for extension + // only. Both functions return true if the match was found and + // validation has been performed. + // + virtual bool + _attribute_impl_phase_one (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + virtual bool + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value); + + // + // + virtual void + _reset (); + + // + // + complex_content (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + complex_content (complex_content* impl, void*); +#endif + protected: + size_t depth_; + parser_stack parser_stack_; + }; + + // Validation state stack for the 'all' particle. + // + struct all_stack + { + all_stack (size_t n, unsigned char* first); + + stack::error + push (); + + void + pop (); + + unsigned char* + top (); + + void + clear (); + + private: + stack stack_; + }; + + // Base for xsd:list. + // + struct list_base: simple_content + { + virtual void + _xsde_parse_item (const ro_string&); + + virtual void + _pre_impl (context&); + + virtual void + _characters (const ro_string&); + + virtual void + _post_impl (); + + // + // +#ifdef XSDE_REUSE_STYLE_TIEIN + list_base (); + list_base (list_base* impl, void*); +#endif + protected: + string buf_; + }; + } + } + } +} + +#include <xsde/cxx/parser/validating/parser.ixx> + +#endif // XSDE_CXX_PARSER_VALIDATING_PARSER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/parser.ixx b/libxsde/xsde/cxx/parser/validating/parser.ixx new file mode 100644 index 0000000..4a0e176 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/parser.ixx @@ -0,0 +1,121 @@ +// file : xsde/cxx/parser/validating/parser.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + + // empty_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline empty_content:: + empty_content () + { + } + + inline empty_content:: + empty_content (empty_content* impl, void*) + : parser_base (impl, 0) + { + } +#endif + + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline simple_content:: + simple_content () + { + } + + inline simple_content:: + simple_content (simple_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + + // complex_content + // + inline complex_content:: + complex_content () + : depth_ (0), parser_stack_ (previous_) + { + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline complex_content:: + complex_content (complex_content* impl, void*) + : empty_content (impl, 0), depth_ (0), parser_stack_ (previous_) + { + } +#endif + + // all_stack + // + + inline all_stack:: + all_stack (size_t n, unsigned char* first) + : stack_ (n, first) + { + } + + inline stack::error all_stack:: + push () + { + if (stack::error e = stack_.push ()) + return e; + + unsigned char* p = static_cast<unsigned char*> (stack_.top ()); + + for (size_t i = 0; i < stack_.element_size (); ++i) + p[i] = 0; + + return stack::error_none; + } + + inline void all_stack:: + pop () + { + stack_.pop (); + } + + inline unsigned char* all_stack:: + top () + { + return static_cast<unsigned char*> (stack_.top ()); + } + + inline void all_stack:: + clear () + { + stack_.clear (); + } + + + // list_base + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline list_base:: + list_base () + { + } + + inline list_base:: + list_base (list_base* impl, void*) + : simple_content (impl, 0) + { + } +#endif + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/positive-integer.cxx b/libxsde/xsde/cxx/parser/validating/positive-integer.cxx new file mode 100644 index 0000000..2a6595a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/positive-integer.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/validating/positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void positive_integer_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void positive_integer_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_positive_integer_value); + } + + void positive_integer_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoul (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0 || value_ == 0) + _schema_error (schema_error::invalid_positive_integer_value); + } + else + _schema_error (schema_error::invalid_positive_integer_value); + } + + unsigned long positive_integer_pimpl:: + post_positive_integer () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/positive-integer.hxx b/libxsde/xsde/cxx/parser/validating/positive-integer.hxx new file mode 100644 index 0000000..59b6b27 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/positive-integer.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_POSITIVE_INTEGER_HXX +#define XSDE_CXX_PARSER_VALIDATING_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Arbitrary-length positive integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct positive_integer_pimpl: virtual positive_integer_pskel, number +#else + struct positive_integer_pimpl: positive_integer_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long + post_positive_integer (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long, assuming we are on a 64 bit machine. + // + char str_[22]; + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/parser/validating/qname-stl.cxx b/libxsde/xsde/cxx/parser/validating/qname-stl.cxx new file mode 100644 index 0000000..a65e367 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname-stl.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/qname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/qname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void qname_pimpl:: + _pre () + { + str_.erase (); + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + void qname_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + const char* s = tmp.data (); + + if (pos != ro_string::npos) + { + if (xml::valid_ncname (s, pos) && + xml::valid_ncname (s + pos + 1, size - pos - 1)) + { + prefix_.assign (s, pos); + name_.assign (s + pos + 1, size - pos - 1); + } + else + _schema_error (schema_error::invalid_qname_value); + } + else + { + if (xml::valid_ncname (s, size)) + { + prefix_.erase (); + str_.resize (size); + name_.swap (str_); + } + else + _schema_error (schema_error::invalid_qname_value); + } + } + + qname qname_pimpl:: + post_qname () + { + return qname (prefix_, name_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/qname-stl.hxx b/libxsde/xsde/cxx/parser/validating/qname-stl.hxx new file mode 100644 index 0000000..c766c55 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname-stl.hxx @@ -0,0 +1,49 @@ +// file : xsde/cxx/parser/validating/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_QNAME_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_QNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual qname + post_qname (); + + protected: + std::string str_; + std::string name_; + std::string prefix_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/qname.cxx b/libxsde/xsde/cxx/parser/validating/qname.cxx new file mode 100644 index 0000000..265179c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname.cxx @@ -0,0 +1,180 @@ +// file : xsde/cxx/parser/validating/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/parser/validating/qname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + qname_pimpl:: + ~qname_pimpl () + { + if (!base_) + delete qn_; + } + + void qname_pimpl:: + _reset () + { + qname_pskel::_reset (); + + if (!base_) + { + delete qn_; + qn_ = 0; + } + } + + qname_pimpl:: + qname_pimpl (bool base) + : base_ (base), qn_ (0) + { + } + + void qname_pimpl:: + pre_impl (qname* qn) + { + qn_ = qn; + } + + void qname_pimpl:: + _pre () + { + if (qn_ == 0) + { + qn_ = new qname (); + +#ifndef XSDE_EXCEPTIONS + if (qn_ == 0) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void qname_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void qname_pimpl:: + _post () + { + ro_string tmp (str_.data (), str_.size ()); + ro_string::size_type size = trim_right (tmp); + ro_string::size_type pos = tmp.find (':'); + + string name; + string prefix; + + const char* s = tmp.data (); + + if (pos != ro_string::npos) + { + if (xml::valid_ncname (s, pos) && + xml::valid_ncname (s + pos + 1, size - pos - 1)) + { +#ifdef XSDE_EXCEPTIONS + prefix.assign (s, pos); + name.assign (s + pos + 1, size - pos - 1); +#else + if (prefix.assign (s, pos) || + name.assign (s + pos + 1, size - pos - 1)) + { + _sys_error (sys_error::no_memory); + return; + } +#endif + } + else + { + _schema_error (schema_error::invalid_qname_value); + return; + } + } + else + { + if (xml::valid_ncname (s, size)) + { +#ifdef XSDE_EXCEPTIONS + prefix.assign ("", 0); + str_.truncate (size); + name.swap (str_); +#else + if (prefix.assign ("", 0)) + { + _sys_error (sys_error::no_memory); + return; + } + else + { + str_.truncate (size); + name.swap (str_); + } +#endif + } + else + { + _schema_error (schema_error::invalid_qname_value); + return; + } + } + + qn_->prefix (prefix.detach ()); + qn_->name (name.detach ()); + } + + qname* qname_pimpl:: + post_qname () + { + qname* r = qn_; + qn_ = 0; + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/qname.hxx b/libxsde/xsde/cxx/parser/validating/qname.hxx new file mode 100644 index 0000000..2201699 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/qname.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/parser/validating/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_QNAME_HXX +#define XSDE_CXX_PARSER_VALIDATING_QNAME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_pimpl: virtual qname_pskel +#else + struct qname_pimpl: qname_pskel +#endif + { + ~qname_pimpl (); + qname_pimpl (bool base = false); + + void + pre_impl (qname*); + + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual qname* + post_qname (); + + virtual void + _reset (); + + protected: + bool base_; + string str_; + qname* qn_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_QNAME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/short.cxx b/libxsde/xsde/cxx/parser/validating/short.cxx new file mode 100644 index 0000000..199465b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/short.cxx @@ -0,0 +1,70 @@ +// file : xsde/cxx/parser/validating/short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void short_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 6)) + _schema_error (schema_error::invalid_short_value); + } + + void short_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + bool neg = (sign_ == minus); + + if (*p != '\0' || (neg && ul > 32768) || (!neg && ul > 32767)) + _schema_error (schema_error::invalid_short_value); + + value_ = neg + ? static_cast<short> (-static_cast<int> (ul)) + : static_cast<short> (ul); + } + else + _schema_error (schema_error::invalid_short_value); + } + + short short_pimpl:: + post_short () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/short.hxx b/libxsde/xsde/cxx/parser/validating/short.hxx new file mode 100644 index 0000000..1bbe7bd --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/short.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_SHORT_HXX +#define XSDE_CXX_PARSER_VALIDATING_SHORT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 16-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct short_pimpl: virtual short_pskel, number +#else + struct short_pimpl: short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual short + post_short (); + + protected: + // We only need strlen("032768") + 1 characters to hold all valid + // and trimmed string representations of short. + // + char str_[7]; + short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/string-stl.cxx b/libxsde/xsde/cxx/parser/validating/string-stl.cxx new file mode 100644 index 0000000..a0394db --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/parser/validating/string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void string_pimpl:: + _pre () + { + str_.erase (); + } + + void string_pimpl:: + _characters (const ro_string& s) + { + str_ += s; + } + + std::string string_pimpl:: + post_string () + { + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/string-stl.hxx b/libxsde/xsde/cxx/parser/validating/string-stl.hxx new file mode 100644 index 0000000..a6220d1 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_STRING_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_string (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/string.cxx b/libxsde/xsde/cxx/parser/validating/string.cxx new file mode 100644 index 0000000..a4319fb --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/parser/validating/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void string_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void string_pimpl:: + _characters (const ro_string& s) + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + + char* string_pimpl:: + post_string () + { + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/string.hxx b/libxsde/xsde/cxx/parser/validating/string.hxx new file mode 100644 index 0000000..2e2bcd5 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/string.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_STRING_HXX +#define XSDE_CXX_PARSER_VALIDATING_STRING_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_pimpl: virtual string_pskel +#else + struct string_pimpl: string_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_string (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_STRING_HXX diff --git a/libxsde/xsde/cxx/parser/validating/time-zone.cxx b/libxsde/xsde/cxx/parser/validating/time-zone.cxx new file mode 100644 index 0000000..fb25f56 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time-zone.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/parser/validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + bool + parse_time_zone (const char* s, size_t n, short& h, short& m) + { + // time_zone := Z|(+|-)HH:MM + // + if (n == 0) + { + return false; + } + else if (s[0] == 'Z') + { + if (n != 1) + return false; + + h = 0; + m = 0; + } + else + { + if (n != 6 || (s[0] != '-' && s[0] != '+') || s[3] != ':') + return false; + + // Parse hours. + // + char d1 = s[1]; + char d2 = s[2]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + h = 10 * (d1 - '0') + (d2 - '0'); + + if (h > 14) + return false; + + // Parse minutes. + // + d1 = s[4]; + d2 = s[5]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + return false; + + m = 10 * (d1 - '0') + (d2 - '0'); + + if (m > 59 || (h == 14 && m != 0)) + return false; + + if (s[0] == '-') + { + h = -h; + m = -m; + } + } + + return true; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/time-zone.hxx b/libxsde/xsde/cxx/parser/validating/time-zone.hxx new file mode 100644 index 0000000..93a8205 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time-zone.hxx @@ -0,0 +1,32 @@ +// file : xsde/cxx/parser/validating/time-zone.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TIME_ZONE_HXX +#define XSDE_CXX_PARSER_VALIDATING_TIME_ZONE_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + namespace bits + { + bool + parse_time_zone (const char* s, + size_t size, + short& hours, + short& minutes); + } + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TIME_ZONE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/time.cxx b/libxsde/xsde/cxx/parser/validating/time.cxx new file mode 100644 index 0000000..eaddc58 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time.cxx @@ -0,0 +1,181 @@ +// file : xsde/cxx/parser/validating/time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtod + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/time.hxx> +#include <xsde/cxx/parser/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void time_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void time_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + void time_pimpl:: + _post () + { + char* s = str_.data (); + ro_string tmp (s, str_.size ()); + ro_string::size_type n = trim_right (tmp); + + // time := HH:MM:SS[.S+][Z|(+|-)HH:MM] + // + + if (n < 8 || s[2] != ':' || s[5] != ':') + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // hours + // + char d1 = s[0]; + char d2 = s[1]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_time_value); + return; + } + + hours_ = 10 * (d1 - '0') + (d2 - '0'); + + if (hours_ > 24) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // minutes + // + d1 = s[3]; + d2 = s[4]; + + if (d1 < '0' || d1 > '9' || d2 < '0' || d2 > '9') + { + _schema_error (schema_error::invalid_time_value); + return; + } + + minutes_ = 10 * (d1 - '0') + (d2 - '0'); + + if (minutes_ > 59) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // Find the end of the seconds fragment. + // + ro_string::size_type pos = 8; + for (; pos < n; ++pos) + { + char c = s[pos]; + + if (c == 'Z' || c == '+' || c == '-') + break; + } + + // At least one digit should follow the fraction point. + // + if ((pos - 6) == 3) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + // Parse the time zone first so that we can truncate and + // reuse the string. + // + if (pos < n) + { + if (!bits::parse_time_zone (s + pos, n - pos, zh_, zm_)) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + z_ = true; + } + else + z_ = false; + + // seconds + // + str_.truncate (pos); + + char* p; + set_errno (0); + seconds_ = strtod (s + 6, &p); + + if (*p != '\0' || get_errno () != 0 || seconds_ >= 60.0) + { + _schema_error (schema_error::invalid_time_value); + return; + } + + if (hours_ == 24 && (minutes_ != 0 || seconds_ != 0.0)) + { + _schema_error (schema_error::invalid_time_value); + return; + } + } + + time time_pimpl:: + post_time () + { + return z_ + ? time (hours_, minutes_, seconds_, zh_, zm_) + : time (hours_, minutes_, seconds_); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/time.hxx b/libxsde/xsde/cxx/parser/validating/time.hxx new file mode 100644 index 0000000..3f68b4c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/time.hxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/parser/validating/time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TIME_HXX +#define XSDE_CXX_PARSER_VALIDATING_TIME_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct time_pimpl: virtual time_pskel +#else + struct time_pimpl: time_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual time + post_time (); + + protected: + string str_; + unsigned short hours_, minutes_; + double seconds_; + bool z_; + short zh_, zm_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TIME_HXX diff --git a/libxsde/xsde/cxx/parser/validating/token-stl.cxx b/libxsde/xsde/cxx/parser/validating/token-stl.cxx new file mode 100644 index 0000000..e6ac6ea --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token-stl.cxx @@ -0,0 +1,73 @@ +// file : xsde/cxx/parser/validating/token-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/token-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void token_pimpl:: + _pre () + { + str_.erase (); + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string token_pimpl:: + post_token () + { + std::string::size_type size = str_.size (); + std::string::size_type j = 0; + + bool subs = false; + + for (std::string::size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.resize (j); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/token-stl.hxx b/libxsde/xsde/cxx/parser/validating/token-stl.hxx new file mode 100644 index 0000000..29e4f9a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/token-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TOKEN_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_TOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_token (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/token.cxx b/libxsde/xsde/cxx/parser/validating/token.cxx new file mode 100644 index 0000000..5e12a60 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token.cxx @@ -0,0 +1,94 @@ +// file : xsde/cxx/parser/validating/token.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/token.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void token_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void token_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* token_pimpl:: + post_token () + { + typedef string::size_type size_type; + + size_type size = str_.size (); + size_type j = 0; + + bool subs = false; + + for (size_type i = 0; i < size; ++i) + { + char c = str_[i]; + + if (c == 0x20 || c == 0x0A || c == 0x0D || c == 0x09) + { + subs = true; + } + else + { + if (subs) + { + subs = false; + str_[j++] = 0x20; + } + + str_[j++] = c; + } + } + + str_.truncate (j); + + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/token.hxx b/libxsde/xsde/cxx/parser/validating/token.hxx new file mode 100644 index 0000000..230466b --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/token.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/token.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_TOKEN_HXX +#define XSDE_CXX_PARSER_VALIDATING_TOKEN_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_pimpl: virtual token_pskel +#else + struct token_pimpl: token_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_token (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_TOKEN_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-byte.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-byte.cxx new file mode 100644 index 0000000..ace72f8 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-byte.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/unsigned-byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_byte_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_byte_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 4)) + _schema_error (schema_error::invalid_unsigned_byte_value); + } + + void unsigned_byte_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || ul > 255) + _schema_error (schema_error::invalid_unsigned_byte_value); + + value_ = static_cast<unsigned char> (ul); + } + else + _schema_error (schema_error::invalid_unsigned_byte_value); + } + + unsigned char unsigned_byte_pimpl:: + post_unsigned_byte () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-byte.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-byte.hxx new file mode 100644 index 0000000..bec1e6d --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-byte.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_BYTE_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_BYTE_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 8-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_byte_pimpl: virtual unsigned_byte_pskel, number +#else + struct unsigned_byte_pimpl: unsigned_byte_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned char + post_unsigned_byte (); + + protected: + // We only need strlen("0256") + 1 characters to hold all valid + // and trimmed string representations of unsigned byte. + // + char str_[5]; + unsigned char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_BYTE_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-int.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-int.cxx new file mode 100644 index 0000000..fbb18aa --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-int.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/unsigned-int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/unsigned-int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_int_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_int_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 11)) + _schema_error (schema_error::invalid_unsigned_int_value); + } + + void unsigned_int_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0 || ul > 4294967295UL) + _schema_error (schema_error::invalid_unsigned_int_value); + + value_ = static_cast<unsigned int> (ul); + } + else + _schema_error (schema_error::invalid_unsigned_int_value); + } + + unsigned int unsigned_int_pimpl:: + post_unsigned_int () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-int.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-int.hxx new file mode 100644 index 0000000..2811557 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-int.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_INT_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_INT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 32-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_int_pimpl: virtual unsigned_int_pskel, number +#else + struct unsigned_int_pimpl: unsigned_int_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned int + post_unsigned_int (); + + protected: + // We only need strlen("04294967295") + 1 characters to hold all + // valid and trimmed string representations of unsigned int. + // + char str_[12]; + unsigned int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_INT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long-long.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.cxx new file mode 100644 index 0000000..5464028 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/validating/unsigned-long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoull + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/unsigned-long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_unsigned_long_value); + } + + void unsigned_long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoull (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_unsigned_long_value); + } + else + _schema_error (schema_error::invalid_unsigned_long_value); + } + + unsigned long long unsigned_long_pimpl:: + post_unsigned_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long-long.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.hxx new file mode 100644 index 0000000..b0aa4cb --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long-long.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/unsigned-long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 64-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + unsigned long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-long.cxx new file mode 100644 index 0000000..eababbf --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long.cxx @@ -0,0 +1,64 @@ +// file : xsde/cxx/parser/validating/unsigned-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/errno.hxx> + +#include <xsde/cxx/parser/validating/unsigned-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_long_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_long_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 21)) + _schema_error (schema_error::invalid_unsigned_long_value); + } + + void unsigned_long_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + char* p; + set_errno (0); + value_ = strtoul (str_, &p, 10); + + if (*p != '\0' || get_errno () != 0) + _schema_error (schema_error::invalid_unsigned_long_value); + } + else + _schema_error (schema_error::invalid_unsigned_long_value); + } + + unsigned long unsigned_long_pimpl:: + post_unsigned_long () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-long.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-long.hxx new file mode 100644 index 0000000..6b2ac19 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-long.hxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_pimpl: virtual unsigned_long_pskel, number +#else + struct unsigned_long_pimpl: unsigned_long_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned long + post_unsigned_long (); + + protected: + // We only need strlen("018446744073709551615") + 1 characters to + // hold all valid and trimmed string representations of unsigned + // long long. + // + char str_[22]; + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_LONG_HXX diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-short.cxx b/libxsde/xsde/cxx/parser/validating/unsigned-short.cxx new file mode 100644 index 0000000..b40b51c --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-short.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/parser/validating/unsigned-short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdlib.h> // strtoul + +#include <xsde/cxx/parser/validating/unsigned-short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void unsigned_short_pimpl:: + _pre () + { + size_ = 0; + sign_ = none; + state_ = leading_ws; + } + + void unsigned_short_pimpl:: + _characters (const ro_string& s) + { + if (!parse (s, str_, 6)) + _schema_error (schema_error::invalid_unsigned_short_value); + } + + void unsigned_short_pimpl:: + _post () + { + ro_string tmp (str_, size_); + size_t size = trim_right (tmp); + + if (size != 0 && sign_ != minus && tmp[0] != '-' && tmp[0] != '+') + { + str_[size] = '\0'; + + // No need to check errno since our string representation + // can never overflow an unsigned long. + // + char* p; + unsigned long ul = strtoul (str_, &p, 10); + + if (*p != '\0' || ul > 65535) + _schema_error (schema_error::invalid_unsigned_short_value); + + value_ = static_cast<unsigned short> (ul); + } + else + _schema_error (schema_error::invalid_unsigned_short_value); + } + + unsigned short unsigned_short_pimpl:: + post_unsigned_short () + { + return value_; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/unsigned-short.hxx b/libxsde/xsde/cxx/parser/validating/unsigned-short.hxx new file mode 100644 index 0000000..be7228a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/unsigned-short.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/parser/validating/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_UNSIGNED_SHORT_HXX +#define XSDE_CXX_PARSER_VALIDATING_UNSIGNED_SHORT_HXX + +#include <xsde/cxx/parser/validating/number.hxx> +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // 16-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_short_pimpl: virtual unsigned_short_pskel, number +#else + struct unsigned_short_pimpl: unsigned_short_pskel, number +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual void + _post (); + + virtual unsigned short + post_unsigned_short (); + + protected: + // We only need strlen("065535") + 1 characters to hold all valid + // and trimmed string representations of unsigned short. + // + char str_[7]; + unsigned short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_UNSIGNED_SHORT_HXX diff --git a/libxsde/xsde/cxx/parser/validating/uri-stl.cxx b/libxsde/xsde/cxx/parser/validating/uri-stl.cxx new file mode 100644 index 0000000..c2947dd --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri-stl.cxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/parser/validating/uri-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/uri-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void uri_pimpl:: + _pre () + { + str_.erase (); + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + str_ += tmp; + } + else + str_ += s; + } + + std::string uri_pimpl:: + post_uri () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + ro_string tmp (str_); + str_.resize (trim_right (tmp)); + + std::string r; + r.swap (str_); + return r; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/uri-stl.hxx b/libxsde/xsde/cxx/parser/validating/uri-stl.hxx new file mode 100644 index 0000000..b964aff --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri-stl.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/uri-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_URI_STL_HXX +#define XSDE_CXX_PARSER_VALIDATING_URI_STL_HXX + +#include <string> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual std::string + post_uri (); + + protected: + std::string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_URI_STL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/uri.cxx b/libxsde/xsde/cxx/parser/validating/uri.cxx new file mode 100644 index 0000000..37acfea --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/parser/validating/uri.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/parser/validating/uri.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + void uri_pimpl:: + _pre () + { +#ifdef XSDE_EXCEPTIONS + str_.assign ("", 0); +#else + if (str_.assign ("", 0)) + _sys_error (sys_error::no_memory); +#endif + } + + void uri_pimpl:: + _characters (const ro_string& s) + { + if (str_.size () == 0) + { + ro_string tmp (s.data (), s.size ()); + + if (trim_left (tmp) != 0) + { +#ifdef XSDE_EXCEPTIONS + str_.append (tmp.data (), tmp.size ()); +#else + if (str_.append (tmp.data (), tmp.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + else + { +#ifdef XSDE_EXCEPTIONS + str_.append (s.data (), s.size ()); +#else + if (str_.append (s.data (), s.size ())) + _sys_error (sys_error::no_memory); +#endif + } + } + + char* uri_pimpl:: + post_uri () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + ro_string tmp (str_); + str_.truncate (trim_right (tmp)); + return str_.detach (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/validating/uri.hxx b/libxsde/xsde/cxx/parser/validating/uri.hxx new file mode 100644 index 0000000..2e19aef --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/uri.hxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/parser/validating/uri.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_URI_HXX +#define XSDE_CXX_PARSER_VALIDATING_URI_HXX + +#include <xsde/cxx/string.hxx> + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_pimpl: virtual uri_pskel +#else + struct uri_pimpl: uri_pskel +#endif + { + virtual void + _pre (); + + virtual void + _characters (const ro_string&); + + virtual char* + post_uri (); + + protected: + string str_; + }; + } + } + } +} + +#endif // XSDE_CXX_PARSER_VALIDATING_URI_HXX diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pimpl.hxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pimpl.hxx new file mode 100644 index 0000000..7552521 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pimpl.hxx @@ -0,0 +1,82 @@ +// file : xsde/cxx/parser/validating/xml-schema-pimpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX +#define XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +#include <xsde/cxx/parser/validating/any-type.hxx> +#include <xsde/cxx/parser/validating/boolean.hxx> +#include <xsde/cxx/parser/validating/byte.hxx> +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/validating/byte.hxx> +#include <xsde/cxx/parser/validating/unsigned-byte.hxx> +#include <xsde/cxx/parser/validating/short.hxx> +#include <xsde/cxx/parser/validating/unsigned-short.hxx> +#include <xsde/cxx/parser/validating/int.hxx> +#include <xsde/cxx/parser/validating/unsigned-int.hxx> + +#ifdef XSDE_LONGLONG +# include <xsde/cxx/parser/validating/long-long.hxx> +# include <xsde/cxx/parser/validating/unsigned-long-long.hxx> +#else +# include <xsde/cxx/parser/validating/long.hxx> +# include <xsde/cxx/parser/validating/unsigned-long.hxx> +#endif + +#include <xsde/cxx/parser/validating/integer.hxx> +#include <xsde/cxx/parser/validating/negative-integer.hxx> +#include <xsde/cxx/parser/validating/non-positive-integer.hxx> +#include <xsde/cxx/parser/validating/positive-integer.hxx> +#include <xsde/cxx/parser/validating/non-negative-integer.hxx> +#include <xsde/cxx/parser/validating/float.hxx> +#include <xsde/cxx/parser/validating/double.hxx> +#include <xsde/cxx/parser/validating/decimal.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/parser/validating/string-stl.hxx> +# include <xsde/cxx/parser/validating/normalized-string-stl.hxx> +# include <xsde/cxx/parser/validating/token-stl.hxx> +# include <xsde/cxx/parser/validating/name-stl.hxx> +# include <xsde/cxx/parser/validating/nmtoken-stl.hxx> +# include <xsde/cxx/parser/validating/nmtokens-stl.hxx> +# include <xsde/cxx/parser/validating/ncname-stl.hxx> +# include <xsde/cxx/parser/validating/id-stl.hxx> +# include <xsde/cxx/parser/validating/idref-stl.hxx> +# include <xsde/cxx/parser/validating/idrefs-stl.hxx> +# include <xsde/cxx/parser/validating/language-stl.hxx> +# include <xsde/cxx/parser/validating/uri-stl.hxx> +# include <xsde/cxx/parser/validating/qname-stl.hxx> +#else +# include <xsde/cxx/parser/validating/string.hxx> +# include <xsde/cxx/parser/validating/normalized-string.hxx> +# include <xsde/cxx/parser/validating/token.hxx> +# include <xsde/cxx/parser/validating/name.hxx> +# include <xsde/cxx/parser/validating/nmtoken.hxx> +# include <xsde/cxx/parser/validating/nmtokens.hxx> +# include <xsde/cxx/parser/validating/ncname.hxx> +# include <xsde/cxx/parser/validating/id.hxx> +# include <xsde/cxx/parser/validating/idref.hxx> +# include <xsde/cxx/parser/validating/idrefs.hxx> +# include <xsde/cxx/parser/validating/language.hxx> +# include <xsde/cxx/parser/validating/uri.hxx> +# include <xsde/cxx/parser/validating/qname.hxx> +#endif + +#include <xsde/cxx/parser/validating/base64-binary.hxx> +#include <xsde/cxx/parser/validating/hex-binary.hxx> + +#include <xsde/cxx/parser/validating/gday.hxx> +#include <xsde/cxx/parser/validating/gmonth.hxx> +#include <xsde/cxx/parser/validating/gyear.hxx> +#include <xsde/cxx/parser/validating/gmonth-day.hxx> +#include <xsde/cxx/parser/validating/gyear-month.hxx> +#include <xsde/cxx/parser/validating/date.hxx> +#include <xsde/cxx/parser/validating/time.hxx> +#include <xsde/cxx/parser/validating/date-time.hxx> +#include <xsde/cxx/parser/validating/duration.hxx> + +#endif // XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PIMPL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.cxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.cxx new file mode 100644 index 0000000..894f674 --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.cxx @@ -0,0 +1,617 @@ +// file : xsde/cxx/parser/validating/xml-schema-pskel.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/parser/validating/xml-schema-pskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type + // +#ifdef XSDE_POLYMORPHIC + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, + const ro_string& name, + const char* type) + { + context& ctx = _context (); + ctx.current_.any_ = true; + ctx.current_.depth_++; + + _start_any_element (ns, name, type); + return true; + } +#else + bool any_type_pskel:: + _start_element_impl (const ro_string& ns, const ro_string& name) + { + context& ctx = _context (); + ctx.current_.any_ = true; + ctx.current_.depth_++; + + _start_any_element (ns, name); + return true; + } +#endif + + bool any_type_pskel:: + _end_element_impl (const ro_string& ns, const ro_string& name) + { + _end_any_element (ns, name); + return true; + } + + bool any_type_pskel:: + _attribute_impl_phase_two (const ro_string& ns, + const ro_string& name, + const ro_string& value) + { + _any_attribute (ns, name, value); + return true; + } + + bool any_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + void any_type_pskel:: + post_any_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_type_impl_) + any_type_impl_->post_any_type (); +#endif + } + + // any_simple_type + // + bool any_simple_type_pskel:: + _characters_impl (const ro_string& s) + { + _any_characters (s); + return true; + } + + void any_simple_type_pskel:: + post_any_simple_type () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_simple_type_impl_) + any_simple_type_impl_->post_any_simple_type (); +#endif + } + + // static/dynamic_type function implementations. + // +#ifdef XSDE_POLYMORPHIC + const char* any_type_pskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_simple_type_pskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_simple_type_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* boolean_pskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + const char* boolean_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* byte_pskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + const char* byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_byte_pskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_byte_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* short_pskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + const char* short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_short_pskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_short_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* int_pskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + const char* int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_int_pskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_int_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* long_pskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + const char* long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_long_pskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_long_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* integer_pskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + const char* integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* negative_integer_pskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_positive_integer_pskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* positive_integer_pskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* positive_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_negative_integer_pskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_negative_integer_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* float_pskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + const char* float_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* double_pskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + const char* double_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* decimal_pskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + const char* decimal_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* string_pskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + const char* string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* normalized_string_pskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + const char* normalized_string_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* token_pskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + const char* token_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* name_pskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + const char* name_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtoken_pskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtoken_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtokens_pskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtokens_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* ncname_pskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + const char* ncname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* id_pskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + const char* id_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idref_pskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + const char* idref_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idrefs_pskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + const char* idrefs_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* language_pskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + const char* language_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* uri_pskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + const char* uri_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* qname_pskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + const char* qname_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* base64_binary_pskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + const char* base64_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* hex_binary_pskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + const char* hex_binary_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gday_pskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gday_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_pskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_pskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_day_pskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_day_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_month_pskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_month_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_pskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + const char* date_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* time_pskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + const char* time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_time_pskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + const char* date_time_pskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* duration_pskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + const char* duration_pskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif // XSDE_POLYMORPHIC + } + } + } +} + diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx new file mode 100644 index 0000000..8f9e33a --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.hxx @@ -0,0 +1,1385 @@ +// file : xsde/cxx/parser/validating/xml-schema-pskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX +#define XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/parser/xml-schema.hxx> + +#include <xsde/cxx/parser/validating/parser.hxx> + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // anyType and anySimpleType. All events are routed to the + // _any_* callbacks. + // + struct any_type_pskel: complex_content + { +#ifdef XSDE_POLYMORPHIC + virtual bool + _start_element_impl (const ro_string&, + const ro_string&, + const char*); +#else + virtual bool + _start_element_impl (const ro_string&, const ro_string&); +#endif + + virtual bool + _end_element_impl (const ro_string&, const ro_string&); + + virtual bool + _attribute_impl_phase_two (const ro_string&, + const ro_string&, + const ro_string&); + + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_pskel (); + any_type_pskel (any_type_pskel* impl, void*); + + protected: + any_type_pskel* any_type_impl_; +#endif + }; + + struct any_simple_type_pskel: simple_content + { + virtual bool + _characters_impl (const ro_string&); + + virtual void + post_any_simple_type (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_simple_type_pskel (); + any_simple_type_pskel (any_simple_type_pskel* impl, void*); + + protected: + any_simple_type_pskel* any_simple_type_impl_; +#endif + }; + + + // Boolean. + // + struct boolean_pskel: simple_content + { + virtual bool + post_boolean () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + boolean_pskel (); + boolean_pskel (boolean_pskel* impl, void*); + + protected: + boolean_pskel* boolean_impl_; +#endif + }; + + + // 8-bit + // + + struct byte_pskel: simple_content + { + virtual signed char + post_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + byte_pskel (); + byte_pskel (byte_pskel* impl, void*); + + protected: + byte_pskel* byte_impl_; +#endif + }; + + struct unsigned_byte_pskel: simple_content + { + virtual unsigned char + post_unsigned_byte () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_byte_pskel (); + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*); + + protected: + unsigned_byte_pskel* unsigned_byte_impl_; +#endif + }; + + + // 16-bit + // + + struct short_pskel: simple_content + { + virtual short + post_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + short_pskel (); + short_pskel (short_pskel* impl, void*); + + protected: + short_pskel* short_impl_; +#endif + }; + + struct unsigned_short_pskel: simple_content + { + virtual unsigned short + post_unsigned_short () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_short_pskel (); + unsigned_short_pskel (unsigned_short_pskel* impl, void*); + + protected: + unsigned_short_pskel* unsigned_short_impl_; +#endif + }; + + + // 32-bit + // + + struct int_pskel: simple_content + { + virtual int + post_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + int_pskel (); + int_pskel (int_pskel* impl, void*); + + protected: + int_pskel* int_impl_; +#endif + }; + + struct unsigned_int_pskel: simple_content + { + virtual unsigned int + post_unsigned_int () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_int_pskel (); + unsigned_int_pskel (unsigned_int_pskel* impl, void*); + + protected: + unsigned_int_pskel* unsigned_int_impl_; +#endif + }; + + + // 64-bit + // +#ifdef XSDE_LONGLONG + + struct long_pskel: simple_content + { + virtual long long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; + +#else + + struct long_pskel: simple_content + { + virtual long + post_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_pskel (); + long_pskel (long_pskel* impl, void*); + + protected: + long_pskel* long_impl_; +#endif + }; + + struct unsigned_long_pskel: simple_content + { + virtual unsigned long + post_unsigned_long () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_pskel (); + unsigned_long_pskel (unsigned_long_pskel* impl, void*); + + protected: + unsigned_long_pskel* unsigned_long_impl_; +#endif + }; +#endif + + + // Arbitrary-length integers. + // + + struct integer_pskel: simple_content + { + virtual long + post_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + integer_pskel (); + integer_pskel (integer_pskel* impl, void*); + + protected: + integer_pskel* integer_impl_; +#endif + }; + + struct negative_integer_pskel: simple_content + { + virtual long + post_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + negative_integer_pskel (); + negative_integer_pskel (negative_integer_pskel* impl, void*); + + protected: + negative_integer_pskel* negative_integer_impl_; +#endif + }; + + struct non_positive_integer_pskel: simple_content + { + virtual long + post_non_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_positive_integer_pskel (); + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*); + + protected: + non_positive_integer_pskel* non_positive_integer_impl_; +#endif + }; + + struct positive_integer_pskel: simple_content + { + virtual unsigned long + post_positive_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + positive_integer_pskel (); + positive_integer_pskel (positive_integer_pskel* impl, void*); + + protected: + positive_integer_pskel* positive_integer_impl_; +#endif + }; + + struct non_negative_integer_pskel: simple_content + { + virtual unsigned long + post_non_negative_integer () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_negative_integer_pskel (); + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*); + + protected: + non_negative_integer_pskel* non_negative_integer_impl_; +#endif + }; + + + // Floats. + // + + struct float_pskel: simple_content + { + virtual float + post_float () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + float_pskel (); + float_pskel (float_pskel* impl, void*); + + protected: + float_pskel* float_impl_; +#endif + }; + + struct double_pskel: simple_content + { + virtual double + post_double () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + double_pskel (); + double_pskel (double_pskel* impl, void*); + + protected: + double_pskel* double_impl_; +#endif + }; + + struct decimal_pskel: simple_content + { + virtual double + post_decimal () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + decimal_pskel (); + decimal_pskel (decimal_pskel* impl, void*); + + protected: + decimal_pskel* decimal_impl_; +#endif + }; + + + // String-based types. + // +#ifdef XSDE_STL + + struct string_pskel: simple_content + { + virtual std::string + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual std::string + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual std::string + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual std::string + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual std::string + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual std::string + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual std::string + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual std::string + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual std::string + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual std::string + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; + +#else // XSDE_STL + + // Note that in this case you are getting a C string that you + // have to delete with delete[]. + // + struct string_pskel: simple_content + { + virtual char* + post_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_pskel (); + string_pskel (string_pskel* impl, void*); + + protected: + string_pskel* string_impl_; +#endif + }; + + struct normalized_string_pskel: simple_content + { + virtual char* + post_normalized_string () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_pskel (); + normalized_string_pskel (normalized_string_pskel* impl, void*); + + protected: + normalized_string_pskel* normalized_string_impl_; +#endif + }; + + struct token_pskel: simple_content + { + virtual char* + post_token () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_pskel (); + token_pskel (token_pskel* impl, void*); + + protected: + token_pskel* token_impl_; +#endif + }; + + struct name_pskel: simple_content + { + virtual char* + post_name () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_pskel (); + name_pskel (name_pskel* impl, void*); + + protected: + name_pskel* name_impl_; +#endif + }; + + struct nmtoken_pskel: simple_content + { + virtual char* + post_nmtoken () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_pskel (); + nmtoken_pskel (nmtoken_pskel* impl, void*); + + protected: + nmtoken_pskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_pskel: list_base + { + virtual string_sequence* + post_nmtokens () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_pskel (); + nmtokens_pskel (nmtokens_pskel* impl, void*); + + protected: + nmtokens_pskel* nmtokens_impl_; +#endif + }; + + struct ncname_pskel: simple_content + { + virtual char* + post_ncname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_pskel (); + ncname_pskel (ncname_pskel* impl, void*); + + protected: + ncname_pskel* ncname_impl_; +#endif + }; + + struct id_pskel: simple_content + { + virtual char* + post_id () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_pskel (); + id_pskel (id_pskel* impl, void*); + + protected: + id_pskel* id_impl_; +#endif + }; + + struct idref_pskel: simple_content + { + virtual char* + post_idref () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_pskel (); + idref_pskel (idref_pskel* impl, void*); + + protected: + idref_pskel* idref_impl_; +#endif + }; + + struct idrefs_pskel: list_base + { + virtual string_sequence* + post_idrefs () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_pskel (); + idrefs_pskel (idrefs_pskel* impl, void*); + + protected: + idrefs_pskel* idrefs_impl_; +#endif + }; + + struct language_pskel: simple_content + { + virtual char* + post_language () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_pskel (); + language_pskel (language_pskel* impl, void*); + + protected: + language_pskel* language_impl_; +#endif + }; + + struct uri_pskel: simple_content + { + virtual char* + post_uri () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_pskel (); + uri_pskel (uri_pskel* impl, void*); + + protected: + uri_pskel* uri_impl_; +#endif + }; + + struct qname_pskel: simple_content + { + virtual qname* + post_qname () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_pskel (); + qname_pskel (qname_pskel* impl, void*); + + protected: + qname_pskel* qname_impl_; +#endif + }; +#endif // XSDE_STL + + + // base64Binary + // + struct base64_binary_pskel: simple_content + { + virtual buffer* + post_base64_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + base64_binary_pskel (); + base64_binary_pskel (base64_binary_pskel* impl, void*); + + protected: + base64_binary_pskel* base64_binary_impl_; +#endif + }; + + // hexBinary + // + struct hex_binary_pskel: simple_content + { + virtual buffer* + post_hex_binary () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + hex_binary_pskel (); + hex_binary_pskel (hex_binary_pskel* impl, void*); + + protected: + hex_binary_pskel* hex_binary_impl_; +#endif + }; + + // Time and date types. + // + struct gday_pskel: simple_content + { + virtual gday + post_gday () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gday_pskel (); + gday_pskel (gday_pskel* impl, void*); + + protected: + gday_pskel* gday_impl_; +#endif + }; + + struct gmonth_pskel: simple_content + { + virtual gmonth + post_gmonth () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_pskel (); + gmonth_pskel (gmonth_pskel* impl, void*); + + protected: + gmonth_pskel* gmonth_impl_; +#endif + }; + + struct gyear_pskel: simple_content + { + virtual gyear + post_gyear () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_pskel (); + gyear_pskel (gyear_pskel* impl, void*); + + protected: + gyear_pskel* gyear_impl_; +#endif + }; + + struct gmonth_day_pskel: simple_content + { + virtual gmonth_day + post_gmonth_day () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_day_pskel (); + gmonth_day_pskel (gmonth_day_pskel* impl, void*); + + protected: + gmonth_day_pskel* gmonth_day_impl_; +#endif + }; + + struct gyear_month_pskel: simple_content + { + virtual gyear_month + post_gyear_month () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_month_pskel (); + gyear_month_pskel (gyear_month_pskel* impl, void*); + + protected: + gyear_month_pskel* gyear_month_impl_; +#endif + }; + + struct date_pskel: simple_content + { + virtual date + post_date () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_pskel (); + date_pskel (date_pskel* impl, void*); + + protected: + date_pskel* date_impl_; +#endif + }; + + struct time_pskel: simple_content + { + virtual time + post_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + time_pskel (); + time_pskel (time_pskel* impl, void*); + + protected: + time_pskel* time_impl_; +#endif + }; + + struct date_time_pskel: simple_content + { + virtual date_time + post_date_time () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_time_pskel (); + date_time_pskel (date_time_pskel* impl, void*); + + protected: + date_time_pskel* date_time_impl_; +#endif + }; + + struct duration_pskel: simple_content + { + virtual duration + post_duration () = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + duration_pskel (); + duration_pskel (duration_pskel* impl, void*); + + protected: + duration_pskel* duration_impl_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/parser/validating/xml-schema-pskel.ixx> + +#endif // XSDE_CXX_PARSER_VALIDATING_XML_SCHEMA_PSKEL_HXX diff --git a/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx new file mode 100644 index 0000000..bb94f3e --- /dev/null +++ b/libxsde/xsde/cxx/parser/validating/xml-schema-pskel.ixx @@ -0,0 +1,704 @@ +// file : xsde/cxx/parser/validating/xml-schema-pskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace parser + { + namespace validating + { + // any_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_pskel:: + any_type_pskel () + : any_type_impl_ (0) + { + } + + inline any_type_pskel:: + any_type_pskel (any_type_pskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + + // any_simple_type_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_simple_type_pskel:: + any_simple_type_pskel () + : any_simple_type_impl_ (0) + { + } + + inline any_simple_type_pskel:: + any_simple_type_pskel (any_simple_type_pskel* impl, void*) + : simple_content (impl, 0), any_simple_type_impl_ (impl) + { + } +#endif + + // boolean_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline boolean_pskel:: + boolean_pskel () + : boolean_impl_ (0) + { + } + + inline boolean_pskel:: + boolean_pskel (boolean_pskel* impl, void*) + : simple_content (impl, 0), boolean_impl_ (impl) + { + } +#endif + + // byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline byte_pskel:: + byte_pskel () + : byte_impl_ (0) + { + } + + inline byte_pskel:: + byte_pskel (byte_pskel* impl, void*) + : simple_content (impl, 0), byte_impl_ (impl) + { + } +#endif + + // unsigned_byte_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_byte_pskel:: + unsigned_byte_pskel () + : unsigned_byte_impl_ (0) + { + } + + inline unsigned_byte_pskel:: + unsigned_byte_pskel (unsigned_byte_pskel* impl, void*) + : simple_content (impl, 0), unsigned_byte_impl_ (impl) + { + } +#endif + + // short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline short_pskel:: + short_pskel () + : short_impl_ (0) + { + } + + inline short_pskel:: + short_pskel (short_pskel* impl, void*) + : simple_content (impl, 0), short_impl_ (impl) + { + } +#endif + + // unsigned_short_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_short_pskel:: + unsigned_short_pskel () + : unsigned_short_impl_ (0) + { + } + + inline unsigned_short_pskel:: + unsigned_short_pskel (unsigned_short_pskel* impl, void*) + : simple_content (impl, 0), unsigned_short_impl_ (impl) + { + } +#endif + + // int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline int_pskel:: + int_pskel () + : int_impl_ (0) + { + } + + inline int_pskel:: + int_pskel (int_pskel* impl, void*) + : simple_content (impl, 0), int_impl_ (impl) + { + } +#endif + + // unsigned_int_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_int_pskel:: + unsigned_int_pskel () + : unsigned_int_impl_ (0) + { + } + + inline unsigned_int_pskel:: + unsigned_int_pskel (unsigned_int_pskel* impl, void*) + : simple_content (impl, 0), unsigned_int_impl_ (impl) + { + } +#endif + + // long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline long_pskel:: + long_pskel () + : long_impl_ (0) + { + } + + inline long_pskel:: + long_pskel (long_pskel* impl, void*) + : simple_content (impl, 0), long_impl_ (impl) + { + } +#endif + + // unsigned_long_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_long_pskel:: + unsigned_long_pskel () + : unsigned_long_impl_ (0) + { + } + + inline unsigned_long_pskel:: + unsigned_long_pskel (unsigned_long_pskel* impl, void*) + : simple_content (impl, 0), unsigned_long_impl_ (impl) + { + } +#endif + + // integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline integer_pskel:: + integer_pskel () + : integer_impl_ (0) + { + } + + inline integer_pskel:: + integer_pskel (integer_pskel* impl, void*) + : simple_content (impl, 0), integer_impl_ (impl) + { + } +#endif + + // negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline negative_integer_pskel:: + negative_integer_pskel () + : negative_integer_impl_ (0) + { + } + + inline negative_integer_pskel:: + negative_integer_pskel (negative_integer_pskel* impl, void*) + : simple_content (impl, 0), negative_integer_impl_ (impl) + { + } +#endif + + // non_positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_positive_integer_pskel:: + non_positive_integer_pskel () + : non_positive_integer_impl_ (0) + { + } + + inline non_positive_integer_pskel:: + non_positive_integer_pskel (non_positive_integer_pskel* impl, void*) + : simple_content (impl, 0), non_positive_integer_impl_ (impl) + { + } +#endif + + // positive_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline positive_integer_pskel:: + positive_integer_pskel () + : positive_integer_impl_ (0) + { + } + + inline positive_integer_pskel:: + positive_integer_pskel (positive_integer_pskel* impl, void*) + : simple_content (impl, 0), positive_integer_impl_ (impl) + { + } +#endif + + // non_negative_integer_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_negative_integer_pskel:: + non_negative_integer_pskel () + : non_negative_integer_impl_ (0) + { + } + + inline non_negative_integer_pskel:: + non_negative_integer_pskel (non_negative_integer_pskel* impl, void*) + : simple_content (impl, 0), non_negative_integer_impl_ (impl) + { + } +#endif + + // float_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline float_pskel:: + float_pskel () + : float_impl_ (0) + { + } + + inline float_pskel:: + float_pskel (float_pskel* impl, void*) + : simple_content (impl, 0), float_impl_ (impl) + { + } +#endif + + // double_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline double_pskel:: + double_pskel () + : double_impl_ (0) + { + } + + inline double_pskel:: + double_pskel (double_pskel* impl, void*) + : simple_content (impl, 0), double_impl_ (impl) + { + } +#endif + + // decimal_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline decimal_pskel:: + decimal_pskel () + : decimal_impl_ (0) + { + } + + inline decimal_pskel:: + decimal_pskel (decimal_pskel* impl, void*) + : simple_content (impl, 0), decimal_impl_ (impl) + { + } +#endif + + // string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline string_pskel:: + string_pskel () + : string_impl_ (0) + { + } + + inline string_pskel:: + string_pskel (string_pskel* impl, void*) + : simple_content (impl, 0), string_impl_ (impl) + { + } +#endif + + // normalized_string_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline normalized_string_pskel:: + normalized_string_pskel () + : normalized_string_impl_ (0) + { + } + + inline normalized_string_pskel:: + normalized_string_pskel (normalized_string_pskel* impl, void*) + : simple_content (impl, 0), normalized_string_impl_ (impl) + { + } +#endif + + // token_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline token_pskel:: + token_pskel () + : token_impl_ (0) + { + } + + inline token_pskel:: + token_pskel (token_pskel* impl, void*) + : simple_content (impl, 0), token_impl_ (impl) + { + } +#endif + + // name_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline name_pskel:: + name_pskel () + : name_impl_ (0) + { + } + + inline name_pskel:: + name_pskel (name_pskel* impl, void*) + : simple_content (impl, 0), name_impl_ (impl) + { + } +#endif + + // nmtoken_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtoken_pskel:: + nmtoken_pskel () + : nmtoken_impl_ (0) + { + } + + inline nmtoken_pskel:: + nmtoken_pskel (nmtoken_pskel* impl, void*) + : simple_content (impl, 0), nmtoken_impl_ (impl) + { + } +#endif + + // nmtokens_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtokens_pskel:: + nmtokens_pskel () + : nmtokens_impl_ (0) + { + } + + inline nmtokens_pskel:: + nmtokens_pskel (nmtokens_pskel* impl, void*) + : list_base (impl, 0), nmtokens_impl_ (impl) + { + } +#endif + + // ncname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline ncname_pskel:: + ncname_pskel () + : ncname_impl_ (0) + { + } + + inline ncname_pskel:: + ncname_pskel (ncname_pskel* impl, void*) + : simple_content (impl, 0), ncname_impl_ (impl) + { + } +#endif + + // id_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline id_pskel:: + id_pskel () + : id_impl_ (0) + { + } + + inline id_pskel:: + id_pskel (id_pskel* impl, void*) + : simple_content (impl, 0), id_impl_ (impl) + { + } +#endif + + // idref_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idref_pskel:: + idref_pskel () + : idref_impl_ (0) + { + } + + inline idref_pskel:: + idref_pskel (idref_pskel* impl, void*) + : simple_content (impl, 0), idref_impl_ (impl) + { + } +#endif + + // idrefs_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idrefs_pskel:: + idrefs_pskel () + : idrefs_impl_ (0) + { + } + + inline idrefs_pskel:: + idrefs_pskel (idrefs_pskel* impl, void*) + : list_base (impl, 0), idrefs_impl_ (impl) + { + } +#endif + + // language_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline language_pskel:: + language_pskel () + : language_impl_ (0) + { + } + + inline language_pskel:: + language_pskel (language_pskel* impl, void*) + : simple_content (impl, 0), language_impl_ (impl) + { + } +#endif + + // uri_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline uri_pskel:: + uri_pskel () + : uri_impl_ (0) + { + } + + inline uri_pskel:: + uri_pskel (uri_pskel* impl, void*) + : simple_content (impl, 0), uri_impl_ (impl) + { + } +#endif + + // qname_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline qname_pskel:: + qname_pskel () + : qname_impl_ (0) + { + } + + inline qname_pskel:: + qname_pskel (qname_pskel* impl, void*) + : simple_content (impl, 0), qname_impl_ (impl) + { + } +#endif + + // base64_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline base64_binary_pskel:: + base64_binary_pskel () + : base64_binary_impl_ (0) + { + } + + inline base64_binary_pskel:: + base64_binary_pskel (base64_binary_pskel* impl, void*) + : simple_content (impl, 0), base64_binary_impl_ (impl) + { + } +#endif + + // hex_binary_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline hex_binary_pskel:: + hex_binary_pskel () + : hex_binary_impl_ (0) + { + } + + inline hex_binary_pskel:: + hex_binary_pskel (hex_binary_pskel* impl, void*) + : simple_content (impl, 0), hex_binary_impl_ (impl) + { + } +#endif + + // gday_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gday_pskel:: + gday_pskel () + : gday_impl_ (0) + { + } + + inline gday_pskel:: + gday_pskel (gday_pskel* impl, void*) + : simple_content (impl, 0), gday_impl_ (impl) + { + } +#endif + + // gmonth_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_pskel:: + gmonth_pskel () + : gmonth_impl_ (0) + { + } + + inline gmonth_pskel:: + gmonth_pskel (gmonth_pskel* impl, void*) + : simple_content (impl, 0), gmonth_impl_ (impl) + { + } +#endif + + // gyear_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_pskel:: + gyear_pskel () + : gyear_impl_ (0) + { + } + + inline gyear_pskel:: + gyear_pskel (gyear_pskel* impl, void*) + : simple_content (impl, 0), gyear_impl_ (impl) + { + } +#endif + + // gmonth_day_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_day_pskel:: + gmonth_day_pskel () + : gmonth_day_impl_ (0) + { + } + + inline gmonth_day_pskel:: + gmonth_day_pskel (gmonth_day_pskel* impl, void*) + : simple_content (impl, 0), gmonth_day_impl_ (impl) + { + } +#endif + + // gyear_month_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_month_pskel:: + gyear_month_pskel () + : gyear_month_impl_ (0) + { + } + + inline gyear_month_pskel:: + gyear_month_pskel (gyear_month_pskel* impl, void*) + : simple_content (impl, 0), gyear_month_impl_ (impl) + { + } +#endif + + // date_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_pskel:: + date_pskel () + : date_impl_ (0) + { + } + + inline date_pskel:: + date_pskel (date_pskel* impl, void*) + : simple_content (impl, 0), date_impl_ (impl) + { + } +#endif + + // time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline time_pskel:: + time_pskel () + : time_impl_ (0) + { + } + + inline time_pskel:: + time_pskel (time_pskel* impl, void*) + : simple_content (impl, 0), time_impl_ (impl) + { + } +#endif + + // date_time_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_time_pskel:: + date_time_pskel () + : date_time_impl_ (0) + { + } + + inline date_time_pskel:: + date_time_pskel (date_time_pskel* impl, void*) + : simple_content (impl, 0), date_time_impl_ (impl) + { + } +#endif + + // duration_pskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline duration_pskel:: + duration_pskel () + : duration_impl_ (0) + { + } + + inline duration_pskel:: + duration_pskel (duration_pskel* impl, void*) + : simple_content (impl, 0), duration_impl_ (impl) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/parser/xml-schema.hxx b/libxsde/xsde/cxx/parser/xml-schema.hxx new file mode 100644 index 0000000..5b17568 --- /dev/null +++ b/libxsde/xsde/cxx/parser/xml-schema.hxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/parser/xml-schema.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_PARSER_XML_SCHEMA_HXX +#define XSDE_CXX_PARSER_XML_SCHEMA_HXX + +#include <xsde/cxx/buffer.hxx> +#include <xsde/cxx/date-time.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/qname-stl.hxx> +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/qname.hxx> +# include <xsde/cxx/string-sequence.hxx> +#endif + +#endif // XSDE_CXX_PARSER_XML_SCHEMA_HXX diff --git a/libxsde/xsde/cxx/post.hxx b/libxsde/xsde/cxx/post.hxx new file mode 100644 index 0000000..2f913ec --- /dev/null +++ b/libxsde/xsde/cxx/post.hxx @@ -0,0 +1,14 @@ +// file : xsde/cxx/post.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifdef _MSC_VER +# if (_MSC_VER >= 1400) +# include <xsde/cxx/compilers/vc-8/post.hxx> +# elif (_MSC_VER >= 1300) +# include <xsde/cxx/compilers/vc-7/post.hxx> +# elif (_MSC_VER >= 1200) +# include <xsde/cxx/compilers/vc-6/post.hxx> +# endif +#endif diff --git a/libxsde/xsde/cxx/pre.hxx b/libxsde/xsde/cxx/pre.hxx new file mode 100644 index 0000000..a73dff1 --- /dev/null +++ b/libxsde/xsde/cxx/pre.hxx @@ -0,0 +1,15 @@ +// file : xsde/cxx/pre.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + + +#ifdef _MSC_VER +# if (_MSC_VER >= 1400) +# include <xsde/cxx/compilers/vc-8/pre.hxx> +# elif (_MSC_VER >= 1300) +# include <xsde/cxx/compilers/vc-7/pre.hxx> +# elif (_MSC_VER >= 1200) +# include <xsde/cxx/compilers/vc-6/pre.hxx> +# endif +#endif diff --git a/libxsde/xsde/cxx/qname-stl.hxx b/libxsde/xsde/cxx/qname-stl.hxx new file mode 100644 index 0000000..ea5b5d8 --- /dev/null +++ b/libxsde/xsde/cxx/qname-stl.hxx @@ -0,0 +1,59 @@ +// file : xsde/cxx/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_QNAME_STL_HXX +#define XSDE_CXX_QNAME_STL_HXX + +#include <string> + +namespace xsde +{ + namespace cxx + { + class qname + { + public: + qname (); + explicit + qname (const std::string& name); + qname (const std::string& prefix, const std::string& name); + + void + swap (qname&); + + const std::string& + prefix () const; + + std::string& + prefix (); + + void + prefix (const std::string&); + + const std::string& + name () const; + + std::string& + name (); + + void + name (const std::string&); + + private: + std::string prefix_; + std::string name_; + }; + + bool + operator== (const qname&, const qname&); + + bool + operator!= (const qname&, const qname&); + } +} + +#include <xsde/cxx/qname-stl.ixx> + +#endif // XSDE_CXX_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/qname-stl.ixx b/libxsde/xsde/cxx/qname-stl.ixx new file mode 100644 index 0000000..f4122e5 --- /dev/null +++ b/libxsde/xsde/cxx/qname-stl.ixx @@ -0,0 +1,82 @@ +// file : xsde/cxx/qname-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline qname:: + qname () + { + } + + inline qname:: + qname (const std::string& name) + : prefix_ (), name_ (name) + { + } + + inline qname:: + qname (const std::string& prefix, const std::string& name) + : prefix_ (prefix), name_ (name) + { + } + + inline void qname:: + swap (qname& x) + { + prefix_.swap (x.prefix_); + name_.swap (x.name_); + } + + inline const std::string& qname:: + prefix () const + { + return prefix_; + } + + inline std::string& qname:: + prefix () + { + return prefix_; + } + + inline void qname:: + prefix (const std::string& prefix) + { + prefix_ = prefix; + } + + inline const std::string& qname:: + name () const + { + return name_; + } + + inline std::string& qname:: + name () + { + return name_; + } + + inline void qname:: + name (const std::string& name) + { + name_ = name; + } + + inline bool + operator== (const qname& x, const qname& y) + { + return x.name () == y.name () && x.prefix () == y.prefix (); + } + + inline bool + operator!= (const qname& x, const qname& y) + { + return !(x == y); + } + } +} diff --git a/libxsde/xsde/cxx/qname.cxx b/libxsde/xsde/cxx/qname.cxx new file mode 100644 index 0000000..ea89f4e --- /dev/null +++ b/libxsde/xsde/cxx/qname.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen, memcpy +#include <stddef.h> // size_t + +#include <xsde/cxx/qname.hxx> + +namespace xsde +{ + namespace cxx + { +#ifndef XSDE_EXCEPTIONS + qname::error qname:: +#else + void qname:: +#endif + prefix_copy (const char* prefix) + { + delete[] prefix_; + + if (prefix) + { + size_t size = strlen (prefix) + 1; + prefix_ = new char[size]; + +#ifndef XSDE_EXCEPTIONS + if (prefix_ == 0) + return error_no_memory; +#endif + memcpy (prefix_, prefix, size); + } + else + prefix_ = 0; + +#ifndef XSDE_EXCEPTIONS + return error_none; +#endif + } + +#ifndef XSDE_EXCEPTIONS + qname::error qname:: +#else + void qname:: +#endif + name_copy (const char* name) + { + delete[] name_; + + if (name) + { + size_t size = strlen (name) + 1; + name_ = new char[size]; + +#ifndef XSDE_EXCEPTIONS + if (name_ == 0) + return error_no_memory; +#endif + memcpy (name_, name, size); + } + else + name_ = 0; + +#ifndef XSDE_EXCEPTIONS + return error_none; +#endif + } + } +} diff --git a/libxsde/xsde/cxx/qname.hxx b/libxsde/xsde/cxx/qname.hxx new file mode 100644 index 0000000..350b8f1 --- /dev/null +++ b/libxsde/xsde/cxx/qname.hxx @@ -0,0 +1,99 @@ +// file : xsde/cxx/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_QNAME_HXX +#define XSDE_CXX_QNAME_HXX + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + class qname + { + public: +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; +#endif + + ~qname (); + + // The default c-tor creates an uninitialized qname. Use + // modifiers to initialize it. + // + qname (); + + explicit + qname (char* name); + qname (char* prefix, char* name); + + void + swap (qname&); + + private: + qname (const qname&); + qname& operator= (const qname&); + + public: + char* + prefix (); + + const char* + prefix () const; + + void + prefix (char*); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + prefix_copy (const char*); + + char* + prefix_detach (); + + public: + char* + name (); + + const char* + name () const; + + void + name (char*); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + name_copy (const char*); + + char* + name_detach (); + + private: + char* prefix_; + char* name_; + }; + + bool + operator== (const qname&, const qname&); + + bool + operator!= (const qname&, const qname&); + } +} + +#include <xsde/cxx/qname.ixx> + +#endif // XSDE_CXX_QNAME_HXX diff --git a/libxsde/xsde/cxx/qname.ixx b/libxsde/xsde/cxx/qname.ixx new file mode 100644 index 0000000..6772556 --- /dev/null +++ b/libxsde/xsde/cxx/qname.ixx @@ -0,0 +1,125 @@ +// file : xsde/cxx/qname.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strcmp + +namespace xsde +{ + namespace cxx + { + // c-tors, d-tor and swap + // + inline qname:: + ~qname () + { + delete[] prefix_; + delete[] name_; + } + + inline qname:: + qname () + : prefix_ (0), name_ (0) + { + } + + inline qname:: + qname (char* n) + : prefix_ (0), name_ (n) + { + } + + inline qname:: + qname (char* p, char* n) + : prefix_ (p), name_ (n) + { + } + + inline void qname:: + swap (qname& x) + { + char* p = prefix_; + char* n = name_; + + prefix_ = x.prefix_; + name_ = x.name_; + + x.prefix_ = p; + x.name_ = n; + } + + // preix + // + inline char* qname:: + prefix () + { + return prefix_; + } + + inline const char* qname:: + prefix () const + { + return prefix_; + } + + inline void qname:: + prefix (char* prefix) + { + delete[] prefix_; + prefix_ = prefix; + } + + inline char* qname:: + prefix_detach () + { + char* r = prefix_; + prefix_ = 0; + return r; + } + + // name + // + inline char* qname:: + name () + { + return name_; + } + + inline const char* qname:: + name () const + { + return name_; + } + + inline void qname:: + name (char* name) + { + delete[] name_; + name_ = name; + } + + inline char* qname:: + name_detach () + { + char* r = name_; + name_ = 0; + return r; + } + + // + // + inline bool + operator== (const qname& x, const qname& y) + { + return strcmp (x.name (), y.name ()) == 0 && + strcmp (x.prefix (), y.prefix ()) == 0; + } + + inline bool + operator!= (const qname& x, const qname& y) + { + return !(x == y); + } + } +} diff --git a/libxsde/xsde/cxx/ro-string.cxx b/libxsde/xsde/cxx/ro-string.cxx new file mode 100644 index 0000000..c74b34f --- /dev/null +++ b/libxsde/xsde/cxx/ro-string.cxx @@ -0,0 +1,116 @@ +// file : xsde/cxx/ro-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/ro-string.hxx> + +#ifdef XSDE_IOSTREAM +# include <iostream> +#endif + +namespace xsde +{ + namespace cxx + { + // ro_string + const size_t ro_string::npos = ~(size_t (0)); + + // operator << + // +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream& os, const ro_string& str) + { + if (str.size () != 0) + os.write (str.data (), str.size ()); + + return os; + } +#endif + + size_t + trim_left (ro_string& s) + { + size_t size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size; + const char* of = f; + + while (f < l && + (*f == 0x20 || *f == 0x0A || *f == 0x0D || *f == 0x09)) + ++f; + + if (f != of) + { + size = f <= l ? l - f : 0; + s.assign ((f <= l ? f : 0), size); + } + } + + return size; + } + + size_t + trim_right (ro_string& s) + { + size_t size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size - 1; + const char* ol = l; + + while (l > f && + (*l == 0x20 || *l == 0x0A || *l == 0x0D || *l == 0x09)) + --l; + + if (l != ol) + { + size = f <= l ? l - f + 1 : 0; + s.assign ((f <= l ? f : 0), size); + } + } + + return size; + } + + size_t + trim (ro_string& s) + { + size_t size = s.size (); + + if (size != 0) + { + const char* f = s.data (); + const char* l = f + size; + + const char* of = f; + + while (f < l && + (*f == 0x20 || *f == 0x0A || *f == 0x0D || *f == 0x09)) + ++f; + + --l; + + const char* ol = l; + + while (l > f && + (*l == 0x20 || *l == 0x0A || *l == 0x0D || *l == 0x09)) + --l; + + if (f != of || l != ol) + { + size = f <= l ? l - f + 1 : 0; + s.assign ((f <= l ? f : 0), size); + } + } + + return size; + } + } +} diff --git a/libxsde/xsde/cxx/ro-string.hxx b/libxsde/xsde/cxx/ro-string.hxx new file mode 100644 index 0000000..aebe6e3 --- /dev/null +++ b/libxsde/xsde/cxx/ro-string.hxx @@ -0,0 +1,281 @@ +// file : xsde/cxx/ro-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_RO_STRING_HXX +#define XSDE_CXX_RO_STRING_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#ifdef XSDE_STL +# include <string> +#endif + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/cxx/string.hxx> + +namespace xsde +{ + namespace cxx + { + // Read-only string. + // + struct ro_string + { + typedef size_t size_type; + static const size_t npos; + + public: + ro_string (); + ro_string (const char*); + ro_string (const char*, size_t); + ro_string (const string&); + +#ifdef XSDE_STL + ro_string (const std::string&); + operator std::string () const; +#endif + + private: + ro_string (const ro_string&); + + ro_string& + operator= (const ro_string&); + + public: + // The returned string is not necessarily terminated with '\0'. + // If size() returns 0, the returned pointer may be 0. + // + const char* + data () const; + + size_t + size () const; + + size_t + length () const; + + public: + bool + empty () const; + + char + operator[] (size_t) const; + + public: + void + assign (const char*); + + void + assign (const char*, size_t); + + void + assign (const string&); + +#ifdef XSDE_STL + void + assign (const std::string&); +#endif + + public: + int + compare (const ro_string&) const; + + int + compare (const char*) const; + + int + compare (const char*, size_t) const; + + int + compare (const string&) const; + +#ifdef XSDE_STL + int + compare (const std::string&) const; +#endif + + public: + size_t + find (char, size_t pos = 0) const; + + private: + const char* data_; + size_t size_; + }; + + + // operator == + // + + bool + operator== (const ro_string&, const ro_string&); + + bool + operator== (const ro_string&, const char*); + + bool + operator== (const char*, const ro_string&); + + bool + operator== (const ro_string&, const string&); + + bool + operator== (const string&, const ro_string&); + +#ifdef XSDE_STL + bool + operator== (const ro_string&, const std::string&); + + bool + operator== (const std::string&, const ro_string&); +#endif + + + // operator != + // + + bool + operator!= (const ro_string&, const ro_string&); + + bool + operator!= (const ro_string&, const char*); + + bool + operator!= (const char*, const ro_string&); + + bool + operator!= (const ro_string&, const string&); + + bool + operator!= (const string&, const ro_string&); + +#ifdef XSDE_STL + bool + operator!= (const ro_string&, const std::string&); + + bool + operator!= (const std::string&, const ro_string&); +#endif + + + // operator < + // + + bool + operator< (const ro_string&, const ro_string&); + + bool + operator< (const ro_string&, const char*); + + bool + operator< (const char*, const ro_string&); + +#ifdef XSDE_STL + bool + operator< (const ro_string&, const std::string&); + + bool + operator< (const std::string&, const ro_string&); +#endif + + + // operator > + // + + bool + operator> (const ro_string&, const ro_string&); + + bool + operator> (const ro_string&, const char*); + + bool + operator> (const char*, const ro_string&); + +#ifdef XSDE_STL + bool + operator> (const ro_string&, const std::string&); + + bool + operator> (const std::string&, const ro_string&); +#endif + + + // operator <= + // + + bool + operator<= (const ro_string&, const ro_string&); + + bool + operator<= (const ro_string&, const char*); + + bool + operator<= (const char*, const ro_string&); + +#ifdef XSDE_STL + bool + operator<= (const ro_string&, const std::string&); + + bool + operator<= (const std::string&, const ro_string&); +#endif + + + // operator>= + // + + bool + operator>= (const ro_string&, const ro_string&); + + bool + operator>= (const ro_string&, const char*); + + bool + operator>= (const char*, const ro_string&); + +#ifdef XSDE_STL + bool + operator>= (const ro_string&, const std::string&); + + bool + operator>= (const std::string&, const ro_string&); +#endif + + // operator += + // +#ifdef XSDE_STL + std::string& + operator+= (std::string&, const ro_string&); +#endif + + // operator << + // +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream&, const ro_string&); +#endif + + // Trim leading and trailing XML whitespaces. Return the new + // string size. + // + size_t + trim_left (ro_string&); + + size_t + trim_right (ro_string&); + + size_t + trim (ro_string&); + } +} + +#include <xsde/cxx/ro-string.ixx> + +#endif // XSDE_CXX_RO_STRING_HXX diff --git a/libxsde/xsde/cxx/ro-string.ixx b/libxsde/xsde/cxx/ro-string.ixx new file mode 100644 index 0000000..ff863a3 --- /dev/null +++ b/libxsde/xsde/cxx/ro-string.ixx @@ -0,0 +1,409 @@ +// file : xsde/cxx/ro-string.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> + +namespace xsde +{ + namespace cxx + { + inline ro_string:: + ro_string () + : data_ (0), size_ (0) + { + } + + inline ro_string:: + ro_string (const char* s) + : data_ (s), size_ (strlen (s)) + { + } + + inline ro_string:: + ro_string (const char* s, size_t size) + : data_ (s), size_ (size) + { + } + + inline ro_string:: + ro_string (const string& s) + : data_ (s.data ()), size_ (s.size ()) + { + } + +#ifdef XSDE_STL + inline ro_string:: + ro_string (const std::string& s) + : data_ (s.data ()), size_ (s.size ()) + { + } + + inline ro_string:: + operator std::string () const + { + return std::string (data (), size ()); + } +#endif + + inline const char* ro_string:: + data () const + { + return data_; + } + + inline size_t ro_string:: + size () const + { + return size_; + } + + inline size_t ro_string:: + length () const + { + return size_; + } + + inline bool ro_string:: + empty () const + { + return size_ == 0; + } + + inline char ro_string:: + operator[] (size_t pos) const + { + return data_[pos]; + } + + inline void ro_string:: + assign (const char* s) + { + data_ = s; + size_ = strlen (s); + } + + inline void ro_string:: + assign (const char* s, size_t size) + { + data_ = s; + size_ = size; + } + + inline void ro_string:: + assign (const string& s) + { + data_ = s.data (); + size_ = s.size (); + } + +#ifdef XSDE_STL + inline void ro_string:: + assign (const std::string& s) + { + data_ = s.c_str (); + size_ = s.size (); + } +#endif + + inline int ro_string:: + compare (const ro_string& str) const + { + return compare (str.data (), str.size ()); + } + + inline int ro_string:: + compare (const char* str) const + { + return compare (str, strlen (str)); + } + + inline int ro_string:: + compare (const char* str, size_t n) const + { + size_t s = size_ < n ? size_ : n; + + int r = s != 0 ? strncmp (data_, str, s) : 0; + + if (!r && size_ != n) + r = size_ < n ? -1 : 1; + + return r; + } + + inline int ro_string:: + compare (const string& s) const + { + return compare (s.data (), s.size ()); + } + +#ifdef XSDE_STL + inline int ro_string:: + compare (const std::string& str) const + { + return compare (str.c_str (), str.size ()); + } +#endif + + inline size_t ro_string:: + find (char c, size_type pos) const + { + for (; pos < size_; ++pos) + if (data_[pos] == c) + return pos; + + return npos; + } + + // operator == + // + + inline bool + operator== (const ro_string& a, const ro_string& b) + { + return a.compare (b) == 0; + } + + inline bool + operator== (const ro_string& a, const char* b) + { + return a.compare (b) == 0; + } + + inline bool + operator== (const char* a, const ro_string& b) + { + return b.compare (a) == 0; + } + + inline bool + operator== (const ro_string& a, const string& b) + { + return a.compare (b) == 0; + } + + inline bool + operator== (const string& a, const ro_string& b) + { + return b.compare (a) == 0; + } + +#ifdef XSDE_STL + inline bool + operator== (const ro_string& a, const std::string& b) + { + return a.compare (b) == 0; + } + + inline bool + operator== (const std::string& a, const ro_string& b) + { + return b.compare (a) == 0; + } +#endif + + + // operator != + // + + inline bool + operator!= (const ro_string& a, const ro_string& b) + { + return a.compare (b) != 0; + } + + inline bool + operator!= (const ro_string& a, const char* b) + { + return a.compare (b) != 0; + } + + inline bool + operator!= (const char* a, const ro_string& b) + { + return b.compare (a) != 0; + } + + inline bool + operator!= (const ro_string& a, const string& b) + { + return a.compare (b) != 0; + } + + inline bool + operator!= (const string& a, const ro_string& b) + { + return b.compare (a) != 0; + } + +#ifdef XSDE_STL + inline bool + operator!= (const ro_string& a, const std::string& b) + { + return a.compare (b) != 0; + } + + inline bool + operator!= (const std::string& a, const ro_string& b) + { + return b.compare (a) != 0; + } +#endif + + + // operator < + // + + inline bool + operator< (const ro_string& l, const ro_string& r) + { + return l.compare (r) < 0; + } + + inline bool + operator< (const ro_string& l, const char* r) + { + return l.compare (r) < 0; + } + + inline bool + operator< (const char* l, const ro_string& r) + { + return r.compare (l) > 0; + } + +#ifdef XSDE_STL + inline bool + operator< (const ro_string& l, const std::string& r) + { + return l.compare (r) < 0; + } + + inline bool + operator< (const std::string& l, const ro_string& r) + { + return r.compare (l) > 0; + } +#endif + + + // operator > + // + + inline bool + operator> (const ro_string& l, const ro_string& r) + { + return l.compare (r) > 0; + } + + inline bool + operator> (const ro_string& l, const char* r) + { + return l.compare (r) > 0; + } + + inline bool + operator> (const char* l, const ro_string& r) + { + return r.compare (l) < 0; + } + +#ifdef XSDE_STL + inline bool + operator> (const ro_string& l, const std::string& r) + { + return l.compare (r) > 0; + } + + inline bool + operator> (const std::string& l, const ro_string& r) + { + return r.compare (l) < 0; + } +#endif + + + // operator <= + // + + inline bool + operator<= (const ro_string& l, const ro_string& r) + { + return l.compare (r) <= 0; + } + + inline bool + operator<= (const ro_string& l, const char* r) + { + return l.compare (r) <= 0; + } + + inline bool + operator<= (const char* l, const ro_string& r) + { + return r.compare (l) >= 0; + } + +#ifdef XSDE_STL + inline bool + operator<= (const ro_string& l, const std::string& r) + { + return l.compare (r) <= 0; + } + + inline bool + operator<= (const std::string& l, const ro_string& r) + { + return r.compare (l) >= 0; + } +#endif + + + // operator>= + // + + inline bool + operator>= (const ro_string& l, const ro_string& r) + { + return l.compare (r) >= 0; + } + + inline bool + operator>= (const ro_string& l, const char* r) + { + return l.compare (r) >= 0; + } + + inline bool + operator>= (const char* l, const ro_string& r) + { + return r.compare (l) <= 0; + } + +#ifdef XSDE_STL + inline bool + operator>= (const ro_string& l, const std::string& r) + { + return l.compare (r) >= 0; + } + + inline bool + operator>= (const std::string& l, const ro_string& r) + { + return r.compare (l) <= 0; + } +#endif + + // operator += + // +#ifdef XSDE_STL + inline std::string& + operator+= (std::string& l, const ro_string& r) + { + l.append (r.data (), r.size ()); + return l; + } +#endif + } +} diff --git a/libxsde/xsde/cxx/schema-error.cxx b/libxsde/xsde/cxx/schema-error.cxx new file mode 100644 index 0000000..7ff8b39 --- /dev/null +++ b/libxsde/xsde/cxx/schema-error.cxx @@ -0,0 +1,69 @@ +// file : xsde/cxx/schema-error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/schema-error.hxx> + +namespace xsde +{ + namespace cxx + { + static const char* const text_[] = + { + "no error", + "expected attribute not encountered", + "unexpected attribute encountered", + "expected element not encountered", + "unexpected element encountered", + "unexpected characters encountered", + "invalid boolean value", + "invalid byte value", + "invalid unsignedByte value", + "invalid short value", + "invalid unsignedShort value", + "invalid int value", + "invalid unsignedInt value", + "invalid long value", + "invalid unsignedLong value", + "invalid integer value", + "invalid negativeInteger value", + "invalid nonPositiveInteger value", + "invalid positiveInteger value", + "invalid nonNegativeInteger value", + "invalid float value", + "invalid double value", + "invalid decimal value", + "invalid normalizedString value", + "invalid token value", + "invalid Name value", + "invalid NMTOKEN value", + "invalid NMTOKENS value", + "invalid NCName value", + "invalid ID value", + "invalid IDREF value", + "invalid IDREFS value", + "invalid language value", + "invalid QName value", + "invalid base64Binary value", + "invalid hexBinary value", + "invalid gDay value", + "invalid gMonth value", + "invalid gYear value", + "invalid gMonthDay value", + "invalid gYearMonth value", + "invalid date value", + "invalid time value", + "invalid dateTime value", + "invalid duration value", + "invalid xsi:type attribute", + "dynamic and static types are not related by inheritance" + }; + + const char* schema_error:: + text (value v) + { + return text_[v]; + } + } +} diff --git a/libxsde/xsde/cxx/schema-error.hxx b/libxsde/xsde/cxx/schema-error.hxx new file mode 100644 index 0000000..b8bf1b1 --- /dev/null +++ b/libxsde/xsde/cxx/schema-error.hxx @@ -0,0 +1,84 @@ +// file : xsde/cxx/schema-error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SCHEMA_ERROR_HXX +#define XSDE_CXX_SCHEMA_ERROR_HXX + +namespace xsde +{ + namespace cxx + { + struct schema_error + { + enum value + { + none, + expected_attribute, + unexpected_attribute, + expected_element, + unexpected_element, + unexpected_characters, + invalid_boolean_value, + invalid_byte_value, + invalid_unsigned_byte_value, + invalid_short_value, + invalid_unsigned_short_value, + invalid_int_value, + invalid_unsigned_int_value, + invalid_long_value, + invalid_unsigned_long_value, + invalid_integer_value, + invalid_negative_integer_value, + invalid_non_positive_integer_value, + invalid_positive_integer_value, + invalid_non_negative_integer_value, + invalid_float_value, + invalid_double_value, + invalid_decimal_value, + invalid_normalized_string_value, + invalid_token_value, + invalid_name_value, + invalid_nmtoken_value, + invalid_nmtokens_value, + invalid_ncname_value, + invalid_id_value, + invalid_idref_value, + invalid_idrefs_value, + invalid_language_value, + invalid_qname_value, + invalid_base64_binary_value, + invalid_hex_binary_value, + invalid_gday_value, + invalid_gmonth_value, + invalid_gyear_value, + invalid_gmonth_day_value, + invalid_gyear_month_value, + invalid_date_value, + invalid_time_value, + invalid_date_time_value, + invalid_duration_value, + invalid_xsi_type, + not_derived + }; + + schema_error (value v); + + operator value () const + { + return v_; + } + + static const char* + text (value); + + private: + value v_; + }; + } +} + +#include <xsde/cxx/schema-error.ixx> + +#endif // XSDE_CXX_SCHEMA_ERROR_HXX diff --git a/libxsde/xsde/cxx/schema-error.ixx b/libxsde/xsde/cxx/schema-error.ixx new file mode 100644 index 0000000..e63e556 --- /dev/null +++ b/libxsde/xsde/cxx/schema-error.ixx @@ -0,0 +1,16 @@ +// file : xsde/cxx/schema-error.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline schema_error:: + schema_error (value v) + : v_ (v) + { + } + } +} diff --git a/libxsde/xsde/cxx/sequence-base.cxx b/libxsde/xsde/cxx/sequence-base.cxx new file mode 100644 index 0000000..03f33f5 --- /dev/null +++ b/libxsde/xsde/cxx/sequence-base.cxx @@ -0,0 +1,135 @@ +// file : xsde/cxx/sequence-base.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy, memmove + +#include <xsde/cxx/sequence-base.hxx> + +namespace xsde +{ + namespace cxx + { + void sequence_base:: + erase_ (void* vp, size_t es, move_forward_func mv) + { + char* p = static_cast<char*> (vp); + char* d = static_cast<char*> (data_); + + if (mv) + mv (p, size_ - 1 - (p - d) / es); + else + memmove (p, p + es, (size_ - 1) * es - (p - d)); + + --size_; + } + +#ifdef XSDE_EXCEPTIONS + struct guard + { + guard (void* p) : p_ (p) {} + ~guard () {if (p_) operator delete (p_);} + + void + release () { p_ = 0; } + + private: + void* p_; + }; + + void sequence_base:: + grow_ (size_t n, size_t es, move_func mv) + { + size_t c = n == 0 ? (capacity_ != 0 ? capacity_ * 2 : 8) : n; + void* d = operator new (c * es); + + if (size_) + { + if (mv) + { + guard g (d); + mv (d, data_, size_); + g.release (); + } + else + memcpy (d, data_, size_ * es); + } + + if (data_) + operator delete (data_); + + data_ = d; + capacity_ = c; + } + + void* sequence_base:: + insert_ (void* vp, size_t es, move_func mv, move_backward_func mvb) + { + size_t i = static_cast<char*> (vp) - static_cast<char*> (data_); + + if (capacity_ < size_ + 1) + grow_ (0, es, mv); + + char* d = static_cast<char*> (data_); + char* p = d + i; + + if (mvb) + mvb (p, size_ - i / es, size_); // increments size_ + else + { + memmove (p + es, p, size_ * es - i); + ++size_; + } + + return p; + } +#else + sequence_base::error sequence_base:: + grow_ (size_t n, size_t es, move_func mv) + { + size_t c = n == 0 ? (capacity_ != 0 ? capacity_ * 2 : 8) : n; + void* d = operator new (c * es); + + if (d == 0) + return error_no_memory; + + if (size_) + { + if (mv) + mv (d, data_, size_); + else + memcpy (d, data_, size_ * es); + } + + if (data_) + operator delete (data_); + + data_ = d; + capacity_ = c; + + return error_none; + } + + void* sequence_base:: + insert_ (void* vp, size_t es, move_func mv, move_backward_func mvb) + { + size_t i = static_cast<char*> (vp) - static_cast<char*> (data_); + + if (capacity_ < size_ + 1 && grow_ (0, es, mv) != error_none) + return 0; + + char* d = static_cast<char*> (data_); + char* p = d + i; + + if (mvb) + mvb (p, size_ - i / es); + else + memmove (p + es, p, size_ * es - i); + + ++size_; + return p; + } +#endif + } +} diff --git a/libxsde/xsde/cxx/sequence-base.hxx b/libxsde/xsde/cxx/sequence-base.hxx new file mode 100644 index 0000000..537ee7c --- /dev/null +++ b/libxsde/xsde/cxx/sequence-base.hxx @@ -0,0 +1,83 @@ +// file : xsde/cxx/sequence-base.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SEQUENCE_BASE_HXX +#define XSDE_CXX_SEQUENCE_BASE_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + // + // + class sequence_base + { + public: +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; +#endif + + private: + sequence_base (sequence_base&); + sequence_base& operator= (sequence_base&); + + public: + ~sequence_base (); + sequence_base (); + + bool + empty () const; + + size_t + size () const; + + size_t + capacity () const; + + protected: + typedef void (*move_func) (void*, void*, size_t); + typedef void (*move_forward_func) (void*, size_t); +#ifdef XSDE_EXCEPTIONS + typedef void (*move_backward_func) (void*, size_t, size_t&); +#else + typedef void (*move_backward_func) (void*, size_t); +#endif + + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + grow_ (size_t n, size_t element_size, move_func); + + void + erase_ (void*, size_t element_size, move_forward_func); + + void* + insert_ (void*, size_t element_size, move_func, move_backward_func); + + void + swap_ (sequence_base&); + + protected: + void* data_; + size_t size_; + size_t capacity_; + }; + } +} + +#include <xsde/cxx/sequence-base.ixx> + +#endif // XSDE_CXX_SEQUENCE_BASE_HXX diff --git a/libxsde/xsde/cxx/sequence-base.ixx b/libxsde/xsde/cxx/sequence-base.ixx new file mode 100644 index 0000000..214070d --- /dev/null +++ b/libxsde/xsde/cxx/sequence-base.ixx @@ -0,0 +1,57 @@ +// file : xsde/cxx/sequence-base.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline sequence_base:: + sequence_base () + : data_ (0), size_ (0), capacity_ (0) + { + } + + inline sequence_base:: + ~sequence_base () + { + if (data_) + operator delete (data_); + } + + inline bool sequence_base:: + empty () const + { + return size_ == 0; + } + + inline size_t sequence_base:: + size () const + { + return size_; + } + + inline size_t sequence_base:: + capacity () const + { + return capacity_; + } + + inline void sequence_base:: + swap_ (sequence_base& x) + { + void* d = x.data_; + size_t s = x.size_; + size_t c = x.capacity_; + + x.data_ = data_; + x.size_ = size_; + x.capacity_ = capacity_; + + data_ = d; + size_ = s; + capacity_ = c; + } + } +} diff --git a/libxsde/xsde/cxx/serializer/context.cxx b/libxsde/xsde/cxx/serializer/context.cxx new file mode 100644 index 0000000..f340e7a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/context.cxx @@ -0,0 +1,107 @@ +// file : xsde/cxx/serializer/context.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> + +#ifdef XSDE_EXCEPTIONS +# include <new> // std::bad_alloc +# include <xsde/cxx/serializer/exceptions.hxx> +#endif + +#include <xsde/cxx/serializer/context.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { +#ifdef XSDE_POLYMORPHIC +#ifdef XSDE_EXCEPTIONS + void context:: +#else + bool context:: +#endif + set_type (const char* type) + { + ro_string t (type); + const char* prefix = 0; + + size_t pos = t.find (' '); + + if (pos != ro_string::npos) + { + prefix = lookup_namespace_prefix (type + pos + 1); + + //@@ TODO: what if prefix is not found? + // +#ifndef XSDE_EXCEPTIONS + if (prefix == 0) + return false; +#endif + if (*prefix == '\0') + prefix = 0; + } + +#ifdef XSDE_EXCEPTIONS + start_attribute ("http://www.w3.org/2001/XMLSchema-instance", "type"); + + if (prefix) + { + characters (prefix); + characters (":"); + } + + characters (type, pos != ro_string::npos ? pos : t.size ()); + end_attribute (); +#else + if (!start_attribute ( + "http://www.w3.org/2001/XMLSchema-instance", "type")) + return false; + + if (prefix) + { + if (!characters (prefix) || !characters (":")) + return false; + } + + if (!characters (type, pos != ro_string::npos ? pos : t.size ()) || + !end_attribute ()) + return false; + + return true; +#endif + } +#endif // XSDE_POLYMORPHIC + +#ifdef XSDE_EXCEPTIONS + void context:: + throw_xml_error (genx::xml_error e) + { + switch (e) + { + case GENX_ALLOC_FAILED: + { + throw std::bad_alloc (); + } + case GENX_IO_ERROR: + { + // This should never happen with consistent exception + // handling usage since the write/flush functions + // throw exceptions to indicate write failures. + // + throw xml (e); + } + default: + { + throw xml (e); + } + } + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/serializer/context.hxx b/libxsde/xsde/cxx/serializer/context.hxx new file mode 100644 index 0000000..fe817eb --- /dev/null +++ b/libxsde/xsde/cxx/serializer/context.hxx @@ -0,0 +1,261 @@ +// file : xsde/cxx/serializer/context.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_CONTEXT_HXX +#define XSDE_CXX_SERIALIZER_CONTEXT_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/c/genx/genx.h> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/sys-error.hxx> +#endif + +#include <xsde/cxx/serializer/genx/xml-error.hxx> + +#ifdef XSDE_SERIALIZER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + class context + { + public: + context (genxWriter xml_serializer); + + public: + genxWriter + xml_serializer (); + +#ifdef XSDE_POLYMORPHIC + public: + // Set/get the dynamic serializer type id (as opaque const void*) + // in case of polymorphic serialization. If type id is not set, + // static type is assumed. + // + void + type_id (const void*); + + const void* + type_id (); +#endif + + public: +#ifdef XSDE_EXCEPTIONS + void + start_element (const char* name); + + void + start_element (const char* ns, const char* name); + + void + end_element (); + + void + start_attribute (const char* name); + + void + start_attribute (const char* ns, const char* name); + + void + end_attribute (); + + void + attribute (const char* name, const char* value); + + void + attribute (const char* ns, const char* name, const char* value); + + void + characters (const char*); + + void + characters (const char*, size_t); + + void + declare_namespace (const char* ns, const char* prefix); + + void + declare_default_namespace (const char* ns); + + void + clear_default_namespace (); + + const char* + lookup_namespace_prefix (const char* ns); + +#ifdef XSDE_POLYMORPHIC + void + set_type (const char* type); +#endif +#else + bool + start_element (const char* name); + + bool + start_element (const char* ns, const char* name); + + bool + end_element (); + + bool + start_attribute (const char* name); + + bool + start_attribute (const char* ns, const char* name); + + bool + end_attribute (); + + bool + attribute (const char* name, const char* value); + + bool + attribute (const char* ns, const char* name, const char* value); + + bool + characters (const char*); + + bool + characters (const char*, size_t); + + bool + declare_namespace (const char* ns, const char* prefix); + + bool + declare_default_namespace (const char* ns); + + bool + clear_default_namespace (); + + const char* + lookup_namespace_prefix (const char* ns); + +#ifdef XSDE_POLYMORPHIC + bool + set_type (const char* type); +#endif +#endif + + // Error handling via exceptions. + // + +#ifdef XSDE_EXCEPTIONS + public: + void + throw_xml_error (genx::xml_error); +#endif + + // Error handling via codes. + // + + // Application error. + // +#ifndef XSDE_EXCEPTIONS + public: + int + app_error () const; + + void + app_error (int); +#endif + + // Schema error. + // +#ifdef XSDE_SERIALIZER_VALIDATION + public: + typedef cxx::schema_error::value schema_error_t; + + schema_error_t + schema_error () const; + + void + schema_error (schema_error_t); +#endif + + // XML error. + // +#ifndef XSDE_EXCEPTIONS + public: + typedef genx::xml_error xml_error_t; + + xml_error_t + xml_error () const; + + void + xml_error (xml_error_t); +#endif + + // System error. + // +#ifndef XSDE_EXCEPTIONS + public: + typedef cxx::sys_error::value sys_error_t; + + sys_error_t + sys_error () const; + + void + sys_error (sys_error_t); +#endif + + // Implementation details. + // +#if defined(XSDE_SERIALIZER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + public: + enum error_type_t + { + error_none = 0, + error_app, + error_schema, + error_xml, + error_sys + }; + + error_type_t + error_type () const; + + protected: + error_type_t error_type_; + + union + { +#ifndef XSDE_EXCEPTIONS + int app; + xml_error_t xml; +#endif +#ifdef XSDE_SERIALIZER_VALIDATION + schema_error_t schema; +#endif +#ifndef XSDE_EXCEPTIONS + sys_error_t sys; +#endif + } error_code_; + +#endif // XSDE_SERIALIZER_VALIDATION || !XSDE_EXCEPTIONS + + protected: + genxWriter xml_serializer_; + +#ifdef XSDE_POLYMORPHIC + const void* type_id_; +#endif + + }; + } + } +} + +#include <xsde/cxx/serializer/context.ixx> + +#endif // XSDE_CXX_SERIALIZER_CONTEXT_HXX diff --git a/libxsde/xsde/cxx/serializer/context.ixx b/libxsde/xsde/cxx/serializer/context.ixx new file mode 100644 index 0000000..d3e578d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/context.ixx @@ -0,0 +1,449 @@ +// file : xsde/cxx/serializer/context.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + inline context:: + context (genxWriter xml_serializer) + : xml_serializer_ (xml_serializer) + { +#if defined(XSDE_SERIALIZER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + error_type_ = error_none; +#endif + } + + inline genxWriter context:: + xml_serializer () + { + return xml_serializer_; + } + +#ifdef XSDE_POLYMORPHIC + inline void context:: + type_id (const void* ti) + { + type_id_ = ti; + } + + inline const void* context:: + type_id () + { + return type_id_; + } +#endif + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + start_element (const char* name) + { + genxStatus e = genxStartElementLiteral ( + xml_serializer_, + 0, + reinterpret_cast<constUtf8> (name)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + start_element (const char* ns, const char* name) + { + genxStatus e = genxStartElementLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (ns), + reinterpret_cast<constUtf8> (name)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + end_element () + { + genxStatus e = genxEndElement (xml_serializer_); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + start_attribute (const char* name) + { + genxStatus e = genxStartAttributeLiteral ( + xml_serializer_, + 0, + reinterpret_cast<constUtf8> (name)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + start_attribute (const char* ns, const char* name) + { + genxStatus e = genxStartAttributeLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (ns), + reinterpret_cast<constUtf8> (name)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + end_attribute () + { + genxStatus e = genxEndAttribute (xml_serializer_); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + attribute (const char* name, const char* value) + { + genxStatus e = genxAddAttributeLiteral ( + xml_serializer_, + 0, + reinterpret_cast<constUtf8> (name), + reinterpret_cast<constUtf8> (value)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + attribute (const char* ns, const char* name, const char* value) + { + genxStatus e = genxAddAttributeLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (ns), + reinterpret_cast<constUtf8> (name), + reinterpret_cast<constUtf8> (value)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + characters (const char* s) + { + genxStatus e = genxAddText ( + xml_serializer_, + reinterpret_cast<constUtf8> (s)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + characters (const char* s, size_t n) + { + genxStatus e = genxAddCountedText ( + xml_serializer_, + reinterpret_cast<constUtf8> (s), + static_cast<int> (n)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + declare_namespace (const char* ns, const char* prefix) + { + genxStatus e = genxAddNamespaceLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (ns), + reinterpret_cast<constUtf8> (prefix)); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + declare_default_namespace (const char* ns) + { + genxStatus e = genxAddNamespaceLiteral ( + xml_serializer_, + reinterpret_cast<constUtf8> (ns), + reinterpret_cast<constUtf8> ("")); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // +#ifdef XSDE_EXCEPTIONS + inline void context:: +#else + inline bool context:: +#endif + clear_default_namespace () + { + genxStatus e = genxUnsetDefaultNamespace (xml_serializer_); + +#ifdef XSDE_EXCEPTIONS + if (e != GENX_SUCCESS) + throw_xml_error (e); +#else + if (e != GENX_SUCCESS) + xml_error (e); + + return e == GENX_SUCCESS; +#endif + } + + // + // + inline const char* context:: + lookup_namespace_prefix (const char* ns) + { + genxStatus e; + genxNamespace gns = genxDeclareNamespace ( + xml_serializer_, reinterpret_cast<constUtf8> (ns), 0, &e); + + if (e != GENX_SUCCESS) + { +#ifdef XSDE_EXCEPTIONS + throw_xml_error (e); +#else + xml_error (e); +#endif + return 0; + } + + return reinterpret_cast<const char*> ( + genxGetNamespacePrefix (gns)); + } + + // + // +#ifndef XSDE_EXCEPTIONS + inline int context:: + app_error () const + { + return error_code_.app; + } + + inline void context:: + app_error (int e) + { + error_type_ = error_app; + error_code_.app = e; + } + + inline void context:: + sys_error (sys_error_t e) + { + error_type_ = error_sys; + error_code_.sys = e; + } + + inline context::sys_error_t context:: + sys_error () const + { + return error_code_.sys; + } + + inline void context:: + xml_error (xml_error_t e) + { + error_type_ = error_xml; + error_code_.xml = e; + } + + inline context::xml_error_t context:: + xml_error () const + { + return error_code_.xml; + } +#endif + +#ifdef XSDE_SERIALIZER_VALIDATION + inline context::schema_error_t context:: + schema_error () const + { + return error_code_.schema; + } + + inline void context:: + schema_error (schema_error_t e) + { + error_type_ = error_schema; + error_code_.schema = e; + } +#endif + +#if defined(XSDE_SERIALIZER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + inline context::error_type_t context:: + error_type () const + { + return error_type_; + } +#endif + + } + } +} diff --git a/libxsde/xsde/cxx/serializer/elements.cxx b/libxsde/xsde/cxx/serializer/elements.cxx new file mode 100644 index 0000000..d20601e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/elements.cxx @@ -0,0 +1,122 @@ +// file : xsde/cxx/serializer/elements.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <assert.h> + +#include <xsde/cxx/serializer/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // serializer_base + // + serializer_base:: + ~serializer_base () + { + } + + void serializer_base:: + _pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_pre (); +#endif + } + + void serializer_base:: + _serialize_attributes () + { + } + + void serializer_base:: + _serialize_content () + { + } + + void serializer_base:: + _post () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_post (); +#endif + } + + void serializer_base:: + post () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->post (); +#endif + } + + void serializer_base:: + _pre_impl (context& c) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + assert (parent_ == 0); + + // Set the parent_ pointers in the tied-in implementations. + // + _set_parent_chain (); +#endif + ++depth_; + context_ = &c; + + _pre (); + } + + void serializer_base:: + _post_impl () + { +#if defined(XSDE_SERIALIZER_VALIDATION) || !defined(XSDE_EXCEPTIONS) + if (!context_->error_type ()) +#endif + _post (); + + if (--depth_ == 0) + context_ = 0; + } + +#ifdef XSDE_POLYMORPHIC + const char* serializer_base:: + _dynamic_type () const + { + return 0; + } +#endif + + void serializer_base:: + _reset () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (impl_) + impl_->_reset (); +#endif + +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + context_ = 0; + depth_ = 0; + } + +#if defined (XSDE_REUSE_STYLE_TIEIN) && !defined (XSDE_EXCEPTIONS) + const serializer_base* serializer_base:: + _ultimate_impl () const + { + const serializer_base* s = impl_; + for (; s->impl_ != 0; s = s->impl_) /*noop*/; + return s; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/serializer/elements.hxx b/libxsde/xsde/cxx/serializer/elements.hxx new file mode 100644 index 0000000..f6c354a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/elements.hxx @@ -0,0 +1,302 @@ +// file : xsde/cxx/serializer/elements.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_ELEMENTS_HXX +#define XSDE_CXX_SERIALIZER_ELEMENTS_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/cxx/serializer/context.hxx> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/serializer/error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // pre() and post() are overridable pre/post callbacks, i.e., the + // derived serializer can override them without calling the base + // version. _pre() and _post() are not overridable pre/post callbacks + // in the sense that the derived serializer may override them but + // has to call the base version. The call sequence is as shown below: + // + // pre (arg) + // _pre () + // _post () + // post () + // + struct serializer_base + { + virtual + ~serializer_base (); + + serializer_base (); + +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base (serializer_base* impl, void*); +#endif + + // The pre() signature varies depending on the serializer argument + // type. + // + + virtual void + _pre (); + + virtual void + _serialize_attributes (); + + virtual void + _serialize_content (); + + virtual void + _post (); + + virtual void + post (); + + // Implementation callbacks for _pre and _post. The _pre and _post + // callbacks should never be called directly. Instead, the *_impl + // versions should be used. The _pre_impl and _post_impl functions + // will eventually call _pre and _post respectively. + // + virtual void + _pre_impl (context&); + + virtual void + _post_impl (); + +#ifdef XSDE_POLYMORPHIC + public: + // Dynamic type in the form "<name> <namespace>" with + // the space and namespace part absent if the type does + // not have a namespace. + // + virtual const char* + _dynamic_type () const; +#endif + + public: + context& + _context (); + + // The XML generation functions below can only be called starting + // from _pre() and ending with _post(). Because namespace declarations + // should come after the start_element and before any attributes, + // _pre is the appropriate place to call the namespace declaration + // functions. If exceptions are disabled, these functions return + // true on success and false otherwise. + // + // The set_type() function sets the xsi:type attribute. Its argument + // is the type id in the form "<name> <namespace>" with the space + // and namespace part absent if the type does not have a namespace. + // +#ifdef XSDE_EXCEPTIONS + void + _start_element (const char* name); + + void + _start_element (const char* ns, const char* name); + + void + _end_element (); + + void + _start_attribute (const char* name); + + void + _start_attribute (const char* ns, const char* name); + + void + _end_attribute (); + + void + _attribute (const char* name, const char* value); + + void + _attribute (const char* ns, const char* name, const char* value); + + void + _characters (const char*); + + void + _characters (const char*, size_t); + + void + _declare_namespace (const char* ns, const char* prefix); + + void + _declare_default_namespace (const char* ns); + + void + _clear_default_namespace (); + + const char* + _lookup_namespace_prefix (const char* ns); + +#ifdef XSDE_POLYMORPHIC + void + _set_type (const char* type); +#endif +#else + bool + _start_element (const char* name); + + bool + _start_element (const char* ns, const char* name); + + bool + _end_element (); + + bool + _start_attribute (const char* name); + + bool + _start_attribute (const char* ns, const char* name); + + bool + _end_attribute (); + + bool + _attribute (const char* name, const char* value); + + bool + _attribute (const char* ns, const char* name, const char* value); + + bool + _characters (const char*); + + bool + _characters (const char*, size_t); + + bool + _declare_namespace (const char* ns, const char* prefix); + + bool + _declare_default_namespace (const char* ns); + + bool + _clear_default_namespace (); + + const char* + _lookup_namespace_prefix (const char* ns); + +#ifdef XSDE_POLYMORPHIC + bool + _set_type (const char* type); +#endif +#endif + // Reset the serializer state after an error. + // + virtual void + _reset (); + + // Error handling via codes. If the error is set while serializer + // is in the context, the error is set in the context, instead + // of the serializer. Since pre() and post() calls are not in + // context, the serializer stores application and system errors + // locally for this case. + // + +#ifndef XSDE_EXCEPTIONS + public: + error + _error () const; + + // Set application error. + // + void + _app_error (int); + + int + _app_error () const; +#endif + + // Schema error. + // +#ifdef XSDE_SERIALIZER_VALIDATION + public: + void + _schema_error (context::schema_error_t); +#endif + + // XML error. + // +#ifndef XSDE_EXCEPTIONS + public: + void + _xml_error (context::xml_error_t); +#endif + + // System error. + // +#ifndef XSDE_EXCEPTIONS + public: + context::sys_error_t + _sys_error () const; + + void + _sys_error (context::sys_error_t); +#endif + + // Implementation. + // +#ifndef XSDE_EXCEPTIONS + public: + enum error_type_t + { + error_none = 0, + error_app, + error_sys + }; + + error_type_t + _error_type () const; + + void + _copy_error (context&) const; + + protected: + error_type_t error_type_; + + union + { + int app; + context::sys_error_t sys; + } error_code_; +#endif + + protected: + bool resetting_; + context* context_; + size_t depth_; + +#ifdef XSDE_REUSE_STYLE_TIEIN + protected: + serializer_base* parent_; + serializer_base* impl_; + + void + _set_parent_chain (); + +#ifndef XSDE_EXCEPTIONS + const serializer_base* + _ultimate_impl () const; +#endif +#endif + }; + } + } +} + +#include <xsde/cxx/serializer/elements.ixx> + +#endif // XSDE_CXX_SERIALIZER_ELEMENTS_HXX diff --git a/libxsde/xsde/cxx/serializer/elements.ixx b/libxsde/xsde/cxx/serializer/elements.ixx new file mode 100644 index 0000000..ead289a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/elements.ixx @@ -0,0 +1,569 @@ +// file : xsde/cxx/serializer/elements.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + inline serializer_base:: + serializer_base () + : resetting_ (false), context_ (0), depth_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif +#ifdef XSDE_REUSE_STYLE_TIEIN + parent_ = 0; + impl_ = 0; +#endif + } + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline serializer_base:: + serializer_base (serializer_base* impl, void*) + : resetting_ (false), context_ (0), depth_ (0) + { +#ifndef XSDE_EXCEPTIONS + error_type_ = error_none; +#endif + parent_ = 0; + impl_ = impl; + } +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + inline void serializer_base:: + _set_parent_chain () + { + if (impl_ && impl_->parent_ == 0) + { + for (serializer_base* s = impl_; s != 0; s = s->impl_) + s->parent_ = this; + } + } +#endif + + inline context& serializer_base:: + _context () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + return *(parent_ ? parent_->context_ : context_); +#else + return *context_; +#endif + } + +#ifdef XSDE_EXCEPTIONS + inline void serializer_base:: + _start_element (const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->start_element (name); + } + + inline void serializer_base:: + _start_element (const char* ns, const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->start_element (ns, name); + } + + inline void serializer_base:: + _end_element () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->end_element (); + } + + inline void serializer_base:: + _start_attribute (const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->start_attribute (name); + } + + inline void serializer_base:: + _start_attribute (const char* ns, const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->start_attribute (ns, name); + } + + inline void serializer_base:: + _end_attribute () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->end_attribute (); + } + + inline void serializer_base:: + _attribute (const char* name, const char* value) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->attribute (name, value); + } + + inline void serializer_base:: + _attribute (const char* ns, const char* name, const char* value) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->attribute (ns, name, value); + } + + inline void serializer_base:: + _characters (const char* str) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->characters (str); + } + + inline void serializer_base:: + _characters (const char* str, size_t n) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->characters (str, n); + } + + inline void serializer_base:: + _declare_namespace (const char* ns, const char* p) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->declare_namespace (ns, p); + } + + inline void serializer_base:: + _declare_default_namespace (const char* ns) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->declare_default_namespace (ns); + } + + inline void serializer_base:: + _clear_default_namespace () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->clear_default_namespace (); + } + + inline const char* serializer_base:: + _lookup_namespace_prefix (const char* ns) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->lookup_namespace_prefix (ns); + } + +#ifdef XSDE_POLYMORPHIC + inline void serializer_base:: + _set_type (const char* type) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->set_type (type); + } +#endif + +#else // XSDE_EXCEPTIONS + + inline bool serializer_base:: + _start_element (const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->start_element (name); + } + + inline bool serializer_base:: + _start_element (const char* ns, const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->start_element (ns, name); + } + + inline bool serializer_base:: + _end_element () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->end_element (); + } + + inline bool serializer_base:: + _start_attribute (const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->start_attribute (name); + } + + inline bool serializer_base:: + _start_attribute (const char* ns, const char* name) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->start_attribute (ns, name); + } + + inline bool serializer_base:: + _end_attribute () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->end_attribute (); + } + + inline bool serializer_base:: + _attribute (const char* name, const char* value) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->attribute (name, value); + } + + inline bool serializer_base:: + _attribute (const char* ns, const char* name, const char* value) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->attribute (ns, name, value); + } + + inline bool serializer_base:: + _characters (const char* str) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->characters (str); + } + + inline bool serializer_base:: + _characters (const char* str, size_t n) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->characters (str, n); + } + + inline bool serializer_base:: + _declare_namespace (const char* ns, const char* p) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->declare_namespace (ns, p); + } + + inline bool serializer_base:: + _declare_default_namespace (const char* ns) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->declare_default_namespace (ns); + } + + inline bool serializer_base:: + _clear_default_namespace () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->clear_default_namespace (); + } + + inline const char* serializer_base:: + _lookup_namespace_prefix (const char* ns) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->lookup_namespace_prefix (ns); + } + +#ifdef XSDE_POLYMORPHIC + inline bool serializer_base:: + _set_type (const char* type) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + return s->context_->set_type (type); + } +#endif + +#endif // !XSDE_EXCEPTIONS + + // Error handling. + // +#ifndef XSDE_EXCEPTIONS + inline error serializer_base:: + _error () const + { + // Unlike context, which is stored in the top-level + // serializer, error state is stored in the "bottom- + // level" implementation. It is done this way since the + // error handling mechanism can be used in constructors + // which would otherwise require passing the pointer to + // parent serializer to each implementation's c-tor. + // +#ifdef XSDE_REUSE_STYLE_TIEIN + const serializer_base* s = !impl_ ? this : _ultimate_impl (); +#else + const serializer_base* s = this; +#endif + switch (s->error_type_) + { + case error_sys: + { + return error (s->error_code_.sys); + } + case error_app: + { + return error (s->error_code_.app); + } + default: + { + return error (); + } + } + } + + inline void serializer_base:: + _app_error (int e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + + if (s->context_ != 0) + { + s->context_->app_error (e); + } + else + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (!impl_) + s = this; + else + for (s = impl_; s->impl_ != 0; s = s->impl_) /*noop*/; +#endif + s->error_type_ = error_app; + s->error_code_.app = e; + } + } + + inline int serializer_base:: + _app_error () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const serializer_base* s = !impl_ ? this : _ultimate_impl (); +#else + const serializer_base* s = this; +#endif + return s->error_code_.app; + } + + inline void serializer_base:: + _sys_error (context::sys_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + if (s->context_ != 0) + { + s->context_->sys_error (e); + } + else + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (!impl_) + s = this; + else + for (s = impl_; s->impl_ != 0; s = s->impl_) /*noop*/; +#endif + s->error_type_ = error_sys; + s->error_code_.sys = e; + } + } + + inline context::sys_error_t serializer_base:: + _sys_error () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const serializer_base* s = !impl_ ? this : _ultimate_impl (); +#else + const serializer_base* s = this; +#endif + return s->error_code_.sys; + } + + inline void serializer_base:: + _xml_error (context::xml_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->xml_error (e); + } + + inline serializer_base::error_type_t serializer_base:: + _error_type () const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const serializer_base* s = !impl_ ? this : _ultimate_impl (); +#else + const serializer_base* s = this; +#endif + return s->error_type_; + } + + inline void serializer_base:: + _copy_error (context& ctx) const + { +#ifdef XSDE_REUSE_STYLE_TIEIN + const serializer_base* s = !impl_ ? this : _ultimate_impl (); +#else + const serializer_base* s = this; +#endif + switch (s->error_type_) + { + case error_app: + { + ctx.app_error (s->error_code_.app); + break; + } + case error_sys: + { + ctx.sys_error (s->error_code_.sys); + break; + } + default: + break; + } + } +#endif // XSDE_EXCEPTIONS + +#ifdef XSDE_SERIALIZER_VALIDATION + inline void serializer_base:: + _schema_error (context::schema_error_t e) + { +#ifdef XSDE_REUSE_STYLE_TIEIN + serializer_base* s = parent_ ? parent_ : this; +#else + serializer_base* s = this; +#endif + s->context_->schema_error (e); + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/serializer/error.cxx b/libxsde/xsde/cxx/serializer/error.cxx new file mode 100644 index 0000000..7ee1981 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/error.cxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/serializer/error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + void error:: + true_ () + { + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/error.hxx b/libxsde/xsde/cxx/serializer/error.hxx new file mode 100644 index 0000000..62776e9 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/error.hxx @@ -0,0 +1,121 @@ +// file : xsde/cxx/serializer/error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_ERROR_HXX +#define XSDE_CXX_SERIALIZER_ERROR_HXX + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/sys-error.hxx> + +#include <xsde/cxx/serializer/genx/xml-error.hxx> + +#ifdef XSDE_SERIALIZER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + using genx::xml_error; + + // This type is only used when C++ exceptions are not used. + // + struct error + { + enum error_type + { + none, + sys, + xml, + schema, + app + }; + + public: + error_type + type () const; + + // Returns true if there is an error so that you can write + // if (s.error ()) or if (error e = s.error ()). + // + typedef void (error::*bool_convertible) (); + operator bool_convertible () const; + + + // sys + // + public: + error (sys_error::value); + + sys_error + sys_code () const; + + const char* + sys_text () const; + + // xml + // + public: + error (xml_error); + + xml_error + xml_code () const; + + const char* + xml_text () const; + + + // schema + // +#ifdef XSDE_SERIALIZER_VALIDATION + public: + error (schema_error::value); + + schema_error + schema_code () const; + + const char* + schema_text () const; +#endif + + // app + // + public: + error (int app_code); + + int + app_code () const; + + + public: + error (); + + private: + void + true_ (); + + private: + error_type type_; + + union + { + sys_error::value sys; + xml_error xml; +#ifdef XSDE_SERIALIZER_VALIDATION + schema_error::value schema; +#endif + int app; + } code_; + }; + } + } +} + +#include <xsde/cxx/serializer/error.ixx> + +#endif // XSDE_CXX_SERIALIZER_ERROR_HXX diff --git a/libxsde/xsde/cxx/serializer/error.ixx b/libxsde/xsde/cxx/serializer/error.ixx new file mode 100644 index 0000000..73b2196 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/error.ixx @@ -0,0 +1,128 @@ +// file : xsde/cxx/serializer/error.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + inline + error::error_type error:: + type () const + { + return type_; + } + + inline + error:: + operator error::bool_convertible () const + { + return type_ != none ? &error::true_ : 0; + } + + // sys + // + + inline + error:: + error (sys_error::value e) + : type_ (sys) + { + code_.sys = e; + } + + inline + sys_error error:: + sys_code () const + { + return code_.sys; + } + + inline + const char* error:: + sys_text () const + { + return sys_error::text (code_.sys); + } + + // xml + // + inline + error:: + error (xml_error e) + : type_ (xml) + { + code_.xml = e; + } + + inline + xml_error error:: + xml_code () const + { + return code_.xml; + } + + inline + const char* error:: + xml_text () const + { + return genx::xml_error_text (code_.xml); + } + + // schema + // + +#ifdef XSDE_SERIALIZER_VALIDATION + inline + error:: + error (schema_error::value e) + : type_ (schema) + { + code_.schema = e; + } + + inline + schema_error error:: + schema_code () const + { + return code_.schema; + } + + inline + const char* error:: + schema_text () const + { + return schema_error::text (code_.schema); + } +#endif + + // app + // + + inline + error:: + error (int e) + : type_ (app) + { + code_.app = e; + } + + inline + int error:: + app_code () const + { + return code_.app; + } + + inline + error:: + error () + : type_ (none) + { + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/exceptions.cxx b/libxsde/xsde/cxx/serializer/exceptions.cxx new file mode 100644 index 0000000..b6ad765 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/exceptions.cxx @@ -0,0 +1,62 @@ +// file : xsde/cxx/serializer/exceptions.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_IOSTREAM +# include <iostream> +#endif + +#include <xsde/cxx/serializer/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // exception + // + +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream& os, const exception& e) + { + return os << e.text (); + } +#endif + + // xml + // + const char* xml:: + text () const + { + return genx::xml_error_text (code_); + } + + const char* xml:: + what () const throw () + { + return "xml error"; + } + + // schema + // +#ifdef XSDE_SERIALIZER_VALIDATION + const char* schema:: + text () const + { + return schema_error::text (code_); + } + + const char* schema:: + what () const throw () + { + return "schema error"; + } +#endif + } + } +} diff --git a/libxsde/xsde/cxx/serializer/exceptions.hxx b/libxsde/xsde/cxx/serializer/exceptions.hxx new file mode 100644 index 0000000..03c2243 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/exceptions.hxx @@ -0,0 +1,91 @@ +// file : xsde/cxx/serializer/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_EXCEPTIONS_HXX +#define XSDE_CXX_SERIALIZER_EXCEPTIONS_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/cxx/exceptions.hxx> // xsde::cxx::exception + +#ifdef XSDE_SERIALIZER_VALIDATION +# include <xsde/cxx/schema-error.hxx> +#endif + +#include <xsde/cxx/serializer/genx/xml-error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // exception + // + struct exception: xsde::cxx::exception + { + virtual const char* + text () const = 0; + }; + +#ifdef XSDE_IOSTREAM + std::ostream& + operator<< (std::ostream&, const exception&); +#endif + + + // xml + // + using genx::xml_error; + + struct xml: exception + { + xml (xml_error); + + xml_error + code () const; + + virtual const char* + text () const; + + virtual const char* + what () const throw (); + + private: + xml_error code_; + }; + + + // schema + // +#ifdef XSDE_SERIALIZER_VALIDATION + struct schema: exception + { + schema (schema_error); + + schema_error + code () const; + + virtual const char* + text () const; + + virtual const char* + what () const throw (); + + private: + schema_error code_; + }; +#endif + } + } +} + +#include <xsde/cxx/serializer/exceptions.ixx> + +#endif // XSDE_CXX_SERIALIZER_EXCEPTIONS_HXX diff --git a/libxsde/xsde/cxx/serializer/exceptions.ixx b/libxsde/xsde/cxx/serializer/exceptions.ixx new file mode 100644 index 0000000..1f81c47 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/exceptions.ixx @@ -0,0 +1,44 @@ +// file : xsde/cxx/serializer/exceptions.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // xml + // + inline xml:: + xml (xml_error code) + : code_ (code) + { + } + + inline xml_error xml:: + code () const + { + return code_; + } + + // schema + // +#ifdef XSDE_SERIALIZER_VALIDATION + inline schema:: + schema (schema_error code) + : code_ (code) + { + } + + inline schema_error schema:: + code () const + { + return code_; + } +#endif + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/genx/document.cxx b/libxsde/xsde/cxx/serializer/genx/document.cxx new file mode 100644 index 0000000..bba4b26 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/genx/document.cxx @@ -0,0 +1,822 @@ +// file : xsde/cxx/serializer/genx/document.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strlen, strcmp + +#ifdef XSDE_EXCEPTIONS +# include <new> // std::bad_alloc +#endif + +#ifdef XSDE_IOSTREAM +# include <iostream> +#endif + +#ifdef XSDE_EXCEPTIONS +# include <xsde/cxx/serializer/exceptions.hxx> +#else +# include <xsde/cxx/serializer/error.hxx> +#endif + +#include <xsde/cxx/serializer/context.hxx> + +#ifdef XSDE_POLYMORPHIC +# include <xsde/cxx/serializer/substitution-map.hxx> +#endif + +#include <xsde/cxx/serializer/genx/document.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace genx + { +#ifdef XSDE_POLYMORPHIC + static substitution_map_init substitution_map_init_; +#endif + + // writer + // + writer:: + ~writer () + { + } + +#ifdef XSDE_EXCEPTIONS + void writer:: + write (const char* s) + { + write (s, strlen (s)); + } +#else + bool writer:: + write (const char* s) + { + return write (s, strlen (s)); + } +#endif + + // document_simpl + // + + document_simpl:: + ~document_simpl () + { + // Prevents auto-generation of this dtor. + } + + document_simpl:: +#ifdef XSDE_POLYMORPHIC + document_simpl (serializer_base& serializer, + const char* name, + bool, + const char* st) +#else + document_simpl (serializer_base& serializer, const char* name) +#endif + : serializer_ (serializer) + { +#ifdef XSDE_POLYMORPHIC + root_static_type_ = st; +#endif + // Leave root_ns_ uninitialized. + // +#ifdef XSDE_EXCEPTIONS + root_name_.assign (name); +#else + if (root_name_.assign (name)) + error_ = error (sys_error::no_memory); +#endif + } + + document_simpl:: +#ifdef XSDE_POLYMORPHIC + document_simpl (serializer_base& serializer, + const char* ns, + const char* name, + bool, + const char* st) +#else + document_simpl (serializer_base& serializer, + const char* ns, + const char* name) +#endif + : serializer_ (serializer) + { +#ifdef XSDE_POLYMORPHIC + root_static_type_ = st; +#endif +#ifdef XSDE_EXCEPTIONS + root_ns_.assign (ns); + root_name_.assign (name); +#else + if (root_ns_.assign (ns) || root_name_.assign (name)) + error_ = error (sys_error::no_memory); +#endif + } + +#ifdef XSDE_STL + document_simpl:: +#ifdef XSDE_POLYMORPHIC + document_simpl (serializer_base& serializer, + const std::string& name, + bool, + const char* st) +#else + document_simpl (serializer_base& serializer, const std::string& name) +#endif + : serializer_ (serializer) + { +#ifdef XSDE_POLYMORPHIC + root_static_type_ = st; +#endif + // Leave root_ns_ uninitialized. + // +#ifdef XSDE_EXCEPTIONS + root_name_.assign (name.c_str (), name.size ()); +#else + if (root_name_.assign (name.c_str (), name.size ())) + error_ = error (sys_error::no_memory); +#endif + } + + document_simpl:: +#ifdef XSDE_POLYMORPHIC + document_simpl (serializer_base& serializer, + const std::string& ns, + const std::string& name, + bool, + const char* st) +#else + document_simpl (serializer_base& serializer, + const std::string& ns, + const std::string& name) +#endif + : serializer_ (serializer) + { +#ifdef XSDE_POLYMORPHIC + root_static_type_ = st; +#endif +#ifdef XSDE_EXCEPTIONS + root_ns_.assign (ns.c_str (), ns.size ()); + root_name_.assign (name.c_str (), name.size ()); +#else + if (root_ns_.assign (ns.c_str (), ns.size ()) || + root_name_.assign (name.c_str (), name.size ())) + error_ = error (sys_error::no_memory); +#endif + } +#endif // XSDE_STL + + + void document_simpl:: + add_prefix (const char* p, const char* ns) + { +#if defined (XSDE_STL) + prefixes_.push_back (p); + prefix_namespaces_.push_back (ns); +#else +#if defined (XSDE_EXCEPTIONS) + prefixes_.push_back_copy (p); + prefix_namespaces_.push_back_copy (ns); +#else + if (prefixes_.push_back_copy (p) || + prefix_namespaces_.push_back_copy (ns)) + error_ = error (sys_error::no_memory); +#endif +#endif + } + + void document_simpl:: + add_default_prefix (const char* ns) + { +#if defined (XSDE_STL) + prefixes_.push_back (""); + prefix_namespaces_.push_back (ns); +#else +#if defined (XSDE_EXCEPTIONS) + prefixes_.push_back_copy (""); + prefix_namespaces_.push_back_copy (ns); +#else + if (prefixes_.push_back_copy ("") || + prefix_namespaces_.push_back_copy (ns)) + error_ = error (sys_error::no_memory); +#endif +#endif + } + + void document_simpl:: + add_schema (const char* ns, const char* l) + { +#if defined (XSDE_STL) + schemas_.push_back (l); + schema_namespaces_.push_back (ns); +#else +#if defined (XSDE_EXCEPTIONS) + schemas_.push_back_copy (l); + schema_namespaces_.push_back_copy (ns); +#else + if (schemas_.push_back_copy (l) || + schema_namespaces_.push_back_copy (ns)) + error_ = error (sys_error::no_memory); +#endif +#endif + } + + void document_simpl:: + add_no_namespace_schema (const char* l) + { +#if defined (XSDE_STL) + schemas_.push_back (l); + schema_namespaces_.push_back (""); +#else +#if defined (XSDE_EXCEPTIONS) + schemas_.push_back_copy (l); + schema_namespaces_.push_back_copy (""); +#else + if (schemas_.push_back_copy (l) || + schema_namespaces_.push_back_copy ("")) + error_ = error (sys_error::no_memory); +#endif +#endif + } + + // + // + void document_simpl:: + reset () + { +#ifndef XSDE_EXCEPTIONS + error_ = error (); +#endif + if (xml_serializer_) + genxReset (xml_serializer_); + + serializer_._reset (); + } + + // istream + // +#ifdef XSDE_IOSTREAM + +#ifdef XSDE_EXCEPTIONS + static void + ostream_write (void* p, const char* s, size_t n) + { + std::ostream* os = reinterpret_cast<std::ostream*> (p); + os->write (s, static_cast<std::streamsize> (n)); + + if (os->bad ()) + throw std::ios_base::failure ("write failed"); + } + + static void + ostream_flush (void* p) + { + std::ostream* os = reinterpret_cast<std::ostream*> (p); + os->flush (); + + if (os->bad ()) + throw std::ios_base::failure ("flush failed"); + } +#else + static bool + ostream_write (void* p, const char* s, size_t n) + { + std::ostream* os = reinterpret_cast<std::ostream*> (p); + os->write (s, static_cast<std::streamsize> (n)); + return !os->bad (); + } + + static bool + ostream_flush (void* p) + { + std::ostream* os = reinterpret_cast<std::ostream*> (p); + os->flush (); + return !os->bad (); + } +#endif + + void document_simpl:: + serialize (std::ostream& os) + { + serialize (&ostream_write, &ostream_flush, &os); + } +#endif // XSDE_IOSTREAM + + // + // +#ifdef XSDE_EXCEPTIONS + static void + write_thunk (void* p, const char* s) + { + reinterpret_cast<writer*> (p)->write (s); + } + + static void + write_bound_thunk (void* p, const char* s, size_t n) + { + reinterpret_cast<writer*> (p)->write (s, n); + } + + static void + flush_thunk (void* p) + { + reinterpret_cast<writer*> (p)->flush (); + } +#else + static bool + write_thunk (void* p, const char* s) + { + return reinterpret_cast<writer*> (p)->write (s); + } + + static bool + write_bound_thunk (void* p, const char* s, size_t n) + { + return reinterpret_cast<writer*> (p)->write (s, n); + } + + static bool + flush_thunk (void* p) + { + return reinterpret_cast<writer*> (p)->flush (); + } +#endif + + void document_simpl:: + serialize (writer& w) + { + serialize (&write_thunk, &write_bound_thunk, &flush_thunk, &w); + } + + // Genx write functions. + // + struct writer_info + { + void* user_data; + document_simpl::write_func write; + document_simpl::write_bound_func write_bound; + document_simpl::flush_func flush; + }; + + extern "C" genxStatus + genx_write (void* p, constUtf8 us) + { + const char* s = reinterpret_cast<const char*> (us); + writer_info* wi = reinterpret_cast<writer_info*> (p); + + if (wi->write != 0) + { +#ifdef XSDE_EXCEPTIONS + wi->write (wi->user_data, s); +#else + if (!wi->write (wi->user_data, s)) + return GENX_IO_ERROR; +#endif + } + else + { +#ifdef XSDE_EXCEPTIONS + wi->write_bound (wi->user_data, s, strlen (s)); +#else + if (!wi->write_bound (wi->user_data, s, strlen (s))) + return GENX_IO_ERROR; +#endif + } + + return GENX_SUCCESS; + } + + extern "C" genxStatus + genx_write_bound (void* p, constUtf8 start, constUtf8 end) + { + size_t size = static_cast<size_t> (end - start); + const char* s = reinterpret_cast<const char*> (start); + writer_info* wi = reinterpret_cast<writer_info*> (p); + +#ifdef XSDE_EXCEPTIONS + wi->write_bound (wi->user_data, s, size); +#else + if (!wi->write_bound (wi->user_data, s, size)) + return GENX_IO_ERROR; +#endif + + return GENX_SUCCESS; + } + + extern "C" genxStatus + genx_flush (void* p) + { + writer_info* wi = reinterpret_cast<writer_info*> (p); + +#ifdef XSDE_EXCEPTIONS + wi->flush (wi->user_data); +#else + if (!wi->flush (wi->user_data)) + return GENX_IO_ERROR; +#endif + + return GENX_SUCCESS; + } + + void document_simpl:: + serialize (write_func w, write_bound_func wb, flush_func f, + void* user_data) + { + if (xml_serializer_ == 0) + { + xml_serializer_ = genxNew (0, 0, 0); + + if (xml_serializer_ == 0) + { +#ifdef XSDE_EXCEPTIONS + throw std::bad_alloc (); +#else + error_ = error (sys_error::no_memory); + return; +#endif + } + } + + writer_info wi; + wi.user_data = user_data; + wi.write = w; + wi.write_bound = wb; + wi.flush = f; + + genxSetUserData (xml_serializer_, &wi); + + genxSender sender; + sender.send = &genx_write; + sender.sendBounded = &genx_write_bound; + sender.flush = &genx_flush; + + genxStatus e = genxStartDocSender (xml_serializer_, &sender); + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + + serialize (xml_serializer_); + +#ifndef XSDE_EXCEPTIONS + if (error_) + return; +#endif + + e = genxEndDocument (xml_serializer_); + + if (e != GENX_SUCCESS) + filter_xml_error (e); + } + + // + // + static const char xsi[] = "http://www.w3.org/2001/XMLSchema-instance"; + + void document_simpl:: + serialize (genxWriter s) + { +#ifndef XSDE_POLYMORPHIC + genxStatus e = genxStartElementLiteral ( + s, + reinterpret_cast<constUtf8> (root_ns_.data ()), + reinterpret_cast<constUtf8> (root_name_.data ())); +#else + const char* ns = root_ns_.data (); + const char* n = root_name_.data (); + const char* dt = 0; + + if (root_static_type_ != 0) + { + dt = serializer_._dynamic_type (); + + // Call to check sets ns and n if successful. + // + if (strcmp (dt, root_static_type_) == 0 || + substitution_map_instance ().check (ns, n, dt)) + dt = 0; + } + + genxStatus e = genxStartElementLiteral ( + s, + reinterpret_cast<constUtf8> (ns), + reinterpret_cast<constUtf8> (n)); + +#endif // XSDE_POLYMORPHIC + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + + // Add namespace prefixes. + // + for (size_t i = 0; i < prefixes_.size (); ++i) + { +#ifdef XSDE_STL + e = genxAddNamespaceLiteral ( + s, + reinterpret_cast<constUtf8> (prefix_namespaces_[i].c_str ()), + reinterpret_cast<constUtf8> (prefixes_[i].c_str ())); +#else + e = genxAddNamespaceLiteral ( + s, + reinterpret_cast<constUtf8> (prefix_namespaces_[i]), + reinterpret_cast<constUtf8> (prefixes_[i])); +#endif + if (e != GENX_SUCCESS) + break; + } + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + + // Add the schema location attributes. + // + if (schemas_.size () != 0) + { + e = genxAddNamespaceLiteral ( + s, + reinterpret_cast<constUtf8> (xsi), + reinterpret_cast<constUtf8> ("xsi")); + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + + // First add the xsi:schemaLocation attribute. + // + bool start = false; + + for (size_t j = 0; j < schemas_.size (); ++j) + { +#ifdef XSDE_STL + const char* l = schemas_[j].c_str (); + const char* ns = schema_namespaces_[j].c_str (); +#else + const char* l = schemas_[j]; + const char* ns = schema_namespaces_[j]; +#endif + if (ns[0] != '\0') + { + if (!start) + { + e = genxStartAttributeLiteral ( + s, + reinterpret_cast<constUtf8> (xsi), + reinterpret_cast<constUtf8> ("schemaLocation")); + + if (e != GENX_SUCCESS) + break; + + start = true; + } + else + { + e = genxAddCharacter (s, ' '); + + if (e != GENX_SUCCESS) + break; + } + + e = genxAddText (s, reinterpret_cast<constUtf8> (ns)); + + if (e != GENX_SUCCESS) + break; + + e = genxAddCharacter (s, ' '); + + if (e != GENX_SUCCESS) + break; + + e = genxAddText (s, reinterpret_cast<constUtf8> (l)); + + if (e != GENX_SUCCESS) + break; + } + } + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + + if (start) + { + e = genxEndAttribute (s); + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + } + + // Now add the xsi:noNamespaceSchemaLocation attribute. + // + start = false; + + for (size_t k = 0; k < schemas_.size (); ++k) + { +#ifdef XSDE_STL + const char* l = schemas_[k].c_str (); + const char* ns = schema_namespaces_[k].c_str (); +#else + const char* l = schemas_[k]; + const char* ns = schema_namespaces_[k]; +#endif + if (ns[0] == '\0') + { + if (!start) + { + e = genxStartAttributeLiteral ( + s, + reinterpret_cast<constUtf8> (xsi), + reinterpret_cast<constUtf8> ("noNamespaceSchemaLocation")); + + if (e != GENX_SUCCESS) + break; + + start = true; + } + else + { + e = genxAddCharacter (s, ' '); + + if (e != GENX_SUCCESS) + break; + } + + e = genxAddText (s, reinterpret_cast<constUtf8> (l)); + + if (e != GENX_SUCCESS) + break; + } + } + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + + if (start) + { + e = genxEndAttribute (s); + + if (e != GENX_SUCCESS) + { + filter_xml_error (e); + return; + } + } + } + + // Call the root type serializer to serialize the content. + // + context ctx (s); + +#if !defined (XSDE_SERIALIZER_VALIDATION) && defined (XSDE_EXCEPTIONS) + +#ifdef XSDE_POLYMORPHIC + // Set xsi:type if necessary. + // + if (dt != 0) + ctx.set_type (dt); +#endif + serializer_._pre_impl (ctx); + serializer_._serialize_attributes (); + serializer_._serialize_content (); + serializer_._post_impl (); + +#else // !defined (XSDE_SERIALIZER_VALIDATION) && defined (XSDE_EXCEPTIONS) + +#ifdef XSDE_POLYMORPHIC + // Set xsi:type if necessary. + // + if (dt != 0) + ctx.set_type (dt); + +#ifndef XSDE_EXCEPTIONS + if (!ctx.error_type ()) +#endif +#endif // XSDE_POLYMORPHIC + + serializer_._pre_impl (ctx); + + if (!ctx.error_type ()) + serializer_._serialize_attributes (); + + if (!ctx.error_type ()) + serializer_._serialize_content (); + + if (!ctx.error_type ()) + serializer_._post_impl (); + + if (context::error_type_t et = ctx.error_type ()) + { + switch (et) + { +#ifndef XSDE_EXCEPTIONS + case context::error_app: + { + error_ = error (ctx.app_error ()); + break; + } +#endif +#ifdef XSDE_SERIALIZER_VALIDATION + case context::error_schema: + { +#ifdef XSDE_EXCEPTIONS + throw schema (ctx.schema_error ()); +#else + error_ = error (ctx.schema_error ()); + break; +#endif + } +#endif +#ifndef XSDE_EXCEPTIONS + case context::error_xml: + { + filter_xml_error (ctx.xml_error ()); + break; + } + case context::error_sys: + { + error_ = error (ctx.sys_error ()); + break; + } +#endif + default: + break; + } + return; + } +#endif // !XSDE_SERIALIZER_VALIDATION && XSDE_EXCEPTIONS + + + e = genxEndElement (s); + + if (e != GENX_SUCCESS) + filter_xml_error (e); + } + + void document_simpl:: + filter_xml_error (genxStatus e) + { + switch (e) + { + case GENX_ALLOC_FAILED: + { +#ifdef XSDE_EXCEPTIONS + throw std::bad_alloc (); +#else + error_ = error (sys_error::no_memory); + break; +#endif + } + case GENX_IO_ERROR: + { +#ifdef XSDE_EXCEPTIONS + // This should never happen with consistent exception + // handling usage since the write/flush functions + // throw exceptions to indicate write failures. + // + throw xml (e); +#else + error_ = error (sys_error::write_failed); + break; +#endif + } + default: + { +#ifdef XSDE_EXCEPTIONS + throw xml (e); +#else + error_ = error (e); + break; +#endif + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/genx/document.hxx b/libxsde/xsde/cxx/serializer/genx/document.hxx new file mode 100644 index 0000000..19117d6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/genx/document.hxx @@ -0,0 +1,280 @@ +// file : xsde/cxx/serializer/genx/document.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_GENX_DOCUMENT_HXX +#define XSDE_CXX_SERIALIZER_GENX_DOCUMENT_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#include <xsde/c/genx/genx.h> + +#ifdef XSDE_IOSTREAM +# include <iosfwd> +#endif + +#include <xsde/cxx/string.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/string-sequence.hxx> +#endif + +#include <xsde/cxx/serializer/elements.hxx> + +#ifndef XSDE_EXCEPTIONS +# include <xsde/cxx/serializer/error.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace genx + { + // Simple auto pointer for genxWriter object. + // + struct serializer_auto_ptr + { + ~serializer_auto_ptr (); + + explicit + serializer_auto_ptr (genxWriter = 0); + + serializer_auto_ptr& + operator= (genxWriter); + + public: + operator genxWriter () + { + return serializer_; + } + + private: + serializer_auto_ptr (const serializer_auto_ptr&); + + serializer_auto_ptr& + operator= (const serializer_auto_ptr&); + + private: + genxWriter serializer_; + }; + + // Writer interface. + // + struct writer + { + virtual + ~writer (); + + // The first write function is called to write a '\0'-terminated + // string. Its default implementation calls the second versions: + // write (s, strlen (s)). If exceptions are enabled, throw to + // indicate a write failure. Otherwise return true if write was + // successful, false otherwise. + // +#ifdef XSDE_EXCEPTIONS + virtual void + write (const char* s); + + virtual void + write (const char* s, size_t n) = 0; + + virtual void + flush () = 0; +#else + virtual bool + write (const char* s); + + virtual bool + write (const char* s, size_t n) = 0; + + virtual bool + flush () = 0; +#endif + }; + + // + // + class document_simpl + { + public: + virtual + ~document_simpl (); + +#ifdef XSDE_POLYMORPHIC + // Note that the static_type string is not deep-copied. + // + document_simpl (serializer_base&, + const char* root_element_name, + bool polymorphic = false, + const char* root_static_type = 0); + + document_simpl (serializer_base&, + const char* root_element_namespace, + const char* root_element_name, + bool polymorphic = false, + const char* root_static_type = 0); + +#ifdef XSDE_STL + document_simpl (serializer_base&, + const std::string& root_element_name, + bool polymorphic = false, + const char* root_static_type = 0); + + document_simpl (serializer_base&, + const std::string& root_element_namespace, + const std::string& root_element_name, + bool polymorphic = false, + const char* root_static_type = 0); +#endif + +#else // XSDE_POLYMORPHIC + + document_simpl (serializer_base&, + const char* root_element_name); + + document_simpl (serializer_base&, + const char* root_element_namespace, + const char* root_element_name); + +#ifdef XSDE_STL + document_simpl (serializer_base&, + const std::string& root_element_name); + + document_simpl (serializer_base&, + const std::string& root_element_namespace, + const std::string& root_element_name); +#endif +#endif // XSDE_POLYMORPHIC + + public: + // Namespace and schema location. + // + void + add_prefix (const char* prefix, const char* namespace_); + + void + add_default_prefix (const char* namespace_); + + void + add_schema (const char* namespace_, const char* location); + + void + add_no_namespace_schema (const char* location); + +#ifdef XSDE_STL + void + add_prefix (const std::string& prefix, + const std::string& namespace_); + + void + add_default_prefix (const std::string& namespace_); + + void + add_schema (const std::string& namespace_, + const std::string& location); + + void + add_no_namespace_schema (const std::string& location); +#endif + + public: + void + reset (); + +#ifdef XSDE_IOSTREAM + public: + // Serialize to std::ostream. The std::ios_base::failure + // exception is used to report io errors (badbit and failbit) + // if XSDE_EXCEPTIONS is defined. Otherwise error codes are + // used. + // + void + serialize (std::ostream&); +#endif + + public: + // Serialize by calling writer::write() and writer::flush() to + // output XML. + // + void + serialize (writer&); + + // Serialize by calling the write and flush functions. If the + // unbounded write function is not provided, the bounded version + // is called: write_bound_func (s, strlen (s)). user_data is + // passed as a first argument to these functions. If exceptions + // are enabled, throw to indicate a write failure. Otherwise return + // true if write was successful, false otherwise. + // + +#ifdef XSDE_EXCEPTIONS + typedef void (*write_func) (void*, const char*); + typedef void (*write_bound_func) (void*, const char*, size_t); + typedef void (*flush_func) (void*); +#else + typedef bool (*write_func) (void*, const char*); + typedef bool (*write_bound_func) (void*, const char*, size_t); + typedef bool (*flush_func) (void*); +#endif + + void + serialize (write_bound_func, flush_func, void* user_data); + + void + serialize (write_func, write_bound_func, flush_func, void* user_data); + + public: + // Low-level, genx-specific serialization. With this method + // it is your responsibility to call genxStartDoc*() and + // genxEndDocument(). + // + void + serialize (genxWriter); + +#ifndef XSDE_EXCEPTIONS + public: + const error& + _error () const; +#endif + + protected: + void + filter_xml_error (genxStatus); + + protected: + serializer_auto_ptr xml_serializer_; + serializer_base& serializer_; + + string root_name_; + string root_ns_; + +#ifdef XSDE_POLYMORPHIC + const char* root_static_type_; +#endif + + string_sequence prefixes_; + string_sequence prefix_namespaces_; + + string_sequence schemas_; + string_sequence schema_namespaces_; + +#ifndef XSDE_EXCEPTIONS + error error_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/serializer/genx/document.ixx> + +#endif // XSDE_CXX_SERIALIZER_GENX_DOCUMENT_HXX diff --git a/libxsde/xsde/cxx/serializer/genx/document.ixx b/libxsde/xsde/cxx/serializer/genx/document.ixx new file mode 100644 index 0000000..7269fa6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/genx/document.ixx @@ -0,0 +1,84 @@ +// file : xsde/cxx/serializer/genx/document.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace genx + { + // serializer_auto_ptr + // + inline serializer_auto_ptr:: + ~serializer_auto_ptr () + { + if (serializer_ != 0) + genxDispose (serializer_); + } + + inline serializer_auto_ptr:: + serializer_auto_ptr (genxWriter serializer) + : serializer_ (serializer) + { + } + + inline serializer_auto_ptr& serializer_auto_ptr:: + operator= (genxWriter serializer) + { + if (serializer_ != 0) + genxDispose (serializer_); + + serializer_ = serializer; + return *this; + } + + // document_simpl + // + +#ifdef XSDE_STL + inline void document_simpl:: + add_prefix (const std::string& p, const std::string& ns) + { + add_prefix (p.c_str (), ns.c_str ()); + } + + inline void document_simpl:: + add_default_prefix (const std::string& ns) + { + add_default_prefix (ns.c_str ()); + } + + inline void document_simpl:: + add_schema (const std::string& ns, const std::string& l ) + { + add_schema (ns.c_str (), l.c_str ()); + } + + inline void document_simpl:: + add_no_namespace_schema (const std::string& l) + { + add_no_namespace_schema (l.c_str ()); + } +#endif + + inline void document_simpl:: + serialize (write_bound_func wb, flush_func f, void* user_data) + { + serialize (0, wb, f, user_data); + } + +#ifndef XSDE_EXCEPTIONS + inline const error& document_simpl:: + _error () const + { + return error_; + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/genx/xml-error.cxx b/libxsde/xsde/cxx/serializer/genx/xml-error.cxx new file mode 100644 index 0000000..8abc7a6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/genx/xml-error.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/serializer/genx/xml-error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/genx/xml-error.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace genx + { + static const char* const text_[] = + { + "no error", + "illegal UTF-8 character", + "illegal XML character", + "illegal name", + "out of memory", + "illegal namespace name", + "internal error", + "duplicate prefix", + "call out of sequence", + "mismatched end element call", + "output error", + "missing attribute value", + "malformed comment body", + "illegal character sequence in processing instruction", + "processing instruction target is XML", + "duplicate attribute", + "attribute in default namespace", + "different prefixes for the same namespace in the same element", + "default namespace in an unqualified element" + }; + + const char* + xml_error_text (xml_error e) + { + return text_[e]; + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/genx/xml-error.hxx b/libxsde/xsde/cxx/serializer/genx/xml-error.hxx new file mode 100644 index 0000000..6287952 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/genx/xml-error.hxx @@ -0,0 +1,28 @@ +// file : xsde/cxx/serializer/genx/xml-error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_GENX_XML_ERROR_HXX +#define XSDE_CXX_SERIALIZER_GENX_XML_ERROR_HXX + +#include <xsde/c/genx/genx.h> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace genx + { + typedef genxStatus xml_error; + + const char* + xml_error_text (xml_error); + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_GENX_XML_ERROR_HXX diff --git a/libxsde/xsde/cxx/serializer/map.cxx b/libxsde/xsde/cxx/serializer/map.cxx new file mode 100644 index 0000000..1ace4ac --- /dev/null +++ b/libxsde/xsde/cxx/serializer/map.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/map.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // serializer_map + // + serializer_map:: + ~serializer_map () + { + } + + // serializer_map_impl + // + void serializer_map_impl:: + reset () const + { + for (hashmap::const_iterator i (map_.begin ()), e (map_.end ()); + i != e; ++i) + { + serializer_base* s = *static_cast<serializer_base* const*> (*i); + s->_reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/map.hxx b/libxsde/xsde/cxx/serializer/map.hxx new file mode 100644 index 0000000..2cfc755 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/map.hxx @@ -0,0 +1,96 @@ +// file : xsde/cxx/serializer/map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_MAP_HXX +#define XSDE_CXX_SERIALIZER_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/hashmap.hxx> + +#include <xsde/cxx/serializer/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + // Serializer map. Used in the polymorphic document parsing. + // + class serializer_map + { + public: + // The type_id argument is the application-specific type id + // object (passed as opaque const void*) that was set by the + // callback in the context or 0 if no type id was provided. + // + virtual serializer_base* + find (const void* type_id) const = 0; + + // Reset the serializers this map contains. + // + virtual void + reset () const = 0; + + virtual + ~serializer_map (); + }; + + // Default serializer map implementation. It assumes that the + // type id is a C string (const char*). + // + class serializer_map_impl: public serializer_map + { + public: +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; + + error + _error () const; +#endif + + public: + serializer_map_impl (size_t buckets); + + // Note that the type_id string is not copied so it should + // be valid for the lifetime of the map. + // + void + insert (const char* type_id, serializer_base&); + + // This version of insert is a shortcut that uses the string + // returned by the serializer's _dynamic_type() function. + // + void + insert (serializer_base&); + + virtual serializer_base* + find (const void* type_id) const; + + virtual void + reset () const; + + private: + serializer_map_impl (const serializer_map_impl&); + + serializer_map_impl& + operator= (const serializer_map_impl&); + + private: + hashmap map_; + }; + } + } +} + +#include <xsde/cxx/serializer/map.ixx> + +#endif // XSDE_CXX_SERIALIZER_MAP_HXX diff --git a/libxsde/xsde/cxx/serializer/map.ixx b/libxsde/xsde/cxx/serializer/map.ixx new file mode 100644 index 0000000..64eb19a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/map.ixx @@ -0,0 +1,51 @@ +// file : xsde/cxx/serializer/map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { +#ifndef XSDE_EXCEPTIONS + inline serializer_map_impl::error serializer_map_impl:: + _error () const + { + return map_._error () ? error_no_memory : error_none; + } +#endif + + inline serializer_map_impl:: + serializer_map_impl (size_t buckets) + : map_ (buckets, sizeof (serializer_base*)) + { + } + + inline void serializer_map_impl:: + insert (const char* type_id, serializer_base& s) + { + serializer_base* tmp = &s; + map_.insert (type_id, &tmp); + } + + inline void serializer_map_impl:: + insert (serializer_base& s) + { + insert (s._dynamic_type (), s); + } + + inline serializer_base* serializer_map_impl:: + find (const void* type_id) const + { + if (type_id) + { + const void* p = map_.find (static_cast<const char*> (type_id)); + return p ? *static_cast<serializer_base* const*> (p) : 0; + } + return 0; + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/any-type.hxx b/libxsde/xsde/cxx/serializer/non-validating/any-type.hxx new file mode 100644 index 0000000..c01b54e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/any-type.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_ANY_TYPE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_ANY_TYPE_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // any_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_simpl: virtual any_type_sskel +#else + struct any_type_simpl: any_type_sskel +#endif + { + }; + + // any_simple_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_simple_type_simpl: virtual any_simple_type_sskel +#else + struct any_simple_type_simpl: any_simple_type_sskel +#endif + { + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/base64-binary.cxx b/libxsde/xsde/cxx/serializer/non-validating/base64-binary.cxx new file mode 100644 index 0000000..51d1b97 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/base64-binary.cxx @@ -0,0 +1,166 @@ +// file : xsde/cxx/serializer/non-validating/base64-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/base64-binary.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + base64_binary_simpl:: + ~base64_binary_simpl () + { + if (free_) + delete const_cast<buffer*> (value_); + } + + void base64_binary_simpl:: + pre (const buffer* value) + { + value_ = value; + } + + static const char base64_tab[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', + 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '+', '/', '\0' + }; + + inline void + split_1 (char b, unsigned char& b1, unsigned char& b2) + { + unsigned char ub = static_cast<unsigned char> (b); + b1 = ub >> 2; + b2 = (ub & 0x3) << 4; + } + + inline void + split_2 (char b, unsigned char& b2, unsigned char& b3) + { + unsigned char ub = static_cast<unsigned char> (b); + b2 |= ub >> 4; + b3 = (ub & 0x0F) << 2; + } + + inline void + split_3 (char b, unsigned char& b3, unsigned char& b4) + { + unsigned char ub = static_cast<unsigned char> (b); + b3 |= ub >> 6; + b4 = ( ub & 0x3F ); + } + + void base64_binary_simpl:: + _serialize_content () + { + // Maximum 76 characters per line, 76/4 = 19 + // + const size_t quads_per_line = 19; + char buf[quads_per_line * 4 + 1]; + + if (size_t size = value_->size ()) + { + const char* data = value_->data (); + size_t quads = (size + 2) / 3; + + // Process all quadruplets except the last, one line at a time. + // + size_t i = 0; + size_t j = 0; + unsigned char b1, b2, b3, b4; + + for (; j < (quads - 1);) + { + for (; i < quads_per_line && j < (quads - 1); ++i, ++j) + { + split_1 (*data++, b1, b2); + split_2 (*data++, b2, b3); + split_3 (*data++, b3, b4); + + buf[i * 4] = base64_tab[b1]; + buf[i * 4 + 1] = base64_tab[b2]; + buf[i * 4 + 2] = base64_tab[b3]; + buf[i * 4 + 3] = base64_tab[b4]; + } + + if (i == quads_per_line) + { + buf[i * 4] = '\n'; + +#ifdef XSDE_EXCEPTIONS + _characters (buf, i * 4 + 1); +#else + if (!_characters (buf, i * 4 + 1)) + break; +#endif + i = 0; + } + } + +#ifndef XSDE_EXCEPTIONS + if (j == (quads - 1)) + { +#endif + // Process last quadruplet. The first byte is always present. + // + split_1 (*data++, b1, b2); + buf[i * 4] = base64_tab[b1]; + + if (data != value_->end ()) + { + // Second byte is present. + // + split_2 (*data++, b2, b3); + buf[i * 4 + 1] = base64_tab[b2]; + + if(data != value_->end ()) + { + // Third byte is present. + // + split_3 (*data++, b3, b4); + buf[i * 4 + 2] = base64_tab[b3]; + buf[i * 4 + 3] = base64_tab[b4]; + } + else + { + buf[i * 4 + 2] = base64_tab[b3]; + buf[i * 4 + 3] = '='; + } + } + else + { + buf[i * 4 + 1] = base64_tab[b2]; + buf[i * 4 + 2] = '='; + buf[i * 4 + 3] = '='; + } + + i++; + + buf[i * 4] = '\n'; + _characters (buf, i * 4 + 1); + +#ifndef XSDE_EXCEPTIONS + } +#endif + } + + if (free_) + { + delete const_cast<buffer*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/base64-binary.hxx b/libxsde/xsde/cxx/serializer/non-validating/base64-binary.hxx new file mode 100644 index 0000000..de4d914 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/base64-binary.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/base64-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_BASE64_BINARY_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_BASE64_BINARY_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct base64_binary_simpl: virtual base64_binary_sskel +#else + struct base64_binary_simpl: base64_binary_sskel +#endif + { + virtual + ~base64_binary_simpl (); + + base64_binary_simpl (bool free = false); + + virtual void + pre (const buffer*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const buffer* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/base64-binary.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_BASE64_BINARY_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/base64-binary.ixx b/libxsde/xsde/cxx/serializer/non-validating/base64-binary.ixx new file mode 100644 index 0000000..59a10d6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/base64-binary.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/base64-binary.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline base64_binary_simpl:: + base64_binary_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/boolean.cxx b/libxsde/xsde/cxx/serializer/non-validating/boolean.cxx new file mode 100644 index 0000000..d505d63 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/boolean.cxx @@ -0,0 +1,30 @@ +// file : xsde/cxx/serializer/non-validating/boolean.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/boolean.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void boolean_simpl:: + pre (bool value) + { + value_ = value; + } + + void boolean_simpl:: + _serialize_content () + { + _characters ((value_ ? "true" : "false"), (value_ ? 4 : 5)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/boolean.hxx b/libxsde/xsde/cxx/serializer/non-validating/boolean.hxx new file mode 100644 index 0000000..5edcdaa --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/boolean.hxx @@ -0,0 +1,39 @@ +// file : xsde/cxx/serializer/non-validating/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_BOOLEAN_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_BOOLEAN_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct boolean_simpl: virtual boolean_sskel +#else + struct boolean_simpl: boolean_sskel +#endif + { + virtual void + pre (bool); + + virtual void + _serialize_content (); + + protected: + bool value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_BOOLEAN_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/byte.cxx b/libxsde/xsde/cxx/serializer/non-validating/byte.cxx new file mode 100644 index 0000000..200d4ab --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/byte.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void byte_simpl:: + pre (signed char value) + { + value_ = value; + } + + void byte_simpl:: + _serialize_content () + { + // We only need strlen("-128") + 1 characters to hold all + // representations of signed byte. + // + char str[5]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 5, "%d", value_); +#else + int n = sprintf (str, "%d", value_); +#endif + if (n > 0 && n < 5) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/byte.hxx b/libxsde/xsde/cxx/serializer/non-validating/byte.hxx new file mode 100644 index 0000000..093adb4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/byte.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_BYTE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_BYTE_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 8-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct byte_simpl: virtual byte_sskel +#else + struct byte_simpl: byte_sskel +#endif + { + virtual void + pre (signed char); + + virtual void + _serialize_content (); + + protected: + signed char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_BYTE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/date-time.cxx b/libxsde/xsde/cxx/serializer/non-validating/date-time.cxx new file mode 100644 index 0000000..fe11566 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/date-time.cxx @@ -0,0 +1,78 @@ +// file : xsde/cxx/serializer/non-validating/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/date-time.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void date_time_simpl:: + pre (const date_time& value) + { + value_ = value; + } + + void date_time_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649-MM-DDThh:mm:ss.ssssss-hh:mm") + // + 1 characters to hold all representations of date_time. We + // know that the seconds part (represented as double) has + // default precision of 6. + // + char str[40]; + + if (value_.month () <= 12 && + value_.day () <= 31 && + value_.hours () <= 24 && + value_.minutes () <= 59 && + value_.seconds () >= 0.0 && + value_.seconds () < 60.0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 34, "%.4d-%.2u-%.2uT%.2u:%.2u:%09f", + value_.year (), value_.month (), value_.day (), + value_.hours (), value_.minutes (), + value_.seconds ()); +#else + int n = sprintf (str, "%.4d-%.2u-%.2uT%.2u:%.2u:%09f", + value_.year (), value_.month (), value_.day (), + value_.hours (), value_.minutes (), + value_.seconds ()); +#endif + if (n > 0 && n < 34) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/date-time.hxx b/libxsde/xsde/cxx/serializer/non-validating/date-time.hxx new file mode 100644 index 0000000..e239564 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/date-time.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_DATE_TIME_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_DATE_TIME_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_time_simpl: virtual date_time_sskel +#else + struct date_time_simpl: date_time_sskel +#endif + { + date_time_simpl (); + + virtual void + pre (const date_time&); + + virtual void + _serialize_content (); + + protected: + date_time value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/date-time.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/date-time.ixx b/libxsde/xsde/cxx/serializer/non-validating/date-time.ixx new file mode 100644 index 0000000..e300c03 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/date-time.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/date-time.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline date_time_simpl:: + date_time_simpl () + : value_ (1, 0, 0, 0, 0, 0.0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/date.cxx b/libxsde/xsde/cxx/serializer/non-validating/date.cxx new file mode 100644 index 0000000..2fa6069 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/date.cxx @@ -0,0 +1,59 @@ +// file : xsde/cxx/serializer/non-validating/date.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/date.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void date_simpl:: + pre (const date& value) + { + value_ = value; + } + + void date_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649-MM-DD+hh:mm") + 1 characters to + // hold all representations of date. + // + char str[24]; + + if (value_.month () < 13 && value_.day () < 32) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 18, "%.4d-%.2u-%.2u", + value_.year (), value_.month (), value_.day ()); +#else + int n = sprintf (str, "%.4d-%.2u-%.2u", + value_.year (), value_.month (), value_.day ()); +#endif + if (n > 0 && n < 18) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/date.hxx b/libxsde/xsde/cxx/serializer/non-validating/date.hxx new file mode 100644 index 0000000..9fb0f40 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/date.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/date.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_DATE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_DATE_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_simpl: virtual date_sskel +#else + struct date_simpl: date_sskel +#endif + { + date_simpl (); + + virtual void + pre (const date&); + + virtual void + _serialize_content (); + + protected: + date value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/date.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_DATE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/date.ixx b/libxsde/xsde/cxx/serializer/non-validating/date.ixx new file mode 100644 index 0000000..c89cea4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/date.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/date.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline date_simpl:: + date_simpl () + : value_ (1, 1, 1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/decimal.cxx b/libxsde/xsde/cxx/serializer/non-validating/decimal.cxx new file mode 100644 index 0000000..dd55ab0 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/decimal.cxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/serializer/non-validating/decimal.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/decimal.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void decimal_simpl:: + pre (double value) + { + value_ = value; + } + + void decimal_simpl:: + _serialize_content () + { + // Assume double values cannot be longer than 127 characters. + // + char str[128]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 128, "%.*f", + static_cast<int> (precision_), value_); +#else + int n = sprintf (str, "%.*f", + static_cast<int> (precision_), value_); +#endif + if (n > 0 && n < 128) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/decimal.hxx b/libxsde/xsde/cxx/serializer/non-validating/decimal.hxx new file mode 100644 index 0000000..b0155b3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/decimal.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/serializer/non-validating/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_DECIMAL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_DECIMAL_HXX + +#include <float.h> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct decimal_simpl: virtual decimal_sskel +#else + struct decimal_simpl: decimal_sskel +#endif + { +#ifdef DBL_DIG + decimal_simpl (unsigned int precision = DBL_DIG); +#else + decimal_simpl (unsigned int precision = 15) +#endif + + virtual void + pre (double); + + virtual void + _serialize_content (); + + protected: + unsigned int precision_; + double value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/decimal.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_DECIMAL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/decimal.ixx b/libxsde/xsde/cxx/serializer/non-validating/decimal.ixx new file mode 100644 index 0000000..af3ab38 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/decimal.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/decimal.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline decimal_simpl:: + decimal_simpl (unsigned int p) + : precision_ (p) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/double.cxx b/libxsde/xsde/cxx/serializer/non-validating/double.cxx new file mode 100644 index 0000000..1f8f459 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/double.cxx @@ -0,0 +1,103 @@ +// file : xsde/cxx/serializer/non-validating/double.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/double.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void double_simpl:: + pre (double value) + { + value_ = value; + } + + void double_simpl:: + _serialize_content () + { + // Assume double values cannot be longer than 127 characters. + // + char str[128]; + + const char* fmt = 0; + + switch (notation_) + { + case notation_auto: + { + fmt = "%.*g"; + break; + } + case notation_fixed: + { + fmt = "%.*f"; + break; + } + case notation_scientific: + { + fmt = "%.*e"; + break; + } + } + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 128, fmt, precision_, value_); +#else + int n = sprintf (str, fmt, precision_, value_); +#endif + if (n > 0 && n < 128) + { + if (str[0] == '-') + { + if (str[1] == 'n' && str[2] == 'a' && str[3] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[1] == 'i' && str[2] == 'n' && str[3] == 'f') + { + _characters ("-INF", 4); + return; + } + } + else + { + if (str[0] == 'n' && str[1] == 'a' && str[2] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[0] == 'i' && str[1] == 'n' && str[2] == 'f') + { + _characters ("INF", 3); + return; + } + } + + if (notation_ == notation_fixed) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/double.hxx b/libxsde/xsde/cxx/serializer/non-validating/double.hxx new file mode 100644 index 0000000..a79c144 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/double.hxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/serializer/non-validating/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_DOUBLE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_DOUBLE_HXX + +#include <float.h> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct double_simpl: virtual double_sskel +#else + struct double_simpl: double_sskel +#endif + { + enum notation + { + notation_auto, + notation_fixed, + notation_scientific + }; + +#ifdef DBL_DIG + double_simpl (notation = notation_auto, + unsigned int precision = DBL_DIG); +#else + double_simpl (notation = notation_auto, + unsigned int precision = 15) +#endif + + virtual void + pre (double); + + virtual void + _serialize_content (); + + protected: + notation notation_; + unsigned int precision_; + double value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/double.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_DOUBLE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/double.ixx b/libxsde/xsde/cxx/serializer/non-validating/double.ixx new file mode 100644 index 0000000..36cc319 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/double.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/double.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline double_simpl:: + double_simpl (notation n, unsigned int p) + : notation_ (n), precision_ (p) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/duration.cxx b/libxsde/xsde/cxx/serializer/non-validating/duration.cxx new file mode 100644 index 0000000..1174af7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/duration.cxx @@ -0,0 +1,171 @@ +// file : xsde/cxx/serializer/non-validating/duration.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/duration.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void duration_simpl:: + pre (const duration& value) + { + value_ = value; + } + + void duration_simpl:: + _serialize_content () + { + // duration := -PnYnMnDTnHnMnS + // + // The years, months, days, hours, and minutes components are + // represented as 32 unsigned integers with maximum string + // representation being strlen ("4294967295") = 10. + // + // We assume that the seconds part (double) cannot be longer + // than 128 chars. + // + // The total representation thus cannot exceed 10*5 + 128 + + // 9 + 1 = 188 characters. + // + char str[188]; + char* p = str; + + if (value_.negative ()) + *p++ = '-'; + + *p++ = 'P'; + + // years + // + // In case it is 0-duration, use the years field to handle + // this case. + // + if (value_.years () != 0 || + (value_.months () == 0 && + value_.days () == 0 && + value_.hours () == 0 && + value_.minutes () == 0 && + value_.seconds () == 0.0)) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.years ()); +#else + int n = sprintf (p, "%u", value_.years ()); +#endif + if (n < 0 || n >= 11) + return; + + p += n; + *p++ = 'Y'; + } + + // months + // + if (value_.months () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.months ()); +#else + int n = sprintf (p, "%u", value_.months ()); +#endif + if (n < 0 || n >= 11) + return; + + p += n; + *p++ = 'M'; + } + + // days + // + if (value_.days () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.days ()); +#else + int n = sprintf (p, "%u", value_.days ()); +#endif + if (n < 0 || n >= 11) + return; + + p += n; + *p++ = 'D'; + } + + // Figure out if we need the 'T' delimiter. + // + if (value_.hours () != 0 || + value_.minutes () != 0 || + value_.seconds () != 0.0) + *p++ = 'T'; + + // hours + // + if (value_.hours () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.hours ()); +#else + int n = sprintf (p, "%u", value_.hours ()); +#endif + if (n < 0 || n >= 11) + return; + + p += n; + *p++ = 'H'; + } + + // minutes + // + if (value_.minutes () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.minutes ()); +#else + int n = sprintf (p, "%u", value_.minutes ()); +#endif + if (n < 0 || n >= 11) + return; + + p += n; + *p++ = 'M'; + } + + // seconds + // + if (value_.seconds () > 0.0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 128, "%f", value_.seconds ()); +#else + int n = sprintf (p, "%f", value_.seconds ()); +#endif + if (n < 0 || n >= 128) + return; + + // Remove trailing '0' and '.' if necessary. + // + while (p[n - 1] == '0') + n--; + + if (p[n - 1] == '.') + n--; + + p += n; + *p++ = 'S'; + } + + _characters (str, static_cast<size_t> (p - str)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/duration.hxx b/libxsde/xsde/cxx/serializer/non-validating/duration.hxx new file mode 100644 index 0000000..88530f4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/duration.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/duration.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_DURATION_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_DURATION_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct duration_simpl: virtual duration_sskel +#else + struct duration_simpl: duration_sskel +#endif + { + duration_simpl (); + + virtual void + pre (const duration&); + + virtual void + _serialize_content (); + + protected: + duration value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/duration.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_DURATION_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/duration.ixx b/libxsde/xsde/cxx/serializer/non-validating/duration.ixx new file mode 100644 index 0000000..10d2287 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/duration.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/duration.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline duration_simpl:: + duration_simpl () + : value_ (false, 1, 0, 0, 0, 0, 0.0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/float.cxx b/libxsde/xsde/cxx/serializer/non-validating/float.cxx new file mode 100644 index 0000000..3af6e76 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/float.cxx @@ -0,0 +1,103 @@ +// file : xsde/cxx/serializer/non-validating/float.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/float.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void float_simpl:: + pre (float value) + { + value_ = value; + } + + void float_simpl:: + _serialize_content () + { + // Assume float values cannot be longer than 127 characters. + // + char str[128]; + + const char* fmt = 0; + + switch (notation_) + { + case notation_auto: + { + fmt = "%.*g"; + break; + } + case notation_fixed: + { + fmt = "%.*f"; + break; + } + case notation_scientific: + { + fmt = "%.*e"; + break; + } + } + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 128, fmt, precision_, value_); +#else + int n = sprintf (str, fmt, precision_, value_); +#endif + if (n > 0 && n < 128) + { + if (str[0] == '-') + { + if (str[1] == 'n' && str[2] == 'a' && str[3] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[1] == 'i' && str[2] == 'n' && str[3] == 'f') + { + _characters ("-INF", 4); + return; + } + } + else + { + if (str[0] == 'n' && str[1] == 'a' && str[2] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[0] == 'i' && str[1] == 'n' && str[2] == 'f') + { + _characters ("INF", 3); + return; + } + } + + if (notation_ == notation_fixed) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/float.hxx b/libxsde/xsde/cxx/serializer/non-validating/float.hxx new file mode 100644 index 0000000..d3da48f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/float.hxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/serializer/non-validating/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_FLOAT_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_FLOAT_HXX + +#include <float.h> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct float_simpl: virtual float_sskel +#else + struct float_simpl: float_sskel +#endif + { + enum notation + { + notation_auto, + notation_fixed, + notation_scientific + }; + +#ifdef FLT_DIG + float_simpl (notation = notation_auto, + unsigned int precision = FLT_DIG); +#else + float_simpl (notation = notation_auto, + unsigned int precision = 6) +#endif + + virtual void + pre (float); + + virtual void + _serialize_content (); + + protected: + notation notation_; + unsigned int precision_; + float value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/float.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_FLOAT_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/float.ixx b/libxsde/xsde/cxx/serializer/non-validating/float.ixx new file mode 100644 index 0000000..192027e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/float.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/float.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline float_simpl:: + float_simpl (notation n, unsigned int p) + : notation_ (n), precision_ (p) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gday.cxx b/libxsde/xsde/cxx/serializer/non-validating/gday.cxx new file mode 100644 index 0000000..5d3a0a3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gday.cxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/serializer/non-validating/gday.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/gday.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void gday_simpl:: + pre (const gday& value) + { + value_ = value; + } + + void gday_simpl:: + _serialize_content () + { + // We only need strlen("---DD+hh:mm") + 1 characters to hold all + // representations of gDay. + // + char str[12]; + + if (value_.day () < 32) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 6, "---%.2u", value_.day ()); +#else + int n = sprintf (str, "---%.2u", value_.day ()); +#endif + if (n > 0 && n < 6) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gday.hxx b/libxsde/xsde/cxx/serializer/non-validating/gday.hxx new file mode 100644 index 0000000..1442664 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gday.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/gday.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_GDAY_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_GDAY_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gday_simpl: virtual gday_sskel +#else + struct gday_simpl: gday_sskel +#endif + { + gday_simpl (); + + virtual void + pre (const gday&); + + virtual void + _serialize_content (); + + protected: + gday value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/gday.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_GDAY_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/gday.ixx b/libxsde/xsde/cxx/serializer/non-validating/gday.ixx new file mode 100644 index 0000000..ba322f6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gday.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/gday.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline gday_simpl:: + gday_simpl () + : value_ (1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.cxx b/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.cxx new file mode 100644 index 0000000..cb0bb4f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.cxx @@ -0,0 +1,59 @@ +// file : xsde/cxx/serializer/non-validating/gmonth-day.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/gmonth-day.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void gmonth_day_simpl:: + pre (const gmonth_day& value) + { + value_ = value; + } + + void gmonth_day_simpl:: + _serialize_content () + { + // We only need strlen("--MM-DD+hh:mm") + 1 characters to hold all + // representations of gMonthDay. + // + char str[14]; + + if (value_.month () < 13 && value_.day () < 32) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 8, "--%.2u-%.2u", + value_.month (), value_.day ()); +#else + int n = sprintf (str, "--%.2u-%.2u", + value_.month (), value_.day ()); +#endif + if (n > 0 && n < 8) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.hxx b/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.hxx new file mode 100644 index 0000000..6ba2ccf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/gmonth-day.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_GMONTH_DAY_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_GMONTH_DAY_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_day_simpl: virtual gmonth_day_sskel +#else + struct gmonth_day_simpl: gmonth_day_sskel +#endif + { + gmonth_day_simpl (); + + virtual void + pre (const gmonth_day&); + + virtual void + _serialize_content (); + + protected: + gmonth_day value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/gmonth-day.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_GMONTH_DAY_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.ixx b/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.ixx new file mode 100644 index 0000000..864f56c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gmonth-day.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/gmonth-day.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline gmonth_day_simpl:: + gmonth_day_simpl () + : value_ (1, 1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gmonth.cxx b/libxsde/xsde/cxx/serializer/non-validating/gmonth.cxx new file mode 100644 index 0000000..09c9739 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gmonth.cxx @@ -0,0 +1,57 @@ +// file : xsde/cxx/serializer/non-validating/gmonth.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/gmonth.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void gmonth_simpl:: + pre (const gmonth& value) + { + value_ = value; + } + + void gmonth_simpl:: + _serialize_content () + { + // We only need strlen("--MM+hh:mm") + 1 characters to hold all + // representations of gMonth. + // + char str[11]; + + if (value_.month () < 13) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 5, "--%.2u", value_.month ()); +#else + int n = sprintf (str, "--%.2u", value_.month ()); +#endif + if (n > 0 && n < 5) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gmonth.hxx b/libxsde/xsde/cxx/serializer/non-validating/gmonth.hxx new file mode 100644 index 0000000..5ed6310 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gmonth.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/gmonth.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_GMONTH_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_GMONTH_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_simpl: virtual gmonth_sskel +#else + struct gmonth_simpl: gmonth_sskel +#endif + { + gmonth_simpl (); + + virtual void + pre (const gmonth&); + + virtual void + _serialize_content (); + + protected: + gmonth value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/gmonth.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_GMONTH_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/gmonth.ixx b/libxsde/xsde/cxx/serializer/non-validating/gmonth.ixx new file mode 100644 index 0000000..c0b98f3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gmonth.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/gmonth.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline gmonth_simpl:: + gmonth_simpl () + : value_ (1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gyear-month.cxx b/libxsde/xsde/cxx/serializer/non-validating/gyear-month.cxx new file mode 100644 index 0000000..bbb2794 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gyear-month.cxx @@ -0,0 +1,59 @@ +// file : xsde/cxx/serializer/non-validating/gyear-month.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/gyear-month.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void gyear_month_simpl:: + pre (const gyear_month& value) + { + value_ = value; + } + + void gyear_month_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649-MM+hh:mm") + 1 characters to + // hold all representations of gYearMonth. + // + char str[21]; + + if (value_.month () < 13) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 15, "%.4d-%.2u", + value_.year (), value_.month ()); +#else + int n = sprintf (str, "%.4d-%.2u", + value_.year (), value_.month ()); +#endif + if (n > 0 && n < 15) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gyear-month.hxx b/libxsde/xsde/cxx/serializer/non-validating/gyear-month.hxx new file mode 100644 index 0000000..32ee339 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gyear-month.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/gyear-month.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_GYEAR_MONTH_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_GYEAR_MONTH_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_month_simpl: virtual gyear_month_sskel +#else + struct gyear_month_simpl: gyear_month_sskel +#endif + { + gyear_month_simpl (); + + virtual void + pre (const gyear_month&); + + virtual void + _serialize_content (); + + protected: + gyear_month value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/gyear-month.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_GYEAR_MONTH_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/gyear-month.ixx b/libxsde/xsde/cxx/serializer/non-validating/gyear-month.ixx new file mode 100644 index 0000000..f33b7b6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gyear-month.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/gyear-month.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline gyear_month_simpl:: + gyear_month_simpl () + : value_ (1, 1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gyear.cxx b/libxsde/xsde/cxx/serializer/non-validating/gyear.cxx new file mode 100644 index 0000000..4d7a796 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gyear.cxx @@ -0,0 +1,54 @@ +// file : xsde/cxx/serializer/non-validating/gyear.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/gyear.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void gyear_simpl:: + pre (const gyear& value) + { + value_ = value; + } + + void gyear_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649+hh:mm") + 1 characters to + // hold all representations of gYear. + // + char str[18]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 12, "%.4d", value_.year ()); +#else + int n = sprintf (str, "%.4d", value_.year ()); +#endif + if (n > 0 && n < 12) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/gyear.hxx b/libxsde/xsde/cxx/serializer/non-validating/gyear.hxx new file mode 100644 index 0000000..ea38751 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gyear.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/gyear.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_GYEAR_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_GYEAR_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_simpl: virtual gyear_sskel +#else + struct gyear_simpl: gyear_sskel +#endif + { + gyear_simpl (); + + virtual void + pre (const gyear&); + + virtual void + _serialize_content (); + + protected: + gyear value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/gyear.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_GYEAR_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/gyear.ixx b/libxsde/xsde/cxx/serializer/non-validating/gyear.ixx new file mode 100644 index 0000000..f1db195 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/gyear.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/gyear.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline gyear_simpl:: + gyear_simpl () + : value_ (1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/hex-binary.cxx b/libxsde/xsde/cxx/serializer/non-validating/hex-binary.cxx new file mode 100644 index 0000000..f341ff2 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/hex-binary.cxx @@ -0,0 +1,70 @@ +// file : xsde/cxx/serializer/non-validating/hex-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/hex-binary.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + hex_binary_simpl:: + ~hex_binary_simpl () + { + if (free_) + delete const_cast<buffer*> (value_); + } + + void hex_binary_simpl:: + pre (const buffer* value) + { + value_ = value; + } + + static const char hex_tab[] = "0123456789ABCDEF"; + + void hex_binary_simpl:: + _serialize_content () + { + char buf[512]; + + size_t size = value_->size (); + const char* data = value_->data (); + + // Covert the data in 256-byte chunks. + // + for (size_t j = 0; j < size;) + { + size_t i = 0; + + for (; i < 512 && j < size; ++j) + { + unsigned char byte = static_cast<unsigned char> (data[j]); + + buf[i++] = hex_tab[byte >> 4]; + buf[i++] = hex_tab[byte & 0x0F]; + } + +#ifdef XSDE_EXCEPTIONS + _characters (buf, i); +#else + if (!_characters (buf, i)) + break; +#endif + } + + if (free_) + { + delete const_cast<buffer*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/hex-binary.hxx b/libxsde/xsde/cxx/serializer/non-validating/hex-binary.hxx new file mode 100644 index 0000000..eb10879 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/hex-binary.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/hex-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_HEX_BINARY_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_HEX_BINARY_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct hex_binary_simpl: virtual hex_binary_sskel +#else + struct hex_binary_simpl: hex_binary_sskel +#endif + { + virtual + ~hex_binary_simpl (); + + hex_binary_simpl (bool free = false); + + virtual void + pre (const buffer*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const buffer* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/hex-binary.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_HEX_BINARY_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/hex-binary.ixx b/libxsde/xsde/cxx/serializer/non-validating/hex-binary.ixx new file mode 100644 index 0000000..3305b15 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/hex-binary.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/hex-binary.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline hex_binary_simpl:: + hex_binary_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/id-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/id-stl.cxx new file mode 100644 index 0000000..ed63192 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/id-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/id-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/id-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void id_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void id_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/id-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/id-stl.hxx new file mode 100644 index 0000000..a615151 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/id-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/id-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_ID_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_ID_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_simpl: virtual id_sskel +#else + struct id_simpl: id_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_ID_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/id.cxx b/libxsde/xsde/cxx/serializer/non-validating/id.cxx new file mode 100644 index 0000000..ab75ad5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/id.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/id.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/id.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + id_simpl:: + ~id_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void id_simpl:: + pre (const char* value) + { + value_ = value; + } + + void id_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/id.hxx b/libxsde/xsde/cxx/serializer/non-validating/id.hxx new file mode 100644 index 0000000..2c0563c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/id.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/id.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_ID_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_ID_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_simpl: virtual id_sskel +#else + struct id_simpl: id_sskel +#endif + { + virtual + ~id_simpl (); + + id_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/id.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_ID_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/id.ixx b/libxsde/xsde/cxx/serializer/non-validating/id.ixx new file mode 100644 index 0000000..22e4201 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/id.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/id.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline id_simpl:: + id_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/idref-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/idref-stl.cxx new file mode 100644 index 0000000..2b128e7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idref-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/idref-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void idref_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void idref_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/idref-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/idref-stl.hxx new file mode 100644 index 0000000..1fc6d08 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idref-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/idref-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREF_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREF_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_simpl: virtual idref_sskel +#else + struct idref_simpl: idref_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREF_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/idref.cxx b/libxsde/xsde/cxx/serializer/non-validating/idref.cxx new file mode 100644 index 0000000..527beb5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idref.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/idref.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + idref_simpl:: + ~idref_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void idref_simpl:: + pre (const char* value) + { + value_ = value; + } + + void idref_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/idref.hxx b/libxsde/xsde/cxx/serializer/non-validating/idref.hxx new file mode 100644 index 0000000..295c701 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idref.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/idref.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREF_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREF_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_simpl: virtual idref_sskel +#else + struct idref_simpl: idref_sskel +#endif + { + virtual + ~idref_simpl (); + + idref_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/idref.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREF_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/idref.ixx b/libxsde/xsde/cxx/serializer/non-validating/idref.ixx new file mode 100644 index 0000000..e558f2f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idref.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/idref.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline idref_simpl:: + idref_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.cxx new file mode 100644 index 0000000..75db514 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.cxx @@ -0,0 +1,108 @@ +// file : xsde/cxx/serializer/non-validating/idrefs-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/idrefs-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + idrefs_simpl:: + ~idrefs_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void idrefs_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void idrefs_simpl:: + _serialize_content () + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { +#ifdef XSDE_EXCEPTIONS + serializer_.pre (*i); + + if (!first) + _characters (" ", 1); + else + first = false; + + serializer_._pre_impl (ctx); + serializer_._serialize_content (); + serializer_._post_impl (); + serializer_.post (); +#else + serializer_.pre (*i); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; + + if (!first) + { + if (!_characters (" ", 1)) + break; + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void idrefs_simpl:: + _reset () + { + idrefs_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.hxx new file mode 100644 index 0000000..bb88871 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/non-validating/idrefs-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREFS_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREFS_STL_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/non-validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_simpl: virtual idrefs_sskel +#else + struct idrefs_simpl: idrefs_sskel +#endif + { + virtual + ~idrefs_simpl (); + + idrefs_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + idref_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/idrefs-stl.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREFS_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.ixx b/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.ixx new file mode 100644 index 0000000..ff15241 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idrefs-stl.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/idrefs-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline idrefs_simpl:: + idrefs_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/idrefs.cxx b/libxsde/xsde/cxx/serializer/non-validating/idrefs.cxx new file mode 100644 index 0000000..a795453 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idrefs.cxx @@ -0,0 +1,109 @@ +// file : xsde/cxx/serializer/non-validating/idrefs.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/idrefs.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + idrefs_simpl:: + ~idrefs_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void idrefs_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void idrefs_simpl:: + _serialize_content () + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { +#ifdef XSDE_EXCEPTIONS + serializer_.pre (*i); + + if (!first) + _characters (" ", 1); + else + first = false; + + serializer_._pre_impl (ctx); + serializer_._serialize_content (); + serializer_._post_impl (); + serializer_.post (); +#else + serializer_.pre (*i); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; + + if (!first) + { + if (!_characters (" ", 1)) + break; + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void idrefs_simpl:: + _reset () + { + idrefs_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/non-validating/idrefs.hxx b/libxsde/xsde/cxx/serializer/non-validating/idrefs.hxx new file mode 100644 index 0000000..2eb7a9e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idrefs.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/non-validating/idrefs.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREFS_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREFS_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/non-validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_simpl: virtual idrefs_sskel +#else + struct idrefs_simpl: idrefs_sskel +#endif + { + virtual + ~idrefs_simpl (); + + idrefs_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + idref_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/idrefs.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_IDREFS_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/idrefs.ixx b/libxsde/xsde/cxx/serializer/non-validating/idrefs.ixx new file mode 100644 index 0000000..773270e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/idrefs.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/idrefs.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline idrefs_simpl:: + idrefs_simpl (bool free) + : free_ (free), value_ (0), serializer_ (false) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/int.cxx b/libxsde/xsde/cxx/serializer/non-validating/int.cxx new file mode 100644 index 0000000..ab318bc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/int.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void int_simpl:: + pre (int value) + { + value_ = value; + } + + void int_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649") + 1 characters to hold all + // representations of int. + // + char str[12]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 12, "%d", value_); +#else + int n = sprintf (str, "%d", value_); +#endif + if (n > 0 && n < 12) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/int.hxx b/libxsde/xsde/cxx/serializer/non-validating/int.hxx new file mode 100644 index 0000000..a4712ac --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/int.hxx @@ -0,0 +1,39 @@ +// file : xsde/cxx/serializer/non-validating/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_INT_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_INT_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct int_simpl: virtual int_sskel +#else + struct int_simpl: int_sskel +#endif + { + virtual void + pre (int); + + virtual void + _serialize_content (); + + protected: + int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_INT_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/integer.cxx b/libxsde/xsde/cxx/serializer/non-validating/integer.cxx new file mode 100644 index 0000000..a9928fd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/integer.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void integer_simpl:: + pre (long value) + { + value_ = value; + } + + void integer_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/integer.hxx b/libxsde/xsde/cxx/serializer/non-validating/integer.hxx new file mode 100644 index 0000000..da83119 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_INTEGER_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Arbitrary-length integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct integer_simpl: virtual integer_sskel +#else + struct integer_simpl: integer_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/language-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/language-stl.cxx new file mode 100644 index 0000000..ba60bdc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/language-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/language-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/language-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void language_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void language_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/language-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/language-stl.hxx new file mode 100644 index 0000000..b141c16 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/language-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/language-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_LANGUAGE_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_LANGUAGE_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_simpl: virtual language_sskel +#else + struct language_simpl: language_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_LANGUAGE_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/language.cxx b/libxsde/xsde/cxx/serializer/non-validating/language.cxx new file mode 100644 index 0000000..558edae --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/language.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/language.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/language.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + language_simpl:: + ~language_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void language_simpl:: + pre (const char* value) + { + value_ = value; + } + + void language_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/language.hxx b/libxsde/xsde/cxx/serializer/non-validating/language.hxx new file mode 100644 index 0000000..56ed635 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/language.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/language.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_LANGUAGE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_LANGUAGE_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_simpl: virtual language_sskel +#else + struct language_simpl: language_sskel +#endif + { + virtual + ~language_simpl (); + + language_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/language.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_LANGUAGE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/language.ixx b/libxsde/xsde/cxx/serializer/non-validating/language.ixx new file mode 100644 index 0000000..3b51aad --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/language.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/language.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline language_simpl:: + language_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/long-long.cxx b/libxsde/xsde/cxx/serializer/non-validating/long-long.cxx new file mode 100644 index 0000000..364a71d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/long-long.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void long_simpl:: + pre (long long value) + { + value_ = value; + } + + void long_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of long long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lld", value_); +#else + int n = sprintf (str, "%lld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/long-long.hxx b/libxsde/xsde/cxx/serializer/non-validating/long-long.hxx new file mode 100644 index 0000000..545bb80 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/long-long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_LONG_LONG_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_LONG_LONG_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 64-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_simpl: virtual long_sskel +#else + struct long_simpl: long_sskel +#endif + { + virtual void + pre (long long); + + virtual void + _serialize_content (); + + protected: + long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/long.cxx b/libxsde/xsde/cxx/serializer/non-validating/long.cxx new file mode 100644 index 0000000..7a9c121 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/long.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void long_simpl:: + pre (long value) + { + value_ = value; + } + + void long_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/long.hxx b/libxsde/xsde/cxx/serializer/non-validating/long.hxx new file mode 100644 index 0000000..a4c63e7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_LONG_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_LONG_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_simpl: virtual long_sskel +#else + struct long_simpl: long_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/name-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/name-stl.cxx new file mode 100644 index 0000000..d84fd65 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/name-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/name-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/name-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void name_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void name_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/name-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/name-stl.hxx new file mode 100644 index 0000000..f06b279 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/name-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/name-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NAME_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NAME_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_simpl: virtual name_sskel +#else + struct name_simpl: name_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NAME_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/name.cxx b/libxsde/xsde/cxx/serializer/non-validating/name.cxx new file mode 100644 index 0000000..70cb5c3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/name.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/name.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/name.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + name_simpl:: + ~name_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void name_simpl:: + pre (const char* value) + { + value_ = value; + } + + void name_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/name.hxx b/libxsde/xsde/cxx/serializer/non-validating/name.hxx new file mode 100644 index 0000000..8a36591 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/name.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/name.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NAME_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NAME_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_simpl: virtual name_sskel +#else + struct name_simpl: name_sskel +#endif + { + virtual + ~name_simpl (); + + name_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/name.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NAME_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/name.ixx b/libxsde/xsde/cxx/serializer/non-validating/name.ixx new file mode 100644 index 0000000..f927928 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/name.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/name.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline name_simpl:: + name_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/ncname-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/ncname-stl.cxx new file mode 100644 index 0000000..3e31290 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/ncname-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/ncname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/ncname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void ncname_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void ncname_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/ncname-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/ncname-stl.hxx new file mode 100644 index 0000000..781b513 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/ncname-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/ncname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NCNAME_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NCNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_simpl: virtual ncname_sskel +#else + struct ncname_simpl: ncname_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NCNAME_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/ncname.cxx b/libxsde/xsde/cxx/serializer/non-validating/ncname.cxx new file mode 100644 index 0000000..ba39a06 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/ncname.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + ncname_simpl:: + ~ncname_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void ncname_simpl:: + pre (const char* value) + { + value_ = value; + } + + void ncname_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/ncname.hxx b/libxsde/xsde/cxx/serializer/non-validating/ncname.hxx new file mode 100644 index 0000000..93a85c5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/ncname.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NCNAME_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NCNAME_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_simpl: virtual ncname_sskel +#else + struct ncname_simpl: ncname_sskel +#endif + { + virtual + ~ncname_simpl (); + + ncname_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/ncname.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NCNAME_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/ncname.ixx b/libxsde/xsde/cxx/serializer/non-validating/ncname.ixx new file mode 100644 index 0000000..36785d6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/ncname.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/ncname.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline ncname_simpl:: + ncname_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/negative-integer.cxx b/libxsde/xsde/cxx/serializer/non-validating/negative-integer.cxx new file mode 100644 index 0000000..713968d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/negative-integer.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void negative_integer_simpl:: + pre (long value) + { + value_ = value; + } + + void negative_integer_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/negative-integer.hxx b/libxsde/xsde/cxx/serializer/non-validating/negative-integer.hxx new file mode 100644 index 0000000..d8d7367 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/negative-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Arbitrary-length negative integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct negative_integer_simpl: virtual negative_integer_sskel +#else + struct negative_integer_simpl: negative_integer_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtoken-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/nmtoken-stl.cxx new file mode 100644 index 0000000..a23aa22 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtoken-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/nmtoken-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void nmtoken_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void nmtoken_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtoken-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/nmtoken-stl.hxx new file mode 100644 index 0000000..e5b56b4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtoken-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/nmtoken-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKEN_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_simpl: virtual nmtoken_sskel +#else + struct nmtoken_simpl: nmtoken_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtoken.cxx b/libxsde/xsde/cxx/serializer/non-validating/nmtoken.cxx new file mode 100644 index 0000000..45132f1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtoken.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/nmtoken.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + nmtoken_simpl:: + ~nmtoken_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void nmtoken_simpl:: + pre (const char* value) + { + value_ = value; + } + + void nmtoken_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtoken.hxx b/libxsde/xsde/cxx/serializer/non-validating/nmtoken.hxx new file mode 100644 index 0000000..14642c9 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtoken.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/nmtoken.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKEN_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKEN_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_simpl: virtual nmtoken_sskel +#else + struct nmtoken_simpl: nmtoken_sskel +#endif + { + virtual + ~nmtoken_simpl (); + + nmtoken_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/nmtoken.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKEN_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtoken.ixx b/libxsde/xsde/cxx/serializer/non-validating/nmtoken.ixx new file mode 100644 index 0000000..68ebd47 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtoken.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/nmtoken.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline nmtoken_simpl:: + nmtoken_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.cxx new file mode 100644 index 0000000..afa663f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.cxx @@ -0,0 +1,108 @@ +// file : xsde/cxx/serializer/non-validating/nmtokens-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/nmtokens-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + nmtokens_simpl:: + ~nmtokens_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void nmtokens_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void nmtokens_simpl:: + _serialize_content () + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { +#ifdef XSDE_EXCEPTIONS + serializer_.pre (*i); + + if (!first) + _characters (" ", 1); + else + first = false; + + serializer_._pre_impl (ctx); + serializer_._serialize_content (); + serializer_._post_impl (); + serializer_.post (); +#else + serializer_.pre (*i); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; + + if (!first) + { + if (!_characters (" ", 1)) + break; + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void nmtokens_simpl:: + _reset () + { + nmtokens_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.hxx new file mode 100644 index 0000000..da6ec57 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/non-validating/nmtokens-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKENS_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKENS_STL_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/non-validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_simpl: virtual nmtokens_sskel +#else + struct nmtokens_simpl: nmtokens_sskel +#endif + { + virtual + ~nmtokens_simpl (); + + nmtokens_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + nmtoken_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/nmtokens-stl.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKENS_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.ixx b/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.ixx new file mode 100644 index 0000000..b0236d8 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtokens-stl.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/nmtokens-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline nmtokens_simpl:: + nmtokens_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtokens.cxx b/libxsde/xsde/cxx/serializer/non-validating/nmtokens.cxx new file mode 100644 index 0000000..f430bda --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtokens.cxx @@ -0,0 +1,109 @@ +// file : xsde/cxx/serializer/non-validating/nmtokens.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/nmtokens.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + nmtokens_simpl:: + ~nmtokens_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void nmtokens_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void nmtokens_simpl:: + _serialize_content () + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { +#ifdef XSDE_EXCEPTIONS + serializer_.pre (*i); + + if (!first) + _characters (" ", 1); + else + first = false; + + serializer_._pre_impl (ctx); + serializer_._serialize_content (); + serializer_._post_impl (); + serializer_.post (); +#else + serializer_.pre (*i); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; + + if (!first) + { + if (!_characters (" ", 1)) + break; + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void nmtokens_simpl:: + _reset () + { + nmtokens_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtokens.hxx b/libxsde/xsde/cxx/serializer/non-validating/nmtokens.hxx new file mode 100644 index 0000000..8a0f651 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtokens.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/non-validating/nmtokens.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKENS_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKENS_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/non-validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_simpl: virtual nmtokens_sskel +#else + struct nmtokens_simpl: nmtokens_sskel +#endif + { + virtual + ~nmtokens_simpl (); + + nmtokens_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + nmtoken_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/nmtokens.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NMTOKENS_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/nmtokens.ixx b/libxsde/xsde/cxx/serializer/non-validating/nmtokens.ixx new file mode 100644 index 0000000..43af4b2 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/nmtokens.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/nmtokens.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline nmtokens_simpl:: + nmtokens_simpl (bool free) + : free_ (free), value_ (0), serializer_ (false) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/non-negative-integer.cxx b/libxsde/xsde/cxx/serializer/non-validating/non-negative-integer.cxx new file mode 100644 index 0000000..8a3ee77 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/non-negative-integer.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/non-negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/non-negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void non_negative_integer_simpl:: + pre (unsigned long value) + { + value_ = value; + } + + void non_negative_integer_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of (possibly 64-bit) unsigned long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lu", value_); +#else + int n = sprintf (str, "%lu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/non-negative-integer.hxx b/libxsde/xsde/cxx/serializer/non-validating/non-negative-integer.hxx new file mode 100644 index 0000000..ba9e1f3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/non-negative-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/non-negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Arbitrary-length non-negative integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_negative_integer_simpl: virtual non_negative_integer_sskel +#else + struct non_negative_integer_simpl: non_negative_integer_sskel +#endif + { + virtual void + pre (unsigned long); + + virtual void + _serialize_content (); + + protected: + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NON_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/non-positive-integer.cxx b/libxsde/xsde/cxx/serializer/non-validating/non-positive-integer.cxx new file mode 100644 index 0000000..4aa51d0 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/non-positive-integer.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/non-positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/non-positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void non_positive_integer_simpl:: + pre (long value) + { + value_ = value; + } + + void non_positive_integer_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/non-positive-integer.hxx b/libxsde/xsde/cxx/serializer/non-validating/non-positive-integer.hxx new file mode 100644 index 0000000..5e8c212 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/non-positive-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/non-positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Arbitrary-length non-positive integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_positive_integer_simpl: virtual non_positive_integer_sskel +#else + struct non_positive_integer_simpl: non_positive_integer_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NON_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/normalized-string-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/normalized-string-stl.cxx new file mode 100644 index 0000000..c96c9cf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/normalized-string-stl.cxx @@ -0,0 +1,36 @@ +// file : xsde/cxx/serializer/non-validating/normalized-string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/normalized-string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void normalized_string_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void normalized_string_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/non-validating/normalized-string-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/normalized-string-stl.hxx new file mode 100644 index 0000000..65da3b6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/normalized-string-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/normalized-string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_simpl: virtual normalized_string_sskel +#else + struct normalized_string_simpl: normalized_string_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NORMALIZED_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/normalized-string.cxx b/libxsde/xsde/cxx/serializer/non-validating/normalized-string.cxx new file mode 100644 index 0000000..fd69cec --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/normalized-string.cxx @@ -0,0 +1,44 @@ +// file : xsde/cxx/serializer/non-validating/normalized-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/normalized-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + normalized_string_simpl:: + ~normalized_string_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void normalized_string_simpl:: + pre (const char* value) + { + value_ = value; + } + + void normalized_string_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/non-validating/normalized-string.hxx b/libxsde/xsde/cxx/serializer/non-validating/normalized-string.hxx new file mode 100644 index 0000000..1ae4270 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/normalized-string.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/normalized-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_NORMALIZED_STRING_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_NORMALIZED_STRING_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_simpl: virtual normalized_string_sskel +#else + struct normalized_string_simpl: normalized_string_sskel +#endif + { + virtual + ~normalized_string_simpl (); + + normalized_string_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/normalized-string.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_NORMALIZED_STRING_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/normalized-string.ixx b/libxsde/xsde/cxx/serializer/non-validating/normalized-string.ixx new file mode 100644 index 0000000..627b93a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/normalized-string.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/normalized-string.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline normalized_string_simpl:: + normalized_string_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/positive-integer.cxx b/libxsde/xsde/cxx/serializer/non-validating/positive-integer.cxx new file mode 100644 index 0000000..193499e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/positive-integer.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void positive_integer_simpl:: + pre (unsigned long value) + { + value_ = value; + } + + void positive_integer_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of (possibly 64-bit) unsigned long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lu", value_); +#else + int n = sprintf (str, "%lu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/positive-integer.hxx b/libxsde/xsde/cxx/serializer/non-validating/positive-integer.hxx new file mode 100644 index 0000000..397e904 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/positive-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_POSITIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Arbitrary-length positive integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct positive_integer_simpl: virtual positive_integer_sskel +#else + struct positive_integer_simpl: positive_integer_sskel +#endif + { + virtual void + pre (unsigned long); + + virtual void + _serialize_content (); + + protected: + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/qname-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/qname-stl.cxx new file mode 100644 index 0000000..92c0b57 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/qname-stl.cxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/serializer/non-validating/qname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/qname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void qname_simpl:: + pre (const qname& value) + { + value_ = value; + } + + void qname_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the qname. + // + qname tmp ("a"); + tmp.swap (value_); + + if (!tmp.prefix ().empty ()) + { +#ifdef XSDE_EXCEPTIONS + _characters (tmp.prefix ().c_str (), tmp.prefix ().size ()); + _characters (":", 1); + _characters (tmp.name ().c_str (), tmp.name ().size ()); +#else + if (_characters (tmp.prefix ().c_str (), tmp.prefix ().size ())) + { + if (_characters (":", 1)) + _characters (tmp.name ().c_str (), tmp.name ().size ()); + } +#endif + } + else + _characters (tmp.name ().c_str (), tmp.name ().size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/qname-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/qname-stl.hxx new file mode 100644 index 0000000..9163de5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/qname-stl.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_QNAME_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_QNAME_STL_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_simpl: virtual qname_sskel +#else + struct qname_simpl: qname_sskel +#endif + { + qname_simpl (); + + virtual void + pre (const qname&); + + virtual void + _serialize_content (); + + protected: + qname value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/qname-stl.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/qname-stl.ixx b/libxsde/xsde/cxx/serializer/non-validating/qname-stl.ixx new file mode 100644 index 0000000..d4bff2d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/qname-stl.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/qname-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline qname_simpl:: + qname_simpl () + : value_ ("a") + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/qname.cxx b/libxsde/xsde/cxx/serializer/non-validating/qname.cxx new file mode 100644 index 0000000..d2e41ff --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/qname.cxx @@ -0,0 +1,62 @@ +// file : xsde/cxx/serializer/non-validating/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/qname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + qname_simpl:: + ~qname_simpl () + { + if (free_) + delete const_cast<qname*> (value_); + } + + void qname_simpl:: + pre (const qname* value) + { + value_ = value; + } + + void qname_simpl:: + _serialize_content () + { + const char* p = value_->prefix (); + + if (p != 0 && *p != '\0') + { +#ifdef XSDE_EXCEPTIONS + _characters (p); + _characters (":", 1); + _characters (value_->name ()); +#else + if (_characters (p)) + { + if (_characters (":", 1)) + _characters (value_->name ()); + } +#endif + } + else + { + _characters (value_->name ()); + } + + if (free_) + { + delete const_cast<qname*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/qname.hxx b/libxsde/xsde/cxx/serializer/non-validating/qname.hxx new file mode 100644 index 0000000..4916726 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/qname.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_QNAME_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_QNAME_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_simpl: virtual qname_sskel +#else + struct qname_simpl: qname_sskel +#endif + { + virtual + ~qname_simpl (); + + qname_simpl (bool free = false); + + virtual void + pre (const qname*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const qname* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/qname.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_QNAME_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/qname.ixx b/libxsde/xsde/cxx/serializer/non-validating/qname.ixx new file mode 100644 index 0000000..e89b8b9 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/qname.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/qname.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline qname_simpl:: + qname_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/serializer.cxx b/libxsde/xsde/cxx/serializer/non-validating/serializer.cxx new file mode 100644 index 0000000..7da8599 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/serializer.cxx @@ -0,0 +1,29 @@ +// file : xsde/cxx/serializer/non-validating/serializer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/serializer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + void simple_content:: + _serialize_content () + { + if (impl_) + impl_->_serialize_content (); + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/serializer.hxx b/libxsde/xsde/cxx/serializer/non-validating/serializer.hxx new file mode 100644 index 0000000..c01476b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/serializer.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/serializer/non-validating/serializer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_SERIALIZER_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_SERIALIZER_HXX + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/serializer/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + struct empty_content: serializer_base + { +#ifdef XSDE_REUSE_STYLE_TIEIN + empty_content (); + empty_content (empty_content* impl, void*); +#endif + }; + + // + // + struct simple_content: empty_content + { +#ifdef XSDE_REUSE_STYLE_TIEIN + virtual void + _serialize_content (); + + simple_content (); + simple_content (simple_content* impl, void*); +#endif + }; + + // + // + struct complex_content: empty_content + { +#ifdef XSDE_REUSE_STYLE_TIEIN + complex_content (); + complex_content (complex_content* impl, void*); +#endif + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/serializer.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_SERIALIZER_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/serializer.ixx b/libxsde/xsde/cxx/serializer/non-validating/serializer.ixx new file mode 100644 index 0000000..b8eacee --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/serializer.ixx @@ -0,0 +1,61 @@ +// file : xsde/cxx/serializer/non-validating/serializer.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // empty_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline empty_content:: + empty_content () + { + } + + inline empty_content:: + empty_content (empty_content* impl, void*) + : serializer_base (impl, 0) + { + } +#endif + + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline simple_content:: + simple_content () + { + } + + inline simple_content:: + simple_content (simple_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + + // complex_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline complex_content:: + complex_content () + { + } + + inline complex_content:: + complex_content (complex_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/short.cxx b/libxsde/xsde/cxx/serializer/non-validating/short.cxx new file mode 100644 index 0000000..ad14306 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/short.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void short_simpl:: + pre (short value) + { + value_ = value; + } + + void short_simpl:: + _serialize_content () + { + // We only need strlen("-32768") + 1 characters to hold all + // representations of short. + // + char str[7]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 7, "%d", value_); +#else + int n = sprintf (str, "%d", value_); +#endif + if (n > 0 && n < 7) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/short.hxx b/libxsde/xsde/cxx/serializer/non-validating/short.hxx new file mode 100644 index 0000000..fb763e7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/short.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_SHORT_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_SHORT_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 16-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct short_simpl: virtual short_sskel +#else + struct short_simpl: short_sskel +#endif + { + virtual void + pre (short); + + virtual void + _serialize_content (); + + protected: + short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_SHORT_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/string-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/string-stl.cxx new file mode 100644 index 0000000..28ba3e9 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/string-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void string_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void string_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/string-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/string-stl.hxx new file mode 100644 index 0000000..0aee653 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/string-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_STRING_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_simpl: virtual string_sskel +#else + struct string_simpl: string_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/string.cxx b/libxsde/xsde/cxx/serializer/non-validating/string.cxx new file mode 100644 index 0000000..a56b3fa --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/string.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + string_simpl:: + ~string_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void string_simpl:: + pre (const char* value) + { + value_ = value; + } + + void string_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/string.hxx b/libxsde/xsde/cxx/serializer/non-validating/string.hxx new file mode 100644 index 0000000..913e2de --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/string.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_STRING_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_STRING_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_simpl: virtual string_sskel +#else + struct string_simpl: string_sskel +#endif + { + virtual + ~string_simpl (); + + string_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/string.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_STRING_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/string.ixx b/libxsde/xsde/cxx/serializer/non-validating/string.ixx new file mode 100644 index 0000000..b620835 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/string.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/string.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline string_simpl:: + string_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx b/libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx new file mode 100644 index 0000000..8f374cf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/time-zone.cxx @@ -0,0 +1,65 @@ +// file : xsde/cxx/serializer/non-validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + namespace bits + { + int + serialize_time_zone (char* s, const time_zone& z) + { + // time-zone := Z|(+|-)HH:MM + // + + short h = z.zone_hours (); + short m = z.zone_minutes (); + + if (h == 0 && m == 0) + { + *s = 'Z'; + return 1; + } + else + { + const char* fmt = "+%.2u:%.2u"; + + if (h < 0 || m < 0) + { + fmt = "-%.2u:%.2u"; + h = -h; + m = -m; + } + + if (h >= 0 && h <= 14 && m >= 0 && m <= 59) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (s, 7, fmt, h, m); +#else + int n = sprintf (s, fmt, h, m); +#endif + if (n > 0 && n < 7) + return n; + } + + return 0; + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/time-zone.hxx b/libxsde/xsde/cxx/serializer/non-validating/time-zone.hxx new file mode 100644 index 0000000..3a342b4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/time-zone.hxx @@ -0,0 +1,33 @@ +// file : xsde/cxx/serializer/non-validating/time-zone.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_TIME_ZONE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_TIME_ZONE_HXX + +#include <xsde/cxx/date-time.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + namespace bits + { + // Returns 0 in case of a failure and the number of + // characters written otherwise. The buffer should + // have space for at least 7 characters. + // + int + serialize_time_zone (char* s, const time_zone&); + } + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_TIME_ZONE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/time.cxx b/libxsde/xsde/cxx/serializer/non-validating/time.cxx new file mode 100644 index 0000000..7643d12 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/time.cxx @@ -0,0 +1,73 @@ +// file : xsde/cxx/serializer/non-validating/time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/time.hxx> +#include <xsde/cxx/serializer/non-validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void time_simpl:: + pre (const time& value) + { + value_ = value; + } + + void time_simpl:: + _serialize_content () + { + // We only need strlen("hh:mm:ss.ssssss-hh:mm") + 1 characters to + // hold all representations of time. We know that the seconds + // part (represented as double) has default precision of 6. + // + char str[22]; + + if (value_.hours () <= 24 && + value_.minutes () <= 59 && + value_.seconds () >= 0.0 && + value_.seconds () < 60.0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 16, "%.2u:%.2u:%09f", + value_.hours (), value_.minutes (), + value_.seconds ()); +#else + int n = sprintf (str, "%.2u:%.2u:%09f", + value_.hours (), value_.minutes (), + value_.seconds ()); +#endif + if (n > 0 && n < 16) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + return; + } + + _characters (str, static_cast<size_t> (n)); + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/time.hxx b/libxsde/xsde/cxx/serializer/non-validating/time.hxx new file mode 100644 index 0000000..69680c5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/time.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_TIME_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_TIME_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct time_simpl: virtual time_sskel +#else + struct time_simpl: time_sskel +#endif + { + time_simpl (); + + virtual void + pre (const time&); + + virtual void + _serialize_content (); + + protected: + time value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/time.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_TIME_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/time.ixx b/libxsde/xsde/cxx/serializer/non-validating/time.ixx new file mode 100644 index 0000000..9a99cb6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/time.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/time.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline time_simpl:: + time_simpl () + : value_ (0, 0, 0.0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/token-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/token-stl.cxx new file mode 100644 index 0000000..baf257a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/token-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/token-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/token-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void token_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void token_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/token-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/token-stl.hxx new file mode 100644 index 0000000..458cb6d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/token-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/token-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_TOKEN_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_TOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_simpl: virtual token_sskel +#else + struct token_simpl: token_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_TOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/token.cxx b/libxsde/xsde/cxx/serializer/non-validating/token.cxx new file mode 100644 index 0000000..e2bfd0e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/token.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/token.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/token.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + token_simpl:: + ~token_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void token_simpl:: + pre (const char* value) + { + value_ = value; + } + + void token_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/token.hxx b/libxsde/xsde/cxx/serializer/non-validating/token.hxx new file mode 100644 index 0000000..0133fd5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/token.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/token.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_TOKEN_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_TOKEN_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_simpl: virtual token_sskel +#else + struct token_simpl: token_sskel +#endif + { + virtual + ~token_simpl (); + + token_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/token.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_TOKEN_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/token.ixx b/libxsde/xsde/cxx/serializer/non-validating/token.ixx new file mode 100644 index 0000000..9cb8594 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/token.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/token.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline token_simpl:: + token_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-byte.cxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-byte.cxx new file mode 100644 index 0000000..3d39100 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-byte.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/unsigned-byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void unsigned_byte_simpl:: + pre (unsigned char value) + { + value_ = value; + } + + void unsigned_byte_simpl:: + _serialize_content () + { + // We only need strlen("256") + 1 characters to hold all + // representations of unsigned byte. + // + char str[4]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 4, "%u", value_); +#else + int n = sprintf (str, "%u", value_); +#endif + if (n > 0 && n < 4) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-byte.hxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-byte.hxx new file mode 100644 index 0000000..9c4f45e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-byte.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_BYTE_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_BYTE_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 8-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_byte_simpl: virtual unsigned_byte_sskel +#else + struct unsigned_byte_simpl: unsigned_byte_sskel +#endif + { + virtual void + pre (unsigned char); + + virtual void + _serialize_content (); + + protected: + unsigned char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_BYTE_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-int.cxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-int.cxx new file mode 100644 index 0000000..5f9f73a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-int.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/unsigned-int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void unsigned_int_simpl:: + pre (unsigned int value) + { + value_ = value; + } + + void unsigned_int_simpl:: + _serialize_content () + { + // We only need strlen("4294967295") + 1 characters to hold all + // representations of unsigned int. + // + char str[11]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 11, "%u", value_); +#else + int n = sprintf (str, "%u", value_); +#endif + if (n > 0 && n < 11) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-int.hxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-int.hxx new file mode 100644 index 0000000..66e88d0 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-int.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_INT_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_INT_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 32-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_int_simpl: virtual unsigned_int_sskel +#else + struct unsigned_int_simpl: unsigned_int_sskel +#endif + { + virtual void + pre (unsigned int); + + virtual void + _serialize_content (); + + protected: + unsigned int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_INT_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-long-long.cxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long-long.cxx new file mode 100644 index 0000000..6e62f87 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long-long.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/unsigned-long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void unsigned_long_simpl:: + pre (unsigned long long value) + { + value_ = value; + } + + void unsigned_long_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of unsigned long long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%llu", value_); +#else + int n = sprintf (str, "%llu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-long-long.hxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long-long.hxx new file mode 100644 index 0000000..34ea158 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long-long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 64-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_simpl: virtual unsigned_long_sskel +#else + struct unsigned_long_simpl: unsigned_long_sskel +#endif + { + virtual void + pre (unsigned long long); + + virtual void + _serialize_content (); + + protected: + unsigned long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-long.cxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long.cxx new file mode 100644 index 0000000..fd70eaf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/unsigned-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void unsigned_long_simpl:: + pre (unsigned long value) + { + value_ = value; + } + + void unsigned_long_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of (possibly 64-bit) unsigned long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lu", value_); +#else + int n = sprintf (str, "%lu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-long.hxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long.hxx new file mode 100644 index 0000000..ba061d3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_LONG_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_LONG_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_simpl: virtual unsigned_long_sskel +#else + struct unsigned_long_simpl: unsigned_long_sskel +#endif + { + virtual void + pre (unsigned long); + + virtual void + _serialize_content (); + + protected: + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-short.cxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-short.cxx new file mode 100644 index 0000000..ffe29e1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-short.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/non-validating/unsigned-short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void unsigned_short_simpl:: + pre (unsigned short value) + { + value_ = value; + } + + void unsigned_short_simpl:: + _serialize_content () + { + // We only need strlen("65535") + 1 characters to hold all + // representations of short. + // + char str[6]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 6, "%u", value_); +#else + int n = sprintf (str, "%u", value_); +#endif + if (n > 0 && n < 6) + _characters (str, static_cast<size_t> (n)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/unsigned-short.hxx b/libxsde/xsde/cxx/serializer/non-validating/unsigned-short.hxx new file mode 100644 index 0000000..ffde97c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/unsigned-short.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_SHORT_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_SHORT_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // 16-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_short_simpl: virtual unsigned_short_sskel +#else + struct unsigned_short_simpl: unsigned_short_sskel +#endif + { + virtual void + pre (unsigned short); + + virtual void + _serialize_content (); + + protected: + unsigned short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_UNSIGNED_SHORT_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/uri-stl.cxx b/libxsde/xsde/cxx/serializer/non-validating/uri-stl.cxx new file mode 100644 index 0000000..c109227 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/uri-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/non-validating/uri-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/uri-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + void uri_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void uri_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/uri-stl.hxx b/libxsde/xsde/cxx/serializer/non-validating/uri-stl.hxx new file mode 100644 index 0000000..38310e5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/uri-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/non-validating/uri-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_URI_STL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_URI_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_simpl: virtual uri_sskel +#else + struct uri_simpl: uri_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_URI_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/uri.cxx b/libxsde/xsde/cxx/serializer/non-validating/uri.cxx new file mode 100644 index 0000000..372c88d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/uri.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/non-validating/uri.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/uri.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + uri_simpl:: + ~uri_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void uri_simpl:: + pre (const char* value) + { + value_ = value; + } + + void uri_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/uri.hxx b/libxsde/xsde/cxx/serializer/non-validating/uri.hxx new file mode 100644 index 0000000..86a3c47 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/uri.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/non-validating/uri.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_URI_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_URI_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_simpl: virtual uri_sskel +#else + struct uri_simpl: uri_sskel +#endif + { + virtual + ~uri_simpl (); + + uri_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/uri.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_URI_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/uri.ixx b/libxsde/xsde/cxx/serializer/non-validating/uri.ixx new file mode 100644 index 0000000..d9dcd79 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/uri.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/non-validating/uri.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + inline uri_simpl:: + uri_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/xml-schema-simpl.hxx b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-simpl.hxx new file mode 100644 index 0000000..adda9fd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-simpl.hxx @@ -0,0 +1,82 @@ +// file : xsde/cxx/serializer/non-validating/xml-schema-simpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_XML_SCHEMA_SIMPL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_XML_SCHEMA_SIMPL_HXX + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +#include <xsde/cxx/serializer/non-validating/any-type.hxx> +#include <xsde/cxx/serializer/non-validating/boolean.hxx> +#include <xsde/cxx/serializer/non-validating/byte.hxx> +#include <xsde/cxx/serializer/non-validating/unsigned-byte.hxx> +#include <xsde/cxx/serializer/non-validating/byte.hxx> +#include <xsde/cxx/serializer/non-validating/unsigned-byte.hxx> +#include <xsde/cxx/serializer/non-validating/short.hxx> +#include <xsde/cxx/serializer/non-validating/unsigned-short.hxx> +#include <xsde/cxx/serializer/non-validating/int.hxx> +#include <xsde/cxx/serializer/non-validating/unsigned-int.hxx> + +#ifdef XSDE_LONGLONG +# include <xsde/cxx/serializer/non-validating/long-long.hxx> +# include <xsde/cxx/serializer/non-validating/unsigned-long-long.hxx> +#else +# include <xsde/cxx/serializer/non-validating/long.hxx> +# include <xsde/cxx/serializer/non-validating/unsigned-long.hxx> +#endif + +#include <xsde/cxx/serializer/non-validating/integer.hxx> +#include <xsde/cxx/serializer/non-validating/negative-integer.hxx> +#include <xsde/cxx/serializer/non-validating/non-positive-integer.hxx> +#include <xsde/cxx/serializer/non-validating/positive-integer.hxx> +#include <xsde/cxx/serializer/non-validating/non-negative-integer.hxx> +#include <xsde/cxx/serializer/non-validating/float.hxx> +#include <xsde/cxx/serializer/non-validating/double.hxx> +#include <xsde/cxx/serializer/non-validating/decimal.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/serializer/non-validating/string-stl.hxx> +# include <xsde/cxx/serializer/non-validating/normalized-string-stl.hxx> +# include <xsde/cxx/serializer/non-validating/token-stl.hxx> +# include <xsde/cxx/serializer/non-validating/name-stl.hxx> +# include <xsde/cxx/serializer/non-validating/nmtoken-stl.hxx> +# include <xsde/cxx/serializer/non-validating/nmtokens-stl.hxx> +# include <xsde/cxx/serializer/non-validating/ncname-stl.hxx> +# include <xsde/cxx/serializer/non-validating/id-stl.hxx> +# include <xsde/cxx/serializer/non-validating/idref-stl.hxx> +# include <xsde/cxx/serializer/non-validating/idrefs-stl.hxx> +# include <xsde/cxx/serializer/non-validating/language-stl.hxx> +# include <xsde/cxx/serializer/non-validating/uri-stl.hxx> +# include <xsde/cxx/serializer/non-validating/qname-stl.hxx> +#else +# include <xsde/cxx/serializer/non-validating/string.hxx> +# include <xsde/cxx/serializer/non-validating/normalized-string.hxx> +# include <xsde/cxx/serializer/non-validating/token.hxx> +# include <xsde/cxx/serializer/non-validating/name.hxx> +# include <xsde/cxx/serializer/non-validating/nmtoken.hxx> +# include <xsde/cxx/serializer/non-validating/nmtokens.hxx> +# include <xsde/cxx/serializer/non-validating/ncname.hxx> +# include <xsde/cxx/serializer/non-validating/id.hxx> +# include <xsde/cxx/serializer/non-validating/idref.hxx> +# include <xsde/cxx/serializer/non-validating/idrefs.hxx> +# include <xsde/cxx/serializer/non-validating/language.hxx> +# include <xsde/cxx/serializer/non-validating/uri.hxx> +# include <xsde/cxx/serializer/non-validating/qname.hxx> +#endif + +#include <xsde/cxx/serializer/non-validating/base64-binary.hxx> +#include <xsde/cxx/serializer/non-validating/hex-binary.hxx> + +#include <xsde/cxx/serializer/non-validating/gday.hxx> +#include <xsde/cxx/serializer/non-validating/gmonth.hxx> +#include <xsde/cxx/serializer/non-validating/gyear.hxx> +#include <xsde/cxx/serializer/non-validating/gmonth-day.hxx> +#include <xsde/cxx/serializer/non-validating/gyear-month.hxx> +#include <xsde/cxx/serializer/non-validating/date.hxx> +#include <xsde/cxx/serializer/non-validating/time.hxx> +#include <xsde/cxx/serializer/non-validating/date-time.hxx> +#include <xsde/cxx/serializer/non-validating/duration.hxx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_XML_SCHEMA_SIMPL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.cxx b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.cxx new file mode 100644 index 0000000..f9bb0b1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.cxx @@ -0,0 +1,560 @@ +// file : xsde/cxx/serializer/non-validating/xml-schema-sskel.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // any_type_sskel + // + void any_type_sskel:: + pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_type_impl_) + any_type_impl_->pre (); +#endif + } + + // any_simple_type_sskel + // + void any_simple_type_sskel:: + pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_simple_type_impl_) + any_simple_type_impl_->pre (); +#endif + } + + // static/dynamic_type function implementations. + // +#ifdef XSDE_POLYMORPHIC + const char* any_type_sskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_simple_type_sskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_simple_type_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* boolean_sskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + const char* boolean_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* byte_sskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + const char* byte_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_byte_sskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_byte_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* short_sskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + const char* short_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_short_sskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_short_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* int_sskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + const char* int_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_int_sskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_int_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* long_sskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + const char* long_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_long_sskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_long_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* integer_sskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + const char* integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* negative_integer_sskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* negative_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_positive_integer_sskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_positive_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* positive_integer_sskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* positive_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_negative_integer_sskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_negative_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* float_sskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + const char* float_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* double_sskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + const char* double_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* decimal_sskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + const char* decimal_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* string_sskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + const char* string_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* normalized_string_sskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + const char* normalized_string_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* token_sskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + const char* token_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* name_sskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + const char* name_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtoken_sskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtoken_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtokens_sskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtokens_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* ncname_sskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + const char* ncname_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* id_sskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + const char* id_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idref_sskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + const char* idref_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idrefs_sskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + const char* idrefs_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* language_sskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + const char* language_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* uri_sskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + const char* uri_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* qname_sskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + const char* qname_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* base64_binary_sskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + const char* base64_binary_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* hex_binary_sskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + const char* hex_binary_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gday_sskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gday_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_sskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_sskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_day_sskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_day_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_month_sskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_month_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_sskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + const char* date_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* time_sskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + const char* time_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_time_sskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + const char* date_time_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* duration_sskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + const char* duration_sskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif // XSDE_POLYMORPHIC + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx new file mode 100644 index 0000000..9365f03 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx @@ -0,0 +1,1382 @@ +// file : xsde/cxx/serializer/non-validating/xml-schema-sskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_NON_VALIDATING_XML_SCHEMA_SSKEL_HXX +#define XSDE_CXX_SERIALIZER_NON_VALIDATING_XML_SCHEMA_SSKEL_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/serializer/xml-schema.hxx> + +#include <xsde/cxx/serializer/non-validating/serializer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // anyType and anySimpleType. + // + struct any_type_sskel: complex_content + { + virtual void + pre (); + + // Override the following two functions to implement + // your logic. + // + + // virtual void + // _serialize_attributes (); + + // virtual void + // _serialize_content (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_sskel (); + any_type_sskel (any_type_sskel* impl, void*); + + protected: + any_type_sskel* any_type_impl_; +#endif + }; + + struct any_simple_type_sskel: simple_content + { + virtual void + pre (); + + // Override the following function to implement your + // logic. + // + + // virtual void + // _serialize_content (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_simple_type_sskel (); + any_simple_type_sskel (any_simple_type_sskel* impl, void*); + + protected: + any_simple_type_sskel* any_simple_type_impl_; +#endif + }; + + // Boolean. + // + struct boolean_sskel: simple_content + { + virtual void + pre (bool) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + boolean_sskel (); + boolean_sskel (boolean_sskel* impl, void*); + + protected: + boolean_sskel* boolean_impl_; +#endif + }; + + // 8-bit + // + + struct byte_sskel: simple_content + { + virtual void + pre (signed char) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + byte_sskel (); + byte_sskel (byte_sskel* impl, void*); + + protected: + byte_sskel* byte_impl_; +#endif + }; + + struct unsigned_byte_sskel: simple_content + { + virtual void + pre (unsigned char) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_byte_sskel (); + unsigned_byte_sskel (unsigned_byte_sskel* impl, void*); + + protected: + unsigned_byte_sskel* unsigned_byte_impl_; +#endif + }; + + + // 16-bit + // + + struct short_sskel: simple_content + { + virtual void + pre (short) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + short_sskel (); + short_sskel (short_sskel* impl, void*); + + protected: + short_sskel* short_impl_; +#endif + }; + + struct unsigned_short_sskel: simple_content + { + virtual void + pre (unsigned short) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_short_sskel (); + unsigned_short_sskel (unsigned_short_sskel* impl, void*); + + protected: + unsigned_short_sskel* unsigned_short_impl_; +#endif + }; + + // 32-bit + // + + struct int_sskel: simple_content + { + virtual void + pre (int) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + int_sskel (); + int_sskel (int_sskel* impl, void*); + + protected: + int_sskel* int_impl_; +#endif + }; + + struct unsigned_int_sskel: simple_content + { + virtual void + pre (unsigned int) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_int_sskel (); + unsigned_int_sskel (unsigned_int_sskel* impl, void*); + + protected: + unsigned_int_sskel* unsigned_int_impl_; +#endif + }; + + // 64-bit + // + +#ifdef XSDE_LONGLONG + struct long_sskel: simple_content + { + virtual void + pre (long long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_sskel (); + long_sskel (long_sskel* impl, void*); + + protected: + long_sskel* long_impl_; +#endif + }; + + struct unsigned_long_sskel: simple_content + { + virtual void + pre (unsigned long long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_sskel (); + unsigned_long_sskel (unsigned_long_sskel* impl, void*); + + protected: + unsigned_long_sskel* unsigned_long_impl_; +#endif + }; +#else + struct long_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_sskel (); + long_sskel (long_sskel* impl, void*); + + protected: + long_sskel* long_impl_; +#endif + }; + + struct unsigned_long_sskel: simple_content + { + virtual void + pre (unsigned long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_sskel (); + unsigned_long_sskel (unsigned_long_sskel* impl, void*); + + protected: + unsigned_long_sskel* unsigned_long_impl_; +#endif + }; +#endif + + // Arbitrary-length integers. + // + + struct integer_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + integer_sskel (); + integer_sskel (integer_sskel* impl, void*); + + protected: + integer_sskel* integer_impl_; +#endif + }; + + struct negative_integer_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + negative_integer_sskel (); + negative_integer_sskel (negative_integer_sskel* impl, void*); + + protected: + negative_integer_sskel* negative_integer_impl_; +#endif + }; + + struct non_positive_integer_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_positive_integer_sskel (); + non_positive_integer_sskel (non_positive_integer_sskel* impl, void*); + + protected: + non_positive_integer_sskel* non_positive_integer_impl_; +#endif + }; + + struct positive_integer_sskel: simple_content + { + virtual void + pre (unsigned long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + positive_integer_sskel (); + positive_integer_sskel (positive_integer_sskel* impl, void*); + + protected: + positive_integer_sskel* positive_integer_impl_; +#endif + }; + + struct non_negative_integer_sskel: simple_content + { + virtual void + pre (unsigned long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_negative_integer_sskel (); + non_negative_integer_sskel (non_negative_integer_sskel* impl, void*); + + protected: + non_negative_integer_sskel* non_negative_integer_impl_; +#endif + }; + + // Floats. + // + + struct float_sskel: simple_content + { + virtual void + pre (float) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + float_sskel (); + float_sskel (float_sskel* impl, void*); + + protected: + float_sskel* float_impl_; +#endif + }; + + struct double_sskel: simple_content + { + virtual void + pre (double) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + double_sskel (); + double_sskel (double_sskel* impl, void*); + + protected: + double_sskel* double_impl_; +#endif + }; + + struct decimal_sskel: simple_content + { + virtual void + pre (double) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + decimal_sskel (); + decimal_sskel (decimal_sskel* impl, void*); + + protected: + decimal_sskel* decimal_impl_; +#endif + }; + + // String-based types. + // +#ifdef XSDE_STL + + struct string_sskel: simple_content + { + virtual void + pre (const std::string&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_sskel (); + string_sskel (string_sskel* impl, void*); + + protected: + string_sskel* string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_sskel: virtual string_sskel +#else + struct normalized_string_sskel: string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_sskel (); + normalized_string_sskel (normalized_string_sskel* impl, void*); + + protected: + normalized_string_sskel* normalized_string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_sskel: virtual normalized_string_sskel +#else + struct token_sskel: normalized_string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_sskel (); + token_sskel (token_sskel* impl, void*); + + protected: + token_sskel* token_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_sskel: virtual token_sskel +#else + struct name_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_sskel (); + name_sskel (name_sskel* impl, void*); + + protected: + name_sskel* name_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_sskel: virtual token_sskel +#else + struct nmtoken_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_sskel (); + nmtoken_sskel (nmtoken_sskel* impl, void*); + + protected: + nmtoken_sskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_sskel (); + nmtokens_sskel (nmtokens_sskel* impl, void*); + + protected: + nmtokens_sskel* nmtokens_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_sskel: virtual name_sskel +#else + struct ncname_sskel: name_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_sskel (); + ncname_sskel (ncname_sskel* impl, void*); + + protected: + ncname_sskel* ncname_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_sskel: virtual ncname_sskel +#else + struct id_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_sskel (); + id_sskel (id_sskel* impl, void*); + + protected: + id_sskel* id_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_sskel: virtual ncname_sskel +#else + struct idref_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_sskel (); + idref_sskel (idref_sskel* impl, void*); + + protected: + idref_sskel* idref_impl_; +#endif + }; + + struct idrefs_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_sskel (); + idrefs_sskel (idrefs_sskel* impl, void*); + + protected: + idrefs_sskel* idrefs_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_sskel: virtual token_sskel +#else + struct language_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_sskel (); + language_sskel (language_sskel* impl, void*); + + protected: + language_sskel* language_impl_; +#endif + }; + + struct uri_sskel: simple_content + { + virtual void + pre (const std::string&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_sskel (); + uri_sskel (uri_sskel* impl, void*); + + protected: + uri_sskel* uri_impl_; +#endif + }; + + struct qname_sskel: simple_content + { + virtual void + pre (const qname&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_sskel (); + qname_sskel (qname_sskel* impl, void*); + + protected: + qname_sskel* qname_impl_; +#endif + }; + +#else // XSDE_STL + + struct string_sskel: simple_content + { + virtual void + pre (const char*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_sskel (); + string_sskel (string_sskel* impl, void*); + + protected: + string_sskel* string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_sskel: virtual string_sskel +#else + struct normalized_string_sskel: string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_sskel (); + normalized_string_sskel (normalized_string_sskel* impl, void*); + + protected: + normalized_string_sskel* normalized_string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_sskel: virtual normalized_string_sskel +#else + struct token_sskel: normalized_string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_sskel (); + token_sskel (token_sskel* impl, void*); + + protected: + token_sskel* token_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_sskel: virtual token_sskel +#else + struct name_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_sskel (); + name_sskel (name_sskel* impl, void*); + + protected: + name_sskel* name_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_sskel: virtual token_sskel +#else + struct nmtoken_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_sskel (); + nmtoken_sskel (nmtoken_sskel* impl, void*); + + protected: + nmtoken_sskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_sskel (); + nmtokens_sskel (nmtokens_sskel* impl, void*); + + protected: + nmtokens_sskel* nmtokens_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_sskel: virtual name_sskel +#else + struct ncname_sskel: name_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_sskel (); + ncname_sskel (ncname_sskel* impl, void*); + + protected: + ncname_sskel* ncname_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_sskel: virtual ncname_sskel +#else + struct id_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_sskel (); + id_sskel (id_sskel* impl, void*); + + protected: + id_sskel* id_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_sskel: virtual ncname_sskel +#else + struct idref_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_sskel (); + idref_sskel (idref_sskel* impl, void*); + + protected: + idref_sskel* idref_impl_; +#endif + }; + + struct idrefs_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_sskel (); + idrefs_sskel (idrefs_sskel* impl, void*); + + protected: + idrefs_sskel* idrefs_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_sskel: virtual token_sskel +#else + struct language_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_sskel (); + language_sskel (language_sskel* impl, void*); + + protected: + language_sskel* language_impl_; +#endif + }; + + struct uri_sskel: simple_content + { + virtual void + pre (const char*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_sskel (); + uri_sskel (uri_sskel* impl, void*); + + protected: + uri_sskel* uri_impl_; +#endif + }; + + struct qname_sskel: simple_content + { + virtual void + pre (const qname*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_sskel (); + qname_sskel (qname_sskel* impl, void*); + + protected: + qname_sskel* qname_impl_; +#endif + }; + +#endif // XSDE_STL + + + // base64Binary + // + struct base64_binary_sskel: simple_content + { + virtual void + pre (const buffer*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + base64_binary_sskel (); + base64_binary_sskel (base64_binary_sskel* impl, void*); + + protected: + base64_binary_sskel* base64_binary_impl_; +#endif + }; + + // hexBinary + // + struct hex_binary_sskel: simple_content + { + virtual void + pre (const buffer*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + hex_binary_sskel (); + hex_binary_sskel (hex_binary_sskel* impl, void*); + + protected: + hex_binary_sskel* hex_binary_impl_; +#endif + }; + + // Time and date types. + // + struct gday_sskel: simple_content + { + virtual void + pre (const gday&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gday_sskel (); + gday_sskel (gday_sskel* impl, void*); + + protected: + gday_sskel* gday_impl_; +#endif + }; + + struct gmonth_sskel: simple_content + { + virtual void + pre (const gmonth&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_sskel (); + gmonth_sskel (gmonth_sskel* impl, void*); + + protected: + gmonth_sskel* gmonth_impl_; +#endif + }; + + struct gyear_sskel: simple_content + { + virtual void + pre (const gyear&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_sskel (); + gyear_sskel (gyear_sskel* impl, void*); + + protected: + gyear_sskel* gyear_impl_; +#endif + }; + + struct gmonth_day_sskel: simple_content + { + virtual void + pre (const gmonth_day&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_day_sskel (); + gmonth_day_sskel (gmonth_day_sskel* impl, void*); + + protected: + gmonth_day_sskel* gmonth_day_impl_; +#endif + }; + + struct gyear_month_sskel: simple_content + { + virtual void + pre (const gyear_month&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_month_sskel (); + gyear_month_sskel (gyear_month_sskel* impl, void*); + + protected: + gyear_month_sskel* gyear_month_impl_; +#endif + }; + + struct date_sskel: simple_content + { + virtual void + pre (const date&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_sskel (); + date_sskel (date_sskel* impl, void*); + + protected: + date_sskel* date_impl_; +#endif + }; + + struct time_sskel: simple_content + { + virtual void + pre (const time&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + time_sskel (); + time_sskel (time_sskel* impl, void*); + + protected: + time_sskel* time_impl_; +#endif + }; + + struct date_time_sskel: simple_content + { + virtual void + pre (const date_time&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_time_sskel (); + date_time_sskel (date_time_sskel* impl, void*); + + protected: + date_time_sskel* date_time_impl_; +#endif + }; + + struct duration_sskel: simple_content + { + virtual void + pre (const duration&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + duration_sskel (); + duration_sskel (duration_sskel* impl, void*); + + protected: + duration_sskel* duration_impl_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/serializer/non-validating/xml-schema-sskel.ixx> + +#endif // XSDE_CXX_SERIALIZER_NON_VALIDATING_XML_SCHEMA_SSKEL_HXX diff --git a/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.ixx b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.ixx new file mode 100644 index 0000000..de78f5d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/non-validating/xml-schema-sskel.ixx @@ -0,0 +1,704 @@ +// file : xsde/cxx/serializer/non-validating/xml-schema-sskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace non_validating + { + // any_type_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_sskel:: + any_type_sskel () + : any_type_impl_ (0) + { + } + + inline any_type_sskel:: + any_type_sskel (any_type_sskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + + // any_simple_type_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_simple_type_sskel:: + any_simple_type_sskel () + : any_simple_type_impl_ (0) + { + } + + inline any_simple_type_sskel:: + any_simple_type_sskel (any_simple_type_sskel* impl, void*) + : simple_content (impl, 0), any_simple_type_impl_ (impl) + { + } +#endif + + // boolean_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline boolean_sskel:: + boolean_sskel () + : boolean_impl_ (0) + { + } + + inline boolean_sskel:: + boolean_sskel (boolean_sskel* impl, void*) + : simple_content (impl, 0), boolean_impl_ (impl) + { + } +#endif + + // byte_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline byte_sskel:: + byte_sskel () + : byte_impl_ (0) + { + } + + inline byte_sskel:: + byte_sskel (byte_sskel* impl, void*) + : simple_content (impl, 0), byte_impl_ (impl) + { + } +#endif + + // unsigned_byte_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_byte_sskel:: + unsigned_byte_sskel () + : unsigned_byte_impl_ (0) + { + } + + inline unsigned_byte_sskel:: + unsigned_byte_sskel (unsigned_byte_sskel* impl, void*) + : simple_content (impl, 0), unsigned_byte_impl_ (impl) + { + } +#endif + + // short_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline short_sskel:: + short_sskel () + : short_impl_ (0) + { + } + + inline short_sskel:: + short_sskel (short_sskel* impl, void*) + : simple_content (impl, 0), short_impl_ (impl) + { + } +#endif + + // unsigned_short_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_short_sskel:: + unsigned_short_sskel () + : unsigned_short_impl_ (0) + { + } + + inline unsigned_short_sskel:: + unsigned_short_sskel (unsigned_short_sskel* impl, void*) + : simple_content (impl, 0), unsigned_short_impl_ (impl) + { + } +#endif + + // int_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline int_sskel:: + int_sskel () + : int_impl_ (0) + { + } + + inline int_sskel:: + int_sskel (int_sskel* impl, void*) + : simple_content (impl, 0), int_impl_ (impl) + { + } +#endif + + // unsigned_int_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_int_sskel:: + unsigned_int_sskel () + : unsigned_int_impl_ (0) + { + } + + inline unsigned_int_sskel:: + unsigned_int_sskel (unsigned_int_sskel* impl, void*) + : simple_content (impl, 0), unsigned_int_impl_ (impl) + { + } +#endif + + // long_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline long_sskel:: + long_sskel () + : long_impl_ (0) + { + } + + inline long_sskel:: + long_sskel (long_sskel* impl, void*) + : simple_content (impl, 0), long_impl_ (impl) + { + } +#endif + + // unsigned_long_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_long_sskel:: + unsigned_long_sskel () + : unsigned_long_impl_ (0) + { + } + + inline unsigned_long_sskel:: + unsigned_long_sskel (unsigned_long_sskel* impl, void*) + : simple_content (impl, 0), unsigned_long_impl_ (impl) + { + } +#endif + + // integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline integer_sskel:: + integer_sskel () + : integer_impl_ (0) + { + } + + inline integer_sskel:: + integer_sskel (integer_sskel* impl, void*) + : simple_content (impl, 0), integer_impl_ (impl) + { + } +#endif + + // negative_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline negative_integer_sskel:: + negative_integer_sskel () + : negative_integer_impl_ (0) + { + } + + inline negative_integer_sskel:: + negative_integer_sskel (negative_integer_sskel* impl, void*) + : simple_content (impl, 0), negative_integer_impl_ (impl) + { + } +#endif + + // non_positive_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_positive_integer_sskel:: + non_positive_integer_sskel () + : non_positive_integer_impl_ (0) + { + } + + inline non_positive_integer_sskel:: + non_positive_integer_sskel (non_positive_integer_sskel* impl, void*) + : simple_content (impl, 0), non_positive_integer_impl_ (impl) + { + } +#endif + + // positive_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline positive_integer_sskel:: + positive_integer_sskel () + : positive_integer_impl_ (0) + { + } + + inline positive_integer_sskel:: + positive_integer_sskel (positive_integer_sskel* impl, void*) + : simple_content (impl, 0), positive_integer_impl_ (impl) + { + } +#endif + + // non_negative_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_negative_integer_sskel:: + non_negative_integer_sskel () + : non_negative_integer_impl_ (0) + { + } + + inline non_negative_integer_sskel:: + non_negative_integer_sskel (non_negative_integer_sskel* impl, void*) + : simple_content (impl, 0), non_negative_integer_impl_ (impl) + { + } +#endif + + // float_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline float_sskel:: + float_sskel () + : float_impl_ (0) + { + } + + inline float_sskel:: + float_sskel (float_sskel* impl, void*) + : simple_content (impl, 0), float_impl_ (impl) + { + } +#endif + + // double_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline double_sskel:: + double_sskel () + : double_impl_ (0) + { + } + + inline double_sskel:: + double_sskel (double_sskel* impl, void*) + : simple_content (impl, 0), double_impl_ (impl) + { + } +#endif + + // decimal_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline decimal_sskel:: + decimal_sskel () + : decimal_impl_ (0) + { + } + + inline decimal_sskel:: + decimal_sskel (decimal_sskel* impl, void*) + : simple_content (impl, 0), decimal_impl_ (impl) + { + } +#endif + + // string_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline string_sskel:: + string_sskel () + : string_impl_ (0) + { + } + + inline string_sskel:: + string_sskel (string_sskel* impl, void*) + : simple_content (impl, 0), string_impl_ (impl) + { + } +#endif + + // normalized_string_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline normalized_string_sskel:: + normalized_string_sskel () + : normalized_string_impl_ (0) + { + } + + inline normalized_string_sskel:: + normalized_string_sskel (normalized_string_sskel* impl, void*) + : string_sskel (impl, 0), normalized_string_impl_ (impl) + { + } +#endif + + // token_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline token_sskel:: + token_sskel () + : token_impl_ (0) + { + } + + inline token_sskel:: + token_sskel (token_sskel* impl, void*) + : normalized_string_sskel (impl, 0), token_impl_ (impl) + { + } +#endif + + // name_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline name_sskel:: + name_sskel () + : name_impl_ (0) + { + } + + inline name_sskel:: + name_sskel (name_sskel* impl, void*) + : token_sskel (impl, 0), name_impl_ (impl) + { + } +#endif + + // nmtoken_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtoken_sskel:: + nmtoken_sskel () + : nmtoken_impl_ (0) + { + } + + inline nmtoken_sskel:: + nmtoken_sskel (nmtoken_sskel* impl, void*) + : token_sskel (impl, 0), nmtoken_impl_ (impl) + { + } +#endif + + // nmtokens_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtokens_sskel:: + nmtokens_sskel () + : nmtokens_impl_ (0) + { + } + + inline nmtokens_sskel:: + nmtokens_sskel (nmtokens_sskel* impl, void*) + : simple_content (impl, 0), nmtokens_impl_ (impl) + { + } +#endif + + // ncname_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline ncname_sskel:: + ncname_sskel () + : ncname_impl_ (0) + { + } + + inline ncname_sskel:: + ncname_sskel (ncname_sskel* impl, void*) + : name_sskel (impl, 0), ncname_impl_ (impl) + { + } +#endif + + // id_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline id_sskel:: + id_sskel () + : id_impl_ (0) + { + } + + inline id_sskel:: + id_sskel (id_sskel* impl, void*) + : ncname_sskel (impl, 0), id_impl_ (impl) + { + } +#endif + + // idref_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idref_sskel:: + idref_sskel () + : idref_impl_ (0) + { + } + + inline idref_sskel:: + idref_sskel (idref_sskel* impl, void*) + : ncname_sskel (impl, 0), idref_impl_ (impl) + { + } +#endif + + // idrefs_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idrefs_sskel:: + idrefs_sskel () + : idrefs_impl_ (0) + { + } + + inline idrefs_sskel:: + idrefs_sskel (idrefs_sskel* impl, void*) + : simple_content (impl, 0), idrefs_impl_ (impl) + { + } +#endif + + // language_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline language_sskel:: + language_sskel () + : language_impl_ (0) + { + } + + inline language_sskel:: + language_sskel (language_sskel* impl, void*) + : token_sskel (impl, 0), language_impl_ (impl) + { + } +#endif + + // uri_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline uri_sskel:: + uri_sskel () + : uri_impl_ (0) + { + } + + inline uri_sskel:: + uri_sskel (uri_sskel* impl, void*) + : simple_content (impl, 0), uri_impl_ (impl) + { + } +#endif + + // qname_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline qname_sskel:: + qname_sskel () + : qname_impl_ (0) + { + } + + inline qname_sskel:: + qname_sskel (qname_sskel* impl, void*) + : simple_content (impl, 0), qname_impl_ (impl) + { + } +#endif + + // base64_binary_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline base64_binary_sskel:: + base64_binary_sskel () + : base64_binary_impl_ (0) + { + } + + inline base64_binary_sskel:: + base64_binary_sskel (base64_binary_sskel* impl, void*) + : simple_content (impl, 0), base64_binary_impl_ (impl) + { + } +#endif + + // hex_binary_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline hex_binary_sskel:: + hex_binary_sskel () + : hex_binary_impl_ (0) + { + } + + inline hex_binary_sskel:: + hex_binary_sskel (hex_binary_sskel* impl, void*) + : simple_content (impl, 0), hex_binary_impl_ (impl) + { + } +#endif + + // gday_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gday_sskel:: + gday_sskel () + : gday_impl_ (0) + { + } + + inline gday_sskel:: + gday_sskel (gday_sskel* impl, void*) + : simple_content (impl, 0), gday_impl_ (impl) + { + } +#endif + + // gmonth_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_sskel:: + gmonth_sskel () + : gmonth_impl_ (0) + { + } + + inline gmonth_sskel:: + gmonth_sskel (gmonth_sskel* impl, void*) + : simple_content (impl, 0), gmonth_impl_ (impl) + { + } +#endif + + // gyear_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_sskel:: + gyear_sskel () + : gyear_impl_ (0) + { + } + + inline gyear_sskel:: + gyear_sskel (gyear_sskel* impl, void*) + : simple_content (impl, 0), gyear_impl_ (impl) + { + } +#endif + + // gmonth_day_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_day_sskel:: + gmonth_day_sskel () + : gmonth_day_impl_ (0) + { + } + + inline gmonth_day_sskel:: + gmonth_day_sskel (gmonth_day_sskel* impl, void*) + : simple_content (impl, 0), gmonth_day_impl_ (impl) + { + } +#endif + + // gyear_month_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_month_sskel:: + gyear_month_sskel () + : gyear_month_impl_ (0) + { + } + + inline gyear_month_sskel:: + gyear_month_sskel (gyear_month_sskel* impl, void*) + : simple_content (impl, 0), gyear_month_impl_ (impl) + { + } +#endif + + // date_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_sskel:: + date_sskel () + : date_impl_ (0) + { + } + + inline date_sskel:: + date_sskel (date_sskel* impl, void*) + : simple_content (impl, 0), date_impl_ (impl) + { + } +#endif + + // time_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline time_sskel:: + time_sskel () + : time_impl_ (0) + { + } + + inline time_sskel:: + time_sskel (time_sskel* impl, void*) + : simple_content (impl, 0), time_impl_ (impl) + { + } +#endif + + // date_time_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_time_sskel:: + date_time_sskel () + : date_time_impl_ (0) + { + } + + inline date_time_sskel:: + date_time_sskel (date_time_sskel* impl, void*) + : simple_content (impl, 0), date_time_impl_ (impl) + { + } +#endif + + // duration_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline duration_sskel:: + duration_sskel () + : duration_impl_ (0) + { + } + + inline duration_sskel:: + duration_sskel (duration_sskel* impl, void*) + : simple_content (impl, 0), duration_impl_ (impl) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/substitution-map-load.hxx b/libxsde/xsde/cxx/serializer/substitution-map-load.hxx new file mode 100644 index 0000000..95083e2 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/substitution-map-load.hxx @@ -0,0 +1,40 @@ +// file : xsde/cxx/serializer/substitution-map-load.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_SUBSTITUTION_MAP_LOAD_HXX +#define XSDE_CXX_SERIALIZER_SUBSTITUTION_MAP_LOAD_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + size_t + serializer_smap_elements (); + + inline size_t + serializer_smap_buckets () + { + return XSDE_SERIALIZER_SMAP_BUCKETS; + } + + size_t + serializer_smap_bucket_elements (); + + inline size_t + serializer_smap_bucket_buckets () + { + return XSDE_SERIALIZER_SMAP_BUCKET_BUCKETS; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_SUBSTITUTION_MAP_LOAD_HXX diff --git a/libxsde/xsde/cxx/serializer/substitution-map.cxx b/libxsde/xsde/cxx/serializer/substitution-map.cxx new file mode 100644 index 0000000..e155882 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/substitution-map.cxx @@ -0,0 +1,248 @@ +// file : xsde/cxx/serializer/substitution-map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strlen, strcmp, strncmp + +#ifndef XSDE_EXCEPTIONS +# include <assert.h> // assert +# include <stdlib.h> // exit +#endif + +#include <xsde/cxx/serializer/substitution-map.hxx> +#include <xsde/cxx/serializer/substitution-map-load.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + substitution_map* substitution_map_init::map = 0; + size_t substitution_map_init::count = 0; + + substitution_map:: + ~substitution_map () + { + for (const_iterator i (begin ()), e (end ()); i != e; ++i) + { + delete *static_cast<hashmap**> (const_cast<void*> (*i)); + } + } + + void substitution_map:: + insert (const char* root, + const char* member_ns, + const char* member_name, + const char* member_type) + { + hashmap* m; + + if (const void* p = find (root)) + m = *static_cast<hashmap**> (const_cast<void*> (p)); + else + { + m = new hashmap (XSDE_SERIALIZER_SMAP_BUCKET_BUCKETS, + sizeof (value)); + +#ifndef XSDE_EXCEPTIONS + if (m == 0 || m->_error () != hashmap::error_none) + { + error_ = error_no_memory; + return; + } +#endif + hashmap::insert (root, &m); + +#ifndef XSDE_EXCEPTIONS + if (_error () != error_none) + return; +#endif + } + + value v; + v.ns_ = member_ns; + v.name_ = member_name; + m->insert (member_type, &v); + +#ifndef XSDE_EXCEPTIONS + if (m->_error () != hashmap::error_none) + error_ = error_no_memory; +#endif + } + + bool substitution_map:: + check_ (const char*& ns, + const char*& name, + const char* type) const + { + size_t h = hash (name); + + if (ns) + { + h = hash (h, " ", 1); + h = hash (h, ns); + } + + const bucket* p = find (h); + + if (p == 0) + return false; + + // Search for the entry in the bucket. + // + const size_t el_size = sizeof (element) + sizeof (hashmap*); + const char* b = reinterpret_cast<const char*> (p) + sizeof (bucket); + const char* e = b + p->size_ * el_size; + + size_t nl = ns ? strlen (name) : 0; + + for (; b < e; b += el_size) + { + const element* e = reinterpret_cast<const element*> (b); + + if (e->hash_ == h) + { + if (ns == 0) + { + if (strcmp (e->key_, name) == 0) + break; + } + else + { + if (strncmp (e->key_, name, nl) == 0 && + e->key_[nl] == ' ' && + strcmp (e->key_ + nl + 1, ns) == 0) + break; + } + } + } + + if (b == e) + return false; + + const hashmap* map = *reinterpret_cast<const hashmap* const*> ( + b + sizeof (element)); + + // See if we have a direct substitution. + // + if (const value* v = static_cast<const value*> (map->find (type))) + { + ns = v->ns_; + name = v->name_; + return true; + } + + // Otherwise we have to iterate over possible substitutions and + // see if any of them can in turn be substituted with something + // that we can use. + // + for (const_iterator i (map->begin ()), end (map->end ()); + i != end; ++i) + { + const value* v = static_cast<const value*> (*i); + + const char* tns = v->ns_; + const char* tn = v->name_; + + if (check_ (tns, tn, type)) + { + ns = tns; + name = tn; + return true; + } + } + + return false; + } + + // substitution_map_init + // + substitution_map_init:: + substitution_map_init () + { + if (count == 0) + { + map = new substitution_map (XSDE_SERIALIZER_SMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != substitution_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + substitution_map_init:: + ~substitution_map_init () + { + if (--count == 0) + delete map; + } + + // substitution_map_entry + // + substitution_map_entry:: + substitution_map_entry (const char* root, + const char* member_ns, + const char* member_name, + const char* member_type) + { + substitution_map& m = substitution_map_instance (); + m.insert (root, member_ns, member_name, member_type); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != substitution_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + serializer_smap_elements () + { + return substitution_map_instance ().size (); + } + + size_t + serializer_smap_bucket_elements () + { + size_t r = 0; + + substitution_map& m = substitution_map_instance (); + + for (substitution_map::const_iterator i (m.begin ()), e (m.end ()); + i != e; ++i) + { + const hashmap* h = *static_cast<const hashmap* const*> (*i); + + if (h->size () > r) + r = h->size (); + } + + return r; + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/substitution-map.hxx b/libxsde/xsde/cxx/serializer/substitution-map.hxx new file mode 100644 index 0000000..601f255 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/substitution-map.hxx @@ -0,0 +1,88 @@ +// file : xsde/cxx/serializer/substitution-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_SUBSTITUTION_MAP_HXX +#define XSDE_CXX_SERIALIZER_SUBSTITUTION_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + struct substitution_map: hashmap + { + ~substitution_map (); + + substitution_map (size_t buckets); + + void + insert (const char* root, + const char* member_ns, + const char* member_name, + const char* member_type); + + // Check whether there is a substitution available for this + // root element with the specified type. If so, return true + // and override namespace and name (ns is 0 if there is no + // namespace). + // + bool + check (const char*& ns, + const char*& name, + const char* type) const; + + private: + bool + check_ (const char*& ns, + const char*& name, + const char* type) const; + + private: + struct value + { + const char* ns_; + const char* name_; + }; + }; + + + // Translation unit initializer. + // + struct substitution_map_init + { + static substitution_map* map; + static size_t count; + + substitution_map_init (); + ~substitution_map_init (); + }; + + substitution_map& + substitution_map_instance (); + + // Map entry initializer. + // + struct substitution_map_entry + { + substitution_map_entry (const char* root, + const char* member_ns, + const char* member_name, + const char* member_type); + }; + } + } +} + +#include <xsde/cxx/serializer/substitution-map.ixx> + +#endif // XSDE_CXX_SERIALIZER_SUBSTITUTION_MAP_HXX + diff --git a/libxsde/xsde/cxx/serializer/substitution-map.ixx b/libxsde/xsde/cxx/serializer/substitution-map.ixx new file mode 100644 index 0000000..63a848a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/substitution-map.ixx @@ -0,0 +1,33 @@ +// file : xsde/cxx/serializer/substitution-map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + inline substitution_map:: + substitution_map (size_t buckets) + : hashmap (buckets, sizeof (hashmap*)) + { + } + + inline bool substitution_map:: + check (const char*& ns, + const char*& name, + const char* type) const + { + return empty () ? false : check_ (ns, name, type); + } + + inline substitution_map& + substitution_map_instance () + { + return *substitution_map_init::map; + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/any-type.hxx b/libxsde/xsde/cxx/serializer/validating/any-type.hxx new file mode 100644 index 0000000..ca80572 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/any-type.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/any-type.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_ANY_TYPE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_ANY_TYPE_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // any_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_type_simpl: virtual any_type_sskel +#else + struct any_type_simpl: any_type_sskel +#endif + { + }; + + // any_simple_type + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct any_simple_type_simpl: virtual any_simple_type_sskel +#else + struct any_simple_type_simpl: any_simple_type_sskel +#endif + { + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_ANY_TYPE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/base64-binary.cxx b/libxsde/xsde/cxx/serializer/validating/base64-binary.cxx new file mode 100644 index 0000000..a649433 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/base64-binary.cxx @@ -0,0 +1,166 @@ +// file : xsde/cxx/serializer/validating/base64-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/base64-binary.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + base64_binary_simpl:: + ~base64_binary_simpl () + { + if (free_) + delete const_cast<buffer*> (value_); + } + + void base64_binary_simpl:: + pre (const buffer* value) + { + value_ = value; + } + + static const char base64_tab[] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', + 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '+', '/', '\0' + }; + + inline void + split_1 (char b, unsigned char& b1, unsigned char& b2) + { + unsigned char ub = static_cast<unsigned char> (b); + b1 = ub >> 2; + b2 = (ub & 0x3) << 4; + } + + inline void + split_2 (char b, unsigned char& b2, unsigned char& b3) + { + unsigned char ub = static_cast<unsigned char> (b); + b2 |= ub >> 4; + b3 = (ub & 0x0F) << 2; + } + + inline void + split_3 (char b, unsigned char& b3, unsigned char& b4) + { + unsigned char ub = static_cast<unsigned char> (b); + b3 |= ub >> 6; + b4 = ( ub & 0x3F ); + } + + void base64_binary_simpl:: + _serialize_content () + { + // Maximum 76 characters per line, 76/4 = 19 + // + const size_t quads_per_line = 19; + char buf[quads_per_line * 4 + 1]; + + if (size_t size = value_->size ()) + { + const char* data = value_->data (); + size_t quads = (size + 2) / 3; + + // Process all quadruplets except the last, one line at a time. + // + size_t i = 0; + size_t j = 0; + unsigned char b1, b2, b3, b4; + + for (; j < (quads - 1);) + { + for (; i < quads_per_line && j < (quads - 1); ++i, ++j) + { + split_1 (*data++, b1, b2); + split_2 (*data++, b2, b3); + split_3 (*data++, b3, b4); + + buf[i * 4] = base64_tab[b1]; + buf[i * 4 + 1] = base64_tab[b2]; + buf[i * 4 + 2] = base64_tab[b3]; + buf[i * 4 + 3] = base64_tab[b4]; + } + + if (i == quads_per_line) + { + buf[i * 4] = '\n'; + +#ifdef XSDE_EXCEPTIONS + _characters (buf, i * 4 + 1); +#else + if (!_characters (buf, i * 4 + 1)) + break; +#endif + i = 0; + } + } + +#ifndef XSDE_EXCEPTIONS + if (j == (quads - 1)) + { +#endif + // Process last quadruplet. The first byte is always present. + // + split_1 (*data++, b1, b2); + buf[i * 4] = base64_tab[b1]; + + if (data != value_->end ()) + { + // Second byte is present. + // + split_2 (*data++, b2, b3); + buf[i * 4 + 1] = base64_tab[b2]; + + if(data != value_->end ()) + { + // Third byte is present. + // + split_3 (*data++, b3, b4); + buf[i * 4 + 2] = base64_tab[b3]; + buf[i * 4 + 3] = base64_tab[b4]; + } + else + { + buf[i * 4 + 2] = base64_tab[b3]; + buf[i * 4 + 3] = '='; + } + } + else + { + buf[i * 4 + 1] = base64_tab[b2]; + buf[i * 4 + 2] = '='; + buf[i * 4 + 3] = '='; + } + + i++; + + buf[i * 4] = '\n'; + _characters (buf, i * 4 + 1); + +#ifndef XSDE_EXCEPTIONS + } +#endif + } + + if (free_) + { + delete const_cast<buffer*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/base64-binary.hxx b/libxsde/xsde/cxx/serializer/validating/base64-binary.hxx new file mode 100644 index 0000000..9b8b050 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/base64-binary.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/base64-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_BASE64_BINARY_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_BASE64_BINARY_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct base64_binary_simpl: virtual base64_binary_sskel +#else + struct base64_binary_simpl: base64_binary_sskel +#endif + { + virtual + ~base64_binary_simpl (); + + base64_binary_simpl (bool free = false); + + virtual void + pre (const buffer*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const buffer* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/base64-binary.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_BASE64_BINARY_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/base64-binary.ixx b/libxsde/xsde/cxx/serializer/validating/base64-binary.ixx new file mode 100644 index 0000000..5da3828 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/base64-binary.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/base64-binary.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline base64_binary_simpl:: + base64_binary_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/boolean.cxx b/libxsde/xsde/cxx/serializer/validating/boolean.cxx new file mode 100644 index 0000000..82e8ed5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/boolean.cxx @@ -0,0 +1,30 @@ +// file : xsde/cxx/serializer/validating/boolean.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/boolean.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void boolean_simpl:: + pre (bool value) + { + value_ = value; + } + + void boolean_simpl:: + _serialize_content () + { + _characters ((value_ ? "true" : "false"), (value_ ? 4 : 5)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/boolean.hxx b/libxsde/xsde/cxx/serializer/validating/boolean.hxx new file mode 100644 index 0000000..d6b698a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/boolean.hxx @@ -0,0 +1,39 @@ +// file : xsde/cxx/serializer/validating/boolean.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_BOOLEAN_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_BOOLEAN_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct boolean_simpl: virtual boolean_sskel +#else + struct boolean_simpl: boolean_sskel +#endif + { + virtual void + pre (bool); + + virtual void + _serialize_content (); + + protected: + bool value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_BOOLEAN_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/byte.cxx b/libxsde/xsde/cxx/serializer/validating/byte.cxx new file mode 100644 index 0000000..c5e5726 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/byte.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void byte_simpl:: + pre (signed char value) + { + value_ = value; + } + + void byte_simpl:: + _serialize_content () + { + // We only need strlen("-128") + 1 characters to hold all + // representations of signed byte. + // + char str[5]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 5, "%d", value_); +#else + int n = sprintf (str, "%d", value_); +#endif + if (n > 0 && n < 5) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_byte_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/byte.hxx b/libxsde/xsde/cxx/serializer/validating/byte.hxx new file mode 100644 index 0000000..be7e683 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/byte.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_BYTE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_BYTE_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 8-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct byte_simpl: virtual byte_sskel +#else + struct byte_simpl: byte_sskel +#endif + { + virtual void + pre (signed char); + + virtual void + _serialize_content (); + + protected: + signed char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_BYTE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/date-time.cxx b/libxsde/xsde/cxx/serializer/validating/date-time.cxx new file mode 100644 index 0000000..cacc6ea --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/date-time.cxx @@ -0,0 +1,87 @@ +// file : xsde/cxx/serializer/validating/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/date-time.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void date_time_simpl:: + pre (const date_time& value) + { + value_ = value; + } + + void date_time_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649-MM-DDThh:mm:ss.ssssss-hh:mm") + // + 1 characters to hold all representations of date_time. We + // know that the seconds part (represented as double) has + // default precision of 6. + // + char str[40]; + + int y = value_.year (); + unsigned short m = value_.month (); + unsigned short d = value_.day (); + + unsigned short h = value_.hours (); + unsigned short tm = value_.minutes (); + double s = value_.seconds (); + + if (y != 0 && m > 0 && m < 13 && d > 0 && d < 32 && + ((h < 24 && tm < 60 && s >= 0.0 && s < 60.0) || + (h == 24 && tm == 0 && s == 0.0)) && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 34, "%.4d-%.2u-%.2uT%.2u:%.2u:%09f", + y, m, d, h, tm, s); +#else + int n = sprintf (str, "%.4d-%.2u-%.2uT%.2u:%.2u:%09f", + y, m, d, h, tm, s); +#endif + if (n > 0 && n < 34) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_date_time_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_date_time_value); + } + else + _schema_error (schema_error::invalid_date_time_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/date-time.hxx b/libxsde/xsde/cxx/serializer/validating/date-time.hxx new file mode 100644 index 0000000..0cfcab1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/date-time.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/date-time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_DATE_TIME_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_DATE_TIME_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_time_simpl: virtual date_time_sskel +#else + struct date_time_simpl: date_time_sskel +#endif + { + date_time_simpl (); + + virtual void + pre (const date_time&); + + virtual void + _serialize_content (); + + protected: + date_time value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/date-time.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_DATE_TIME_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/date-time.ixx b/libxsde/xsde/cxx/serializer/validating/date-time.ixx new file mode 100644 index 0000000..e5e5813 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/date-time.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/date-time.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline date_time_simpl:: + date_time_simpl () + : value_ (1, 0, 0, 0, 0, 0.0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/date.cxx b/libxsde/xsde/cxx/serializer/validating/date.cxx new file mode 100644 index 0000000..b374c1c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/date.cxx @@ -0,0 +1,71 @@ +// file : xsde/cxx/serializer/validating/date.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/date.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void date_simpl:: + pre (const date& value) + { + value_ = value; + } + + void date_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649-MM-DD+hh:mm") + 1 characters to + // hold all representations of date. + // + char str[24]; + + int y = value_.year (); + unsigned short m = value_.month (); + unsigned short d = value_.day (); + + if (y != 0 && m > 0 && m < 13 && d > 0 && d < 32 && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 18, "%.4d-%.2u-%.2u", + value_.year (), value_.month (), value_.day ()); +#else + int n = sprintf (str, "%.4d-%.2u-%.2u", + value_.year (), value_.month (), value_.day ()); +#endif + if (n > 0 && n < 18) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_date_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_date_value); + } + else + _schema_error (schema_error::invalid_date_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/date.hxx b/libxsde/xsde/cxx/serializer/validating/date.hxx new file mode 100644 index 0000000..caaf4a5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/date.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/date.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_DATE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_DATE_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct date_simpl: virtual date_sskel +#else + struct date_simpl: date_sskel +#endif + { + date_simpl (); + + virtual void + pre (const date&); + + virtual void + _serialize_content (); + + protected: + date value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/date.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_DATE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/date.ixx b/libxsde/xsde/cxx/serializer/validating/date.ixx new file mode 100644 index 0000000..f5c3706 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/date.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/date.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline date_simpl:: + date_simpl () + : value_ (1, 1, 1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/decimal.cxx b/libxsde/xsde/cxx/serializer/validating/decimal.cxx new file mode 100644 index 0000000..7383025 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/decimal.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/serializer/validating/decimal.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/decimal.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void decimal_simpl:: + pre (double value) + { + value_ = value; + } + + void decimal_simpl:: + _serialize_content () + { + // Assume double values cannot be longer than 127 characters. + // + char str[128]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 128, "%.*f", + static_cast<int> (precision_), value_); +#else + int n = sprintf (str, "%.*f", + static_cast<int> (precision_), value_); +#endif + if (n > 0 && n < 128) + { + // For decimal, NaN and INF are not allowed. + // + int i = (str[0] == '-' ? 1 : 0); + if ((str[i] == 'i' && str[i + 1] == 'n' && str[i + 2] == 'f') || + (str[i] == 'n' && str[i + 1] == 'a' && str[i + 2] == 'n')) + { + _schema_error (schema_error::invalid_decimal_value); + return; + } + + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_decimal_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/decimal.hxx b/libxsde/xsde/cxx/serializer/validating/decimal.hxx new file mode 100644 index 0000000..af2c0f1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/decimal.hxx @@ -0,0 +1,50 @@ +// file : xsde/cxx/serializer/validating/decimal.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_DECIMAL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_DECIMAL_HXX + +#include <float.h> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct decimal_simpl: virtual decimal_sskel +#else + struct decimal_simpl: decimal_sskel +#endif + { +#ifdef DBL_DIG + decimal_simpl (unsigned int precision = DBL_DIG); +#else + decimal_simpl (unsigned int precision = 15) +#endif + + virtual void + pre (double); + + virtual void + _serialize_content (); + + protected: + unsigned int precision_; + double value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/decimal.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_DECIMAL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/decimal.ixx b/libxsde/xsde/cxx/serializer/validating/decimal.ixx new file mode 100644 index 0000000..803253d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/decimal.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/decimal.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline decimal_simpl:: + decimal_simpl (unsigned int p) + : precision_ (p) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/double.cxx b/libxsde/xsde/cxx/serializer/validating/double.cxx new file mode 100644 index 0000000..526eba0 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/double.cxx @@ -0,0 +1,105 @@ +// file : xsde/cxx/serializer/validating/double.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/double.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void double_simpl:: + pre (double value) + { + value_ = value; + } + + void double_simpl:: + _serialize_content () + { + // Assume double values cannot be longer than 127 characters. + // + char str[128]; + + const char* fmt = 0; + + switch (notation_) + { + case notation_auto: + { + fmt = "%.*g"; + break; + } + case notation_fixed: + { + fmt = "%.*f"; + break; + } + case notation_scientific: + { + fmt = "%.*e"; + break; + } + } + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 128, fmt, precision_, value_); +#else + int n = sprintf (str, fmt, precision_, value_); +#endif + if (n > 0 && n < 128) + { + if (str[0] == '-') + { + if (str[1] == 'n' && str[2] == 'a' && str[3] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[1] == 'i' && str[2] == 'n' && str[3] == 'f') + { + _characters ("-INF", 4); + return; + } + } + else + { + if (str[0] == 'n' && str[1] == 'a' && str[2] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[0] == 'i' && str[1] == 'n' && str[2] == 'f') + { + _characters ("INF", 3); + return; + } + } + + if (notation_ == notation_fixed) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_double_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/double.hxx b/libxsde/xsde/cxx/serializer/validating/double.hxx new file mode 100644 index 0000000..e7d1324 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/double.hxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/serializer/validating/double.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_DOUBLE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_DOUBLE_HXX + +#include <float.h> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct double_simpl: virtual double_sskel +#else + struct double_simpl: double_sskel +#endif + { + enum notation + { + notation_auto, + notation_fixed, + notation_scientific + }; + +#ifdef DBL_DIG + double_simpl (notation = notation_auto, + unsigned int precision = DBL_DIG); +#else + double_simpl (notation = notation_auto, + unsigned int precision = 15) +#endif + + virtual void + pre (double); + + virtual void + _serialize_content (); + + protected: + notation notation_; + unsigned int precision_; + double value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/double.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_DOUBLE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/double.ixx b/libxsde/xsde/cxx/serializer/validating/double.ixx new file mode 100644 index 0000000..8ae69e6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/double.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/double.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline double_simpl:: + double_simpl (notation n, unsigned int p) + : notation_ (n), precision_ (p) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/duration.cxx b/libxsde/xsde/cxx/serializer/validating/duration.cxx new file mode 100644 index 0000000..7187da5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/duration.cxx @@ -0,0 +1,195 @@ +// file : xsde/cxx/serializer/validating/duration.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/duration.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void duration_simpl:: + pre (const duration& value) + { + value_ = value; + } + + void duration_simpl:: + _serialize_content () + { + if (value_.seconds () < 0.0) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + // duration := -PnYnMnDTnHnMnS + // + // The years, months, days, hours, and minutes components are + // represented as 32 unsigned integers with maximum string + // representation being strlen ("4294967295") = 10. + // + // We assume that the seconds part (double) cannot be longer + // than 128 chars. + // + // The total representation thus cannot exceed 10*5 + 128 + + // 9 + 1 = 188 characters. + // + char str[188]; + char* p = str; + + if (value_.negative ()) + *p++ = '-'; + + *p++ = 'P'; + + // years + // + // In case it is 0-duration, use the years field to handle + // this case. + // + if (value_.years () != 0 || + (value_.months () == 0 && + value_.days () == 0 && + value_.hours () == 0 && + value_.minutes () == 0 && + value_.seconds () == 0.0)) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.years ()); +#else + int n = sprintf (p, "%u", value_.years ()); +#endif + if (n < 0 || n >= 11) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + p += n; + *p++ = 'Y'; + } + + // months + // + if (value_.months () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.months ()); +#else + int n = sprintf (p, "%u", value_.months ()); +#endif + if (n < 0 || n >= 11) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + p += n; + *p++ = 'M'; + } + + // days + // + if (value_.days () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.days ()); +#else + int n = sprintf (p, "%u", value_.days ()); +#endif + if (n < 0 || n >= 11) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + p += n; + *p++ = 'D'; + } + + // Figure out if we need the 'T' delimiter. + // + if (value_.hours () != 0 || + value_.minutes () != 0 || + value_.seconds () != 0.0) + *p++ = 'T'; + + // hours + // + if (value_.hours () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.hours ()); +#else + int n = sprintf (p, "%u", value_.hours ()); +#endif + if (n < 0 || n >= 11) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + p += n; + *p++ = 'H'; + } + + // minutes + // + if (value_.minutes () != 0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 11, "%u", value_.minutes ()); +#else + int n = sprintf (p, "%u", value_.minutes ()); +#endif + if (n < 0 || n >= 11) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + p += n; + *p++ = 'M'; + } + + // seconds + // + if (value_.seconds () > 0.0) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (p, 128, "%f", value_.seconds ()); +#else + int n = sprintf (p, "%f", value_.seconds ()); +#endif + if (n < 0 || n >= 128) + { + _schema_error (schema_error::invalid_duration_value); + return; + } + + // Remove trailing '0' and '.' if necessary. + // + while (p[n - 1] == '0') + n--; + + if (p[n - 1] == '.') + n--; + + p += n; + *p++ = 'S'; + } + + _characters (str, static_cast<size_t> (p - str)); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/duration.hxx b/libxsde/xsde/cxx/serializer/validating/duration.hxx new file mode 100644 index 0000000..edc5473 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/duration.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/duration.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_DURATION_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_DURATION_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct duration_simpl: virtual duration_sskel +#else + struct duration_simpl: duration_sskel +#endif + { + duration_simpl (); + + virtual void + pre (const duration&); + + virtual void + _serialize_content (); + + protected: + duration value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/duration.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_DURATION_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/duration.ixx b/libxsde/xsde/cxx/serializer/validating/duration.ixx new file mode 100644 index 0000000..334a288 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/duration.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/duration.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline duration_simpl:: + duration_simpl () + : value_ (false, 1, 0, 0, 0, 0, 0.0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/float.cxx b/libxsde/xsde/cxx/serializer/validating/float.cxx new file mode 100644 index 0000000..d9ee49c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/float.cxx @@ -0,0 +1,105 @@ +// file : xsde/cxx/serializer/validating/float.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/float.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void float_simpl:: + pre (float value) + { + value_ = value; + } + + void float_simpl:: + _serialize_content () + { + // Assume float values cannot be longer than 127 characters. + // + char str[128]; + + const char* fmt = 0; + + switch (notation_) + { + case notation_auto: + { + fmt = "%.*g"; + break; + } + case notation_fixed: + { + fmt = "%.*f"; + break; + } + case notation_scientific: + { + fmt = "%.*e"; + break; + } + } + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 128, fmt, precision_, value_); +#else + int n = sprintf (str, fmt, precision_, value_); +#endif + if (n > 0 && n < 128) + { + if (str[0] == '-') + { + if (str[1] == 'n' && str[2] == 'a' && str[3] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[1] == 'i' && str[2] == 'n' && str[3] == 'f') + { + _characters ("-INF", 4); + return; + } + } + else + { + if (str[0] == 'n' && str[1] == 'a' && str[2] == 'n') + { + _characters ("NaN", 3); + return; + } + else if (str[0] == 'i' && str[1] == 'n' && str[2] == 'f') + { + _characters ("INF", 3); + return; + } + } + + if (notation_ == notation_fixed) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_float_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/float.hxx b/libxsde/xsde/cxx/serializer/validating/float.hxx new file mode 100644 index 0000000..6a9b9df --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/float.hxx @@ -0,0 +1,60 @@ +// file : xsde/cxx/serializer/validating/float.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_FLOAT_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_FLOAT_HXX + +#include <float.h> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct float_simpl: virtual float_sskel +#else + struct float_simpl: float_sskel +#endif + { + enum notation + { + notation_auto, + notation_fixed, + notation_scientific + }; + +#ifdef FLT_DIG + float_simpl (notation = notation_auto, + unsigned int precision = FLT_DIG); +#else + float_simpl (notation = notation_auto, + unsigned int precision = 6) +#endif + + virtual void + pre (float); + + virtual void + _serialize_content (); + + protected: + notation notation_; + unsigned int precision_; + float value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/float.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_FLOAT_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/float.ixx b/libxsde/xsde/cxx/serializer/validating/float.ixx new file mode 100644 index 0000000..b240b6e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/float.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/float.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline float_simpl:: + float_simpl (notation n, unsigned int p) + : notation_ (n), precision_ (p) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gday.cxx b/libxsde/xsde/cxx/serializer/validating/gday.cxx new file mode 100644 index 0000000..363757b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gday.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/serializer/validating/gday.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/gday.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void gday_simpl:: + pre (const gday& value) + { + value_ = value; + } + + void gday_simpl:: + _serialize_content () + { + // We only need strlen("---DD+hh:mm") + 1 characters to hold all + // representations of gDay. + // + char str[12]; + + unsigned short d = value_.day (); + + if (d > 0 && d < 32 && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 6, "---%.2u", d); +#else + int n = sprintf (str, "---%.2u", d); +#endif + if (n > 0 && n < 6) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_gday_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_gday_value); + } + else + _schema_error (schema_error::invalid_gday_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gday.hxx b/libxsde/xsde/cxx/serializer/validating/gday.hxx new file mode 100644 index 0000000..856229b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gday.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/gday.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_GDAY_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_GDAY_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gday_simpl: virtual gday_sskel +#else + struct gday_simpl: gday_sskel +#endif + { + gday_simpl (); + + virtual void + pre (const gday&); + + virtual void + _serialize_content (); + + protected: + gday value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/gday.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_GDAY_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/gday.ixx b/libxsde/xsde/cxx/serializer/validating/gday.ixx new file mode 100644 index 0000000..04e6261 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gday.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/gday.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline gday_simpl:: + gday_simpl () + : value_ (1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gmonth-day.cxx b/libxsde/xsde/cxx/serializer/validating/gmonth-day.cxx new file mode 100644 index 0000000..fd8f461 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gmonth-day.cxx @@ -0,0 +1,68 @@ +// file : xsde/cxx/serializer/validating/gmonth-day.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/gmonth-day.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void gmonth_day_simpl:: + pre (const gmonth_day& value) + { + value_ = value; + } + + void gmonth_day_simpl:: + _serialize_content () + { + // We only need strlen("--MM-DD+hh:mm") + 1 characters to hold all + // representations of gMonthDay. + // + char str[14]; + + unsigned short m = value_.month (); + unsigned short d = value_.day (); + + if (m > 0 && m < 13 && d > 0 && d < 32 && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 8, "--%.2u-%.2u", m, d); +#else + int n = sprintf (str, "--%.2u-%.2u", m, d); +#endif + if (n > 0 && n < 8) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_gmonth_day_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_gmonth_day_value); + } + else + _schema_error (schema_error::invalid_gmonth_day_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gmonth-day.hxx b/libxsde/xsde/cxx/serializer/validating/gmonth-day.hxx new file mode 100644 index 0000000..60d5d11 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gmonth-day.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/gmonth-day.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_GMONTH_DAY_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_GMONTH_DAY_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_day_simpl: virtual gmonth_day_sskel +#else + struct gmonth_day_simpl: gmonth_day_sskel +#endif + { + gmonth_day_simpl (); + + virtual void + pre (const gmonth_day&); + + virtual void + _serialize_content (); + + protected: + gmonth_day value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/gmonth-day.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_GMONTH_DAY_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/gmonth-day.ixx b/libxsde/xsde/cxx/serializer/validating/gmonth-day.ixx new file mode 100644 index 0000000..23581ee --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gmonth-day.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/gmonth-day.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline gmonth_day_simpl:: + gmonth_day_simpl () + : value_ (1, 1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gmonth.cxx b/libxsde/xsde/cxx/serializer/validating/gmonth.cxx new file mode 100644 index 0000000..ad5cf27 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gmonth.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/serializer/validating/gmonth.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/gmonth.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void gmonth_simpl:: + pre (const gmonth& value) + { + value_ = value; + } + + void gmonth_simpl:: + _serialize_content () + { + // We only need strlen("--MM+hh:mm") + 1 characters to hold all + // representations of gMonth. + // + char str[11]; + + unsigned short m = value_.month (); + + if (m > 0 && m < 13 && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 5, "--%.2u", m); +#else + int n = sprintf (str, "--%.2u", m); +#endif + if (n > 0 && n < 5) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_gmonth_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_gmonth_value); + } + else + _schema_error (schema_error::invalid_gmonth_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gmonth.hxx b/libxsde/xsde/cxx/serializer/validating/gmonth.hxx new file mode 100644 index 0000000..10d9575 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gmonth.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/gmonth.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_GMONTH_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_GMONTH_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gmonth_simpl: virtual gmonth_sskel +#else + struct gmonth_simpl: gmonth_sskel +#endif + { + gmonth_simpl (); + + virtual void + pre (const gmonth&); + + virtual void + _serialize_content (); + + protected: + gmonth value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/gmonth.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_GMONTH_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/gmonth.ixx b/libxsde/xsde/cxx/serializer/validating/gmonth.ixx new file mode 100644 index 0000000..ae0a8dc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gmonth.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/gmonth.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline gmonth_simpl:: + gmonth_simpl () + : value_ (1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gyear-month.cxx b/libxsde/xsde/cxx/serializer/validating/gyear-month.cxx new file mode 100644 index 0000000..ab4ab15 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gyear-month.cxx @@ -0,0 +1,68 @@ +// file : xsde/cxx/serializer/validating/gyear-month.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/gyear-month.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void gyear_month_simpl:: + pre (const gyear_month& value) + { + value_ = value; + } + + void gyear_month_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649-MM+hh:mm") + 1 characters to + // hold all representations of gYearMonth. + // + char str[21]; + + int y = value_.year (); + unsigned short m = value_.month (); + + if (y != 0 && m > 0 && m < 13 && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 15, "%.4d-%.2u", y, m); +#else + int n = sprintf (str, "%.4d-%.2u", y, m); +#endif + if (n > 0 && n < 15) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_gyear_month_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_gyear_month_value); + } + else + _schema_error (schema_error::invalid_gyear_month_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gyear-month.hxx b/libxsde/xsde/cxx/serializer/validating/gyear-month.hxx new file mode 100644 index 0000000..9a0107e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gyear-month.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/gyear-month.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_GYEAR_MONTH_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_GYEAR_MONTH_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_month_simpl: virtual gyear_month_sskel +#else + struct gyear_month_simpl: gyear_month_sskel +#endif + { + gyear_month_simpl (); + + virtual void + pre (const gyear_month&); + + virtual void + _serialize_content (); + + protected: + gyear_month value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/gyear-month.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_GYEAR_MONTH_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/gyear-month.ixx b/libxsde/xsde/cxx/serializer/validating/gyear-month.ixx new file mode 100644 index 0000000..5aea7eb --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gyear-month.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/gyear-month.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline gyear_month_simpl:: + gyear_month_simpl () + : value_ (1, 1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gyear.cxx b/libxsde/xsde/cxx/serializer/validating/gyear.cxx new file mode 100644 index 0000000..6b34506 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gyear.cxx @@ -0,0 +1,67 @@ +// file : xsde/cxx/serializer/validating/gyear.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/gyear.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void gyear_simpl:: + pre (const gyear& value) + { + value_ = value; + } + + void gyear_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649+hh:mm") + 1 characters to + // hold all representations of gYear. + // + char str[18]; + + int y = value_.year (); + + if (y != 0 && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 12, "%.4d", y); +#else + int n = sprintf (str, "%.4d", y); +#endif + if (n > 0 && n < 12) + { + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_gyear_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_gyear_value); + } + else + _schema_error (schema_error::invalid_gyear_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/gyear.hxx b/libxsde/xsde/cxx/serializer/validating/gyear.hxx new file mode 100644 index 0000000..0ae7e1a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gyear.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/gyear.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_GYEAR_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_GYEAR_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct gyear_simpl: virtual gyear_sskel +#else + struct gyear_simpl: gyear_sskel +#endif + { + gyear_simpl (); + + virtual void + pre (const gyear&); + + virtual void + _serialize_content (); + + protected: + gyear value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/gyear.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_GYEAR_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/gyear.ixx b/libxsde/xsde/cxx/serializer/validating/gyear.ixx new file mode 100644 index 0000000..7502a6b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/gyear.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/gyear.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline gyear_simpl:: + gyear_simpl () + : value_ (1) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/hex-binary.cxx b/libxsde/xsde/cxx/serializer/validating/hex-binary.cxx new file mode 100644 index 0000000..0250e71 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/hex-binary.cxx @@ -0,0 +1,70 @@ +// file : xsde/cxx/serializer/validating/hex-binary.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/hex-binary.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + hex_binary_simpl:: + ~hex_binary_simpl () + { + if (free_) + delete const_cast<buffer*> (value_); + } + + void hex_binary_simpl:: + pre (const buffer* value) + { + value_ = value; + } + + static const char hex_tab[] = "0123456789ABCDEF"; + + void hex_binary_simpl:: + _serialize_content () + { + char buf[512]; + + size_t size = value_->size (); + const char* data = value_->data (); + + // Covert the data in 256-byte chunks. + // + for (size_t j = 0; j < size;) + { + size_t i = 0; + + for (; i < 512 && j < size; ++j) + { + unsigned char byte = static_cast<unsigned char> (data[j]); + + buf[i++] = hex_tab[byte >> 4]; + buf[i++] = hex_tab[byte & 0x0F]; + } + +#ifdef XSDE_EXCEPTIONS + _characters (buf, i); +#else + if (!_characters (buf, i)) + break; +#endif + } + + if (free_) + { + delete const_cast<buffer*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/hex-binary.hxx b/libxsde/xsde/cxx/serializer/validating/hex-binary.hxx new file mode 100644 index 0000000..524d9a9 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/hex-binary.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/hex-binary.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_HEX_BINARY_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_HEX_BINARY_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct hex_binary_simpl: virtual hex_binary_sskel +#else + struct hex_binary_simpl: hex_binary_sskel +#endif + { + virtual + ~hex_binary_simpl (); + + hex_binary_simpl (bool free = false); + + virtual void + pre (const buffer*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const buffer* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/hex-binary.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_HEX_BINARY_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/hex-binary.ixx b/libxsde/xsde/cxx/serializer/validating/hex-binary.ixx new file mode 100644 index 0000000..134d30a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/hex-binary.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/hex-binary.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline hex_binary_simpl:: + hex_binary_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/id-stl.cxx b/libxsde/xsde/cxx/serializer/validating/id-stl.cxx new file mode 100644 index 0000000..0166069 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/id-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/serializer/validating/id-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/id-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void id_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void id_simpl:: + _serialize_content () + { + std::string tmp; + tmp.swap (value_); + + if (xml::valid_ncname (tmp.c_str (), tmp.size ())) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_id_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/id-stl.hxx b/libxsde/xsde/cxx/serializer/validating/id-stl.hxx new file mode 100644 index 0000000..f804eac --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/id-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/id-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_ID_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_ID_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_simpl: virtual id_sskel +#else + struct id_simpl: id_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_ID_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/id.cxx b/libxsde/xsde/cxx/serializer/validating/id.cxx new file mode 100644 index 0000000..2926ffe --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/id.cxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/id.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/id.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + id_simpl:: + ~id_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void id_simpl:: + pre (const char* value) + { + value_ = value; + } + + void id_simpl:: + _serialize_content () + { + size_t n = strlen (value_); + + if (xml::valid_ncname (value_, n)) + _characters (value_, n); + else + _schema_error (schema_error::invalid_id_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/id.hxx b/libxsde/xsde/cxx/serializer/validating/id.hxx new file mode 100644 index 0000000..dac47f3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/id.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/id.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_ID_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_ID_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_simpl: virtual id_sskel +#else + struct id_simpl: id_sskel +#endif + { + virtual + ~id_simpl (); + + id_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/id.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_ID_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/id.ixx b/libxsde/xsde/cxx/serializer/validating/id.ixx new file mode 100644 index 0000000..d771919 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/id.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/id.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline id_simpl:: + id_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/idref-stl.cxx b/libxsde/xsde/cxx/serializer/validating/idref-stl.cxx new file mode 100644 index 0000000..620b16f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idref-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/serializer/validating/idref-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void idref_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void idref_simpl:: + _serialize_content () + { + std::string tmp; + tmp.swap (value_); + + if (xml::valid_ncname (tmp.c_str (), tmp.size ())) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_idref_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/idref-stl.hxx b/libxsde/xsde/cxx/serializer/validating/idref-stl.hxx new file mode 100644 index 0000000..e90443e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idref-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/idref-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_IDREF_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_IDREF_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_simpl: virtual idref_sskel +#else + struct idref_simpl: idref_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_IDREF_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/idref.cxx b/libxsde/xsde/cxx/serializer/validating/idref.cxx new file mode 100644 index 0000000..87d6c5c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idref.cxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/idref.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + idref_simpl:: + ~idref_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void idref_simpl:: + pre (const char* value) + { + value_ = value; + } + + void idref_simpl:: + _serialize_content () + { + size_t n = strlen (value_); + + if (xml::valid_ncname (value_, n)) + _characters (value_, n); + else + _schema_error (schema_error::invalid_idref_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/idref.hxx b/libxsde/xsde/cxx/serializer/validating/idref.hxx new file mode 100644 index 0000000..b8d82ce --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idref.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/idref.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_IDREF_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_IDREF_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_simpl: virtual idref_sskel +#else + struct idref_simpl: idref_sskel +#endif + { + virtual + ~idref_simpl (); + + idref_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/idref.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_IDREF_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/idref.ixx b/libxsde/xsde/cxx/serializer/validating/idref.ixx new file mode 100644 index 0000000..34a6838 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idref.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/idref.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline idref_simpl:: + idref_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/idrefs-stl.cxx b/libxsde/xsde/cxx/serializer/validating/idrefs-stl.cxx new file mode 100644 index 0000000..bdcf937 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idrefs-stl.cxx @@ -0,0 +1,109 @@ +// file : xsde/cxx/serializer/validating/idrefs-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/idrefs-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + idrefs_simpl:: + ~idrefs_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void idrefs_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void idrefs_simpl:: + _serialize_content () + { + // Should have at least one element. + // + if (!value_->empty ()) + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { + serializer_.pre (*i); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + + if (!first) + { +#ifdef XSDE_EXCEPTIONS + _characters (" ", 1); +#else + if (!_characters (" ", 1)) + break; +#endif + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + } + else + _schema_error (schema_error::invalid_idrefs_value); + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void idrefs_simpl:: + _reset () + { + idrefs_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/idrefs-stl.hxx b/libxsde/xsde/cxx/serializer/validating/idrefs-stl.hxx new file mode 100644 index 0000000..03cd1da --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idrefs-stl.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/idrefs-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_IDREFS_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_IDREFS_STL_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/validating/idref-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_simpl: virtual idrefs_sskel +#else + struct idrefs_simpl: idrefs_sskel +#endif + { + virtual + ~idrefs_simpl (); + + idrefs_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + idref_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/idrefs-stl.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_IDREFS_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/idrefs-stl.ixx b/libxsde/xsde/cxx/serializer/validating/idrefs-stl.ixx new file mode 100644 index 0000000..9c6e46c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idrefs-stl.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/idrefs-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline idrefs_simpl:: + idrefs_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/idrefs.cxx b/libxsde/xsde/cxx/serializer/validating/idrefs.cxx new file mode 100644 index 0000000..e6548c4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idrefs.cxx @@ -0,0 +1,110 @@ +// file : xsde/cxx/serializer/validating/idrefs.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/idrefs.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + idrefs_simpl:: + ~idrefs_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void idrefs_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void idrefs_simpl:: + _serialize_content () + { + // Should have at least one element. + // + if (!value_->empty ()) + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { + serializer_.pre (*i); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + + if (!first) + { +#ifdef XSDE_EXCEPTIONS + _characters (" ", 1); +#else + if (!_characters (" ", 1)) + break; +#endif + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + } + else + _schema_error (schema_error::invalid_idrefs_value); + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void idrefs_simpl:: + _reset () + { + idrefs_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/validating/idrefs.hxx b/libxsde/xsde/cxx/serializer/validating/idrefs.hxx new file mode 100644 index 0000000..23386dd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idrefs.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/idrefs.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_IDREFS_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_IDREFS_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/validating/idref.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idrefs_simpl: virtual idrefs_sskel +#else + struct idrefs_simpl: idrefs_sskel +#endif + { + virtual + ~idrefs_simpl (); + + idrefs_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + idref_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/idrefs.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_IDREFS_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/idrefs.ixx b/libxsde/xsde/cxx/serializer/validating/idrefs.ixx new file mode 100644 index 0000000..b077e58 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/idrefs.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/idrefs.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline idrefs_simpl:: + idrefs_simpl (bool free) + : free_ (free), value_ (0), serializer_ (false) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/inheritance-map-load.hxx b/libxsde/xsde/cxx/serializer/validating/inheritance-map-load.hxx new file mode 100644 index 0000000..abdcd43 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/inheritance-map-load.hxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/validating/inheritance-map-load.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_INHERITANCE_MAP_LOAD_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_INHERITANCE_MAP_LOAD_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + size_t + serializer_imap_elements (); + + inline size_t + serializer_imap_buckets () + { + return XSDE_SERIALIZER_IMAP_BUCKETS; + } + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_INHERITANCE_MAP_LOAD_HXX + diff --git a/libxsde/xsde/cxx/serializer/validating/inheritance-map.cxx b/libxsde/xsde/cxx/serializer/validating/inheritance-map.cxx new file mode 100644 index 0000000..94fdabc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/inheritance-map.cxx @@ -0,0 +1,111 @@ +// file : xsde/cxx/serializer/validating/inheritance-map.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#include <string.h> // strcmp + +#ifndef XSDE_EXCEPTIONS +# include <assert.h> // assert +# include <stdlib.h> // exit +#endif + +#include <xsde/cxx/serializer/validating/inheritance-map.hxx> +#include <xsde/cxx/serializer/validating/inheritance-map-load.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inheritance_map* inheritance_map_init::map = 0; + size_t inheritance_map_init::count = 0; + + bool inheritance_map:: + check (const char* derived, const char* base) const + { + if (strcmp (derived, base) == 0) + return true; + + const void* p = find (derived); + + if (p) + { + const char* b = *static_cast<const char* const*> (p); + return strcmp (base, b) == 0 ? true : check (b, base); + } + + return false; + } + + // inheritance_map_init + // + inheritance_map_init:: + inheritance_map_init () + { + if (count == 0) + { + map = new inheritance_map (XSDE_SERIALIZER_IMAP_BUCKETS); + +#ifndef XSDE_EXCEPTIONS + if (map == 0 || map->_error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + ++count; + } + + inheritance_map_init:: + ~inheritance_map_init () + { + if (--count == 0) + delete map; + } + + // inheritance_map_entry + // + inheritance_map_entry:: + inheritance_map_entry (const char* derived, const char* base) + { + inheritance_map& m = inheritance_map_instance (); + m.insert (derived, base); + +#ifndef XSDE_EXCEPTIONS + if (m._error () != inheritance_map::error_none) + { + // This is static initialization so there is nothing we can do. + // The best thing is to fail fast. abort() would have probably + // been the better choice here but it is not available on some + // platforms (notably, WinCE). + // + assert (false); + exit (1); + } +#endif + } + + // + // + size_t + serializer_imap_elements () + { + return inheritance_map_instance ().size (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/inheritance-map.hxx b/libxsde/xsde/cxx/serializer/validating/inheritance-map.hxx new file mode 100644 index 0000000..051dbfc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/inheritance-map.hxx @@ -0,0 +1,63 @@ +// file : xsde/cxx/serializer/validating/inheritance-map.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_INHERITANCE_MAP_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_INHERITANCE_MAP_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/ro-string.hxx> +#include <xsde/cxx/hashmap.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + struct inheritance_map: hashmap + { + inheritance_map (size_t buckets); + + void + insert (const char* derived, const char* base); + + bool + check (const char* derived, const char* base) const; + }; + + + // Translation unit initializer. + // + struct inheritance_map_init + { + static inheritance_map* map; + static size_t count; + + inheritance_map_init (); + ~inheritance_map_init (); + }; + + inline inheritance_map& + inheritance_map_instance (); + + // Map entry initializer. + // + struct inheritance_map_entry + { + inheritance_map_entry (const char* derived, const char* base); + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/inheritance-map.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_INHERITANCE_MAP_HXX + diff --git a/libxsde/xsde/cxx/serializer/validating/inheritance-map.ixx b/libxsde/xsde/cxx/serializer/validating/inheritance-map.ixx new file mode 100644 index 0000000..2ae6fcf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/inheritance-map.ixx @@ -0,0 +1,34 @@ +// file : xsde/cxx/serializer/validating/inheritance-map.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline inheritance_map:: + inheritance_map (size_t buckets) + : hashmap (buckets, sizeof (const char*)) + { + } + + inline void inheritance_map:: + insert (const char* derived, const char* base) + { + hashmap::insert (derived, &base); + } + + inline inheritance_map& + inheritance_map_instance () + { + return *inheritance_map_init::map; + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/int.cxx b/libxsde/xsde/cxx/serializer/validating/int.cxx new file mode 100644 index 0000000..780abbe --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/int.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void int_simpl:: + pre (int value) + { + value_ = value; + } + + void int_simpl:: + _serialize_content () + { + // We only need strlen("-2147483649") + 1 characters to hold all + // representations of int. + // + char str[12]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 12, "%d", value_); +#else + int n = sprintf (str, "%d", value_); +#endif + if (n > 0 && n < 12) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_int_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/int.hxx b/libxsde/xsde/cxx/serializer/validating/int.hxx new file mode 100644 index 0000000..6d798d6 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/int.hxx @@ -0,0 +1,39 @@ +// file : xsde/cxx/serializer/validating/int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_INT_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_INT_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct int_simpl: virtual int_sskel +#else + struct int_simpl: int_sskel +#endif + { + virtual void + pre (int); + + virtual void + _serialize_content (); + + protected: + int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_INT_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/integer.cxx b/libxsde/xsde/cxx/serializer/validating/integer.cxx new file mode 100644 index 0000000..8df6c55 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/integer.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void integer_simpl:: + pre (long value) + { + value_ = value; + } + + void integer_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_integer_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/integer.hxx b/libxsde/xsde/cxx/serializer/validating/integer.hxx new file mode 100644 index 0000000..ada9796 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_INTEGER_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Arbitrary-length integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct integer_simpl: virtual integer_sskel +#else + struct integer_simpl: integer_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/language-stl.cxx b/libxsde/xsde/cxx/serializer/validating/language-stl.cxx new file mode 100644 index 0000000..cd4e1d2 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/language-stl.cxx @@ -0,0 +1,73 @@ +// file : xsde/cxx/serializer/validating/language-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/language-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void language_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void language_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + bool ok = true; + const char* s = tmp.c_str (); + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + for (size_t tag = 0; ; ++tag) + { + size_t n = 0; + + for (; *s != '\0' && n < 8; ++n, ++s) + { + char c = *s; + + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (tag != 0 && c >= '0' && c <= '9'))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (*s == '\0') + break; + + if (*s++ != '-') + { + ok = false; + break; + } + } + + if (ok) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_language_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/language-stl.hxx b/libxsde/xsde/cxx/serializer/validating/language-stl.hxx new file mode 100644 index 0000000..2216bff --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/language-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/language-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_LANGUAGE_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_LANGUAGE_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_simpl: virtual language_sskel +#else + struct language_simpl: language_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_LANGUAGE_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/language.cxx b/libxsde/xsde/cxx/serializer/validating/language.cxx new file mode 100644 index 0000000..14f69fc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/language.cxx @@ -0,0 +1,81 @@ +// file : xsde/cxx/serializer/validating/language.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/language.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + language_simpl:: + ~language_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void language_simpl:: + pre (const char* value) + { + value_ = value; + } + + void language_simpl:: + _serialize_content () + { + bool ok = true; + const char* s = value_; + + // language := ALPHA{1,8} *(-(ALPHA | DIGIT){1,8}) + // + for (size_t tag = 0; ; ++tag) + { + size_t n = 0; + + for (; *s != '\0' && n < 8; ++n, ++s) + { + char c = *s; + + if (!((c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (tag != 0 && c >= '0' && c <= '9'))) + break; + } + + if (n == 0) + { + ok = false; + break; + } + + if (*s == '\0') + break; + + if (*s++ != '-') + { + ok = false; + break; + } + } + + if (ok) + _characters (value_); + else + _schema_error (schema_error::invalid_language_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/language.hxx b/libxsde/xsde/cxx/serializer/validating/language.hxx new file mode 100644 index 0000000..708a5b0 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/language.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/language.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_LANGUAGE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_LANGUAGE_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_simpl: virtual language_sskel +#else + struct language_simpl: language_sskel +#endif + { + virtual + ~language_simpl (); + + language_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/language.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_LANGUAGE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/language.ixx b/libxsde/xsde/cxx/serializer/validating/language.ixx new file mode 100644 index 0000000..3385220 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/language.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/language.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline language_simpl:: + language_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/long-long.cxx b/libxsde/xsde/cxx/serializer/validating/long-long.cxx new file mode 100644 index 0000000..2773ec7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/long-long.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void long_simpl:: + pre (long long value) + { + value_ = value; + } + + void long_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of long long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lld", value_); +#else + int n = sprintf (str, "%lld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_long_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/long-long.hxx b/libxsde/xsde/cxx/serializer/validating/long-long.hxx new file mode 100644 index 0000000..97e14d1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/long-long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_LONG_LONG_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_LONG_LONG_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 64-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_simpl: virtual long_sskel +#else + struct long_simpl: long_sskel +#endif + { + virtual void + pre (long long); + + virtual void + _serialize_content (); + + protected: + long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/long.cxx b/libxsde/xsde/cxx/serializer/validating/long.cxx new file mode 100644 index 0000000..574a22e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/long.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void long_simpl:: + pre (long value) + { + value_ = value; + } + + void long_simpl:: + _serialize_content () + { + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_long_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/long.hxx b/libxsde/xsde/cxx/serializer/validating/long.hxx new file mode 100644 index 0000000..7ffadc7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_LONG_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_LONG_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct long_simpl: virtual long_sskel +#else + struct long_simpl: long_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/name-stl.cxx b/libxsde/xsde/cxx/serializer/validating/name-stl.cxx new file mode 100644 index 0000000..e80bf9b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/name-stl.cxx @@ -0,0 +1,62 @@ +// file : xsde/cxx/serializer/validating/name-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/serializer/validating/name-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void name_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void name_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + const char* s = tmp.c_str (); + bool ok = (*s != '\0'); + + // For now we are only checking the US-ASCII characters. + // + if (ok) + { + // First character. + // + unsigned char c = static_cast<unsigned char> (*s); + + ok = c >= 0x80 || (xml::char_table[c] & xml::name_first_char_mask); + + for (++s; ok && *s != '\0'; ++s) + { + c = static_cast<unsigned char> (*s); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + ok = false; + } + } + + if (ok) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_name_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/name-stl.hxx b/libxsde/xsde/cxx/serializer/validating/name-stl.hxx new file mode 100644 index 0000000..8e67a28 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/name-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/name-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NAME_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NAME_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_simpl: virtual name_sskel +#else + struct name_simpl: name_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NAME_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/name.cxx b/libxsde/xsde/cxx/serializer/validating/name.cxx new file mode 100644 index 0000000..7c916d8 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/name.cxx @@ -0,0 +1,70 @@ +// file : xsde/cxx/serializer/validating/name.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/serializer/validating/name.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + name_simpl:: + ~name_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void name_simpl:: + pre (const char* value) + { + value_ = value; + } + + void name_simpl:: + _serialize_content () + { + const char* s = value_; + bool ok = (*s != '\0'); + + // For now we are only checking the US-ASCII characters. + // + if (ok) + { + // First character. + // + unsigned char c = static_cast<unsigned char> (*s); + + ok = c >= 0x80 || (xml::char_table[c] & xml::name_first_char_mask); + + for (++s; ok && *s != '\0'; ++s) + { + c = static_cast<unsigned char> (*s); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + ok = false; + } + } + + if (ok) + _characters (value_); + else + _schema_error (schema_error::invalid_name_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/name.hxx b/libxsde/xsde/cxx/serializer/validating/name.hxx new file mode 100644 index 0000000..3c4fe2e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/name.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/name.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NAME_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NAME_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_simpl: virtual name_sskel +#else + struct name_simpl: name_sskel +#endif + { + virtual + ~name_simpl (); + + name_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/name.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NAME_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/name.ixx b/libxsde/xsde/cxx/serializer/validating/name.ixx new file mode 100644 index 0000000..84fbdf3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/name.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/name.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline name_simpl:: + name_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/ncname-stl.cxx b/libxsde/xsde/cxx/serializer/validating/ncname-stl.cxx new file mode 100644 index 0000000..4dec901 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/ncname-stl.cxx @@ -0,0 +1,38 @@ +// file : xsde/cxx/serializer/validating/ncname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/ncname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void ncname_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void ncname_simpl:: + _serialize_content () + { + std::string tmp; + tmp.swap (value_); + + if (xml::valid_ncname (tmp.c_str (), tmp.size ())) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_ncname_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/ncname-stl.hxx b/libxsde/xsde/cxx/serializer/validating/ncname-stl.hxx new file mode 100644 index 0000000..f9bd61d --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/ncname-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/ncname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NCNAME_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NCNAME_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_simpl: virtual ncname_sskel +#else + struct ncname_simpl: ncname_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NCNAME_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/ncname.cxx b/libxsde/xsde/cxx/serializer/validating/ncname.cxx new file mode 100644 index 0000000..9f74a59 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/ncname.cxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + ncname_simpl:: + ~ncname_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void ncname_simpl:: + pre (const char* value) + { + value_ = value; + } + + void ncname_simpl:: + _serialize_content () + { + size_t n = strlen (value_); + + if (xml::valid_ncname (value_, n)) + _characters (value_, n); + else + _schema_error (schema_error::invalid_ncname_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/ncname.hxx b/libxsde/xsde/cxx/serializer/validating/ncname.hxx new file mode 100644 index 0000000..baafaa4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/ncname.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NCNAME_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NCNAME_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_simpl: virtual ncname_sskel +#else + struct ncname_simpl: ncname_sskel +#endif + { + virtual + ~ncname_simpl (); + + ncname_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/ncname.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NCNAME_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/ncname.ixx b/libxsde/xsde/cxx/serializer/validating/ncname.ixx new file mode 100644 index 0000000..5d6bf02 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/ncname.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/ncname.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline ncname_simpl:: + ncname_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/negative-integer.cxx b/libxsde/xsde/cxx/serializer/validating/negative-integer.cxx new file mode 100644 index 0000000..bb41770 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/negative-integer.cxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/serializer/validating/negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void negative_integer_simpl:: + pre (long value) + { + value_ = value; + } + + void negative_integer_simpl:: + _serialize_content () + { + if (value_ >= 0) + { + _schema_error (schema_error::invalid_negative_integer_value); + return; + } + + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_negative_integer_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/negative-integer.hxx b/libxsde/xsde/cxx/serializer/validating/negative-integer.hxx new file mode 100644 index 0000000..40fcd80 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/negative-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Arbitrary-length negative integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct negative_integer_simpl: virtual negative_integer_sskel +#else + struct negative_integer_simpl: negative_integer_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/nmtoken-stl.cxx b/libxsde/xsde/cxx/serializer/validating/nmtoken-stl.cxx new file mode 100644 index 0000000..c0cf793 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtoken-stl.cxx @@ -0,0 +1,53 @@ +// file : xsde/cxx/serializer/validating/nmtoken-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/serializer/validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void nmtoken_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void nmtoken_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + const char* s = tmp.c_str (); + bool ok = (*s != '\0'); + + // For now we are only checking the US-ASCII characters. + // + for (; ok && *s != '\0'; ++s) + { + unsigned char c = static_cast<unsigned char> (*s); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + ok = false; + } + + if (ok) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_nmtoken_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/nmtoken-stl.hxx b/libxsde/xsde/cxx/serializer/validating/nmtoken-stl.hxx new file mode 100644 index 0000000..3de2784 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtoken-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/nmtoken-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NMTOKEN_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NMTOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_simpl: virtual nmtoken_sskel +#else + struct nmtoken_simpl: nmtoken_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NMTOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/nmtoken.cxx b/libxsde/xsde/cxx/serializer/validating/nmtoken.cxx new file mode 100644 index 0000000..2563023 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtoken.cxx @@ -0,0 +1,61 @@ +// file : xsde/cxx/serializer/validating/nmtoken.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +#include <xsde/cxx/serializer/validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + nmtoken_simpl:: + ~nmtoken_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void nmtoken_simpl:: + pre (const char* value) + { + value_ = value; + } + + void nmtoken_simpl:: + _serialize_content () + { + const char* s = value_; + bool ok = (*s != '\0'); + + // For now we are only checking the US-ASCII characters. + // + for (; ok && *s != '\0'; ++s) + { + unsigned char c = static_cast<unsigned char> (*s); + + if (c < 0x80 && !(xml::char_table[c] & xml::name_char_mask)) + ok = false; + } + + if (ok) + _characters (value_); + else + _schema_error (schema_error::invalid_nmtoken_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/nmtoken.hxx b/libxsde/xsde/cxx/serializer/validating/nmtoken.hxx new file mode 100644 index 0000000..7951384 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtoken.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/nmtoken.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NMTOKEN_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NMTOKEN_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_simpl: virtual nmtoken_sskel +#else + struct nmtoken_simpl: nmtoken_sskel +#endif + { + virtual + ~nmtoken_simpl (); + + nmtoken_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/nmtoken.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NMTOKEN_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/nmtoken.ixx b/libxsde/xsde/cxx/serializer/validating/nmtoken.ixx new file mode 100644 index 0000000..4559310 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtoken.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/nmtoken.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline nmtoken_simpl:: + nmtoken_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.cxx b/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.cxx new file mode 100644 index 0000000..6607177 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.cxx @@ -0,0 +1,109 @@ +// file : xsde/cxx/serializer/validating/nmtokens-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/nmtokens-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + nmtokens_simpl:: + ~nmtokens_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void nmtokens_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void nmtokens_simpl:: + _serialize_content () + { + // Should have at least one element. + // + if (!value_->empty ()) + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { + serializer_.pre (*i); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + + if (!first) + { +#ifdef XSDE_EXCEPTIONS + _characters (" ", 1); +#else + if (!_characters (" ", 1)) + break; +#endif + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + } + else + _schema_error (schema_error::invalid_nmtokens_value); + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void nmtokens_simpl:: + _reset () + { + nmtokens_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.hxx b/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.hxx new file mode 100644 index 0000000..aab3fae --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/nmtokens-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NMTOKENS_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NMTOKENS_STL_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/validating/nmtoken-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_simpl: virtual nmtokens_sskel +#else + struct nmtokens_simpl: nmtokens_sskel +#endif + { + virtual + ~nmtokens_simpl (); + + nmtokens_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + nmtoken_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/nmtokens-stl.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NMTOKENS_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.ixx b/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.ixx new file mode 100644 index 0000000..988c9cd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtokens-stl.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/nmtokens-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline nmtokens_simpl:: + nmtokens_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/nmtokens.cxx b/libxsde/xsde/cxx/serializer/validating/nmtokens.cxx new file mode 100644 index 0000000..74e111b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtokens.cxx @@ -0,0 +1,110 @@ +// file : xsde/cxx/serializer/validating/nmtokens.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/nmtokens.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + nmtokens_simpl:: + ~nmtokens_simpl () + { + if (free_) + delete const_cast<string_sequence*> (value_); + } + + void nmtokens_simpl:: + pre (const string_sequence* value) + { + value_ = value; + } + + void nmtokens_simpl:: + _serialize_content () + { + // Should have at least one element. + // + if (!value_->empty ()) + { + bool first = true; + context& ctx = _context (); + + for (string_sequence::const_iterator i (value_->begin ()), + e (value_->end ()); i != e; ++i) + { + serializer_.pre (*i); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + + if (!first) + { +#ifdef XSDE_EXCEPTIONS + _characters (" ", 1); +#else + if (!_characters (" ", 1)) + break; +#endif + } + else + first = false; + + serializer_._pre_impl (ctx); + + if (ctx.error_type ()) + break; + + serializer_._serialize_content (); + + if (ctx.error_type ()) + break; + + serializer_._post_impl (); + + if (ctx.error_type ()) + break; + + serializer_.post (); + +#ifndef XSDE_EXCEPTIONS + if (serializer_._error_type ()) + serializer_._copy_error (ctx); + + if (ctx.error_type ()) + break; +#endif + } + } + else + _schema_error (schema_error::invalid_nmtokens_value); + + if (free_) + { + delete const_cast<string_sequence*> (value_); + value_ = 0; + } + } + + void nmtokens_simpl:: + _reset () + { + nmtokens_sskel::_reset (); + serializer_._reset (); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/validating/nmtokens.hxx b/libxsde/xsde/cxx/serializer/validating/nmtokens.hxx new file mode 100644 index 0000000..525ab13 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtokens.hxx @@ -0,0 +1,52 @@ +// file : xsde/cxx/serializer/validating/nmtokens.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NMTOKENS_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NMTOKENS_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> +#include <xsde/cxx/serializer/validating/nmtoken.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtokens_simpl: virtual nmtokens_sskel +#else + struct nmtokens_simpl: nmtokens_sskel +#endif + { + virtual + ~nmtokens_simpl (); + + nmtokens_simpl (bool free = false); + + virtual void + pre (const string_sequence*); + + virtual void + _serialize_content (); + + virtual void + _reset (); + + protected: + bool free_; + const string_sequence* value_; + nmtoken_simpl serializer_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/nmtokens.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NMTOKENS_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/nmtokens.ixx b/libxsde/xsde/cxx/serializer/validating/nmtokens.ixx new file mode 100644 index 0000000..0526e30 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/nmtokens.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/nmtokens.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline nmtokens_simpl:: + nmtokens_simpl (bool free) + : free_ (free), value_ (0), serializer_ (false) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/non-negative-integer.cxx b/libxsde/xsde/cxx/serializer/validating/non-negative-integer.cxx new file mode 100644 index 0000000..87a6e22 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/non-negative-integer.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/non-negative-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/non-negative-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void non_negative_integer_simpl:: + pre (unsigned long value) + { + value_ = value; + } + + void non_negative_integer_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of (possibly 64-bit) unsigned long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lu", value_); +#else + int n = sprintf (str, "%lu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_non_negative_integer_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/non-negative-integer.hxx b/libxsde/xsde/cxx/serializer/validating/non-negative-integer.hxx new file mode 100644 index 0000000..8d5b769 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/non-negative-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/non-negative-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NON_NEGATIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NON_NEGATIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Arbitrary-length non-negative integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_negative_integer_simpl: virtual non_negative_integer_sskel +#else + struct non_negative_integer_simpl: non_negative_integer_sskel +#endif + { + virtual void + pre (unsigned long); + + virtual void + _serialize_content (); + + protected: + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NON_NEGATIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/non-positive-integer.cxx b/libxsde/xsde/cxx/serializer/validating/non-positive-integer.cxx new file mode 100644 index 0000000..bbd2854 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/non-positive-integer.cxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/serializer/validating/non-positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/non-positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void non_positive_integer_simpl:: + pre (long value) + { + value_ = value; + } + + void non_positive_integer_simpl:: + _serialize_content () + { + if (value_ > 0) + { + _schema_error (schema_error::invalid_non_positive_integer_value); + return; + } + + // We only need strlen("-9223372036854775808") + 1 characters to + // hold all representations of (possibly 64-bit) long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%ld", value_); +#else + int n = sprintf (str, "%ld", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_non_positive_integer_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/non-positive-integer.hxx b/libxsde/xsde/cxx/serializer/validating/non-positive-integer.hxx new file mode 100644 index 0000000..9defbba --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/non-positive-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/non-positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NON_POSITIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NON_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Arbitrary-length non-positive integer. Mapped to long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct non_positive_integer_simpl: virtual non_positive_integer_sskel +#else + struct non_positive_integer_simpl: non_positive_integer_sskel +#endif + { + virtual void + pre (long); + + virtual void + _serialize_content (); + + protected: + long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NON_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/normalized-string-stl.cxx b/libxsde/xsde/cxx/serializer/validating/normalized-string-stl.cxx new file mode 100644 index 0000000..7c945da --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/normalized-string-stl.cxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/normalized-string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/normalized-string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void normalized_string_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void normalized_string_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + const char* s = tmp.c_str (); + + for (; *s != '\0'; ++s) + { + if (*s == 0x0A || *s == 0x0D || *s == 0x09) + break; + } + + if (*s == '\0') + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_normalized_string_value); + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/validating/normalized-string-stl.hxx b/libxsde/xsde/cxx/serializer/validating/normalized-string-stl.hxx new file mode 100644 index 0000000..98ae359 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/normalized-string-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/normalized-string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NORMALIZED_STRING_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NORMALIZED_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_simpl: virtual normalized_string_sskel +#else + struct normalized_string_simpl: normalized_string_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NORMALIZED_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/normalized-string.cxx b/libxsde/xsde/cxx/serializer/validating/normalized-string.cxx new file mode 100644 index 0000000..1e29376 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/normalized-string.cxx @@ -0,0 +1,55 @@ +// file : xsde/cxx/serializer/validating/normalized-string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/normalized-string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + normalized_string_simpl:: + ~normalized_string_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void normalized_string_simpl:: + pre (const char* value) + { + value_ = value; + } + + void normalized_string_simpl:: + _serialize_content () + { + const char* s = value_; + + for (; *s != '\0'; ++s) + { + if (*s == 0x0A || *s == 0x0D || *s == 0x09) + break; + } + + if (*s == '\0') + _characters (value_); + else + _schema_error (schema_error::invalid_normalized_string_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} + diff --git a/libxsde/xsde/cxx/serializer/validating/normalized-string.hxx b/libxsde/xsde/cxx/serializer/validating/normalized-string.hxx new file mode 100644 index 0000000..6496ab9 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/normalized-string.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/normalized-string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_NORMALIZED_STRING_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_NORMALIZED_STRING_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_simpl: virtual normalized_string_sskel +#else + struct normalized_string_simpl: normalized_string_sskel +#endif + { + virtual + ~normalized_string_simpl (); + + normalized_string_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/normalized-string.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_NORMALIZED_STRING_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/normalized-string.ixx b/libxsde/xsde/cxx/serializer/validating/normalized-string.ixx new file mode 100644 index 0000000..dc9085f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/normalized-string.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/normalized-string.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline normalized_string_simpl:: + normalized_string_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/positive-integer.cxx b/libxsde/xsde/cxx/serializer/validating/positive-integer.cxx new file mode 100644 index 0000000..dbb83cd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/positive-integer.cxx @@ -0,0 +1,51 @@ +// file : xsde/cxx/serializer/validating/positive-integer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/positive-integer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void positive_integer_simpl:: + pre (unsigned long value) + { + value_ = value; + } + + void positive_integer_simpl:: + _serialize_content () + { + if (value_ == 0) + { + _schema_error (schema_error::invalid_positive_integer_value); + return; + } + + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of (possibly 64-bit) unsigned long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lu", value_); +#else + int n = sprintf (str, "%lu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_positive_integer_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/positive-integer.hxx b/libxsde/xsde/cxx/serializer/validating/positive-integer.hxx new file mode 100644 index 0000000..329145e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/positive-integer.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/positive-integer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_POSITIVE_INTEGER_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_POSITIVE_INTEGER_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Arbitrary-length positive integer. Mapped to unsigned long. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct positive_integer_simpl: virtual positive_integer_sskel +#else + struct positive_integer_simpl: positive_integer_sskel +#endif + { + virtual void + pre (unsigned long); + + virtual void + _serialize_content (); + + protected: + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_POSITIVE_INTEGER_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/qname-stl.cxx b/libxsde/xsde/cxx/serializer/validating/qname-stl.cxx new file mode 100644 index 0000000..0e48748 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/qname-stl.cxx @@ -0,0 +1,68 @@ +// file : xsde/cxx/serializer/validating/qname-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/qname-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void qname_simpl:: + pre (const qname& value) + { + value_ = value; + } + + void qname_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the qname. + // + qname tmp ("a"); + tmp.swap (value_); + + const char* ns = tmp.name ().c_str (); + size_t nn = tmp.name ().size (); + + if (!tmp.prefix ().empty ()) + { + const char* ps = tmp.prefix ().c_str (); + size_t pn = tmp.prefix ().size (); + + if (xml::valid_ncname (ps, pn) && xml::valid_ncname (ns, nn)) + { +#ifdef XSDE_EXCEPTIONS + _characters (ps, pn); + _characters (":", 1); + _characters (ns, nn); +#else + if (_characters (ps, pn)) + { + if (_characters (":", 1)) + _characters (ns, nn); + } +#endif + } + else + _schema_error (schema_error::invalid_qname_value); + } + else + { + if (xml::valid_ncname (ns, nn)) + _characters (ns, nn); + else + _schema_error (schema_error::invalid_qname_value); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/qname-stl.hxx b/libxsde/xsde/cxx/serializer/validating/qname-stl.hxx new file mode 100644 index 0000000..8d87a4b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/qname-stl.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/qname-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_QNAME_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_QNAME_STL_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_simpl: virtual qname_sskel +#else + struct qname_simpl: qname_sskel +#endif + { + qname_simpl (); + + virtual void + pre (const qname&); + + virtual void + _serialize_content (); + + protected: + qname value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/qname-stl.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_QNAME_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/qname-stl.ixx b/libxsde/xsde/cxx/serializer/validating/qname-stl.ixx new file mode 100644 index 0000000..99edfdd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/qname-stl.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/qname-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline qname_simpl:: + qname_simpl () + : value_ ("a") + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/qname.cxx b/libxsde/xsde/cxx/serializer/validating/qname.cxx new file mode 100644 index 0000000..b69eb54 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/qname.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/serializer/validating/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen + +#include <xsde/cxx/xml/ncname.hxx> + +#include <xsde/cxx/serializer/validating/qname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + qname_simpl:: + ~qname_simpl () + { + if (free_) + delete const_cast<qname*> (value_); + } + + void qname_simpl:: + pre (const qname* value) + { + value_ = value; + } + + void qname_simpl:: + _serialize_content () + { + const char* ns = value_->name (); + size_t nn = strlen (ns); + + const char* ps = value_->prefix (); + + if (ps != 0 && *ps != '\0') + { + size_t pn = strlen (ps); + + if (xml::valid_ncname (ps, pn) && xml::valid_ncname (ns, nn)) + { +#ifdef XSDE_EXCEPTIONS + _characters (ps, pn); + _characters (":", 1); + _characters (ns, nn); +#else + if (_characters (ps, pn)) + { + if (_characters (":", 1)) + _characters (ns, nn); + } +#endif + } + else + _schema_error (schema_error::invalid_qname_value); + } + else + { + if (xml::valid_ncname (ns, nn)) + _characters (ns, nn); + else + _schema_error (schema_error::invalid_qname_value); + } + + if (free_) + { + delete const_cast<qname*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/qname.hxx b/libxsde/xsde/cxx/serializer/validating/qname.hxx new file mode 100644 index 0000000..e9790f5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/qname.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/qname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_QNAME_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_QNAME_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct qname_simpl: virtual qname_sskel +#else + struct qname_simpl: qname_sskel +#endif + { + virtual + ~qname_simpl (); + + qname_simpl (bool free = false); + + virtual void + pre (const qname*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const qname* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/qname.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_QNAME_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/qname.ixx b/libxsde/xsde/cxx/serializer/validating/qname.ixx new file mode 100644 index 0000000..08d69d1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/qname.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/qname.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline qname_simpl:: + qname_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/serializer.cxx b/libxsde/xsde/cxx/serializer/validating/serializer.cxx new file mode 100644 index 0000000..280c09f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/serializer.cxx @@ -0,0 +1,29 @@ +// file : xsde/cxx/serializer/validating/serializer.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/serializer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + void simple_content:: + _serialize_content () + { + if (impl_) + impl_->_serialize_content (); + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/serializer.hxx b/libxsde/xsde/cxx/serializer/validating/serializer.hxx new file mode 100644 index 0000000..d8ba64c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/serializer.hxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/serializer/validating/serializer.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_SERIALIZER_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_SERIALIZER_HXX + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/serializer/elements.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + struct empty_content: serializer_base + { +#ifdef XSDE_REUSE_STYLE_TIEIN + empty_content (); + empty_content (empty_content* impl, void*); +#endif + }; + + // + // + struct simple_content: empty_content + { +#ifdef XSDE_REUSE_STYLE_TIEIN + virtual void + _serialize_content (); + + simple_content (); + simple_content (simple_content* impl, void*); +#endif + }; + + // + // + struct complex_content: empty_content + { +#ifdef XSDE_REUSE_STYLE_TIEIN + complex_content (); + complex_content (complex_content* impl, void*); +#endif + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/serializer.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_SERIALIZER_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/serializer.ixx b/libxsde/xsde/cxx/serializer/validating/serializer.ixx new file mode 100644 index 0000000..66b9ad7 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/serializer.ixx @@ -0,0 +1,61 @@ +// file : xsde/cxx/serializer/validating/serializer.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // empty_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline empty_content:: + empty_content () + { + } + + inline empty_content:: + empty_content (empty_content* impl, void*) + : serializer_base (impl, 0) + { + } +#endif + + // simple_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline simple_content:: + simple_content () + { + } + + inline simple_content:: + simple_content (simple_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + + // complex_content + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline complex_content:: + complex_content () + { + } + + inline complex_content:: + complex_content (complex_content* impl, void*) + : empty_content (impl, 0) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/short.cxx b/libxsde/xsde/cxx/serializer/validating/short.cxx new file mode 100644 index 0000000..61e7132 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/short.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void short_simpl:: + pre (short value) + { + value_ = value; + } + + void short_simpl:: + _serialize_content () + { + // We only need strlen("-32768") + 1 characters to hold all + // representations of short. + // + char str[7]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 7, "%d", value_); +#else + int n = sprintf (str, "%d", value_); +#endif + if (n > 0 && n < 7) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_short_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/short.hxx b/libxsde/xsde/cxx/serializer/validating/short.hxx new file mode 100644 index 0000000..51da86f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/short.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_SHORT_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_SHORT_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 16-bit signed integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct short_simpl: virtual short_sskel +#else + struct short_simpl: short_sskel +#endif + { + virtual void + pre (short); + + virtual void + _serialize_content (); + + protected: + short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_SHORT_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/string-stl.cxx b/libxsde/xsde/cxx/serializer/validating/string-stl.cxx new file mode 100644 index 0000000..a70533f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/string-stl.cxx @@ -0,0 +1,35 @@ +// file : xsde/cxx/serializer/validating/string-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/string-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void string_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void string_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/string-stl.hxx b/libxsde/xsde/cxx/serializer/validating/string-stl.hxx new file mode 100644 index 0000000..74f55cc --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/string-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/string-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_STRING_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_STRING_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_simpl: virtual string_sskel +#else + struct string_simpl: string_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_STRING_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/string.cxx b/libxsde/xsde/cxx/serializer/validating/string.cxx new file mode 100644 index 0000000..b8a4068 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/string.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/string.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + string_simpl:: + ~string_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void string_simpl:: + pre (const char* value) + { + value_ = value; + } + + void string_simpl:: + _serialize_content () + { + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/string.hxx b/libxsde/xsde/cxx/serializer/validating/string.hxx new file mode 100644 index 0000000..5385355 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/string.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_STRING_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_STRING_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct string_simpl: virtual string_sskel +#else + struct string_simpl: string_sskel +#endif + { + virtual + ~string_simpl (); + + string_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/string.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_STRING_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/string.ixx b/libxsde/xsde/cxx/serializer/validating/string.ixx new file mode 100644 index 0000000..a23e517 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/string.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/string.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline string_simpl:: + string_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/time-zone.cxx b/libxsde/xsde/cxx/serializer/validating/time-zone.cxx new file mode 100644 index 0000000..ae28d70 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/time-zone.cxx @@ -0,0 +1,65 @@ +// file : xsde/cxx/serializer/validating/time-zone.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/config.hxx> + +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + namespace bits + { + int + serialize_time_zone (char* s, const time_zone& z) + { + // time-zone := Z|(+|-)HH:MM + // + + short h = z.zone_hours (); + short m = z.zone_minutes (); + + if (h == 0 && m == 0) + { + *s = 'Z'; + return 1; + } + else + { + const char* fmt = "+%.2u:%.2u"; + + if (h < 0) + { + fmt = "-%.2u:%.2u"; + h = -h; + m = -m; + } + + if (h >= 0 && h <= 14 && m >= 0 && m <= 59) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (s, 7, fmt, h, m); +#else + int n = sprintf (s, fmt, h, m); +#endif + if (n > 0 && n < 7) + return n; + } + + return 0; + } + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/time-zone.hxx b/libxsde/xsde/cxx/serializer/validating/time-zone.hxx new file mode 100644 index 0000000..27784cf --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/time-zone.hxx @@ -0,0 +1,40 @@ +// file : xsde/cxx/serializer/validating/time-zone.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_TIME_ZONE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_TIME_ZONE_HXX + +#include <xsde/cxx/date-time.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + namespace bits + { + bool + valid_time_zone (const time_zone&); + + // Returns 0 in case of a failure and the number of + // characters written otherwise. The buffer should + // have space for at least 7 characters. Note that + // this function expects that the time zone was + // verified by valid_time_zone() above. + // + int + serialize_time_zone (char* s, const time_zone&); + } + } + } + } +} + +#include <xsde/cxx/serializer/validating/time-zone.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_TIME_ZONE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/time-zone.ixx b/libxsde/xsde/cxx/serializer/validating/time-zone.ixx new file mode 100644 index 0000000..c6e80f4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/time-zone.ixx @@ -0,0 +1,32 @@ +// file : xsde/cxx/serializer/validating/time-zone.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + namespace bits + { + inline bool + valid_time_zone (const time_zone& z) + { + short h = z.zone_hours (); + short m = z.zone_minutes (); + + unsigned short ah = h < 0 ? -h : h; + unsigned short am = m < 0 ? -m : m; + + return ((h <= 0 && m <= 0) || (h >= 0 && m >= 0)) && + ((ah < 14 && am < 60) || (ah == 14 && am == 0)); + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/time.cxx b/libxsde/xsde/cxx/serializer/validating/time.cxx new file mode 100644 index 0000000..5ab5c22 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/time.cxx @@ -0,0 +1,79 @@ +// file : xsde/cxx/serializer/validating/time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/time.hxx> +#include <xsde/cxx/serializer/validating/time-zone.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void time_simpl:: + pre (const time& value) + { + value_ = value; + } + + void time_simpl:: + _serialize_content () + { + // We only need strlen("hh:mm:ss.ssssss-hh:mm") + 1 characters to + // hold all representations of time. We know that the seconds + // part (represented as double) has default precision of 6. + // + char str[22]; + + unsigned short h = value_.hours (); + unsigned short m = value_.minutes (); + double s = value_.seconds (); + + if (((h < 24 && m < 60 && s >= 0.0 && s < 60.0) || + (h == 24 && m == 0 && s == 0.0)) && + (!value_.zone_present () || bits::valid_time_zone (value_))) + { +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 16, "%.2u:%.2u:%09f", h, m, s); +#else + int n = sprintf (str, "%.2u:%.2u:%09f", h, m, s); +#endif + if (n > 0 && n < 16) + { + // Remove trailing '0' and '.' if necessary. + // + while (str[n - 1] == '0') + n--; + + if (str[n - 1] == '.') + n--; + + if (value_.zone_present ()) + { + if (int z = bits::serialize_time_zone (str + n, value_)) + n += z; + else + { + _schema_error (schema_error::invalid_time_value); + return; + } + } + + _characters (str, static_cast<size_t> (n)); + } + else + _schema_error (schema_error::invalid_time_value); + } + else + _schema_error (schema_error::invalid_time_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/time.hxx b/libxsde/xsde/cxx/serializer/validating/time.hxx new file mode 100644 index 0000000..1eedc7a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/time.hxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/serializer/validating/time.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_TIME_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_TIME_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct time_simpl: virtual time_sskel +#else + struct time_simpl: time_sskel +#endif + { + time_simpl (); + + virtual void + pre (const time&); + + virtual void + _serialize_content (); + + protected: + time value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/time.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_TIME_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/time.ixx b/libxsde/xsde/cxx/serializer/validating/time.ixx new file mode 100644 index 0000000..5262419 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/time.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/time.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline time_simpl:: + time_simpl () + : value_ (0, 0, 0.0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/token-stl.cxx b/libxsde/xsde/cxx/serializer/validating/token-stl.cxx new file mode 100644 index 0000000..0de2a54 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/token-stl.cxx @@ -0,0 +1,58 @@ +// file : xsde/cxx/serializer/validating/token-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/token-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void token_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void token_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + bool ok = true; + const char* s = tmp.c_str (); + + // No leading whitespaces. + // + if (*s == 0x20) + ok = false; + + for (; ok && *s != '\0'; ++s) + { + if (*s == 0x0A || *s == 0x0D || *s == 0x09 || + (*s == 0x20 && *(s + 1) == 0x20)) + ok = false; + } + + // No trailing whitespaces. + // + if (ok && s != tmp.c_str () && *(s - 1) == 0x20) + ok = false; + + if (ok) + _characters (tmp.c_str (), tmp.size ()); + else + _schema_error (schema_error::invalid_token_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/token-stl.hxx b/libxsde/xsde/cxx/serializer/validating/token-stl.hxx new file mode 100644 index 0000000..6de5f1e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/token-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/token-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_TOKEN_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_TOKEN_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_simpl: virtual token_sskel +#else + struct token_simpl: token_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_TOKEN_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/token.cxx b/libxsde/xsde/cxx/serializer/validating/token.cxx new file mode 100644 index 0000000..76bbce4 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/token.cxx @@ -0,0 +1,66 @@ +// file : xsde/cxx/serializer/validating/token.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/token.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + token_simpl:: + ~token_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void token_simpl:: + pre (const char* value) + { + value_ = value; + } + + void token_simpl:: + _serialize_content () + { + bool ok = true; + const char* s = value_; + + // No leading whitespaces. + // + if (*s == 0x20) + ok = false; + + for (; ok && *s != '\0'; ++s) + { + if (*s == 0x0A || *s == 0x0D || *s == 0x09 || + (*s == 0x20 && *(s + 1) == 0x20)) + ok = false; + } + + // No trailing whitespaces. + // + if (ok && s != value_ && *(s - 1) == 0x20) + ok = false; + + if (ok) + _characters (value_); + else + _schema_error (schema_error::invalid_token_value); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/token.hxx b/libxsde/xsde/cxx/serializer/validating/token.hxx new file mode 100644 index 0000000..3b3c099 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/token.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/token.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_TOKEN_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_TOKEN_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_simpl: virtual token_sskel +#else + struct token_simpl: token_sskel +#endif + { + virtual + ~token_simpl (); + + token_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/token.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_TOKEN_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/token.ixx b/libxsde/xsde/cxx/serializer/validating/token.ixx new file mode 100644 index 0000000..30d119c --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/token.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/token.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline token_simpl:: + token_simpl (bool free) + : free_ (free) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx new file mode 100644 index 0000000..97b45f3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/unsigned-byte.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/unsigned-byte.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void unsigned_byte_simpl:: + pre (unsigned char value) + { + value_ = value; + } + + void unsigned_byte_simpl:: + _serialize_content () + { + // We only need strlen("256") + 1 characters to hold all + // representations of unsigned byte. + // + char str[4]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 4, "%u", value_); +#else + int n = sprintf (str, "%u", value_); +#endif + if (n > 0 && n < 4) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_unsigned_byte_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-byte.hxx b/libxsde/xsde/cxx/serializer/validating/unsigned-byte.hxx new file mode 100644 index 0000000..1afa8db --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-byte.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/unsigned-byte.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_BYTE_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_BYTE_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 8-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_byte_simpl: virtual unsigned_byte_sskel +#else + struct unsigned_byte_simpl: unsigned_byte_sskel +#endif + { + virtual void + pre (unsigned char); + + virtual void + _serialize_content (); + + protected: + unsigned char value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_BYTE_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx new file mode 100644 index 0000000..14e478f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/unsigned-int.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/unsigned-int.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void unsigned_int_simpl:: + pre (unsigned int value) + { + value_ = value; + } + + void unsigned_int_simpl:: + _serialize_content () + { + // We only need strlen("4294967295") + 1 characters to hold all + // representations of unsigned int. + // + char str[11]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 11, "%u", value_); +#else + int n = sprintf (str, "%u", value_); +#endif + if (n > 0 && n < 11) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_unsigned_int_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-int.hxx b/libxsde/xsde/cxx/serializer/validating/unsigned-int.hxx new file mode 100644 index 0000000..fb103cd --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-int.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/unsigned-int.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_INT_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_INT_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 32-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_int_simpl: virtual unsigned_int_sskel +#else + struct unsigned_int_simpl: unsigned_int_sskel +#endif + { + virtual void + pre (unsigned int); + + virtual void + _serialize_content (); + + protected: + unsigned int value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_INT_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-long-long.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-long-long.cxx new file mode 100644 index 0000000..3520b31 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-long-long.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/unsigned-long-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/unsigned-long-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void unsigned_long_simpl:: + pre (unsigned long long value) + { + value_ = value; + } + + void unsigned_long_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of unsigned long long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%llu", value_); +#else + int n = sprintf (str, "%llu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_unsigned_long_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-long-long.hxx b/libxsde/xsde/cxx/serializer/validating/unsigned-long-long.hxx new file mode 100644 index 0000000..8a746e3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-long-long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/unsigned-long-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_LONG_LONG_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_LONG_LONG_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 64-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_simpl: virtual unsigned_long_sskel +#else + struct unsigned_long_simpl: unsigned_long_sskel +#endif + { + virtual void + pre (unsigned long long); + + virtual void + _serialize_content (); + + protected: + unsigned long long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_LONG_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-long.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-long.cxx new file mode 100644 index 0000000..b34d8aa --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-long.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/unsigned-long.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/unsigned-long.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void unsigned_long_simpl:: + pre (unsigned long value) + { + value_ = value; + } + + void unsigned_long_simpl:: + _serialize_content () + { + // We only need strlen("18446744073709551615") + 1 characters to + // hold all representations of (possibly 64-bit) unsigned long. + // + char str[21]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 21, "%lu", value_); +#else + int n = sprintf (str, "%lu", value_); +#endif + if (n > 0 && n < 21) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_unsigned_long_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-long.hxx b/libxsde/xsde/cxx/serializer/validating/unsigned-long.hxx new file mode 100644 index 0000000..2659ef1 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-long.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/unsigned-long.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_LONG_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_LONG_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // Fall-back implementation when 64 bit long long is not available. + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_long_simpl: virtual unsigned_long_sskel +#else + struct unsigned_long_simpl: unsigned_long_sskel +#endif + { + virtual void + pre (unsigned long); + + virtual void + _serialize_content (); + + protected: + unsigned long value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_LONG_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx new file mode 100644 index 0000000..d9bb308 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx @@ -0,0 +1,45 @@ +// file : xsde/cxx/serializer/validating/unsigned-short.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <stdio.h> // sprintf/snprintf + +#include <xsde/cxx/serializer/validating/unsigned-short.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void unsigned_short_simpl:: + pre (unsigned short value) + { + value_ = value; + } + + void unsigned_short_simpl:: + _serialize_content () + { + // We only need strlen("65535") + 1 characters to hold all + // representations of short. + // + char str[6]; + +#ifdef XSDE_SNPRINTF + int n = snprintf (str, 6, "%u", value_); +#else + int n = sprintf (str, "%u", value_); +#endif + if (n > 0 && n < 6) + _characters (str, static_cast<size_t> (n)); + else + _schema_error (schema_error::invalid_unsigned_short_value); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-short.hxx b/libxsde/xsde/cxx/serializer/validating/unsigned-short.hxx new file mode 100644 index 0000000..902d75e --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/unsigned-short.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/unsigned-short.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_SHORT_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_SHORT_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // 16-bit unsigned integer + // +#ifdef XSDE_REUSE_STYLE_MIXIN + struct unsigned_short_simpl: virtual unsigned_short_sskel +#else + struct unsigned_short_simpl: unsigned_short_sskel +#endif + { + virtual void + pre (unsigned short); + + virtual void + _serialize_content (); + + protected: + unsigned short value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_UNSIGNED_SHORT_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/uri-stl.cxx b/libxsde/xsde/cxx/serializer/validating/uri-stl.cxx new file mode 100644 index 0000000..d22c992 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/uri-stl.cxx @@ -0,0 +1,39 @@ +// file : xsde/cxx/serializer/validating/uri-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/uri-stl.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void uri_simpl:: + pre (const std::string& value) + { + value_ = value; + } + + void uri_simpl:: + _serialize_content () + { + // Make sure we don't hold any references to the string. + // + std::string tmp; + tmp.swap (value_); + + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + _characters (tmp.c_str (), tmp.size ()); + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/uri-stl.hxx b/libxsde/xsde/cxx/serializer/validating/uri-stl.hxx new file mode 100644 index 0000000..4de5922 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/uri-stl.hxx @@ -0,0 +1,41 @@ +// file : xsde/cxx/serializer/validating/uri-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_URI_STL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_URI_STL_HXX + +#include <string> + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_simpl: virtual uri_sskel +#else + struct uri_simpl: uri_sskel +#endif + { + virtual void + pre (const std::string&); + + virtual void + _serialize_content (); + + protected: + std::string value_; + }; + } + } + } +} + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_URI_STL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/uri.cxx b/libxsde/xsde/cxx/serializer/validating/uri.cxx new file mode 100644 index 0000000..46148d3 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/uri.cxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/uri.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/uri.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + uri_simpl:: + ~uri_simpl () + { + if (free_) + delete[] const_cast<char*> (value_); + } + + void uri_simpl:: + pre (const char* value) + { + value_ = value; + } + + void uri_simpl:: + _serialize_content () + { + // According to Datatypes 3.2.17 and RFC2396 pretty much anything + // can be a URI and conforming processors do not need to figure + // out and verify particular URI schemes. + // + _characters (value_); + + if (free_) + { + delete[] const_cast<char*> (value_); + value_ = 0; + } + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/uri.hxx b/libxsde/xsde/cxx/serializer/validating/uri.hxx new file mode 100644 index 0000000..63b502a --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/uri.hxx @@ -0,0 +1,47 @@ +// file : xsde/cxx/serializer/validating/uri.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_URI_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_URI_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { +#ifdef XSDE_REUSE_STYLE_MIXIN + struct uri_simpl: virtual uri_sskel +#else + struct uri_simpl: uri_sskel +#endif + { + virtual + ~uri_simpl (); + + uri_simpl (bool free = false); + + virtual void + pre (const char*); + + virtual void + _serialize_content (); + + protected: + bool free_; + const char* value_; + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/uri.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_URI_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/uri.ixx b/libxsde/xsde/cxx/serializer/validating/uri.ixx new file mode 100644 index 0000000..6cbf6ae --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/uri.ixx @@ -0,0 +1,22 @@ +// file : xsde/cxx/serializer/validating/uri.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + inline uri_simpl:: + uri_simpl (bool free) + : free_ (free), value_ (0) + { + } + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/xml-schema-simpl.hxx b/libxsde/xsde/cxx/serializer/validating/xml-schema-simpl.hxx new file mode 100644 index 0000000..039722f --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/xml-schema-simpl.hxx @@ -0,0 +1,82 @@ +// file : xsde/cxx/serializer/validating/xml-schema-simpl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_XML_SCHEMA_SIMPL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_XML_SCHEMA_SIMPL_HXX + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +#include <xsde/cxx/serializer/validating/any-type.hxx> +#include <xsde/cxx/serializer/validating/boolean.hxx> +#include <xsde/cxx/serializer/validating/byte.hxx> +#include <xsde/cxx/serializer/validating/unsigned-byte.hxx> +#include <xsde/cxx/serializer/validating/byte.hxx> +#include <xsde/cxx/serializer/validating/unsigned-byte.hxx> +#include <xsde/cxx/serializer/validating/short.hxx> +#include <xsde/cxx/serializer/validating/unsigned-short.hxx> +#include <xsde/cxx/serializer/validating/int.hxx> +#include <xsde/cxx/serializer/validating/unsigned-int.hxx> + +#ifdef XSDE_LONGLONG +# include <xsde/cxx/serializer/validating/long-long.hxx> +# include <xsde/cxx/serializer/validating/unsigned-long-long.hxx> +#else +# include <xsde/cxx/serializer/validating/long.hxx> +# include <xsde/cxx/serializer/validating/unsigned-long.hxx> +#endif + +#include <xsde/cxx/serializer/validating/integer.hxx> +#include <xsde/cxx/serializer/validating/negative-integer.hxx> +#include <xsde/cxx/serializer/validating/non-positive-integer.hxx> +#include <xsde/cxx/serializer/validating/positive-integer.hxx> +#include <xsde/cxx/serializer/validating/non-negative-integer.hxx> +#include <xsde/cxx/serializer/validating/float.hxx> +#include <xsde/cxx/serializer/validating/double.hxx> +#include <xsde/cxx/serializer/validating/decimal.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/serializer/validating/string-stl.hxx> +# include <xsde/cxx/serializer/validating/normalized-string-stl.hxx> +# include <xsde/cxx/serializer/validating/token-stl.hxx> +# include <xsde/cxx/serializer/validating/name-stl.hxx> +# include <xsde/cxx/serializer/validating/nmtoken-stl.hxx> +# include <xsde/cxx/serializer/validating/nmtokens-stl.hxx> +# include <xsde/cxx/serializer/validating/ncname-stl.hxx> +# include <xsde/cxx/serializer/validating/id-stl.hxx> +# include <xsde/cxx/serializer/validating/idref-stl.hxx> +# include <xsde/cxx/serializer/validating/idrefs-stl.hxx> +# include <xsde/cxx/serializer/validating/language-stl.hxx> +# include <xsde/cxx/serializer/validating/uri-stl.hxx> +# include <xsde/cxx/serializer/validating/qname-stl.hxx> +#else +# include <xsde/cxx/serializer/validating/string.hxx> +# include <xsde/cxx/serializer/validating/normalized-string.hxx> +# include <xsde/cxx/serializer/validating/token.hxx> +# include <xsde/cxx/serializer/validating/name.hxx> +# include <xsde/cxx/serializer/validating/nmtoken.hxx> +# include <xsde/cxx/serializer/validating/nmtokens.hxx> +# include <xsde/cxx/serializer/validating/ncname.hxx> +# include <xsde/cxx/serializer/validating/id.hxx> +# include <xsde/cxx/serializer/validating/idref.hxx> +# include <xsde/cxx/serializer/validating/idrefs.hxx> +# include <xsde/cxx/serializer/validating/language.hxx> +# include <xsde/cxx/serializer/validating/uri.hxx> +# include <xsde/cxx/serializer/validating/qname.hxx> +#endif + +#include <xsde/cxx/serializer/validating/base64-binary.hxx> +#include <xsde/cxx/serializer/validating/hex-binary.hxx> + +#include <xsde/cxx/serializer/validating/gday.hxx> +#include <xsde/cxx/serializer/validating/gmonth.hxx> +#include <xsde/cxx/serializer/validating/gyear.hxx> +#include <xsde/cxx/serializer/validating/gmonth-day.hxx> +#include <xsde/cxx/serializer/validating/gyear-month.hxx> +#include <xsde/cxx/serializer/validating/date.hxx> +#include <xsde/cxx/serializer/validating/time.hxx> +#include <xsde/cxx/serializer/validating/date-time.hxx> +#include <xsde/cxx/serializer/validating/duration.hxx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_XML_SCHEMA_SIMPL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.cxx b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.cxx new file mode 100644 index 0000000..a18141b --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.cxx @@ -0,0 +1,560 @@ +// file : xsde/cxx/serializer/validating/xml-schema-sskel.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // any_type_sskel + // + void any_type_sskel:: + pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_type_impl_) + any_type_impl_->pre (); +#endif + } + + // any_simple_type_sskel + // + void any_simple_type_sskel:: + pre () + { +#ifdef XSDE_REUSE_STYLE_TIEIN + if (any_simple_type_impl_) + any_simple_type_impl_->pre (); +#endif + } + + // static/dynamic_type function implementations. + // +#ifdef XSDE_POLYMORPHIC + const char* any_type_sskel:: + _static_type () + { + return "anyType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_type_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* any_simple_type_sskel:: + _static_type () + { + return "anySimpleType http://www.w3.org/2001/XMLSchema"; + } + + const char* any_simple_type_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* boolean_sskel:: + _static_type () + { + return "boolean http://www.w3.org/2001/XMLSchema"; + } + + const char* boolean_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* byte_sskel:: + _static_type () + { + return "byte http://www.w3.org/2001/XMLSchema"; + } + + const char* byte_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_byte_sskel:: + _static_type () + { + return "unsignedByte http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_byte_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* short_sskel:: + _static_type () + { + return "short http://www.w3.org/2001/XMLSchema"; + } + + const char* short_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_short_sskel:: + _static_type () + { + return "unsignedShort http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_short_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* int_sskel:: + _static_type () + { + return "int http://www.w3.org/2001/XMLSchema"; + } + + const char* int_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_int_sskel:: + _static_type () + { + return "unsignedInt http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_int_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* long_sskel:: + _static_type () + { + return "long http://www.w3.org/2001/XMLSchema"; + } + + const char* long_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* unsigned_long_sskel:: + _static_type () + { + return "unsignedLong http://www.w3.org/2001/XMLSchema"; + } + + const char* unsigned_long_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* integer_sskel:: + _static_type () + { + return "integer http://www.w3.org/2001/XMLSchema"; + } + + const char* integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* negative_integer_sskel:: + _static_type () + { + return "negativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* negative_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_positive_integer_sskel:: + _static_type () + { + return "nonPositiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_positive_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* positive_integer_sskel:: + _static_type () + { + return "positiveInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* positive_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* non_negative_integer_sskel:: + _static_type () + { + return "nonNegativeInteger http://www.w3.org/2001/XMLSchema"; + } + + const char* non_negative_integer_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* float_sskel:: + _static_type () + { + return "float http://www.w3.org/2001/XMLSchema"; + } + + const char* float_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* double_sskel:: + _static_type () + { + return "double http://www.w3.org/2001/XMLSchema"; + } + + const char* double_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* decimal_sskel:: + _static_type () + { + return "decimal http://www.w3.org/2001/XMLSchema"; + } + + const char* decimal_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* string_sskel:: + _static_type () + { + return "string http://www.w3.org/2001/XMLSchema"; + } + + const char* string_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* normalized_string_sskel:: + _static_type () + { + return "normalizedString http://www.w3.org/2001/XMLSchema"; + } + + const char* normalized_string_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* token_sskel:: + _static_type () + { + return "token http://www.w3.org/2001/XMLSchema"; + } + + const char* token_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* name_sskel:: + _static_type () + { + return "Name http://www.w3.org/2001/XMLSchema"; + } + + const char* name_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtoken_sskel:: + _static_type () + { + return "NMTOKEN http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtoken_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* nmtokens_sskel:: + _static_type () + { + return "NMTOKENS http://www.w3.org/2001/XMLSchema"; + } + + const char* nmtokens_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* ncname_sskel:: + _static_type () + { + return "NCName http://www.w3.org/2001/XMLSchema"; + } + + const char* ncname_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* id_sskel:: + _static_type () + { + return "ID http://www.w3.org/2001/XMLSchema"; + } + + const char* id_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idref_sskel:: + _static_type () + { + return "IDREF http://www.w3.org/2001/XMLSchema"; + } + + const char* idref_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* idrefs_sskel:: + _static_type () + { + return "IDREFS http://www.w3.org/2001/XMLSchema"; + } + + const char* idrefs_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* language_sskel:: + _static_type () + { + return "language http://www.w3.org/2001/XMLSchema"; + } + + const char* language_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* uri_sskel:: + _static_type () + { + return "anyURI http://www.w3.org/2001/XMLSchema"; + } + + const char* uri_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* qname_sskel:: + _static_type () + { + return "QName http://www.w3.org/2001/XMLSchema"; + } + + const char* qname_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* base64_binary_sskel:: + _static_type () + { + return "base64Binary http://www.w3.org/2001/XMLSchema"; + } + + const char* base64_binary_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* hex_binary_sskel:: + _static_type () + { + return "hexBinary http://www.w3.org/2001/XMLSchema"; + } + + const char* hex_binary_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gday_sskel:: + _static_type () + { + return "gDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gday_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_sskel:: + _static_type () + { + return "gMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_sskel:: + _static_type () + { + return "gYear http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gmonth_day_sskel:: + _static_type () + { + return "gMonthDay http://www.w3.org/2001/XMLSchema"; + } + + const char* gmonth_day_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* gyear_month_sskel:: + _static_type () + { + return "gYearMonth http://www.w3.org/2001/XMLSchema"; + } + + const char* gyear_month_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_sskel:: + _static_type () + { + return "date http://www.w3.org/2001/XMLSchema"; + } + + const char* date_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* time_sskel:: + _static_type () + { + return "time http://www.w3.org/2001/XMLSchema"; + } + + const char* time_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* date_time_sskel:: + _static_type () + { + return "dateTime http://www.w3.org/2001/XMLSchema"; + } + + const char* date_time_sskel:: + _dynamic_type () const + { + return _static_type (); + } + + const char* duration_sskel:: + _static_type () + { + return "duration http://www.w3.org/2001/XMLSchema"; + } + + const char* duration_sskel:: + _dynamic_type () const + { + return _static_type (); + } +#endif // XSDE_POLYMORPHIC + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx new file mode 100644 index 0000000..9a158b0 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx @@ -0,0 +1,1382 @@ +// file : xsde/cxx/serializer/validating/xml-schema-sskel.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_VALIDATING_XML_SCHEMA_SSKEL_HXX +#define XSDE_CXX_SERIALIZER_VALIDATING_XML_SCHEMA_SSKEL_HXX + +#include <xsde/cxx/config.hxx> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/serializer/xml-schema.hxx> + +#include <xsde/cxx/serializer/validating/serializer.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // anyType and anySimpleType. + // + struct any_type_sskel: complex_content + { + virtual void + pre (); + + // Override the following two functions to implement + // your logic. + // + + // virtual void + // _serialize_attributes (); + + // virtual void + // _serialize_content (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_type_sskel (); + any_type_sskel (any_type_sskel* impl, void*); + + protected: + any_type_sskel* any_type_impl_; +#endif + }; + + struct any_simple_type_sskel: simple_content + { + virtual void + pre (); + + // Override the following function to implement your + // logic. + // + + // virtual void + // _serialize_content (); + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + any_simple_type_sskel (); + any_simple_type_sskel (any_simple_type_sskel* impl, void*); + + protected: + any_simple_type_sskel* any_simple_type_impl_; +#endif + }; + + // Boolean. + // + struct boolean_sskel: simple_content + { + virtual void + pre (bool) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + boolean_sskel (); + boolean_sskel (boolean_sskel* impl, void*); + + protected: + boolean_sskel* boolean_impl_; +#endif + }; + + // 8-bit + // + + struct byte_sskel: simple_content + { + virtual void + pre (signed char) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + byte_sskel (); + byte_sskel (byte_sskel* impl, void*); + + protected: + byte_sskel* byte_impl_; +#endif + }; + + struct unsigned_byte_sskel: simple_content + { + virtual void + pre (unsigned char) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_byte_sskel (); + unsigned_byte_sskel (unsigned_byte_sskel* impl, void*); + + protected: + unsigned_byte_sskel* unsigned_byte_impl_; +#endif + }; + + + // 16-bit + // + + struct short_sskel: simple_content + { + virtual void + pre (short) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + short_sskel (); + short_sskel (short_sskel* impl, void*); + + protected: + short_sskel* short_impl_; +#endif + }; + + struct unsigned_short_sskel: simple_content + { + virtual void + pre (unsigned short) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_short_sskel (); + unsigned_short_sskel (unsigned_short_sskel* impl, void*); + + protected: + unsigned_short_sskel* unsigned_short_impl_; +#endif + }; + + // 32-bit + // + + struct int_sskel: simple_content + { + virtual void + pre (int) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + int_sskel (); + int_sskel (int_sskel* impl, void*); + + protected: + int_sskel* int_impl_; +#endif + }; + + struct unsigned_int_sskel: simple_content + { + virtual void + pre (unsigned int) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_int_sskel (); + unsigned_int_sskel (unsigned_int_sskel* impl, void*); + + protected: + unsigned_int_sskel* unsigned_int_impl_; +#endif + }; + + // 64-bit + // + +#ifdef XSDE_LONGLONG + struct long_sskel: simple_content + { + virtual void + pre (long long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_sskel (); + long_sskel (long_sskel* impl, void*); + + protected: + long_sskel* long_impl_; +#endif + }; + + struct unsigned_long_sskel: simple_content + { + virtual void + pre (unsigned long long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_sskel (); + unsigned_long_sskel (unsigned_long_sskel* impl, void*); + + protected: + unsigned_long_sskel* unsigned_long_impl_; +#endif + }; +#else + struct long_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + long_sskel (); + long_sskel (long_sskel* impl, void*); + + protected: + long_sskel* long_impl_; +#endif + }; + + struct unsigned_long_sskel: simple_content + { + virtual void + pre (unsigned long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + unsigned_long_sskel (); + unsigned_long_sskel (unsigned_long_sskel* impl, void*); + + protected: + unsigned_long_sskel* unsigned_long_impl_; +#endif + }; +#endif + + // Arbitrary-length integers. + // + + struct integer_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + integer_sskel (); + integer_sskel (integer_sskel* impl, void*); + + protected: + integer_sskel* integer_impl_; +#endif + }; + + struct negative_integer_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + negative_integer_sskel (); + negative_integer_sskel (negative_integer_sskel* impl, void*); + + protected: + negative_integer_sskel* negative_integer_impl_; +#endif + }; + + struct non_positive_integer_sskel: simple_content + { + virtual void + pre (long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_positive_integer_sskel (); + non_positive_integer_sskel (non_positive_integer_sskel* impl, void*); + + protected: + non_positive_integer_sskel* non_positive_integer_impl_; +#endif + }; + + struct positive_integer_sskel: simple_content + { + virtual void + pre (unsigned long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + positive_integer_sskel (); + positive_integer_sskel (positive_integer_sskel* impl, void*); + + protected: + positive_integer_sskel* positive_integer_impl_; +#endif + }; + + struct non_negative_integer_sskel: simple_content + { + virtual void + pre (unsigned long) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + non_negative_integer_sskel (); + non_negative_integer_sskel (non_negative_integer_sskel* impl, void*); + + protected: + non_negative_integer_sskel* non_negative_integer_impl_; +#endif + }; + + // Floats. + // + + struct float_sskel: simple_content + { + virtual void + pre (float) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + float_sskel (); + float_sskel (float_sskel* impl, void*); + + protected: + float_sskel* float_impl_; +#endif + }; + + struct double_sskel: simple_content + { + virtual void + pre (double) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + double_sskel (); + double_sskel (double_sskel* impl, void*); + + protected: + double_sskel* double_impl_; +#endif + }; + + struct decimal_sskel: simple_content + { + virtual void + pre (double) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + decimal_sskel (); + decimal_sskel (decimal_sskel* impl, void*); + + protected: + decimal_sskel* decimal_impl_; +#endif + }; + + // String-based types. + // +#ifdef XSDE_STL + + struct string_sskel: simple_content + { + virtual void + pre (const std::string&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_sskel (); + string_sskel (string_sskel* impl, void*); + + protected: + string_sskel* string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_sskel: virtual string_sskel +#else + struct normalized_string_sskel: string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_sskel (); + normalized_string_sskel (normalized_string_sskel* impl, void*); + + protected: + normalized_string_sskel* normalized_string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_sskel: virtual normalized_string_sskel +#else + struct token_sskel: normalized_string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_sskel (); + token_sskel (token_sskel* impl, void*); + + protected: + token_sskel* token_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_sskel: virtual token_sskel +#else + struct name_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_sskel (); + name_sskel (name_sskel* impl, void*); + + protected: + name_sskel* name_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_sskel: virtual token_sskel +#else + struct nmtoken_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_sskel (); + nmtoken_sskel (nmtoken_sskel* impl, void*); + + protected: + nmtoken_sskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_sskel (); + nmtokens_sskel (nmtokens_sskel* impl, void*); + + protected: + nmtokens_sskel* nmtokens_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_sskel: virtual name_sskel +#else + struct ncname_sskel: name_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_sskel (); + ncname_sskel (ncname_sskel* impl, void*); + + protected: + ncname_sskel* ncname_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_sskel: virtual ncname_sskel +#else + struct id_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_sskel (); + id_sskel (id_sskel* impl, void*); + + protected: + id_sskel* id_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_sskel: virtual ncname_sskel +#else + struct idref_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_sskel (); + idref_sskel (idref_sskel* impl, void*); + + protected: + idref_sskel* idref_impl_; +#endif + }; + + struct idrefs_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_sskel (); + idrefs_sskel (idrefs_sskel* impl, void*); + + protected: + idrefs_sskel* idrefs_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_sskel: virtual token_sskel +#else + struct language_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_sskel (); + language_sskel (language_sskel* impl, void*); + + protected: + language_sskel* language_impl_; +#endif + }; + + struct uri_sskel: simple_content + { + virtual void + pre (const std::string&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_sskel (); + uri_sskel (uri_sskel* impl, void*); + + protected: + uri_sskel* uri_impl_; +#endif + }; + + struct qname_sskel: simple_content + { + virtual void + pre (const qname&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_sskel (); + qname_sskel (qname_sskel* impl, void*); + + protected: + qname_sskel* qname_impl_; +#endif + }; + +#else // XSDE_STL + + struct string_sskel: simple_content + { + virtual void + pre (const char*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + string_sskel (); + string_sskel (string_sskel* impl, void*); + + protected: + string_sskel* string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct normalized_string_sskel: virtual string_sskel +#else + struct normalized_string_sskel: string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + normalized_string_sskel (); + normalized_string_sskel (normalized_string_sskel* impl, void*); + + protected: + normalized_string_sskel* normalized_string_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct token_sskel: virtual normalized_string_sskel +#else + struct token_sskel: normalized_string_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + token_sskel (); + token_sskel (token_sskel* impl, void*); + + protected: + token_sskel* token_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct name_sskel: virtual token_sskel +#else + struct name_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + name_sskel (); + name_sskel (name_sskel* impl, void*); + + protected: + name_sskel* name_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct nmtoken_sskel: virtual token_sskel +#else + struct nmtoken_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtoken_sskel (); + nmtoken_sskel (nmtoken_sskel* impl, void*); + + protected: + nmtoken_sskel* nmtoken_impl_; +#endif + }; + + struct nmtokens_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + nmtokens_sskel (); + nmtokens_sskel (nmtokens_sskel* impl, void*); + + protected: + nmtokens_sskel* nmtokens_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct ncname_sskel: virtual name_sskel +#else + struct ncname_sskel: name_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + ncname_sskel (); + ncname_sskel (ncname_sskel* impl, void*); + + protected: + ncname_sskel* ncname_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct id_sskel: virtual ncname_sskel +#else + struct id_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + id_sskel (); + id_sskel (id_sskel* impl, void*); + + protected: + id_sskel* id_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct idref_sskel: virtual ncname_sskel +#else + struct idref_sskel: ncname_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idref_sskel (); + idref_sskel (idref_sskel* impl, void*); + + protected: + idref_sskel* idref_impl_; +#endif + }; + + struct idrefs_sskel: simple_content + { + virtual void + pre (const string_sequence*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + idrefs_sskel (); + idrefs_sskel (idrefs_sskel* impl, void*); + + protected: + idrefs_sskel* idrefs_impl_; +#endif + }; + +#ifdef XSDE_REUSE_STYLE_MIXIN + struct language_sskel: virtual token_sskel +#else + struct language_sskel: token_sskel +#endif + { +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + language_sskel (); + language_sskel (language_sskel* impl, void*); + + protected: + language_sskel* language_impl_; +#endif + }; + + struct uri_sskel: simple_content + { + virtual void + pre (const char*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + uri_sskel (); + uri_sskel (uri_sskel* impl, void*); + + protected: + uri_sskel* uri_impl_; +#endif + }; + + struct qname_sskel: simple_content + { + virtual void + pre (const qname*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + qname_sskel (); + qname_sskel (qname_sskel* impl, void*); + + protected: + qname_sskel* qname_impl_; +#endif + }; + +#endif // XSDE_STL + + + // base64Binary + // + struct base64_binary_sskel: simple_content + { + virtual void + pre (const buffer*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + base64_binary_sskel (); + base64_binary_sskel (base64_binary_sskel* impl, void*); + + protected: + base64_binary_sskel* base64_binary_impl_; +#endif + }; + + // hexBinary + // + struct hex_binary_sskel: simple_content + { + virtual void + pre (const buffer*) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + hex_binary_sskel (); + hex_binary_sskel (hex_binary_sskel* impl, void*); + + protected: + hex_binary_sskel* hex_binary_impl_; +#endif + }; + + // Time and date types. + // + struct gday_sskel: simple_content + { + virtual void + pre (const gday&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gday_sskel (); + gday_sskel (gday_sskel* impl, void*); + + protected: + gday_sskel* gday_impl_; +#endif + }; + + struct gmonth_sskel: simple_content + { + virtual void + pre (const gmonth&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_sskel (); + gmonth_sskel (gmonth_sskel* impl, void*); + + protected: + gmonth_sskel* gmonth_impl_; +#endif + }; + + struct gyear_sskel: simple_content + { + virtual void + pre (const gyear&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_sskel (); + gyear_sskel (gyear_sskel* impl, void*); + + protected: + gyear_sskel* gyear_impl_; +#endif + }; + + struct gmonth_day_sskel: simple_content + { + virtual void + pre (const gmonth_day&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gmonth_day_sskel (); + gmonth_day_sskel (gmonth_day_sskel* impl, void*); + + protected: + gmonth_day_sskel* gmonth_day_impl_; +#endif + }; + + struct gyear_month_sskel: simple_content + { + virtual void + pre (const gyear_month&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + gyear_month_sskel (); + gyear_month_sskel (gyear_month_sskel* impl, void*); + + protected: + gyear_month_sskel* gyear_month_impl_; +#endif + }; + + struct date_sskel: simple_content + { + virtual void + pre (const date&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_sskel (); + date_sskel (date_sskel* impl, void*); + + protected: + date_sskel* date_impl_; +#endif + }; + + struct time_sskel: simple_content + { + virtual void + pre (const time&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + time_sskel (); + time_sskel (time_sskel* impl, void*); + + protected: + time_sskel* time_impl_; +#endif + }; + + struct date_time_sskel: simple_content + { + virtual void + pre (const date_time&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + date_time_sskel (); + date_time_sskel (date_time_sskel* impl, void*); + + protected: + date_time_sskel* date_time_impl_; +#endif + }; + + struct duration_sskel: simple_content + { + virtual void + pre (const duration&) = 0; + +#ifdef XSDE_POLYMORPHIC + static const char* + _static_type (); + + virtual const char* + _dynamic_type () const; +#endif + +#ifdef XSDE_REUSE_STYLE_TIEIN + duration_sskel (); + duration_sskel (duration_sskel* impl, void*); + + protected: + duration_sskel* duration_impl_; +#endif + }; + } + } + } +} + +#include <xsde/cxx/serializer/validating/xml-schema-sskel.ixx> + +#endif // XSDE_CXX_SERIALIZER_VALIDATING_XML_SCHEMA_SSKEL_HXX diff --git a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx new file mode 100644 index 0000000..23647b5 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx @@ -0,0 +1,704 @@ +// file : xsde/cxx/serializer/validating/xml-schema-sskel.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + // any_type_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_type_sskel:: + any_type_sskel () + : any_type_impl_ (0) + { + } + + inline any_type_sskel:: + any_type_sskel (any_type_sskel* impl, void*) + : complex_content (impl, 0), any_type_impl_ (impl) + { + } +#endif + + // any_simple_type_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline any_simple_type_sskel:: + any_simple_type_sskel () + : any_simple_type_impl_ (0) + { + } + + inline any_simple_type_sskel:: + any_simple_type_sskel (any_simple_type_sskel* impl, void*) + : simple_content (impl, 0), any_simple_type_impl_ (impl) + { + } +#endif + + // boolean_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline boolean_sskel:: + boolean_sskel () + : boolean_impl_ (0) + { + } + + inline boolean_sskel:: + boolean_sskel (boolean_sskel* impl, void*) + : simple_content (impl, 0), boolean_impl_ (impl) + { + } +#endif + + // byte_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline byte_sskel:: + byte_sskel () + : byte_impl_ (0) + { + } + + inline byte_sskel:: + byte_sskel (byte_sskel* impl, void*) + : simple_content (impl, 0), byte_impl_ (impl) + { + } +#endif + + // unsigned_byte_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_byte_sskel:: + unsigned_byte_sskel () + : unsigned_byte_impl_ (0) + { + } + + inline unsigned_byte_sskel:: + unsigned_byte_sskel (unsigned_byte_sskel* impl, void*) + : simple_content (impl, 0), unsigned_byte_impl_ (impl) + { + } +#endif + + // short_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline short_sskel:: + short_sskel () + : short_impl_ (0) + { + } + + inline short_sskel:: + short_sskel (short_sskel* impl, void*) + : simple_content (impl, 0), short_impl_ (impl) + { + } +#endif + + // unsigned_short_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_short_sskel:: + unsigned_short_sskel () + : unsigned_short_impl_ (0) + { + } + + inline unsigned_short_sskel:: + unsigned_short_sskel (unsigned_short_sskel* impl, void*) + : simple_content (impl, 0), unsigned_short_impl_ (impl) + { + } +#endif + + // int_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline int_sskel:: + int_sskel () + : int_impl_ (0) + { + } + + inline int_sskel:: + int_sskel (int_sskel* impl, void*) + : simple_content (impl, 0), int_impl_ (impl) + { + } +#endif + + // unsigned_int_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_int_sskel:: + unsigned_int_sskel () + : unsigned_int_impl_ (0) + { + } + + inline unsigned_int_sskel:: + unsigned_int_sskel (unsigned_int_sskel* impl, void*) + : simple_content (impl, 0), unsigned_int_impl_ (impl) + { + } +#endif + + // long_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline long_sskel:: + long_sskel () + : long_impl_ (0) + { + } + + inline long_sskel:: + long_sskel (long_sskel* impl, void*) + : simple_content (impl, 0), long_impl_ (impl) + { + } +#endif + + // unsigned_long_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline unsigned_long_sskel:: + unsigned_long_sskel () + : unsigned_long_impl_ (0) + { + } + + inline unsigned_long_sskel:: + unsigned_long_sskel (unsigned_long_sskel* impl, void*) + : simple_content (impl, 0), unsigned_long_impl_ (impl) + { + } +#endif + + // integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline integer_sskel:: + integer_sskel () + : integer_impl_ (0) + { + } + + inline integer_sskel:: + integer_sskel (integer_sskel* impl, void*) + : simple_content (impl, 0), integer_impl_ (impl) + { + } +#endif + + // negative_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline negative_integer_sskel:: + negative_integer_sskel () + : negative_integer_impl_ (0) + { + } + + inline negative_integer_sskel:: + negative_integer_sskel (negative_integer_sskel* impl, void*) + : simple_content (impl, 0), negative_integer_impl_ (impl) + { + } +#endif + + // non_positive_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_positive_integer_sskel:: + non_positive_integer_sskel () + : non_positive_integer_impl_ (0) + { + } + + inline non_positive_integer_sskel:: + non_positive_integer_sskel (non_positive_integer_sskel* impl, void*) + : simple_content (impl, 0), non_positive_integer_impl_ (impl) + { + } +#endif + + // positive_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline positive_integer_sskel:: + positive_integer_sskel () + : positive_integer_impl_ (0) + { + } + + inline positive_integer_sskel:: + positive_integer_sskel (positive_integer_sskel* impl, void*) + : simple_content (impl, 0), positive_integer_impl_ (impl) + { + } +#endif + + // non_negative_integer_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline non_negative_integer_sskel:: + non_negative_integer_sskel () + : non_negative_integer_impl_ (0) + { + } + + inline non_negative_integer_sskel:: + non_negative_integer_sskel (non_negative_integer_sskel* impl, void*) + : simple_content (impl, 0), non_negative_integer_impl_ (impl) + { + } +#endif + + // float_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline float_sskel:: + float_sskel () + : float_impl_ (0) + { + } + + inline float_sskel:: + float_sskel (float_sskel* impl, void*) + : simple_content (impl, 0), float_impl_ (impl) + { + } +#endif + + // double_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline double_sskel:: + double_sskel () + : double_impl_ (0) + { + } + + inline double_sskel:: + double_sskel (double_sskel* impl, void*) + : simple_content (impl, 0), double_impl_ (impl) + { + } +#endif + + // decimal_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline decimal_sskel:: + decimal_sskel () + : decimal_impl_ (0) + { + } + + inline decimal_sskel:: + decimal_sskel (decimal_sskel* impl, void*) + : simple_content (impl, 0), decimal_impl_ (impl) + { + } +#endif + + // string_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline string_sskel:: + string_sskel () + : string_impl_ (0) + { + } + + inline string_sskel:: + string_sskel (string_sskel* impl, void*) + : simple_content (impl, 0), string_impl_ (impl) + { + } +#endif + + // normalized_string_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline normalized_string_sskel:: + normalized_string_sskel () + : normalized_string_impl_ (0) + { + } + + inline normalized_string_sskel:: + normalized_string_sskel (normalized_string_sskel* impl, void*) + : string_sskel (impl, 0), normalized_string_impl_ (impl) + { + } +#endif + + // token_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline token_sskel:: + token_sskel () + : token_impl_ (0) + { + } + + inline token_sskel:: + token_sskel (token_sskel* impl, void*) + : normalized_string_sskel (impl, 0), token_impl_ (impl) + { + } +#endif + + // name_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline name_sskel:: + name_sskel () + : name_impl_ (0) + { + } + + inline name_sskel:: + name_sskel (name_sskel* impl, void*) + : token_sskel (impl, 0), name_impl_ (impl) + { + } +#endif + + // nmtoken_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtoken_sskel:: + nmtoken_sskel () + : nmtoken_impl_ (0) + { + } + + inline nmtoken_sskel:: + nmtoken_sskel (nmtoken_sskel* impl, void*) + : token_sskel (impl, 0), nmtoken_impl_ (impl) + { + } +#endif + + // nmtokens_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline nmtokens_sskel:: + nmtokens_sskel () + : nmtokens_impl_ (0) + { + } + + inline nmtokens_sskel:: + nmtokens_sskel (nmtokens_sskel* impl, void*) + : simple_content (impl, 0), nmtokens_impl_ (impl) + { + } +#endif + + // ncname_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline ncname_sskel:: + ncname_sskel () + : ncname_impl_ (0) + { + } + + inline ncname_sskel:: + ncname_sskel (ncname_sskel* impl, void*) + : name_sskel (impl, 0), ncname_impl_ (impl) + { + } +#endif + + // id_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline id_sskel:: + id_sskel () + : id_impl_ (0) + { + } + + inline id_sskel:: + id_sskel (id_sskel* impl, void*) + : ncname_sskel (impl, 0), id_impl_ (impl) + { + } +#endif + + // idref_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idref_sskel:: + idref_sskel () + : idref_impl_ (0) + { + } + + inline idref_sskel:: + idref_sskel (idref_sskel* impl, void*) + : ncname_sskel (impl, 0), idref_impl_ (impl) + { + } +#endif + + // idrefs_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline idrefs_sskel:: + idrefs_sskel () + : idrefs_impl_ (0) + { + } + + inline idrefs_sskel:: + idrefs_sskel (idrefs_sskel* impl, void*) + : simple_content (impl, 0), idrefs_impl_ (impl) + { + } +#endif + + // language_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline language_sskel:: + language_sskel () + : language_impl_ (0) + { + } + + inline language_sskel:: + language_sskel (language_sskel* impl, void*) + : token_sskel (impl, 0), language_impl_ (impl) + { + } +#endif + + // uri_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline uri_sskel:: + uri_sskel () + : uri_impl_ (0) + { + } + + inline uri_sskel:: + uri_sskel (uri_sskel* impl, void*) + : simple_content (impl, 0), uri_impl_ (impl) + { + } +#endif + + // qname_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline qname_sskel:: + qname_sskel () + : qname_impl_ (0) + { + } + + inline qname_sskel:: + qname_sskel (qname_sskel* impl, void*) + : simple_content (impl, 0), qname_impl_ (impl) + { + } +#endif + + // base64_binary_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline base64_binary_sskel:: + base64_binary_sskel () + : base64_binary_impl_ (0) + { + } + + inline base64_binary_sskel:: + base64_binary_sskel (base64_binary_sskel* impl, void*) + : simple_content (impl, 0), base64_binary_impl_ (impl) + { + } +#endif + + // hex_binary_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline hex_binary_sskel:: + hex_binary_sskel () + : hex_binary_impl_ (0) + { + } + + inline hex_binary_sskel:: + hex_binary_sskel (hex_binary_sskel* impl, void*) + : simple_content (impl, 0), hex_binary_impl_ (impl) + { + } +#endif + + // gday_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gday_sskel:: + gday_sskel () + : gday_impl_ (0) + { + } + + inline gday_sskel:: + gday_sskel (gday_sskel* impl, void*) + : simple_content (impl, 0), gday_impl_ (impl) + { + } +#endif + + // gmonth_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_sskel:: + gmonth_sskel () + : gmonth_impl_ (0) + { + } + + inline gmonth_sskel:: + gmonth_sskel (gmonth_sskel* impl, void*) + : simple_content (impl, 0), gmonth_impl_ (impl) + { + } +#endif + + // gyear_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_sskel:: + gyear_sskel () + : gyear_impl_ (0) + { + } + + inline gyear_sskel:: + gyear_sskel (gyear_sskel* impl, void*) + : simple_content (impl, 0), gyear_impl_ (impl) + { + } +#endif + + // gmonth_day_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gmonth_day_sskel:: + gmonth_day_sskel () + : gmonth_day_impl_ (0) + { + } + + inline gmonth_day_sskel:: + gmonth_day_sskel (gmonth_day_sskel* impl, void*) + : simple_content (impl, 0), gmonth_day_impl_ (impl) + { + } +#endif + + // gyear_month_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline gyear_month_sskel:: + gyear_month_sskel () + : gyear_month_impl_ (0) + { + } + + inline gyear_month_sskel:: + gyear_month_sskel (gyear_month_sskel* impl, void*) + : simple_content (impl, 0), gyear_month_impl_ (impl) + { + } +#endif + + // date_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_sskel:: + date_sskel () + : date_impl_ (0) + { + } + + inline date_sskel:: + date_sskel (date_sskel* impl, void*) + : simple_content (impl, 0), date_impl_ (impl) + { + } +#endif + + // time_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline time_sskel:: + time_sskel () + : time_impl_ (0) + { + } + + inline time_sskel:: + time_sskel (time_sskel* impl, void*) + : simple_content (impl, 0), time_impl_ (impl) + { + } +#endif + + // date_time_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline date_time_sskel:: + date_time_sskel () + : date_time_impl_ (0) + { + } + + inline date_time_sskel:: + date_time_sskel (date_time_sskel* impl, void*) + : simple_content (impl, 0), date_time_impl_ (impl) + { + } +#endif + + // duration_sskel + // +#ifdef XSDE_REUSE_STYLE_TIEIN + inline duration_sskel:: + duration_sskel () + : duration_impl_ (0) + { + } + + inline duration_sskel:: + duration_sskel (duration_sskel* impl, void*) + : simple_content (impl, 0), duration_impl_ (impl) + { + } +#endif + } + } + } +} diff --git a/libxsde/xsde/cxx/serializer/xml-schema.hxx b/libxsde/xsde/cxx/serializer/xml-schema.hxx new file mode 100644 index 0000000..5897914 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/xml-schema.hxx @@ -0,0 +1,20 @@ +// file : xsde/cxx/serializer/xml-schema.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SERIALIZER_XML_SCHEMA_HXX +#define XSDE_CXX_SERIALIZER_XML_SCHEMA_HXX + +#include <xsde/cxx/buffer.hxx> +#include <xsde/cxx/date-time.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/qname-stl.hxx> +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/qname.hxx> +# include <xsde/cxx/string-sequence.hxx> +#endif + +#endif // XSDE_CXX_SERIALIZER_XML_SCHEMA_HXX diff --git a/libxsde/xsde/cxx/strdupx.cxx b/libxsde/xsde/cxx/strdupx.cxx new file mode 100644 index 0000000..254df2a --- /dev/null +++ b/libxsde/xsde/cxx/strdupx.cxx @@ -0,0 +1,48 @@ +// file : xsde/cxx/strdupx.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen, memcpy + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/strdupx.hxx> + +namespace xsde +{ + namespace cxx + { + char* + strdupx (const char* s) + { + size_t n = strlen (s); + char* r = new char[n + 1]; + +#ifndef XSDE_EXCEPTIONS + if (r) +#endif + memcpy (r, s, n + 1); + + return r; + } + + char* + strndupx (const char* s, size_t n) + { + char* r = new char[n + 1]; + +#ifndef XSDE_EXCEPTIONS + if (r) + { +#endif + memcpy (r, s, n); + r[n] = '\0'; + +#ifndef XSDE_EXCEPTIONS + } +#endif + + return r; + } + } +} diff --git a/libxsde/xsde/cxx/strdupx.hxx b/libxsde/xsde/cxx/strdupx.hxx new file mode 100644 index 0000000..9277f3c --- /dev/null +++ b/libxsde/xsde/cxx/strdupx.hxx @@ -0,0 +1,27 @@ +// file : xsde/cxx/strdupx.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_STRDUPX_HXX +#define XSDE_CXX_STRDUPX_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + // C++ versions of strdup and strndup. They allocate the string + // using new char[]. In the no-exceptions case return 0 if + // allocation fails. + // + char* + strdupx (const char*); + + char* + strndupx (const char*, size_t); + } +} + +#endif // XSDE_CXX_STRDUPX_HXX diff --git a/libxsde/xsde/cxx/string-sequence-stl.cxx b/libxsde/xsde/cxx/string-sequence-stl.cxx new file mode 100644 index 0000000..ea2cb81 --- /dev/null +++ b/libxsde/xsde/cxx/string-sequence-stl.cxx @@ -0,0 +1,147 @@ +// file : xsde/cxx/string-sequence-stl.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/string-sequence-stl.hxx> + +namespace xsde +{ + namespace cxx + { + void string_sequence:: + clear () + { + typedef std::string type; + for (size_t i = 0; i < size_; ++i) + static_cast<std::string*> (data_)[i].~type (); + + size_ = 0; + } + +#ifdef XSDE_EXCEPTIONS + struct guard + { + guard (std::string* p, size_t& n) : p_ (p), n_ (n) {} + + ~guard () + { + typedef std::string type; + if (p_) + for (; n_ > 0; --n_) + p_[n_ - 1].~type (); + } + + void + release () { p_ = 0; } + + private: + std::string* p_; + size_t& n_; + }; + + void string_sequence:: + move_ (void* dst, void* src, size_t n) + { + std::string* d = static_cast<std::string*> (dst); + std::string* s = static_cast<std::string*> (src); + + // The copy c-tor can throw in which case we need to destroy + // whatever objects we already copied into d. + // + size_t i = 0; + guard g (d, i); + + for (; i < n; i++) + new (d + i) std::string (s[i]); + + g.release (); + + typedef std::string type; + for (size_t j = 0; j < n; j++) + s[j].~type (); + } +#else + void string_sequence:: + move_ (void* dst, void* src, size_t n) + { + std::string* d = static_cast<std::string*> (dst); + std::string* s = static_cast<std::string*> (src); + + for (size_t i = 0; i < n; i++) + { + typedef std::string type; + new (d + i) std::string (s[i]); + s[i].~type (); + } + } +#endif + + void string_sequence:: + move_forward_ (void* p, size_t n) + { + // We are moving a sequence of elements one position to the left. + // The tricky part is to make sure we are in at least destructable + // state if things turn bad. We assume that there is a valid + // element at position p. + // + std::string* d = static_cast<std::string*> (p); + + for (size_t i = 0; i < n; i++) + d[i] = d[i + 1]; + + typedef std::string type; + d[n].~type (); + } + +#ifdef XSDE_EXCEPTIONS + void string_sequence:: + move_backward_ (void* p, size_t n, size_t& size) + { + // We are moving a sequence of elements one position to the right. + // The tricky part is to make sure we are in at least destructable + // state if things turn bad. + // + std::string* d = static_cast<std::string*> (p); + std::string* e = d + n; + + new (e) std::string; + size++; + + for (size_t i = n; i > 0; i--) + d[i] = d[i - 1]; + } +#else + void string_sequence:: + move_backward_ (void* p, size_t n) + { + // We are moving a sequence of elements one position to the right. + // + std::string* d = static_cast<std::string*> (p); + std::string* e = d + n; + + new (e) std::string; + + for (size_t i = n; i > 0; i--) + d[i] = d[i - 1]; + } +#endif + + bool + operator== (const string_sequence& x, const string_sequence& y) + { + if (x.size () != y.size ()) + return false; + + for (string_sequence::const_iterator + xi (x.begin ()), yi (y.begin ()), xe (x.end ()); + xi != xe; ++xi, ++yi) + { + if (*xi != *yi) + return false; + } + + return true; + } + } +} diff --git a/libxsde/xsde/cxx/string-sequence-stl.hxx b/libxsde/xsde/cxx/string-sequence-stl.hxx new file mode 100644 index 0000000..d466d85 --- /dev/null +++ b/libxsde/xsde/cxx/string-sequence-stl.hxx @@ -0,0 +1,135 @@ +// file : xsde/cxx/string-sequence-stl.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_STRING_SEQUENCE_STL_HXX +#define XSDE_CXX_STRING_SEQUENCE_STL_HXX + +#include <string> +#include <stddef.h> // size_t, ptrdiff_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/sequence-base.hxx> + +namespace xsde +{ + namespace cxx + { + class string_sequence: public sequence_base + { + public: + typedef std::string value_type; + typedef std::string* pointer; + typedef const std::string* const_pointer; + typedef std::string& reference; + typedef const std::string& const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef std::string* iterator; + typedef const std::string* const_iterator; + + public: + ~string_sequence (); + + public: + iterator + begin (); + + const_iterator + begin () const; + + iterator + end (); + + const_iterator + end () const; + + std::string& + front (); + + const std::string& + front () const; + + std::string& + back (); + + const std::string& + back () const; + + std::string& + operator[] (size_t); + + const std::string& + operator[] (size_t) const; + + public: + size_t + max_size () const; + + void + clear (); + + void + pop_back (); + + iterator + erase (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back (const std::string&); + +#ifndef XSDE_EXCEPTIONS + error + insert (iterator, const std::string&); + + error + insert (iterator, const std::string&, iterator& result); +#else + iterator + insert (iterator, const std::string&); +#endif + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + reserve (size_t); + + void + swap (string_sequence&); + + private: + static void + move_ (void* dst, void* src, size_t n); + + static void + move_forward_ (void* p, size_t n); + +#ifdef XSDE_EXCEPTIONS + static void + move_backward_ (void* p, size_t n, size_t& size); +#else + static void + move_backward_ (void* p, size_t n); +#endif + }; + + bool + operator== (const string_sequence&, const string_sequence&); + + bool + operator!= (const string_sequence&, const string_sequence&); + } +} + +#include <xsde/cxx/string-sequence-stl.ixx> + +#endif // XSDE_CXX_STRING_SEQUENCE_STL_HXX diff --git a/libxsde/xsde/cxx/string-sequence-stl.ixx b/libxsde/xsde/cxx/string-sequence-stl.ixx new file mode 100644 index 0000000..be05012 --- /dev/null +++ b/libxsde/xsde/cxx/string-sequence-stl.ixx @@ -0,0 +1,204 @@ +// file : xsde/cxx/string-sequence-stl.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline string_sequence:: + ~string_sequence () + { + clear (); + } + + inline size_t string_sequence:: + max_size () const + { + return size_t (-1) / sizeof (std::string); + } + + inline void string_sequence:: + swap (string_sequence& x) + { + swap_ (x); + } + + inline std::string* string_sequence:: + begin () + { + return static_cast<std::string*> (data_); + } + + inline const std::string* string_sequence:: + begin () const + { + // g++ 2.95 does not like static_cast here. + // + return (const std::string*) (data_); + } + + inline std::string* string_sequence:: + end () + { + return static_cast<std::string*> (data_) + size_; + } + + inline const std::string* string_sequence:: + end () const + { + return ((const std::string*) (data_)) + size_; + } + + inline std::string& string_sequence:: + front () + { + return *static_cast<std::string*> (data_); + } + + inline const std::string& string_sequence:: + front () const + { + return *((const std::string*) (data_)); + } + + inline std::string& string_sequence:: + back () + { + return static_cast<std::string*> (data_)[size_ - 1]; + } + + inline const std::string& string_sequence:: + back () const + { + return ((const std::string*) (data_))[size_ - 1]; + } + + inline std::string& string_sequence:: + operator[] (size_t i) + { + return static_cast<std::string*> (data_)[i]; + } + + inline const std::string& string_sequence:: + operator[] (size_t i) const + { + return ((const std::string*) (data_))[i]; + } + + inline void string_sequence:: + pop_back () + { + typedef std::string type; + static_cast<std::string*> (data_)[size_ - 1].~type (); + --size_; + } + + inline std::string* string_sequence:: + erase (std::string* i) + { + if (i != static_cast<std::string*> (data_) + (size_ - 1)) + erase_ (i, sizeof (std::string), &move_forward_); + else + { + typedef std::string type; + static_cast<std::string*> (data_)[size_ - 1].~type (); + --size_; + } + + return i; + } + +#ifdef XSDE_EXCEPTIONS + inline void string_sequence:: + push_back (const std::string& x) + { + if (capacity_ < size_ + 1) + grow_ (0, sizeof (std::string), &move_); + + new (static_cast<std::string*> (data_) + size_) std::string (x); + size_++; + } + + inline std::string* string_sequence:: + insert (std::string* i, const std::string& x) + { + std::string* p = static_cast<std::string*> ( + insert_ (i, sizeof (std::string), &move_, &move_backward_)); + *p = x; + return p; + } + + inline void string_sequence:: + reserve (size_t n) + { + if (capacity_ < n) + grow_ (n, sizeof (std::string*), &move_); + } +#else + inline sequence_base::error string_sequence:: + push_back (const std::string& x) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (std::string), &move_); + + if (r == error_none) + { + new (static_cast<std::string*> (data_) + size_) std::string (x); + size_++; + } + + return r; + } + + inline sequence_base::error string_sequence:: + insert (std::string* i, const std::string& x) + { + std::string* p = static_cast<std::string*> ( + insert_ (i, sizeof (std::string), &move_, &move_backward_)); + + if (p) + { + *p = x; + return error_none; + } + else + return error_no_memory; + } + + inline sequence_base::error string_sequence:: + insert (std::string* i, const std::string& x, std::string*& r) + { + std::string* p = static_cast<std::string*> ( + insert_ (i, sizeof (std::string), &move_, &move_backward_)); + + if (p) + { + *p = x; + r = p; + return error_none; + } + else + return error_no_memory; + } + + inline sequence_base::error string_sequence:: + reserve (size_t n) + { + error r = error_none; + if (capacity_ < n) + r = grow_ (n, sizeof (std::string), &move_); + return r; + } +#endif + + inline bool + operator!= (const string_sequence& x, const string_sequence& y) + { + return !(x == y); + } + } +} diff --git a/libxsde/xsde/cxx/string-sequence.cxx b/libxsde/xsde/cxx/string-sequence.cxx new file mode 100644 index 0000000..beb58ef --- /dev/null +++ b/libxsde/xsde/cxx/string-sequence.cxx @@ -0,0 +1,76 @@ +// file : xsde/cxx/string-sequence.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // memcpy, strlen, strcmp + +#include <xsde/cxx/string-sequence.hxx> + +namespace xsde +{ + namespace cxx + { + void string_sequence:: + clear () + { + for (size_t i = 0; i < size_; ++i) + delete[] static_cast<char**> (data_)[i]; + + size_ = 0; + } + +#ifdef XSDE_EXCEPTIONS + void string_sequence:: + push_back_copy (const char* cs) + { + if (capacity_ < size_ + 1) + grow_ (0, sizeof (char*), 0); + + size_t n = strlen (cs) + 1; + char* s = new char[n]; + memcpy (s, cs, n); + + static_cast<char**> (data_)[size_++] = s; + } +#else + string_sequence::error string_sequence:: + push_back_copy (const char* cs) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (char*), 0); + + if (r == error_none) + { + size_t n = strlen (cs) + 1; + char* s = new char[n]; + + if (s != 0) + { + memcpy (s, cs, n); + static_cast<char**> (data_)[size_++] = s; + } + else + r = error_no_memory; + } + + return r; + } +#endif + + bool + operator== (const string_sequence& x, const string_sequence& y) + { + if (x.size () != y.size ()) + return false; + + for (size_t i = 0; i < x.size (); ++i) + if (strcmp (x[i], y[i]) != 0) + return false; + + return true; + } + } +} diff --git a/libxsde/xsde/cxx/string-sequence.hxx b/libxsde/xsde/cxx/string-sequence.hxx new file mode 100644 index 0000000..50c0025 --- /dev/null +++ b/libxsde/xsde/cxx/string-sequence.hxx @@ -0,0 +1,133 @@ +// file : xsde/cxx/string-sequence.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_STRING_SEQUENCE_HXX +#define XSDE_CXX_STRING_SEQUENCE_HXX + +#include <stddef.h> // size_t, ptrdiff_t + +#include <xsde/cxx/config.hxx> +#include <xsde/cxx/sequence-base.hxx> + +namespace xsde +{ + namespace cxx + { + class string_sequence: public sequence_base + { + public: + typedef char* value_type; + typedef char** pointer; + typedef const char** const_pointer; + typedef char* reference; + typedef const char* const_reference; + + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef char** iterator; + typedef const char* const* const_iterator; + + public: + ~string_sequence (); + + public: + iterator + begin (); + + const_iterator + begin () const; + + iterator + end (); + + const_iterator + end () const; + + char* + front (); + + const char* + front () const; + + char* + back (); + + const char* + back () const; + + char* + operator[] (size_t); + + const char* + operator[] (size_t) const; + + public: + size_t + max_size () const; + + void + clear (); + + void + pop_back (); + + iterator + erase (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back (char*); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + push_back_copy (const char*); + +#ifndef XSDE_EXCEPTIONS + error + insert (iterator, char*); + + error + insert (iterator, char*, iterator& result); +#else + iterator + insert (iterator, char*); +#endif + + // Detach a string from the sequence at a given position. + // The string pointer at this position in the sequence is + // set to 0. + // + char* + detach (iterator); + +#ifndef XSDE_EXCEPTIONS + error +#else + void +#endif + reserve (size_t); + + void + swap (string_sequence&); + }; + + bool + operator== (const string_sequence&, const string_sequence&); + + bool + operator!= (const string_sequence&, const string_sequence&); + } +} + +#include <xsde/cxx/string-sequence.ixx> + +#endif // XSDE_CXX_STRING_SEQUENCE_HXX diff --git a/libxsde/xsde/cxx/string-sequence.ixx b/libxsde/xsde/cxx/string-sequence.ixx new file mode 100644 index 0000000..58878b7 --- /dev/null +++ b/libxsde/xsde/cxx/string-sequence.ixx @@ -0,0 +1,233 @@ +// file : xsde/cxx/string-sequence.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline string_sequence:: + ~string_sequence () + { + clear (); + } + + inline size_t string_sequence:: + max_size () const + { + return size_t (-1) / sizeof (char*); + } + + inline void string_sequence:: + swap (string_sequence& x) + { + swap_ (x); + } + + inline string_sequence::iterator string_sequence:: + begin () + { + return static_cast<char**> (data_); + } + + inline string_sequence::const_iterator string_sequence:: + begin () const + { + // g++ 2.95 does not like static_cast here. + // + return (const char* const*) (data_); + } + + inline string_sequence::iterator string_sequence:: + end () + { + return static_cast<char**> (data_) + size_; + } + + inline string_sequence::const_iterator string_sequence:: + end () const + { + return ((const char* const*) (data_)) + size_; + } + + inline char* string_sequence:: + front () + { + return *static_cast<char**> (data_); + } + + inline const char* string_sequence:: + front () const + { + return *((const char* const*) (data_)); + } + + inline char* string_sequence:: + back () + { + return static_cast<char**> (data_)[size_ - 1]; + } + + inline const char* string_sequence:: + back () const + { + return ((const char* const*) (data_))[size_ - 1]; + } + + inline char* string_sequence:: + operator[] (size_t i) + { + return static_cast<char**> (data_)[i]; + } + + inline const char* string_sequence:: + operator[] (size_t i) const + { + return ((const char* const*) (data_))[i]; + } + + inline void string_sequence:: + pop_back () + { + delete[] static_cast<char**> (data_)[size_ - 1]; + --size_; + } + + inline string_sequence::iterator string_sequence:: + erase (iterator i) + { + delete[] *i; + + if (i != static_cast<char**> (data_) + (size_ - 1)) + erase_ (i, sizeof (char*), 0); + else + --size_; + + return i; + } + +#ifdef XSDE_EXCEPTIONS + namespace string_sequence_bits + { + struct guard + { + ~guard () { delete[] p_; } + guard (char* p) : p_ (p) {} + + void + release () { p_ = 0; } + + private: + char* p_; + }; + } + + inline void string_sequence:: + push_back (char* x) + { + string_sequence_bits::guard g (x); + + if (capacity_ < size_ + 1) + grow_ (0, sizeof (char*), 0); + + static_cast<char**> (data_)[size_++] = x; + + g.release (); + } + + inline string_sequence::iterator string_sequence:: + insert (iterator i, char* x) + { + string_sequence_bits::guard g (x); + char** p = static_cast<char**> (insert_ (i, sizeof (char*), 0, 0)); + *p = x; + g.release (); + return p; + } + + inline void string_sequence:: + reserve (size_t n) + { + if (capacity_ < n) + grow_ (n, sizeof (char*), 0); + } +#else + inline sequence_base::error string_sequence:: + push_back (char* x) + { + error r = error_none; + + if (capacity_ < size_ + 1) + r = grow_ (0, sizeof (char*), 0); + + if (r == error_none) + static_cast<char**> (data_)[size_++] = x; + else + delete[] x; + + return r; + } + + inline sequence_base::error string_sequence:: + insert (iterator i, char* x) + { + char** p = static_cast<char**> (insert_ (i, sizeof (char*), 0, 0)); + + if (p) + { + *p = x; + return error_none; + } + else + { + delete[] x; + return error_no_memory; + } + } + + inline sequence_base::error string_sequence:: + insert (iterator i, char* x, iterator& r) + { + char** p = static_cast<char**> (insert_ (i, sizeof (char*), 0, 0)); + + if (p) + { + *p = x; + r = p; + return error_none; + } + else + { + delete[] x; + return error_no_memory; + } + } + + inline sequence_base::error string_sequence:: + reserve (size_t n) + { + error r = error_none; + if (capacity_ < n) + r = grow_ (n, sizeof (char*), 0); + return r; + } +#endif + + inline char* string_sequence:: + detach (iterator p) + { + char* r = *p; + *p = 0; + return r; + } + + // + // + inline bool + operator!= (const string_sequence& x, const string_sequence& y) + { + return !(x == y); + } + } +} diff --git a/libxsde/xsde/cxx/string.cxx b/libxsde/xsde/cxx/string.cxx new file mode 100644 index 0000000..2edb3cb --- /dev/null +++ b/libxsde/xsde/cxx/string.cxx @@ -0,0 +1,75 @@ +// file : xsde/cxx/string.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> + +#include <xsde/cxx/string.hxx> + +namespace xsde +{ + namespace cxx + { + string::error string:: + assign (const char* s, size_t size) + { + if (size + 1 > capacity_) + if (error e = resize (size + 1, false)) + return e; + + if (size != 0) + memcpy (data_, s, size); + + data_[size] = '\0'; + + size_ = size; + + return error_none; + } + + string::error string:: + append (const char* s, size_t size) + { + if (size_ + size + 1 > capacity_) + if (error e = resize (size_ + size + 1, true)) + return e; + + if (size != 0) + memcpy (data_ + size_, s, size); + + size_ += size; + data_[size_] = '\0'; + + return error_none; + } + + string::error string:: + resize (size_t new_cap, bool copy) + { + // Start with at least 64 chars (32 * 2). + // + size_t cap = capacity_ ? capacity_ : 32; + + if (new_cap <= 2 * cap) + new_cap = 2 * cap; + else + new_cap += (new_cap & 1) ? 1 : 0; // Make even. + + char* p = new char[new_cap]; + + if (p == 0) + return error_no_memory; + + if (copy && size_ != 0) + memcpy (p, data_, size_ + 1); + + delete[] data_; + + data_ = p; + capacity_ = new_cap; + + return error_none; + } + } +} diff --git a/libxsde/xsde/cxx/string.hxx b/libxsde/xsde/cxx/string.hxx new file mode 100644 index 0000000..27620bc --- /dev/null +++ b/libxsde/xsde/cxx/string.hxx @@ -0,0 +1,112 @@ +// file : xsde/cxx/string.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_STRING_HXX +#define XSDE_CXX_STRING_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + // Simple string for situations where std::string is not available. + // + struct string + { + enum error + { + error_none, + error_no_memory + }; + + typedef size_t size_type; + + ~string (); + + // The default c-tor creates an uninitialized string, not an + // empty string. Use assign() to initialize it. + // + string (); + + error + assign (const char*); + + error + assign (const char*, size_t); + + error + append (const char*); + + error + append (const char*, size_t); + + char& + operator[] (size_t); + + const char& + operator[] (size_t) const; + + size_t + size () const; + + char* + data (); + + const char* + data () const; + + bool + empty () const; + + void + swap (string&); + + public: + size_t + capacity () const; + + void + truncate (size_t); + + char* + detach (); + + void + attach (char*); + + private: + string (const string&); + + string& + operator= (const string&); + + private: + error + resize (size_t capacity, bool copy); + + private: + char* data_; + size_t size_; + size_t capacity_; + }; + + bool + operator== (const string&, const char*); + + bool + operator== (const char*, const string&); + + bool + operator!= (const string&, const char*); + + bool + operator!= (const char*, const string&); + } +} + +#include <xsde/cxx/string.ixx> + +#endif // XSDE_CXX_STRING_HXX diff --git a/libxsde/xsde/cxx/string.ixx b/libxsde/xsde/cxx/string.ixx new file mode 100644 index 0000000..4977526 --- /dev/null +++ b/libxsde/xsde/cxx/string.ixx @@ -0,0 +1,149 @@ +// file : xsde/cxx/string.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> + +namespace xsde +{ + namespace cxx + { + inline string:: + ~string () + { + delete[] data_; + } + + inline string:: + string () + : data_ (0), size_ (0), capacity_ (0) + { + } + + inline char* string:: + detach () + { + char* r = data_; + data_ = 0; + size_ = 0; + capacity_ = 0; + return r; + } + + inline void string:: + attach (char* s) + { + delete[] data_; + + data_ = s; + size_ = (s != 0 ? strlen (s) : 0); + capacity_ = (s != 0 ? size_ + 1 : 0); + } + + inline string::error string:: + assign (const char* s) + { + return assign (s, strlen (s)); + } + + inline string::error string:: + append (const char* s) + { + return append (s, strlen (s)); + } + + inline char& string:: + operator[] (size_t i) + { + return data_[i]; + } + + inline const char& string:: + operator[] (size_t i) const + { + return data_[i]; + } + + inline size_t string:: + size () const + { + return size_; + } + + inline char* string:: + data () + { + return data_; + } + + inline const char* string:: + data () const + { + return data_; + } + + inline bool string:: + empty () const + { + return size_ == 0; + } + + inline void string:: + swap (string& str) + { + char* d = data_; + data_ = str.data_; + str.data_ = d; + + size_t s = size_; + size_ = str.size_; + str.size_ = s; + + size_t c = capacity_; + capacity_ = str.capacity_; + str.capacity_ = c; + } + + inline size_t string:: + capacity () const + { + return capacity_; + } + + inline void string:: + truncate (size_t s) + { + if (s < size_) + { + size_ = s; + data_[s] = '\0'; + } + } + + inline bool + operator== (const string& a, const char* b) + { + return strcmp (a.data (), b) == 0; + } + + inline bool + operator== (const char* a, const string& b) + { + return strcmp (b.data (), a) == 0; + } + + inline bool + operator!= (const string& a, const char* b) + { + return strcmp (a.data (), b) != 0; + } + + inline bool + operator!= (const char* a, const string& b) + { + return strcmp (b.data (), a) != 0; + } + } +} + diff --git a/libxsde/xsde/cxx/sys-error.cxx b/libxsde/xsde/cxx/sys-error.cxx new file mode 100644 index 0000000..5f6d33a --- /dev/null +++ b/libxsde/xsde/cxx/sys-error.cxx @@ -0,0 +1,27 @@ +// file : xsde/cxx/sys-error.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/sys-error.hxx> + +namespace xsde +{ + namespace cxx + { + static const char* const text_[] = + { + "no error", + "no memory", + "open failed", + "read failed", + "write failed" + }; + + const char* sys_error:: + text (value v) + { + return text_[v]; + } + } +} diff --git a/libxsde/xsde/cxx/sys-error.hxx b/libxsde/xsde/cxx/sys-error.hxx new file mode 100644 index 0000000..2c1c770 --- /dev/null +++ b/libxsde/xsde/cxx/sys-error.hxx @@ -0,0 +1,42 @@ +// file : xsde/cxx/sys-error.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_SYS_ERROR_HXX +#define XSDE_CXX_SYS_ERROR_HXX + +namespace xsde +{ + namespace cxx + { + struct sys_error + { + enum value + { + none, + no_memory, + open_failed, + read_failed, + write_failed + }; + + sys_error (value); + + operator value () const + { + return v_; + } + + static const char* + text (value); + + private: + value v_; + }; + } +} + +#include <xsde/cxx/sys-error.ixx> + +#endif // XSDE_CXX_SYS_ERROR_HXX diff --git a/libxsde/xsde/cxx/sys-error.ixx b/libxsde/xsde/cxx/sys-error.ixx new file mode 100644 index 0000000..35c382c --- /dev/null +++ b/libxsde/xsde/cxx/sys-error.ixx @@ -0,0 +1,16 @@ +// file : xsde/cxx/sys-error.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline sys_error:: + sys_error (value v) + : v_ (v) + { + } + } +} diff --git a/libxsde/xsde/cxx/version.hxx b/libxsde/xsde/cxx/version.hxx new file mode 100644 index 0000000..9033af7 --- /dev/null +++ b/libxsde/xsde/cxx/version.hxx @@ -0,0 +1,29 @@ +// file : xsde/cxx/version.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_VERSION_HXX +#define XSDE_CXX_VERSION_HXX + +// Version format is AABBCCDD where +// +// AA - major version number +// BB - minor version number +// CC - bugfix version number +// DD - alpha / beta (DD + 50) version number +// +// When DD is not 00, 1 is subtracted from AABBCC. For example: +// +// Version AABBCCDD +// 2.0.0 02000000 +// 2.1.0 02010000 +// 2.1.1 02010100 +// 2.2.0.a1 02019901 +// 3.0.0.b2 02999952 +// + +#define XSDE_STR_VERSION "3.0.0" +#define XSDE_INT_VERSION 3000000L + +#endif // XSDE_CXX_VERSION_HXX diff --git a/libxsde/xsde/cxx/xml/char-table.cxx b/libxsde/xsde/cxx/xml/char-table.cxx new file mode 100644 index 0000000..ae6239d --- /dev/null +++ b/libxsde/xsde/cxx/xml/char-table.cxx @@ -0,0 +1,27 @@ +// file : xsde/cxx/xml/char-table.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> + +namespace xsde +{ + namespace cxx + { + namespace xml + { + unsigned char char_table[0x80] = + { + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8, 0xD0, 0x00, 0x00, 0xD0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xD8, 0x48, 0x58, 0x48, 0x48, 0x48, 0x40, 0x58, 0x48, 0x48, 0x48, 0x48, 0x48, 0x4D, 0x4D, 0x58, + 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4D, 0x4E, 0x48, 0x50, 0x48, 0x58, 0x48, + 0x48, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, + 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x48, 0x48, 0x40, 0x48, 0x4F, + 0x48, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, + 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x4F, 0x48, 0x48, 0x48, 0x48, 0x48 + }; + } + } +} diff --git a/libxsde/xsde/cxx/xml/char-table.hxx b/libxsde/xsde/cxx/xml/char-table.hxx new file mode 100644 index 0000000..cd919f3 --- /dev/null +++ b/libxsde/xsde/cxx/xml/char-table.hxx @@ -0,0 +1,24 @@ +// file : xsde/cxx/xml/char-table.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_XML_CHAR_TABLE_HXX +#define XSDE_CXX_XML_CHAR_TABLE_HXX + +namespace xsde +{ + namespace cxx + { + namespace xml + { + const unsigned char ncname_char_mask = 0x1; + const unsigned char name_first_char_mask = 0x2; + const unsigned char name_char_mask = 0x4; + + extern unsigned char char_table[0x80]; + } + } +} + +#endif // XSDE_CXX_XML_CHAR_TABLE_HXX diff --git a/libxsde/xsde/cxx/xml/ncname.cxx b/libxsde/xsde/cxx/xml/ncname.cxx new file mode 100644 index 0000000..788a73d --- /dev/null +++ b/libxsde/xsde/cxx/xml/ncname.cxx @@ -0,0 +1,43 @@ +// file : xsde/cxx/xml/ncname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/xml/char-table.hxx> +#include <xsde/cxx/xml/ncname.hxx> + +namespace xsde +{ + namespace cxx + { + namespace xml + { + bool + valid_ncname (const char* s, size_t size) + { + // For now we are only checking the US-ASCII characters. + // + + bool ok = (size != 0); + + if (ok) + { + unsigned char c = static_cast<unsigned char> (s[0]); + + ok = c >= 0x80 || + ((char_table[c] & name_first_char_mask) && c != ':'); + + for (size_t i = 1; ok && i < size; ++i) + { + c = static_cast<unsigned char> (s[i]); + + if (c < 0x80 && !(xml::char_table[c] & xml::ncname_char_mask)) + ok = false; + } + } + + return ok; + } + } + } +} diff --git a/libxsde/xsde/cxx/xml/ncname.hxx b/libxsde/xsde/cxx/xml/ncname.hxx new file mode 100644 index 0000000..3e0fa98 --- /dev/null +++ b/libxsde/xsde/cxx/xml/ncname.hxx @@ -0,0 +1,23 @@ +// file : xsde/cxx/xml/ncname.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_XML_NCNAME_HXX +#define XSDE_CXX_XML_NCNAME_HXX + +#include <stddef.h> // size_t + +namespace xsde +{ + namespace cxx + { + namespace xml + { + bool + valid_ncname (const char* s, size_t size); + } + } +} + +#endif // XSDE_CXX_XML_NCNAME_HXX diff --git a/libxsde/xsde/makefile b/libxsde/xsde/makefile new file mode 100644 index 0000000..e095030 --- /dev/null +++ b/libxsde/xsde/makefile @@ -0,0 +1,558 @@ +# file : xsde/makefile +# author : Boris Kolpackov <boris@codesynthesis.com> +# copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +# license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make + +cxx_tun := cxx/string.cxx cxx/ro-string.cxx + +ifeq ($(xsde_stl),n) +cxx_tun += cxx/strdupx.cxx +endif + +ifeq ($(xsde_exceptions),n) +cxx_tun += cxx/sys-error.cxx +endif + +ifneq ($(xsde_parser_validation)$(xsde_serializer_validation),nn) +cxx_tun += cxx/schema-error.cxx +endif + +ifeq ($(xsde_polymorphic),y) +cxx_tun += cxx/hashmap.cxx +endif + +# Common data types. +# +cxx_tun += cxx/buffer.cxx cxx/sequence-base.cxx + +ifeq ($(xsde_stl),y) +cxx_tun += cxx/string-sequence-stl.cxx +else +cxx_tun += cxx/qname.cxx cxx/string-sequence.cxx +endif + + +## XML +## +ifneq ($(xsde_parser_validation)$(xsde_serializer_validation),nn) +cxx_tun += cxx/xml/char-table.cxx cxx/xml/ncname.cxx +endif + + +## C++/Hybrid +## +cxx_tun += cxx/hybrid/sequence.cxx + + +## C++/Parser +## +cxx_tun += cxx/parser/elements.cxx cxx/parser/state.cxx + +ifeq ($(xsde_polymorphic),y) +cxx_tun += cxx/parser/map.cxx cxx/parser/substitution-map.cxx +endif + +ifeq ($(xsde_exceptions),y) +cxx_tun += cxx/parser/exceptions.cxx +else +cxx_tun += cxx/parser/error.cxx +endif + +cxx_tun += cxx/parser/expat/document.cxx cxx/parser/expat/xml-error.cxx + + +# Parser implementations. +# +ifeq ($(xsde_parser_validation),y) + +cxx_tun += \ +cxx/parser/validating/parser.cxx \ +cxx/parser/validating/time-zone.cxx \ +cxx/parser/validating/xml-schema-pskel.cxx + +ifeq ($(xsde_polymorphic),y) +cxx_tun += cxx/parser/validating/inheritance-map.cxx +endif + +cxx_tun += \ +cxx/parser/validating/boolean.cxx \ +cxx/parser/validating/number.cxx \ +cxx/parser/validating/byte.cxx \ +cxx/parser/validating/unsigned-byte.cxx \ +cxx/parser/validating/short.cxx \ +cxx/parser/validating/unsigned-short.cxx \ +cxx/parser/validating/int.cxx \ +cxx/parser/validating/unsigned-int.cxx \ +cxx/parser/validating/integer.cxx \ +cxx/parser/validating/negative-integer.cxx \ +cxx/parser/validating/non-positive-integer.cxx \ +cxx/parser/validating/positive-integer.cxx \ +cxx/parser/validating/non-negative-integer.cxx \ +cxx/parser/validating/float.cxx \ +cxx/parser/validating/double.cxx \ +cxx/parser/validating/decimal.cxx + +ifeq ($(xsde_longlong),y) +cxx_tun += \ +cxx/parser/validating/long-long.cxx \ +cxx/parser/validating/unsigned-long-long.cxx +else +cxx_tun += \ +cxx/parser/validating/long.cxx \ +cxx/parser/validating/unsigned-long.cxx +endif + +ifeq ($(xsde_stl),y) + +cxx_tun += \ +cxx/parser/validating/string-stl.cxx \ +cxx/parser/validating/normalized-string-stl.cxx \ +cxx/parser/validating/token-stl.cxx \ +cxx/parser/validating/name-stl.cxx \ +cxx/parser/validating/nmtoken-stl.cxx \ +cxx/parser/validating/nmtokens-stl.cxx \ +cxx/parser/validating/ncname-stl.cxx \ +cxx/parser/validating/id-stl.cxx \ +cxx/parser/validating/idref-stl.cxx \ +cxx/parser/validating/idrefs-stl.cxx \ +cxx/parser/validating/language-stl.cxx \ +cxx/parser/validating/uri-stl.cxx \ +cxx/parser/validating/qname-stl.cxx + +else + +cxx_tun += \ +cxx/parser/validating/string.cxx \ +cxx/parser/validating/normalized-string.cxx \ +cxx/parser/validating/token.cxx \ +cxx/parser/validating/name.cxx \ +cxx/parser/validating/nmtoken.cxx \ +cxx/parser/validating/nmtokens.cxx \ +cxx/parser/validating/ncname.cxx \ +cxx/parser/validating/id.cxx \ +cxx/parser/validating/idref.cxx \ +cxx/parser/validating/idrefs.cxx \ +cxx/parser/validating/language.cxx \ +cxx/parser/validating/uri.cxx \ +cxx/parser/validating/qname.cxx + +endif # stl + +cxx_tun += \ +cxx/parser/validating/base64-binary.cxx \ +cxx/parser/validating/hex-binary.cxx \ +cxx/parser/validating/gday.cxx \ +cxx/parser/validating/gmonth.cxx \ +cxx/parser/validating/gyear.cxx \ +cxx/parser/validating/gmonth-day.cxx \ +cxx/parser/validating/gyear-month.cxx \ +cxx/parser/validating/date.cxx \ +cxx/parser/validating/time.cxx \ +cxx/parser/validating/date-time.cxx \ +cxx/parser/validating/duration.cxx + +else # validation + +cxx_tun += \ +cxx/parser/non-validating/parser.cxx \ +cxx/parser/non-validating/time-zone.cxx \ +cxx/parser/non-validating/xml-schema-pskel.cxx + +cxx_tun += \ +cxx/parser/non-validating/boolean.cxx \ +cxx/parser/non-validating/number.cxx \ +cxx/parser/non-validating/byte.cxx \ +cxx/parser/non-validating/unsigned-byte.cxx \ +cxx/parser/non-validating/short.cxx \ +cxx/parser/non-validating/unsigned-short.cxx \ +cxx/parser/non-validating/int.cxx \ +cxx/parser/non-validating/unsigned-int.cxx \ +cxx/parser/non-validating/integer.cxx \ +cxx/parser/non-validating/negative-integer.cxx \ +cxx/parser/non-validating/non-positive-integer.cxx \ +cxx/parser/non-validating/positive-integer.cxx \ +cxx/parser/non-validating/non-negative-integer.cxx \ +cxx/parser/non-validating/float.cxx \ +cxx/parser/non-validating/double.cxx \ +cxx/parser/non-validating/decimal.cxx + +ifeq ($(xsde_longlong),y) +cxx_tun += \ +cxx/parser/non-validating/long-long.cxx \ +cxx/parser/non-validating/unsigned-long-long.cxx +else +cxx_tun += \ +cxx/parser/non-validating/long.cxx \ +cxx/parser/non-validating/unsigned-long.cxx +endif + +ifeq ($(xsde_stl),y) + +cxx_tun += \ +cxx/parser/non-validating/string-stl.cxx \ +cxx/parser/non-validating/normalized-string-stl.cxx \ +cxx/parser/non-validating/token-stl.cxx \ +cxx/parser/non-validating/name-stl.cxx \ +cxx/parser/non-validating/nmtoken-stl.cxx \ +cxx/parser/non-validating/nmtokens-stl.cxx \ +cxx/parser/non-validating/ncname-stl.cxx \ +cxx/parser/non-validating/id-stl.cxx \ +cxx/parser/non-validating/idref-stl.cxx \ +cxx/parser/non-validating/idrefs-stl.cxx \ +cxx/parser/non-validating/language-stl.cxx \ +cxx/parser/non-validating/uri-stl.cxx \ +cxx/parser/non-validating/qname-stl.cxx + +else + +cxx_tun += \ +cxx/parser/non-validating/string.cxx \ +cxx/parser/non-validating/normalized-string.cxx \ +cxx/parser/non-validating/token.cxx \ +cxx/parser/non-validating/name.cxx \ +cxx/parser/non-validating/nmtoken.cxx \ +cxx/parser/non-validating/nmtokens.cxx \ +cxx/parser/non-validating/ncname.cxx \ +cxx/parser/non-validating/id.cxx \ +cxx/parser/non-validating/idref.cxx \ +cxx/parser/non-validating/idrefs.cxx \ +cxx/parser/non-validating/language.cxx \ +cxx/parser/non-validating/uri.cxx \ +cxx/parser/non-validating/qname.cxx + +endif # stl + +cxx_tun += \ +cxx/parser/non-validating/base64-binary.cxx \ +cxx/parser/non-validating/hex-binary.cxx \ +cxx/parser/non-validating/gday.cxx \ +cxx/parser/non-validating/gmonth.cxx \ +cxx/parser/non-validating/gyear.cxx \ +cxx/parser/non-validating/gmonth-day.cxx \ +cxx/parser/non-validating/gyear-month.cxx \ +cxx/parser/non-validating/date.cxx \ +cxx/parser/non-validating/time.cxx \ +cxx/parser/non-validating/date-time.cxx \ +cxx/parser/non-validating/duration.cxx + +endif # validation + + +## C++/Serializer +## +cxx_tun += cxx/serializer/elements.cxx cxx/serializer/context.cxx + +ifeq ($(xsde_polymorphic),y) +cxx_tun += cxx/serializer/map.cxx cxx/serializer/substitution-map.cxx +endif + +ifeq ($(xsde_exceptions),y) +cxx_tun += cxx/serializer/exceptions.cxx +else +cxx_tun += cxx/serializer/error.cxx +endif + +cxx_tun += cxx/serializer/genx/document.cxx cxx/serializer/genx/xml-error.cxx + +# Serializer implementations. +# +ifeq ($(xsde_serializer_validation),y) + +cxx_tun += \ +cxx/serializer/validating/serializer.cxx \ +cxx/serializer/validating/time-zone.cxx \ +cxx/serializer/validating/xml-schema-sskel.cxx + +ifeq ($(xsde_polymorphic),y) +cxx_tun += cxx/serializer/validating/inheritance-map.cxx +endif + +cxx_tun += \ +cxx/serializer/validating/boolean.cxx \ +cxx/serializer/validating/byte.cxx \ +cxx/serializer/validating/unsigned-byte.cxx \ +cxx/serializer/validating/short.cxx \ +cxx/serializer/validating/unsigned-short.cxx \ +cxx/serializer/validating/int.cxx \ +cxx/serializer/validating/unsigned-int.cxx \ +cxx/serializer/validating/integer.cxx \ +cxx/serializer/validating/negative-integer.cxx \ +cxx/serializer/validating/non-positive-integer.cxx \ +cxx/serializer/validating/positive-integer.cxx \ +cxx/serializer/validating/non-negative-integer.cxx \ +cxx/serializer/validating/float.cxx \ +cxx/serializer/validating/double.cxx \ +cxx/serializer/validating/decimal.cxx + +ifeq ($(xsde_longlong),y) +cxx_tun += \ +cxx/serializer/validating/long-long.cxx \ +cxx/serializer/validating/unsigned-long-long.cxx +else +cxx_tun += \ +cxx/serializer/validating/long.cxx \ +cxx/serializer/validating/unsigned-long.cxx +endif + +ifeq ($(xsde_stl),y) + +cxx_tun += \ +cxx/serializer/validating/string-stl.cxx \ +cxx/serializer/validating/normalized-string-stl.cxx \ +cxx/serializer/validating/token-stl.cxx \ +cxx/serializer/validating/name-stl.cxx \ +cxx/serializer/validating/nmtoken-stl.cxx \ +cxx/serializer/validating/ncname-stl.cxx \ +cxx/serializer/validating/id-stl.cxx \ +cxx/serializer/validating/idref-stl.cxx \ +cxx/serializer/validating/language-stl.cxx \ +cxx/serializer/validating/uri-stl.cxx \ +cxx/serializer/validating/idrefs-stl.cxx \ +cxx/serializer/validating/nmtokens-stl.cxx \ +cxx/serializer/validating/qname-stl.cxx + +else + +cxx_tun += \ +cxx/serializer/validating/string.cxx \ +cxx/serializer/validating/normalized-string.cxx \ +cxx/serializer/validating/token.cxx \ +cxx/serializer/validating/name.cxx \ +cxx/serializer/validating/nmtoken.cxx \ +cxx/serializer/validating/ncname.cxx \ +cxx/serializer/validating/id.cxx \ +cxx/serializer/validating/idref.cxx \ +cxx/serializer/validating/language.cxx \ +cxx/serializer/validating/uri.cxx \ +cxx/serializer/validating/idrefs.cxx \ +cxx/serializer/validating/nmtokens.cxx \ +cxx/serializer/validating/qname.cxx + +endif # stl + +cxx_tun += \ +cxx/serializer/validating/base64-binary.cxx \ +cxx/serializer/validating/hex-binary.cxx \ +cxx/serializer/validating/gday.cxx \ +cxx/serializer/validating/gmonth.cxx \ +cxx/serializer/validating/gyear.cxx \ +cxx/serializer/validating/gmonth-day.cxx \ +cxx/serializer/validating/gyear-month.cxx \ +cxx/serializer/validating/date.cxx \ +cxx/serializer/validating/time.cxx \ +cxx/serializer/validating/date-time.cxx \ +cxx/serializer/validating/duration.cxx + +else # validation + +cxx_tun += \ +cxx/serializer/non-validating/serializer.cxx \ +cxx/serializer/non-validating/time-zone.cxx \ +cxx/serializer/non-validating/xml-schema-sskel.cxx + +cxx_tun += \ +cxx/serializer/non-validating/boolean.cxx \ +cxx/serializer/non-validating/byte.cxx \ +cxx/serializer/non-validating/unsigned-byte.cxx \ +cxx/serializer/non-validating/short.cxx \ +cxx/serializer/non-validating/unsigned-short.cxx \ +cxx/serializer/non-validating/int.cxx \ +cxx/serializer/non-validating/unsigned-int.cxx \ +cxx/serializer/non-validating/integer.cxx \ +cxx/serializer/non-validating/negative-integer.cxx \ +cxx/serializer/non-validating/non-positive-integer.cxx \ +cxx/serializer/non-validating/positive-integer.cxx \ +cxx/serializer/non-validating/non-negative-integer.cxx \ +cxx/serializer/non-validating/float.cxx \ +cxx/serializer/non-validating/double.cxx \ +cxx/serializer/non-validating/decimal.cxx + +ifeq ($(xsde_longlong),y) +cxx_tun += \ +cxx/serializer/non-validating/long-long.cxx \ +cxx/serializer/non-validating/unsigned-long-long.cxx +else +cxx_tun += \ +cxx/serializer/non-validating/long.cxx \ +cxx/serializer/non-validating/unsigned-long.cxx +endif + +ifeq ($(xsde_stl),y) + +cxx_tun += \ +cxx/serializer/non-validating/string-stl.cxx \ +cxx/serializer/non-validating/normalized-string-stl.cxx \ +cxx/serializer/non-validating/token-stl.cxx \ +cxx/serializer/non-validating/name-stl.cxx \ +cxx/serializer/non-validating/nmtoken-stl.cxx \ +cxx/serializer/non-validating/ncname-stl.cxx \ +cxx/serializer/non-validating/id-stl.cxx \ +cxx/serializer/non-validating/idref-stl.cxx \ +cxx/serializer/non-validating/language-stl.cxx \ +cxx/serializer/non-validating/uri-stl.cxx \ +cxx/serializer/non-validating/idrefs-stl.cxx \ +cxx/serializer/non-validating/nmtokens-stl.cxx \ +cxx/serializer/non-validating/qname-stl.cxx + +else + +cxx_tun += \ +cxx/serializer/non-validating/string.cxx \ +cxx/serializer/non-validating/normalized-string.cxx \ +cxx/serializer/non-validating/token.cxx \ +cxx/serializer/non-validating/name.cxx \ +cxx/serializer/non-validating/nmtoken.cxx \ +cxx/serializer/non-validating/ncname.cxx \ +cxx/serializer/non-validating/id.cxx \ +cxx/serializer/non-validating/idref.cxx \ +cxx/serializer/non-validating/language.cxx \ +cxx/serializer/non-validating/uri.cxx \ +cxx/serializer/non-validating/idrefs.cxx \ +cxx/serializer/non-validating/nmtokens.cxx \ +cxx/serializer/non-validating/qname.cxx + +endif # stl + +cxx_tun += \ +cxx/serializer/non-validating/base64-binary.cxx \ +cxx/serializer/non-validating/hex-binary.cxx \ +cxx/serializer/non-validating/gday.cxx \ +cxx/serializer/non-validating/gmonth.cxx \ +cxx/serializer/non-validating/gyear.cxx \ +cxx/serializer/non-validating/gmonth-day.cxx \ +cxx/serializer/non-validating/gyear-month.cxx \ +cxx/serializer/non-validating/date.cxx \ +cxx/serializer/non-validating/time.cxx \ +cxx/serializer/non-validating/date-time.cxx \ +cxx/serializer/non-validating/duration.cxx + +endif # validation + + +cxx_o := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) +cxx_d := $(cxx_o:.o=.o.d) + +xsde.l := $(out_base)/xsde.l +xsde.l.cpp-options := $(out_base)/xsde.l.cpp-options + +clean := $(out_base)/.clean + + +# Build. +# +$(xsde.l): $(cxx_o) -lexpat -lgenx + +$(cxx_o) $(cxx_d): $(xsde.l.cpp-options) $(out_base)/config.h + +$(xsde.l.cpp-options): prefix := xsde/ $(out_root)/libxsde/ +$(xsde.l.cpp-options): value := -I$(out_root)/libxsde -I$(src_root)/libxsde + +$(call include-dep,$(cxx_d)) + +# config.h +# +$(out_base)/config.h: $(dcf_root)/configuration-dynamic.make + @echo '// file : xsde/config.h' >$@ + @echo '// author : automatically generated' >>$@ + @echo '' >>$@ + @echo '#ifndef XSDE_CONFIG_H' >>$@ + @echo '#define XSDE_CONFIG_H' >>$@ + @echo '' >>$@ + @echo '#define XSDE_PLATFORM_POSIX' >>$@ + @echo '#define XSDE_ARCH_WIDTH $(xsde_arch_width)' >>$@ +ifeq ($(xsde_byteorder),l) + @echo '#define XSDE_BYTEORDER 1234' >>$@ +else + @echo '#define XSDE_BYTEORDER 4321' >>$@ +endif +ifeq ($(xsde_stl),y) + @echo '#define XSDE_STL' >>$@ +else + @echo '#undef XSDE_STL' >>$@ +endif +ifeq ($(xsde_iostream),y) + @echo '#define XSDE_IOSTREAM' >>$@ +else + @echo '#undef XSDE_IOSTREAM' >>$@ +endif +ifeq ($(xsde_exceptions),y) + @echo '#define XSDE_EXCEPTIONS' >>$@ +else + @echo '#undef XSDE_EXCEPTIONS' >>$@ +endif +ifeq ($(xsde_longlong),y) + @echo '#define XSDE_LONGLONG' >>$@ +else + @echo '#undef XSDE_LONGLONG' >>$@ +endif +ifeq ($(xsde_snprintf),y) + @echo '#define XSDE_SNPRINTF' >>$@ +else + @echo '#undef XSDE_SNPRINTF' >>$@ +endif +ifeq ($(xsde_parser_validation),y) + @echo '#define XSDE_PARSER_VALIDATION' >>$@ +else + @echo '#undef XSDE_PARSER_VALIDATION' >>$@ +endif +ifeq ($(xsde_serializer_validation),y) + @echo '#define XSDE_SERIALIZER_VALIDATION' >>$@ +else + @echo '#undef XSDE_SERIALIZER_VALIDATION' >>$@ +endif +ifeq ($(xsde_reuse_style),mixin) + @echo '#define XSDE_REUSE_STYLE_MIXIN' >>$@ +else + @echo '#undef XSDE_REUSE_STYLE_MIXIN' >>$@ +endif +ifeq ($(xsde_reuse_style),tiein) + @echo '#define XSDE_REUSE_STYLE_TIEIN' >>$@ +else + @echo '#undef XSDE_REUSE_STYLE_TIEIN' >>$@ +endif +ifeq ($(xsde_reuse_style),none) + @echo '#define XSDE_REUSE_STYLE_NONE' >>$@ +else + @echo '#undef XSDE_REUSE_STYLE_NONE' >>$@ +endif +ifeq ($(xsde_polymorphic),y) + @echo '#define XSDE_POLYMORPHIC' >>$@ + @echo '#define XSDE_PARSER_SMAP_BUCKETS $(xsde_parser_smap_buckets)UL' >>$@ +ifeq ($(xsde_parser_validation),y) + @echo '#define XSDE_PARSER_IMAP_BUCKETS $(xsde_parser_imap_buckets)UL' >>$@ +endif + @echo '#define XSDE_SERIALIZER_SMAP_BUCKETS $(xsde_serializer_smap_buckets)UL' >>$@ + @echo '#define XSDE_SERIALIZER_SMAP_BUCKET_BUCKETS $(xsde_serializer_smap_bucket_buckets)UL' >>$@ +ifeq ($(xsde_serializer_validation),y) + @echo '#define XSDE_SERIALIZER_IMAP_BUCKETS $(xsde_serializer_imap_buckets)UL' >>$@ +endif +else + @echo '#undef XSDE_POLYMORPHIC' >>$@ +endif + @echo '' >>$@ + @echo '#endif // XSDE_CONFIG_H' >>$@ + + +# Convenience alias for default target. +# +.PHONY: $(out_base)/ +$(out_base)/: $(xsde.l) + + +# Clean. +# +.PHONY: $(clean) + +$(clean): $(xsde.l).o.clean \ + $(xsde.l.cpp-options).clean \ + $(addsuffix .cxx.clean,$(cxx_o)) \ + $(addsuffix .cxx.clean,$(cxx_d)) + $(call message,rm $$1,rm -f $$1,$(out_base)/config.h) + +# How to. +# +$(call include,$(bld_root)/cxx/o-l.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/cxx-d.make) |