summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libxsd/xsd/cxx/tree/istream.hxx149
-rw-r--r--xsd/cxx/tree/stream-extraction-source.cxx28
-rw-r--r--xsd/cxx/tree/stream-insertion-source.cxx38
3 files changed, 208 insertions, 7 deletions
diff --git a/libxsd/xsd/cxx/tree/istream.hxx b/libxsd/xsd/cxx/tree/istream.hxx
index 2f8f8cb..07bba53 100644
--- a/libxsd/xsd/cxx/tree/istream.hxx
+++ b/libxsd/xsd/cxx/tree/istream.hxx
@@ -138,6 +138,52 @@ namespace xsd
return s_;
}
+ public:
+ // 8-bit
+ //
+ signed char
+ read_char ();
+
+ unsigned char
+ read_uchar ();
+
+ // 16-bit
+ //
+ unsigned short
+ read_short ();
+
+ unsigned short
+ read_ushort ();
+
+ // 32-bit
+ //
+ unsigned int
+ read_int ();
+
+ unsigned int
+ read_uint ();
+
+ // 64-bit
+ //
+ unsigned long long
+ read_ulonglong ();
+
+ unsigned long long
+ read_longlong ();
+
+ // Boolean
+ //
+ bool
+ read_bool ();
+
+ // Floating-point
+ //
+ float
+ read_float ();
+
+ double
+ read_double ();
+
private:
istream (const istream&);
istream&
@@ -251,6 +297,109 @@ namespace xsd
istream_common::as_float64<double> as_float64 (x);
return s >> as_float64;
}
+
+ //
+ // read_* functions.
+ //
+
+ template <typename S>
+ inline signed char istream<S>::
+ read_char ()
+ {
+ signed char r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned char istream<S>::
+ read_uchar ()
+ {
+ unsigned char r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned short istream<S>::
+ read_short ()
+ {
+ short r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned short istream<S>::
+ read_ushort ()
+ {
+ unsigned short r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned int istream<S>::
+ read_int ()
+ {
+ int r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned int istream<S>::
+ read_uint ()
+ {
+ unsigned int r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned long long istream<S>::
+ read_ulonglong ()
+ {
+ long long r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline unsigned long long istream<S>::
+ read_longlong ()
+ {
+ unsigned long long r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline bool istream<S>::
+ read_bool ()
+ {
+ bool r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline float istream<S>::
+ read_float ()
+ {
+ float r;
+ *this >> r;
+ return r;
+ }
+
+ template <typename S>
+ inline double istream<S>::
+ read_double ()
+ {
+ double r;
+ *this >> r;
+ return r;
+ }
}
}
}
diff --git a/xsd/cxx/tree/stream-extraction-source.cxx b/xsd/cxx/tree/stream-extraction-source.cxx
index 0828c79..3fe1bf0 100644
--- a/xsd/cxx/tree/stream-extraction-source.cxx
+++ b/xsd/cxx/tree/stream-extraction-source.cxx
@@ -175,6 +175,20 @@ namespace CXX
t.dispatch (e);
}
+ Boolean enum_based (false);
+ if (string_based)
+ {
+ SemanticGraph::Enumeration* base_enum (0);
+ IsEnumBasedType t (base_enum);
+ t.dispatch (e);
+
+ enum_based = (base_enum != 0);
+ }
+
+ String value;
+ if (string_based)
+ value = evalue (e);
+
UnsignedLong n (0);
Streams const& st (options.value<CLI::generate_extraction> ());
for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i)
@@ -188,8 +202,18 @@ namespace CXX
inherits (e, inherits_base_);
- os << " (s, f, c)"
- << "{";
+ if (string_based && !enum_based)
+ {
+ // Use copy c-tor to pass the flags and container.
+ //
+ os << " (" << endl;
+ inherits (e, inherits_base_);
+ os << " (_xsd_" << name << "_literals_[s.read_uint ()]), f, c)";
+ }
+ else
+ os << " (s, f, c)";
+
+ os << "{";
if (string_based)
os << "_xsd_" << name << "_convert ();";
diff --git a/xsd/cxx/tree/stream-insertion-source.cxx b/xsd/cxx/tree/stream-insertion-source.cxx
index 09faf71..99b3c74 100644
--- a/xsd/cxx/tree/stream-insertion-source.cxx
+++ b/xsd/cxx/tree/stream-insertion-source.cxx
@@ -168,6 +168,26 @@ namespace CXX
if (renamed_type (e, name) && !name)
return;
+ Boolean string_based (false);
+ {
+ IsStringBasedType t (string_based);
+ t.dispatch (e);
+ }
+
+ Boolean enum_based (false);
+ if (string_based)
+ {
+ SemanticGraph::Enumeration* base_enum (0);
+ IsEnumBasedType t (base_enum);
+ t.dispatch (e);
+
+ enum_based = (base_enum != 0);
+ }
+
+ String value;
+ if (string_based)
+ value = evalue (e);
+
UnsignedLong n (0);
Streams const& st (options.value<CLI::generate_insertion> ());
for (Streams::ConstIterator i (st.begin ()); i != st.end (); ++i)
@@ -177,13 +197,21 @@ namespace CXX
os << stream_type << "&" << endl
<< "operator<< (" << stream_type << "& s," << endl
<< "const " << name << "& x)"
- << "{"
- << "return s << static_cast< const ";
+ << "{";
- inherits (e, inherits_base_);
+ if (!string_based || enum_based)
+ {
+ os << "return s << static_cast< const ";
+ inherits (e, inherits_base_);
+ os << "& > (x);";
+ }
+ else
+ {
+ os << name << "::" << value << " v (x);"
+ << "return s << static_cast< unsigned int > (v);";
+ }
- os << "& > (x);"
- << "}";
+ os << "}";
// Register with type map.
//