diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-05-14 21:29:29 -0700 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-05-14 21:29:29 -0700 |
commit | e897aa91a2a5c68a2f795f6a0a995600f13a85f8 (patch) | |
tree | 75a17430ba9cec822651b881003f66da8c89d7f9 /xml/qname | |
parent | 3bf332a7b77e9ce9e5eb0a1dfd5f64f238f4f17f (diff) |
Convert to extension-less headers for API
Diffstat (limited to 'xml/qname')
-rw-r--r-- | xml/qname | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/xml/qname b/xml/qname new file mode 100644 index 0000000..85d6424 --- /dev/null +++ b/xml/qname @@ -0,0 +1,87 @@ +// file : xml/qname -*- C++ -*- +// copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef XML_QNAME +#define XML_QNAME + +#include <xml/details/pre.hxx> + +#include <string> +#include <iosfwd> + +#include <xml/forward> + +#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_;} + + bool + empty () const {return name_.empty () && ns_.empty ();} + + // 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&); +} + +#include <xml/details/post.hxx> + +#endif // XML_QNAME |