aboutsummaryrefslogtreecommitdiff
path: root/xsd-frontend
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-06-22 11:51:14 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-06-22 11:51:14 +0200
commit26899a31d9a85e6ec6cfb782b0977af05e3330c1 (patch)
tree2e22074dad490a2195ef22bf2f7f6ca4ed67aa88 /xsd-frontend
parent90801c5afeb37e4297076bdd5354ba41a7009a3f (diff)
Get rid of dependency on libcult
Diffstat (limited to 'xsd-frontend')
-rw-r--r--xsd-frontend/makefile11
-rw-r--r--xsd-frontend/parser.cxx22
-rw-r--r--xsd-frontend/parser.hxx11
-rw-r--r--xsd-frontend/semantic-graph/annotation.hxx6
-rw-r--r--xsd-frontend/semantic-graph/any-attribute.cxx8
-rw-r--r--xsd-frontend/semantic-graph/any-attribute.hxx4
-rw-r--r--xsd-frontend/semantic-graph/any.cxx8
-rw-r--r--xsd-frontend/semantic-graph/any.hxx4
-rw-r--r--xsd-frontend/semantic-graph/elements.hxx18
-rw-r--r--xsd-frontend/transformations/anonymous.cxx4
-rw-r--r--xsd-frontend/transformations/anonymous.hxx14
-rw-r--r--xsd-frontend/transformations/enum-synthesis.cxx3
-rw-r--r--xsd-frontend/transformations/enum-synthesis.hxx4
-rw-r--r--xsd-frontend/transformations/restriction.cxx6
-rw-r--r--xsd-frontend/transformations/restriction.hxx4
-rw-r--r--xsd-frontend/transformations/schema-per-type.cxx18
-rw-r--r--xsd-frontend/transformations/schema-per-type.hxx12
-rw-r--r--xsd-frontend/transformations/simplifier.cxx2
-rw-r--r--xsd-frontend/transformations/simplifier.hxx4
-rw-r--r--xsd-frontend/traversal/elements.hxx4
-rw-r--r--xsd-frontend/types.cxx62
-rw-r--r--xsd-frontend/types.hxx237
-rw-r--r--xsd-frontend/xml.hxx2
23 files changed, 365 insertions, 103 deletions
diff --git a/xsd-frontend/makefile b/xsd-frontend/makefile
index 010ec7d..68b427a 100644
--- a/xsd-frontend/makefile
+++ b/xsd-frontend/makefile
@@ -44,7 +44,7 @@ cxx_tun += transformations/anonymous.cxx \
transformations/schema-per-type.cxx \
transformations/simplifier.cxx
-cxx_tun += parser.cxx schema-dom-parser.cxx
+cxx_tun += types.cxx parser.cxx schema-dom-parser.cxx
cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o))
@@ -71,19 +71,14 @@ $(call import,\
$(scf_root)/import/libcutl/stub.make,\
l: cutl.l,cpp-options: cutl.l.cpp-options)
-$(call import,\
- $(scf_root)/import/libcult/stub.make,\
- l: cult.l,cpp-options: cult.l.cpp-options)
-
-# what to build
+# What to build.
#
-$(xsd_frontend.l): $(cxx_obj) $(cult.l) $(cutl.l) $(xerces_c.l) $(fs.l)
+$(xsd_frontend.l): $(cxx_obj) $(cutl.l) $(xerces_c.l) $(fs.l)
$(xsd_frontend.l.cpp-options): prefix := xsd-frontend/ $(out_root)/
$(xsd_frontend.l.cpp-options): value := -I$(src_root) -I$(out_root)
$(xsd_frontend.l.cpp-options): \
$(fs.l.cpp-options) \
- $(cult.l.cpp-options) \
$(cutl.l.cpp-options)
#@@ This can be further optimized since only parser depends on xerces.
diff --git a/xsd-frontend/parser.cxx b/xsd-frontend/parser.cxx
index 782b01f..3a0b180 100644
--- a/xsd-frontend/parser.cxx
+++ b/xsd-frontend/parser.cxx
@@ -11,7 +11,6 @@
#include <cutl/compiler/type-id.hxx>
-#include <xsd-frontend/types.hxx>
#include <xsd-frontend/parser.hxx>
#include <xsd-frontend/xml.hxx>
#include <xsd-frontend/schema-dom-parser.hxx>
@@ -107,10 +106,10 @@ namespace XSDFrontend
// Trim leading and trailing whitespaces.
//
template <typename C>
- Cult::StringTemplate<C>
- trim (Cult::StringTemplate<C> const& s)
+ StringTemplate<C>
+ trim (StringTemplate<C> const& s)
{
- typedef Cult::StringTemplate<C> String;
+ typedef StringTemplate<C> String;
size_t size (s.size ());
@@ -1312,8 +1311,11 @@ namespace XSDFrontend
// Parser::Impl
//
- class Parser::Impl: public NonCopyable
+ class Parser::Impl
{
+ Impl (Impl const&);
+ Impl& operator= (Impl const&);
+
public:
~Impl ();
@@ -1417,7 +1419,7 @@ namespace XSDFrontend
private:
bool
- is_disabled (Char const* warning)
+ is_disabled (char const* warning)
{
return disabled_warnings_all_ ||
(disabled_warnings_ &&
@@ -4750,8 +4752,10 @@ namespace XSDFrontend
// that can later be used in diagnostics. Unfortunately, it doesn't
// work. So we will have to keep our own track.
//
- struct Context: public NonCopyable
+ struct Context
{
+ Context () {}
+
// File map for diagnostic.
//
Path const&
@@ -4776,6 +4780,10 @@ namespace XSDFrontend
}
private:
+ Context (Context const&);
+ Context& operator= (Context const&);
+
+ private:
typedef std::map<Path, Path, FilePathComparator> FileMap;
FileMap file_map_;
};
diff --git a/xsd-frontend/parser.hxx b/xsd-frontend/parser.hxx
index 2efb75f..cf8122f 100644
--- a/xsd-frontend/parser.hxx
+++ b/xsd-frontend/parser.hxx
@@ -9,14 +9,11 @@
#include <set>
#include <memory> // std::auto_ptr
-#include <cult/types.hxx>
-
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/schema.hxx>
namespace XSDFrontend
{
- using namespace Cult::Types;
-
struct InvalidSchema {};
class LocationTranslator
@@ -34,7 +31,7 @@ namespace XSDFrontend
//
typedef std::set<NarrowString> WarningSet;
- class Parser: public NonCopyable
+ class Parser
{
public:
~Parser ();
@@ -49,6 +46,10 @@ namespace XSDFrontend
LocationTranslator&,
const WarningSet& disabled);
+ private:
+ Parser (Parser const&);
+ Parser& operator= (Parser const&);
+
public:
// Parse a schema file. Throws InvalidSchema in case of a failure.
//
diff --git a/xsd-frontend/semantic-graph/annotation.hxx b/xsd-frontend/semantic-graph/annotation.hxx
index 3d6f098..6752a86 100644
--- a/xsd-frontend/semantic-graph/annotation.hxx
+++ b/xsd-frontend/semantic-graph/annotation.hxx
@@ -49,7 +49,7 @@ namespace XSDFrontend
class Annotation: public virtual Node
{
public:
- WideString const&
+ String const&
documentation () const
{
return documentation_;
@@ -59,7 +59,7 @@ namespace XSDFrontend
Annotation (Path const& file,
unsigned long line,
unsigned long column,
- WideString const& documentation)
+ String const& documentation)
: Node (file, line, column), documentation_ (documentation)
{
}
@@ -68,7 +68,7 @@ namespace XSDFrontend
add_edge_left (Annotates&) {}
private:
- WideString documentation_;
+ String documentation_;
};
}
}
diff --git a/xsd-frontend/semantic-graph/any-attribute.cxx b/xsd-frontend/semantic-graph/any-attribute.cxx
index 8a8660c..a5dcd36 100644
--- a/xsd-frontend/semantic-graph/any-attribute.cxx
+++ b/xsd-frontend/semantic-graph/any-attribute.cxx
@@ -16,7 +16,7 @@ namespace XSDFrontend
AnyAttribute (Path const& file,
unsigned long line,
unsigned long column,
- WideString const& namespaces)
+ String const& namespaces)
: Node (file, line, column),
prototype_ (0)
{
@@ -26,9 +26,9 @@ namespace XSDFrontend
for (size_t i (0), j (namespaces.find (L' '));;)
{
- if (j != WideString::npos)
+ if (j != String::npos)
{
- namespaces_.push_back (WideString (namespaces, i, j - i));
+ namespaces_.push_back (String (namespaces, i, j - i));
i = j + 1;
j = namespaces.find (L' ', i);
@@ -37,7 +37,7 @@ namespace XSDFrontend
{
// Last element.
//
- namespaces_.push_back (WideString (namespaces, i));
+ namespaces_.push_back (String (namespaces, i));
break;
}
}
diff --git a/xsd-frontend/semantic-graph/any-attribute.hxx b/xsd-frontend/semantic-graph/any-attribute.hxx
index 8827987..a5ce78a 100644
--- a/xsd-frontend/semantic-graph/any-attribute.hxx
+++ b/xsd-frontend/semantic-graph/any-attribute.hxx
@@ -17,7 +17,7 @@ namespace XSDFrontend
{
class AnyAttribute: public virtual Nameable
{
- typedef std::vector<WideString> Namespaces;
+ typedef std::vector<String> Namespaces;
public:
typedef Namespaces::const_iterator NamespaceIterator;
@@ -63,7 +63,7 @@ namespace XSDFrontend
AnyAttribute (Path const& file,
unsigned long line,
unsigned long column,
- WideString const& namespaces);
+ String const& namespaces);
AnyAttribute (Path const& file,
unsigned long line,
diff --git a/xsd-frontend/semantic-graph/any.cxx b/xsd-frontend/semantic-graph/any.cxx
index 75eb5dd..8aff295 100644
--- a/xsd-frontend/semantic-graph/any.cxx
+++ b/xsd-frontend/semantic-graph/any.cxx
@@ -16,7 +16,7 @@ namespace XSDFrontend
Any (Path const& file,
unsigned long line,
unsigned long column,
- WideString const& namespaces)
+ String const& namespaces)
: Node (file, line, column),
prototype_ (0)
{
@@ -26,9 +26,9 @@ namespace XSDFrontend
for (size_t i (0), j (namespaces.find (L' '));;)
{
- if (j != WideString::npos)
+ if (j != String::npos)
{
- namespaces_.push_back (WideString (namespaces, i, j - i));
+ namespaces_.push_back (String (namespaces, i, j - i));
i = j + 1;
j = namespaces.find (L' ', i);
@@ -37,7 +37,7 @@ namespace XSDFrontend
{
// Last element.
//
- namespaces_.push_back (WideString (namespaces, i));
+ namespaces_.push_back (String (namespaces, i));
break;
}
}
diff --git a/xsd-frontend/semantic-graph/any.hxx b/xsd-frontend/semantic-graph/any.hxx
index b0506d0..47513b9 100644
--- a/xsd-frontend/semantic-graph/any.hxx
+++ b/xsd-frontend/semantic-graph/any.hxx
@@ -19,7 +19,7 @@ namespace XSDFrontend
class Any: public virtual Nameable,
public virtual Particle
{
- typedef std::vector<WideString> Namespaces;
+ typedef std::vector<String> Namespaces;
public:
typedef Namespaces::const_iterator NamespaceIterator;
@@ -65,7 +65,7 @@ namespace XSDFrontend
Any (Path const& file,
unsigned long line,
unsigned long column,
- WideString const& namespaces);
+ String const& namespaces);
Any (Path const& file,
unsigned long line,
diff --git a/xsd-frontend/semantic-graph/elements.hxx b/xsd-frontend/semantic-graph/elements.hxx
index ad70221..1847572 100644
--- a/xsd-frontend/semantic-graph/elements.hxx
+++ b/xsd-frontend/semantic-graph/elements.hxx
@@ -21,7 +21,7 @@
#include <cutl/container/pointer-iterator.hxx>
#include <cutl/compiler/context.hxx>
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
namespace XSDFrontend
{
@@ -31,8 +31,6 @@ namespace XSDFrontend
using container::pointer_iterator;
- using namespace Cult::Types;
-
//
//
typedef boost::filesystem::path Path;
@@ -181,7 +179,7 @@ namespace XSDFrontend
//
//
- typedef WideString Name;
+ typedef String Name;
//
@@ -648,7 +646,7 @@ namespace XSDFrontend
class Restricts: public virtual Inherits
{
public:
- typedef std::map<WideString, WideString> Facets;
+ typedef std::map<String, String> Facets;
typedef Facets::iterator FacetIterator;
bool
@@ -670,7 +668,7 @@ namespace XSDFrontend
}
FacetIterator
- facet_find (WideString const& name)
+ facet_find (String const& name)
{
return facets_.find (name);
}
@@ -782,7 +780,7 @@ namespace XSDFrontend
struct NoValue {};
- WideString
+ String
value () const
{
if (value_type_ != ValueType::none)
@@ -794,14 +792,14 @@ namespace XSDFrontend
//
//
void
- default_ (WideString const& v)
+ default_ (String const& v)
{
value_ = v;
value_type_ = ValueType::default_;
}
void
- fixed (WideString const& v)
+ fixed (String const& v)
{
value_ = v;
value_type_ = ValueType::fixed;
@@ -841,7 +839,7 @@ namespace XSDFrontend
};
};
- WideString value_;
+ String value_;
ValueType::Value value_type_;
};
diff --git a/xsd-frontend/transformations/anonymous.cxx b/xsd-frontend/transformations/anonymous.cxx
index afaf66a..3fa4f00 100644
--- a/xsd-frontend/transformations/anonymous.cxx
+++ b/xsd-frontend/transformations/anonymous.cxx
@@ -17,10 +17,6 @@ using std::endl;
namespace XSDFrontend
{
- using namespace Cult;
-
- typedef WideString String;
-
namespace
{
using Transformations::AnonymousNameTranslator;
diff --git a/xsd-frontend/transformations/anonymous.hxx b/xsd-frontend/transformations/anonymous.hxx
index 992b7ff..4f1dcdd 100644
--- a/xsd-frontend/transformations/anonymous.hxx
+++ b/xsd-frontend/transformations/anonymous.hxx
@@ -6,7 +6,7 @@
#ifndef XSD_FRONTEND_TRANSFORMATIONS_ANONYMOUS_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_ANONYMOUS_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +15,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
class AnonymousNameTranslator
{
public:
@@ -26,11 +24,11 @@ namespace XSDFrontend
// The file argument is empty for the currect translation
// unit.
//
- virtual WideString
- translate (WideString const& file,
- WideString const& ns,
- WideString const& name,
- WideString const& xpath) = 0;
+ virtual String
+ translate (String const& file,
+ String const& ns,
+ String const& name,
+ String const& xpath) = 0;
};
// This transformation morphs anonymous types into named ones
diff --git a/xsd-frontend/transformations/enum-synthesis.cxx b/xsd-frontend/transformations/enum-synthesis.cxx
index c1ef5a7..169d27e 100644
--- a/xsd-frontend/transformations/enum-synthesis.cxx
+++ b/xsd-frontend/transformations/enum-synthesis.cxx
@@ -12,9 +12,6 @@
namespace XSDFrontend
{
- using namespace Cult;
- typedef WideString String;
-
namespace
{
typedef std::set<String> Enumerators;
diff --git a/xsd-frontend/transformations/enum-synthesis.hxx b/xsd-frontend/transformations/enum-synthesis.hxx
index 97658a3..edbee07 100644
--- a/xsd-frontend/transformations/enum-synthesis.hxx
+++ b/xsd-frontend/transformations/enum-synthesis.hxx
@@ -6,7 +6,7 @@
#ifndef XSD_FRONTEND_TRANSFORMATIONS_ENUM_SYNTHESIS_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_ENUM_SYNTHESIS_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +15,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
// This transformation replaces unions of one or more enumerations
// with the same base with an equivalent synthesized enumeration.
// This transformation assumes that there are no anonymous types.
diff --git a/xsd-frontend/transformations/restriction.cxx b/xsd-frontend/transformations/restriction.cxx
index dae1f03..0d63a9f 100644
--- a/xsd-frontend/transformations/restriction.cxx
+++ b/xsd-frontend/transformations/restriction.cxx
@@ -11,14 +11,10 @@
#include <xsd-frontend/transformations/restriction.hxx>
-using std::wcerr;
-using std::endl;
+using namespace std;
namespace XSDFrontend
{
- using namespace Cult;
-
- typedef WideString String;
typedef Transformations::Restriction::Failed Failed;
typedef std::vector<SemanticGraph::Complex*> BaseList;
diff --git a/xsd-frontend/transformations/restriction.hxx b/xsd-frontend/transformations/restriction.hxx
index 8cf4cd8..2adeb03 100644
--- a/xsd-frontend/transformations/restriction.hxx
+++ b/xsd-frontend/transformations/restriction.hxx
@@ -6,7 +6,7 @@
#ifndef XSD_FRONTEND_TRANSFORMATIONS_RESTRICTION_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_RESTRICTION_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +15,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
// This transformation performs two major tasks. It transfers omitted
// attribute declarations from the base to derived-by-restriction type
// and establishes correspondence between particles and compositors by
diff --git a/xsd-frontend/transformations/schema-per-type.cxx b/xsd-frontend/transformations/schema-per-type.cxx
index 69b43ca..caae52d 100644
--- a/xsd-frontend/transformations/schema-per-type.cxx
+++ b/xsd-frontend/transformations/schema-per-type.cxx
@@ -22,15 +22,9 @@ using std::endl;
namespace XSDFrontend
{
- using namespace Cult;
-
- typedef WideString String;
typedef Transformations::SchemaPerType::Failed Failed;
-
typedef std::vector<SemanticGraph::Schema*> Schemas;
- typedef
- std::map<SemanticGraph::Type*, SemanticGraph::Schema*>
- TypeSchemaMap;
+ typedef std::map<SemanticGraph::Type*, SemanticGraph::Schema*> TypeSchemaMap;
// Compare file paths case-insensitively.
//
@@ -143,7 +137,7 @@ namespace XSDFrontend
//
if (!tn)
{
- for (NarrowString::Iterator i (base.begin ()), e (base.end ());
+ for (NarrowString::iterator i (base.begin ()), e (base.end ());
i != e; ++i)
{
if (*i == '/' || *i == '\\')
@@ -182,7 +176,7 @@ namespace XSDFrontend
throw Failed ();
}
}
- catch (String::NonRepresentable const&)
+ catch (NonRepresentable const&)
{
wcerr << "error: '" << wbase << "' cannot be represented as a "
<< "narrow string" << endl;
@@ -251,7 +245,7 @@ namespace XSDFrontend
{
Type (SemanticGraph::Schema& schema,
SemanticGraph::Schema& root,
- Char const* by_value_key,
+ char const* by_value_key,
TypeSchemaMap& tsm)
: schema_ (schema),
root_ (root),
@@ -333,7 +327,7 @@ namespace XSDFrontend
private:
SemanticGraph::Schema& schema_;
SemanticGraph::Schema& root_;
- Char const* by_value_key_;
+ char const* by_value_key_;
TypeSchemaMap& tsm_;
std::set<SemanticGraph::Type*> type_set_;
@@ -346,7 +340,7 @@ namespace XSDFrontend
SchemaPerType::
SchemaPerType (SchemaPerTypeTranslator& trans,
bool fat,
- Char const* key)
+ char const* key)
: fat_type_file_ (fat), by_value_key_ (key), trans_ (trans)
{
}
diff --git a/xsd-frontend/transformations/schema-per-type.hxx b/xsd-frontend/transformations/schema-per-type.hxx
index 6e034d6..9498d42 100644
--- a/xsd-frontend/transformations/schema-per-type.hxx
+++ b/xsd-frontend/transformations/schema-per-type.hxx
@@ -8,7 +8,7 @@
#include <vector>
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -17,8 +17,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
class SchemaPerTypeTranslator
{
public:
@@ -28,8 +26,8 @@ namespace XSDFrontend
// The following two functions should return empty string if
// there is no match.
//
- virtual WideString
- translate_type (WideString const& ns, WideString const& name) = 0;
+ virtual String
+ translate_type (String const& ns, String const& name) = 0;
virtual NarrowString
translate_schema (NarrowString const& abs_path) = 0;
@@ -49,14 +47,14 @@ namespace XSDFrontend
//
SchemaPerType (SchemaPerTypeTranslator&,
bool fat_type_file,
- Char const* by_value_key = 0);
+ char const* by_value_key = 0);
std::vector<SemanticGraph::Schema*>
transform (SemanticGraph::Schema&);
private:
bool fat_type_file_;
- Char const* by_value_key_;
+ char const* by_value_key_;
SchemaPerTypeTranslator& trans_;
};
}
diff --git a/xsd-frontend/transformations/simplifier.cxx b/xsd-frontend/transformations/simplifier.cxx
index ba6b04f..16f07a1 100644
--- a/xsd-frontend/transformations/simplifier.cxx
+++ b/xsd-frontend/transformations/simplifier.cxx
@@ -10,8 +10,6 @@
namespace XSDFrontend
{
- using namespace Cult;
-
namespace
{
struct Compositor: Traversal::All,
diff --git a/xsd-frontend/transformations/simplifier.hxx b/xsd-frontend/transformations/simplifier.hxx
index 44a3429..d516943 100644
--- a/xsd-frontend/transformations/simplifier.hxx
+++ b/xsd-frontend/transformations/simplifier.hxx
@@ -6,7 +6,7 @@
#ifndef XSD_FRONTEND_TRANSFORMATIONS_SIMPLIFIER_HXX
#define XSD_FRONTEND_TRANSFORMATIONS_SIMPLIFIER_HXX
-#include <cult/types.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx> // Path
#include <xsd-frontend/semantic-graph/schema.hxx>
@@ -15,8 +15,6 @@ namespace XSDFrontend
{
namespace Transformations
{
- using namespace Cult::Types;
-
// This transformation performs various schema simplifications
// (e.g., removing empty compositors, etc). This transformation
// assumes that there are no anonymous types.
diff --git a/xsd-frontend/traversal/elements.hxx b/xsd-frontend/traversal/elements.hxx
index bf4b0f1..9e2b106 100644
--- a/xsd-frontend/traversal/elements.hxx
+++ b/xsd-frontend/traversal/elements.hxx
@@ -6,10 +6,9 @@
#ifndef XSD_FRONTEND_TRAVERSAL_ELEMENTS_HXX
#define XSD_FRONTEND_TRAVERSAL_ELEMENTS_HXX
-#include <cult/types.hxx>
-
#include <cutl/compiler/traversal.hxx>
+#include <xsd-frontend/types.hxx>
#include <xsd-frontend/semantic-graph/elements.hxx>
namespace XSDFrontend
@@ -17,7 +16,6 @@ namespace XSDFrontend
namespace Traversal
{
using namespace cutl;
- using namespace Cult::Types;
typedef compiler::dispatcher<SemanticGraph::Node> NodeDispatcher;
typedef compiler::dispatcher<SemanticGraph::Edge> EdgeDispatcher;
diff --git a/xsd-frontend/types.cxx b/xsd-frontend/types.cxx
new file mode 100644
index 0000000..126a2e1
--- /dev/null
+++ b/xsd-frontend/types.cxx
@@ -0,0 +1,62 @@
+// file : xsd-frontend/types.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+
+#include <cstdlib> // std::mbstowcs
+
+#include <xsd-frontend/types.hxx>
+
+namespace XSDFrontend
+{
+ // NonRepresentable
+ //
+ char const* NonRepresentable::
+ what () const throw ()
+ {
+ return "character is not representable in the narrower encoding";
+ }
+
+ // StringTemplate
+ //
+
+ // Specialization for char to wchar_t conversion.
+ //
+ template <>
+ void StringTemplate<wchar_t, char>::
+ from_narrow (char const* s)
+ {
+ size_type size (std::mbstowcs (0, s, 0) + 1);
+
+ // I dare to change the guts!
+ //
+ resize (size - 1);
+
+ wchar_t* p (const_cast<wchar_t*> (data ()));
+
+ std::mbstowcs (p, s, size);
+ }
+
+ // Specialization for wchar_t to char conversion.
+ //
+ template <>
+ StringTemplate<char> StringTemplate<wchar_t, char>::
+ to_narrow () const
+ {
+ size_type size (std::wcstombs (0, c_str (), 0));
+
+ if (size == size_type (-1))
+ throw NonRepresentable ();
+
+ // I dare to change the guts!
+ //
+ StringTemplate<char> r;
+ r.resize (size);
+
+ char* p (const_cast<char*> (r.data ()));
+
+ std::wcstombs (p, c_str (), size + 1);
+
+ return r;
+ }
+}
diff --git a/xsd-frontend/types.hxx b/xsd-frontend/types.hxx
index f3512e1..5e7793e 100644
--- a/xsd-frontend/types.hxx
+++ b/xsd-frontend/types.hxx
@@ -6,17 +6,246 @@
#ifndef XSD_FRONTEND_TYPES_HXX
#define XSD_FRONTEND_TYPES_HXX
+#include <string>
#include <cstddef> // std::size_t
-#include <cult/types.hxx>
-
namespace XSDFrontend
{
using std::size_t;
- using namespace Cult::Types;
+ namespace Bits
+ {
+ struct None {};
+
+ template <typename C>
+ struct NarrowerChar
+ {
+ typedef None Type;
+ };
+
+ template <>
+ struct NarrowerChar<wchar_t>
+ {
+ typedef char Type;
+ };
+ }
+
+ struct NonRepresentable: std::exception
+ {
+ virtual char const*
+ what () const throw ();
+ };
+
+ template <typename C, typename NC = typename Bits::NarrowerChar<C>::Type>
+ class StringTemplate;
+
+ template <>
+ class StringTemplate<Bits::None, Bits::None>
+ {
+ };
+
+ template <typename C, typename NC>
+ class StringTemplate : public std::basic_string<C>
+ {
+ typedef std::basic_string<C> Base;
+ typedef std::basic_string<NC> NarrowerBase;
+
+ Base&
+ base ()
+ {
+ return *this;
+ }
+
+ Base const&
+ base () const
+ {
+ return *this;
+ }
+
+ public:
+ typedef typename Base::size_type size_type;
+
+ using Base::npos;
+
+ public:
+ StringTemplate ()
+ {
+ }
+
+ StringTemplate (StringTemplate const& str,
+ size_type pos,
+ size_type n = npos)
+ : Base (str, pos, n)
+ {
+ }
+
+ StringTemplate (C const* s, size_type n)
+ : Base (s, n)
+ {
+ }
+
+ StringTemplate (C const* s)
+ : Base (s)
+ {
+ }
+
+ StringTemplate (size_type n, C c)
+ : Base (n, c)
+ {
+ }
+
+ template <typename I>
+ StringTemplate(I begin, I end)
+ : Base (begin, end)
+ {
+ }
+
+ StringTemplate (StringTemplate const& other)
+ : Base (other)
+ {
+ }
+
+ // Conversion from Base.
+ //
+ StringTemplate (Base const& str)
+ : Base (str)
+ {
+ }
+
+ // Conversion from the Narrower type. Experimental.
+ //
+ StringTemplate (NC const* s)
+ {
+ from_narrow (s);
+ }
+
+ StringTemplate (StringTemplate<NC> const& other)
+ {
+ from_narrow (other.c_str ());
+ }
+
+ StringTemplate (NarrowerBase const& other)
+ {
+ from_narrow (other.c_str ());
+ }
+
+ // Assignment.
+ //
+ StringTemplate&
+ operator= (StringTemplate const& str)
+ {
+ base () = str;
+ return *this;
+ }
+
+ StringTemplate&
+ operator= (C const* s)
+ {
+ base () = s;
+ return *this;
+ }
+
+ StringTemplate&
+ operator= (C c)
+ {
+ base () = c;
+ return *this;
+ }
+
+ // Assignment from Base.
+ //
+ StringTemplate&
+ operator= (Base const& str)
+ {
+ base () = str;
+ return *this;
+ }
+
+ public:
+ StringTemplate&
+ operator+= (StringTemplate const& str)
+ {
+ base () += str;
+ return *this;
+ }
+
+ StringTemplate&
+ operator+= (C const* s)
+ {
+ base () += s;
+ return *this;
+ }
+
+ StringTemplate&
+ operator+= (C c)
+ {
+ base () += c;
+ return *this;
+ }
+
+ // Conversion to the Narrower type.
+ //
+ public:
+ StringTemplate<NC>
+ to_narrow () const;
+
+ // Conversion to bool.
+ //
+ private:
+ typedef void (StringTemplate::*BooleanConvertible)();
+ void true_ () {}
+
+ public:
+ operator BooleanConvertible () const
+ {
+ return this->empty () ? 0 : &StringTemplate::true_;
+ }
+
+ private:
+ void
+ from_narrow (NC const* s);
+ };
+
+
+ template<typename C>
+ StringTemplate<C>
+ operator+ (StringTemplate<C> const& lhs, StringTemplate<C> const& rhs)
+ {
+ return StringTemplate<C> (lhs) += rhs;
+ }
+
+ template<typename C>
+ StringTemplate<C>
+ operator+ (C const* lhs, StringTemplate<C> const& rhs)
+ {
+ return StringTemplate<C> (lhs) += rhs;
+ }
+
+ template<typename C>
+ StringTemplate<C>
+ operator+ (StringTemplate<C> const& lhs, C const* rhs)
+ {
+ return StringTemplate<C> (lhs) += rhs;
+ }
+
+ template<typename C>
+ StringTemplate<C>
+ operator+ (C lhs, StringTemplate<C> const& rhs)
+ {
+ return StringTemplate<C> (1, lhs) += rhs;
+ }
+
+ template<typename C>
+ StringTemplate<C>
+ operator+ (StringTemplate<C> const& lhs, C rhs)
+ {
+ return StringTemplate<C> (lhs) += rhs;
+ }
+
+ typedef StringTemplate<char> NarrowString;
+ typedef StringTemplate<wchar_t> WideString;
- typedef Cult::WideString String;
+ typedef WideString String;
}
#endif // XSD_FRONTEND_TYPES_HXX
diff --git a/xsd-frontend/xml.hxx b/xsd-frontend/xml.hxx
index 4b8effa..a785eee 100644
--- a/xsd-frontend/xml.hxx
+++ b/xsd-frontend/xml.hxx
@@ -96,7 +96,7 @@ namespace XSDFrontend
NarrowString
transcode_to_narrow (XMLCh const* xs)
{
- Char* s (Xerces::XMLString::transcode (xs));
+ char* s (Xerces::XMLString::transcode (xs));
NarrowString r (s);
Xerces::XMLString::release (&s);
return r;