aboutsummaryrefslogtreecommitdiff
path: root/xml/qname.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-04-27 12:32:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-04-27 12:32:17 +0200
commit2c57a439676481590179718091f7404eb2e03ad7 (patch)
treea008f641f62fc995c9f93a5b37ee5f329bbaa525 /xml/qname.hxx
parent78e1a4d4a0a6022c13f251fbe23a20b2262830b2 (diff)
Initial source code import
Diffstat (limited to 'xml/qname.hxx')
-rw-r--r--xml/qname.hxx78
1 files changed, 78 insertions, 0 deletions
diff --git a/xml/qname.hxx b/xml/qname.hxx
new file mode 100644
index 0000000..be1bf00
--- /dev/null
+++ b/xml/qname.hxx
@@ -0,0 +1,78 @@
+// file : xml/qname.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef XML_QNAME_HXX
+#define XML_QNAME_HXX
+
+#include <string>
+#include <iosfwd>
+
+#include <xml/details/export.hxx>
+
+namespace xml
+{
+ // Note that the optional prefix is just a "syntactic sugar". In
+ // particular, it is ignored by the comparison operators and the
+ // std::ostream insertion operator.
+ //
+ class LIBSTUDXML_EXPORT qname
+ {
+ public:
+ qname () {}
+ qname (const std::string& name): name_ (name) {}
+ qname (const std::string& ns, const std::string& name)
+ : ns_ (ns), name_ (name) {}
+ qname (const std::string& ns,
+ const std::string& name,
+ const std::string& prefix)
+ : ns_ (ns), name_ (name), prefix_ (prefix) {}
+
+ const std::string& namespace_ () const {return ns_;}
+ const std::string& name () const {return name_;}
+ const std::string& prefix () const {return prefix_;}
+
+ std::string& namespace_ () {return ns_;}
+ std::string& name () {return name_;}
+ std::string& prefix () {return prefix_;}
+
+ // String representation in the [<namespace>#]<name> form.
+ //
+ std::string
+ string () const;
+
+ // Note that comparison operators ignore prefixes.
+ //
+ public:
+ friend bool
+ operator< (const qname& x, const qname& y)
+ {
+ return x.ns_ < y.ns_ || (x.ns_ == y.ns_ && x.name_ < y.name_);
+ }
+
+ friend bool
+ operator== (const qname& x, const qname& y)
+ {
+ return x.ns_ == y.ns_ && x.name_ == y.name_;
+ }
+
+ friend bool
+ operator!= (const qname& x, const qname& y)
+ {
+ return !(x == y);
+ }
+
+ private:
+ std::string ns_;
+ std::string name_;
+ std::string prefix_;
+ };
+
+ // Print the string representation ([<namespace>#]<name>).
+ //
+ LIBSTUDXML_EXPORT
+ std::ostream&
+ operator<< (std::ostream&, const qname&);
+}
+
+#endif // XML_QNAME_HXX