diff options
Diffstat (limited to 'libxsde/xsde/cxx')
674 files changed, 59091 insertions, 0 deletions
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 |