aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/serializer
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-03-17 13:10:42 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-03-17 13:10:42 +0200
commit2fc01f7a270d76177e8653e2b74f8ca1b7711cc3 (patch)
tree93fe46eb145bf8ec8654c28b7a261c01f2eba1b0 /libxsde/xsde/cxx/serializer
parent3ac8660a6e084014d047e1c121305094eace9bfa (diff)
Partial support for simple type facet validation
For now only certain types and facets are supported.
Diffstat (limited to 'libxsde/xsde/cxx/serializer')
-rw-r--r--libxsde/xsde/cxx/serializer/validating/short.cxx18
-rw-r--r--libxsde/xsde/cxx/serializer/validating/string-stl.cxx22
-rw-r--r--libxsde/xsde/cxx/serializer/validating/string.cxx27
-rw-r--r--libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx18
-rw-r--r--libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx18
-rw-r--r--libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx18
-rw-r--r--libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx180
-rw-r--r--libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx192
8 files changed, 477 insertions, 16 deletions
diff --git a/libxsde/xsde/cxx/serializer/validating/short.cxx b/libxsde/xsde/cxx/serializer/validating/short.cxx
index 1fea40f..1189cd5 100644
--- a/libxsde/xsde/cxx/serializer/validating/short.cxx
+++ b/libxsde/xsde/cxx/serializer/validating/short.cxx
@@ -24,6 +24,24 @@ namespace xsde
void short_simpl::
_serialize_content ()
{
+ // Check facets.
+ //
+ const facets& f = _facets ();
+
+ if (f.min_set_ &&
+ (value_ < f.min_ || (!f.min_inc_ && value_ == f.min_)))
+ {
+ _schema_error (schema_error::value_less_than_min);
+ return;
+ }
+
+ if (f.max_set_ &&
+ (value_ > f.max_ || (!f.max_inc_ && value_ == f.max_)))
+ {
+ _schema_error (schema_error::value_greater_than_max);
+ return;
+ }
+
// We only need strlen("-32768") + 1 characters to hold all
// representations of short.
//
diff --git a/libxsde/xsde/cxx/serializer/validating/string-stl.cxx b/libxsde/xsde/cxx/serializer/validating/string-stl.cxx
index fe87f7d..1e9a37b 100644
--- a/libxsde/xsde/cxx/serializer/validating/string-stl.cxx
+++ b/libxsde/xsde/cxx/serializer/validating/string-stl.cxx
@@ -22,6 +22,28 @@ namespace xsde
void string_simpl::
_serialize_content ()
{
+ // Check facets.
+ //
+ const facets& f = _facets ();
+
+ if (f.length_set_ && value_.size () != f.length_)
+ {
+ _schema_error (schema_error::length_not_equal_prescribed);
+ return;
+ }
+
+ if (f.min_length_set_ && value_.size () < f.min_length_)
+ {
+ _schema_error (schema_error::length_less_than_min);
+ return;
+ }
+
+ if (f.max_length_set_ && value_.size () > f.max_length_)
+ {
+ _schema_error (schema_error::length_greater_than_max);
+ return;
+ }
+
// Make sure we don't hold any references to the string.
//
std::string tmp;
diff --git a/libxsde/xsde/cxx/serializer/validating/string.cxx b/libxsde/xsde/cxx/serializer/validating/string.cxx
index 8082baa..0def094 100644
--- a/libxsde/xsde/cxx/serializer/validating/string.cxx
+++ b/libxsde/xsde/cxx/serializer/validating/string.cxx
@@ -3,6 +3,7 @@
// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+#include <string.h> // strlen
#include <xsde/cxx/serializer/validating/string.hxx>
namespace xsde
@@ -29,6 +30,32 @@ namespace xsde
void string_simpl::
_serialize_content ()
{
+ // Check facets.
+ //
+ if (length_set_ || min_length_set_ || max_length_set_)
+ {
+ size_t n = strlen (value_);
+ const facets& f = _facets ();
+
+ if (f.length_set_ && n != f.length_)
+ {
+ _schema_error (schema_error::length_not_equal_prescribed);
+ return;
+ }
+
+ if (f.min_length_set_ && n < f.min_length_)
+ {
+ _schema_error (schema_error::length_less_than_min);
+ return;
+ }
+
+ if (f.max_length_set_ && n > f.max_length_)
+ {
+ _schema_error (schema_error::length_greater_than_max);
+ return;
+ }
+ }
+
_characters (value_);
if (free_)
diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx
index 8a8f74e..bc8e5f9 100644
--- a/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx
+++ b/libxsde/xsde/cxx/serializer/validating/unsigned-byte.cxx
@@ -24,6 +24,24 @@ namespace xsde
void unsigned_byte_simpl::
_serialize_content ()
{
+ // Check facets.
+ //
+ const facets& f = _facets ();
+
+ if (f.min_set_ &&
+ (value_ < f.min_ || (!f.min_inc_ && value_ == f.min_)))
+ {
+ _schema_error (schema_error::value_less_than_min);
+ return;
+ }
+
+ if (f.max_set_ &&
+ (value_ > f.max_ || (!f.max_inc_ && value_ == f.max_)))
+ {
+ _schema_error (schema_error::value_greater_than_max);
+ return;
+ }
+
// We only need strlen("256") + 1 characters to hold all
// representations of unsigned byte.
//
diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx
index 0aece87..596dc0d 100644
--- a/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx
+++ b/libxsde/xsde/cxx/serializer/validating/unsigned-int.cxx
@@ -24,6 +24,24 @@ namespace xsde
void unsigned_int_simpl::
_serialize_content ()
{
+ // Check facets.
+ //
+ const facets& f = _facets ();
+
+ if (f.min_set_ &&
+ (value_ < f.min_ || (!f.min_inc_ && value_ == f.min_)))
+ {
+ _schema_error (schema_error::value_less_than_min);
+ return;
+ }
+
+ if (f.max_set_ &&
+ (value_ > f.max_ || (!f.max_inc_ && value_ == f.max_)))
+ {
+ _schema_error (schema_error::value_greater_than_max);
+ return;
+ }
+
// We only need strlen("4294967295") + 1 characters to hold all
// representations of unsigned int.
//
diff --git a/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx b/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx
index 4996128..3a96372 100644
--- a/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx
+++ b/libxsde/xsde/cxx/serializer/validating/unsigned-short.cxx
@@ -24,6 +24,24 @@ namespace xsde
void unsigned_short_simpl::
_serialize_content ()
{
+ // Check facets.
+ //
+ const facets& f = _facets ();
+
+ if (f.min_set_ &&
+ (value_ < f.min_ || (!f.min_inc_ && value_ == f.min_)))
+ {
+ _schema_error (schema_error::value_less_than_min);
+ return;
+ }
+
+ if (f.max_set_ &&
+ (value_ > f.max_ || (!f.max_inc_ && value_ == f.max_)))
+ {
+ _schema_error (schema_error::value_greater_than_max);
+ return;
+ }
+
// We only need strlen("65535") + 1 characters to hold all
// representations of short.
//
diff --git a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx
index 9f2a98e..c0b77d6 100644
--- a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx
+++ b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.hxx
@@ -149,13 +149,40 @@ namespace xsde
_dynamic_type () const;
#endif
-#ifdef XSDE_REUSE_STYLE_TIEIN
unsigned_byte_sskel ();
+
+#ifdef XSDE_REUSE_STYLE_TIEIN
unsigned_byte_sskel (unsigned_byte_sskel* impl, void*);
protected:
unsigned_byte_sskel* unsigned_byte_impl_;
#endif
+ // Facets.
+ //
+ public:
+ void
+ _max_facet (unsigned char, bool inclusive);
+
+ void
+ _min_facet (unsigned char, bool inclusive);
+
+ protected:
+ struct facets
+ {
+ unsigned char min_;
+ unsigned char max_;
+
+ unsigned int min_set_ : 1;
+ unsigned int min_inc_ : 1;
+ unsigned int max_set_ : 1;
+ unsigned int max_inc_ : 1;
+ };
+
+ const facets&
+ _facets () const;
+
+ private:
+ facets facets_;
};
@@ -175,13 +202,40 @@ namespace xsde
_dynamic_type () const;
#endif
-#ifdef XSDE_REUSE_STYLE_TIEIN
short_sskel ();
+
+#ifdef XSDE_REUSE_STYLE_TIEIN
short_sskel (short_sskel* impl, void*);
protected:
short_sskel* short_impl_;
#endif
+ // Facets.
+ //
+ public:
+ void
+ _max_facet (short, bool inclusive);
+
+ void
+ _min_facet (short, bool inclusive);
+
+ protected:
+ struct facets
+ {
+ short min_;
+ short max_;
+
+ unsigned int min_set_ : 1;
+ unsigned int min_inc_ : 1;
+ unsigned int max_set_ : 1;
+ unsigned int max_inc_ : 1;
+ };
+
+ const facets&
+ _facets () const;
+
+ private:
+ facets facets_;
};
struct unsigned_short_sskel: simple_content
@@ -197,13 +251,40 @@ namespace xsde
_dynamic_type () const;
#endif
-#ifdef XSDE_REUSE_STYLE_TIEIN
unsigned_short_sskel ();
+
+#ifdef XSDE_REUSE_STYLE_TIEIN
unsigned_short_sskel (unsigned_short_sskel* impl, void*);
protected:
unsigned_short_sskel* unsigned_short_impl_;
#endif
+ // Facets.
+ //
+ public:
+ void
+ _max_facet (unsigned short, bool inclusive);
+
+ void
+ _min_facet (unsigned short, bool inclusive);
+
+ protected:
+ struct facets
+ {
+ unsigned short min_;
+ unsigned short max_;
+
+ unsigned int min_set_ : 1;
+ unsigned int min_inc_ : 1;
+ unsigned int max_set_ : 1;
+ unsigned int max_inc_ : 1;
+ };
+
+ const facets&
+ _facets () const;
+
+ private:
+ facets facets_;
};
// 32-bit
@@ -244,13 +325,40 @@ namespace xsde
_dynamic_type () const;
#endif
-#ifdef XSDE_REUSE_STYLE_TIEIN
unsigned_int_sskel ();
+
+#ifdef XSDE_REUSE_STYLE_TIEIN
unsigned_int_sskel (unsigned_int_sskel* impl, void*);
protected:
unsigned_int_sskel* unsigned_int_impl_;
#endif
+ // Facets.
+ //
+ public:
+ void
+ _max_facet (unsigned int, bool inclusive);
+
+ void
+ _min_facet (unsigned int, bool inclusive);
+
+ protected:
+ struct facets
+ {
+ unsigned int min_;
+ unsigned int max_;
+
+ unsigned int min_set_ : 1;
+ unsigned int min_inc_ : 1;
+ unsigned int max_set_ : 1;
+ unsigned int max_inc_ : 1;
+ };
+
+ const facets&
+ _facets () const;
+
+ private:
+ facets facets_;
};
// 64-bit
@@ -545,13 +653,43 @@ namespace xsde
_dynamic_type () const;
#endif
-#ifdef XSDE_REUSE_STYLE_TIEIN
string_sskel ();
+
+#ifdef XSDE_REUSE_STYLE_TIEIN
string_sskel (string_sskel* impl, void*);
protected:
string_sskel* string_impl_;
#endif
+ // Facets.
+ //
+ public:
+ void
+ _length_facet (size_t);
+
+ void
+ _max_length_facet (size_t);
+
+ void
+ _min_length_facet (size_t);
+
+ protected:
+ struct facets
+ {
+ size_t length_;
+ size_t min_length_;
+ size_t max_length_;
+
+ unsigned int length_set_ : 1;
+ unsigned int min_length_set_ : 1;
+ unsigned int max_length_set_ : 1;
+ };
+
+ const facets&
+ _facets () const;
+
+ private:
+ facets facets_;
};
#ifdef XSDE_REUSE_STYLE_MIXIN
@@ -841,13 +979,43 @@ namespace xsde
_dynamic_type () const;
#endif
-#ifdef XSDE_REUSE_STYLE_TIEIN
string_sskel ();
+
+#ifdef XSDE_REUSE_STYLE_TIEIN
string_sskel (string_sskel* impl, void*);
protected:
string_sskel* string_impl_;
#endif
+ // Facets.
+ //
+ public:
+ void
+ _length_facet (size_t);
+
+ void
+ _max_length_facet (size_t);
+
+ void
+ _min_length_facet (size_t);
+
+ protected:
+ struct facets
+ {
+ size_t length_;
+ size_t min_length_;
+ size_t max_length_;
+
+ unsigned int length_set_ : 1;
+ unsigned int min_length_set_ : 1;
+ unsigned int max_length_set_ : 1;
+ };
+
+ const facets&
+ _facets () const;
+
+ private:
+ facets facets_;
};
#ifdef XSDE_REUSE_STYLE_MIXIN
diff --git a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx
index 1ea39b0..fd84bf0 100644
--- a/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx
+++ b/libxsde/xsde/cxx/serializer/validating/xml-schema-sskel.ixx
@@ -77,51 +77,150 @@ namespace xsde
// unsigned_byte_sskel
//
-#ifdef XSDE_REUSE_STYLE_TIEIN
inline unsigned_byte_sskel::
unsigned_byte_sskel ()
- : unsigned_byte_impl_ (0)
{
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ unsigned_byte_impl_ = 0;
+#endif
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
}
+#ifdef XSDE_REUSE_STYLE_TIEIN
inline unsigned_byte_sskel::
unsigned_byte_sskel (unsigned_byte_sskel* impl, void*)
: simple_content (impl, 0), unsigned_byte_impl_ (impl)
{
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
+ }
+#endif
+
+ inline void unsigned_byte_sskel::
+ _max_facet (unsigned char v, bool inc)
+ {
+ facets_.max_ = v;
+ facets_.max_set_ = 1;
+ facets_.max_inc_ = inc;
+ }
+
+ inline void unsigned_byte_sskel::
+ _min_facet (unsigned char v, bool inc)
+ {
+ facets_.min_ = v;
+ facets_.min_set_ = 1;
+ facets_.min_inc_ = inc;
}
+
+ inline const unsigned_byte_sskel::facets& unsigned_byte_sskel::
+ _facets () const
+ {
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ if (parent_ != 0)
+ return static_cast<const unsigned_byte_sskel&> (*parent_).facets_;
+ else
#endif
+ return facets_;
+ }
// short_sskel
//
-#ifdef XSDE_REUSE_STYLE_TIEIN
inline short_sskel::
short_sskel ()
- : short_impl_ (0)
{
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ short_impl_ = 0;
+#endif
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
}
+#ifdef XSDE_REUSE_STYLE_TIEIN
inline short_sskel::
short_sskel (short_sskel* impl, void*)
: simple_content (impl, 0), short_impl_ (impl)
{
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
}
#endif
+ inline void short_sskel::
+ _max_facet (short v, bool inc)
+ {
+ facets_.max_ = v;
+ facets_.max_set_ = 1;
+ facets_.max_inc_ = inc;
+ }
+
+ inline void short_sskel::
+ _min_facet (short v, bool inc)
+ {
+ facets_.min_ = v;
+ facets_.min_set_ = 1;
+ facets_.min_inc_ = inc;
+ }
+
+ inline const short_sskel::facets& short_sskel::
+ _facets () const
+ {
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ if (parent_ != 0)
+ return static_cast<const short_sskel&> (*parent_).facets_;
+ else
+#endif
+ return facets_;
+ }
+
// unsigned_short_sskel
//
-#ifdef XSDE_REUSE_STYLE_TIEIN
inline unsigned_short_sskel::
unsigned_short_sskel ()
- : unsigned_short_impl_ (0)
{
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ unsigned_short_impl_ = 0;
+#endif
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
}
+#ifdef XSDE_REUSE_STYLE_TIEIN
inline unsigned_short_sskel::
unsigned_short_sskel (unsigned_short_sskel* impl, void*)
: simple_content (impl, 0), unsigned_short_impl_ (impl)
{
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
+ }
+#endif
+
+ inline void unsigned_short_sskel::
+ _max_facet (unsigned short v, bool inc)
+ {
+ facets_.max_ = v;
+ facets_.max_set_ = 1;
+ facets_.max_inc_ = inc;
+ }
+
+ inline void unsigned_short_sskel::
+ _min_facet (unsigned short v, bool inc)
+ {
+ facets_.min_ = v;
+ facets_.min_set_ = 1;
+ facets_.min_inc_ = inc;
}
+
+ inline const unsigned_short_sskel::facets& unsigned_short_sskel::
+ _facets () const
+ {
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ if (parent_ != 0)
+ return static_cast<const unsigned_short_sskel&> (*parent_).facets_;
+ else
#endif
+ return facets_;
+ }
// int_sskel
//
@@ -141,20 +240,53 @@ namespace xsde
// unsigned_int_sskel
//
-#ifdef XSDE_REUSE_STYLE_TIEIN
inline unsigned_int_sskel::
unsigned_int_sskel ()
- : unsigned_int_impl_ (0)
{
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ unsigned_int_impl_ = 0;
+#endif
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
}
+#ifdef XSDE_REUSE_STYLE_TIEIN
inline unsigned_int_sskel::
unsigned_int_sskel (unsigned_int_sskel* impl, void*)
: simple_content (impl, 0), unsigned_int_impl_ (impl)
{
+ facets_.min_set_ = 0;
+ facets_.max_set_ = 0;
}
#endif
+ inline void unsigned_int_sskel::
+ _max_facet (unsigned int v, bool inc)
+ {
+ facets_.max_ = v;
+ facets_.max_set_ = 1;
+ facets_.max_inc_ = inc;
+ }
+
+ inline void unsigned_int_sskel::
+ _min_facet (unsigned int v, bool inc)
+ {
+ facets_.min_ = v;
+ facets_.min_set_ = 1;
+ facets_.min_inc_ = inc;
+ }
+
+ inline const unsigned_int_sskel::facets& unsigned_int_sskel::
+ _facets () const
+ {
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ if (parent_ != 0)
+ return static_cast<const unsigned_int_sskel&> (*parent_).facets_;
+ else
+#endif
+ return facets_;
+ }
+
// long_sskel
//
#ifdef XSDE_REUSE_STYLE_TIEIN
@@ -317,20 +449,60 @@ namespace xsde
// string_sskel
//
-#ifdef XSDE_REUSE_STYLE_TIEIN
inline string_sskel::
string_sskel ()
- : string_impl_ (0)
{
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ string_impl_ = 0;
+#endif
+ facets_.length_set_ = 0;
+ facets_.min_length_set_ = 0;
+ facets_.max_length_set_ = 0;
}
+#ifdef XSDE_REUSE_STYLE_TIEIN
inline string_sskel::
string_sskel (string_sskel* impl, void*)
: simple_content (impl, 0), string_impl_ (impl)
{
+ facets_.length_set_ = 0;
+ facets_.min_length_set_ = 0;
+ facets_.max_length_set_ = 0;
}
#endif
+ inline void string_sskel::
+ _length_facet (size_t v)
+ {
+ facets_.length_ = v;
+ facets_.length_set_ = 1;
+ }
+
+ inline void string_sskel::
+ _max_length_facet (size_t v)
+ {
+ facets_.max_length_ = v;
+ facets_.max_length_set_ = 1;
+ }
+
+ inline void string_sskel::
+ _min_length_facet (size_t v)
+ {
+ facets_.min_length_ = v;
+ facets_.min_length_set_ = 1;
+ }
+
+ inline const string_sskel::facets& string_sskel::
+ _facets () const
+ {
+#ifdef XSDE_REUSE_STYLE_TIEIN
+ if (parent_ != 0)
+ return static_cast<const string_sskel&> (*parent_).facets_;
+ else
+#endif
+ return facets_;
+ }
+
// normalized_string_sskel
//
#ifdef XSDE_REUSE_STYLE_TIEIN