| 1 |
// file : cutl/xml/qname.hxx |
| 2 |
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC |
| 3 |
// license : MIT; see accompanying LICENSE file |
| 4 |
|
| 5 |
#ifndef CUTL_XML_QNAME_HXX |
| 6 |
#define CUTL_XML_QNAME_HXX |
| 7 |
|
| 8 |
#include <string> |
| 9 |
#include <iosfwd> |
| 10 |
|
| 11 |
#include <cutl/details/export.hxx> |
| 12 |
|
| 13 |
namespace cutl |
| 14 |
{ |
| 15 |
namespace xml |
| 16 |
{ |
| 17 |
// Note that the optional prefix is just a "syntactic sugar". In |
| 18 |
// particular, it is ignored by the comparison operators and the |
| 19 |
// std::ostream insertion operator. |
| 20 |
// |
| 21 |
class LIBCUTL_EXPORT qname |
| 22 |
{ |
| 23 |
public: |
| 24 |
qname () {} |
| 25 |
qname (const std::string& name): name_ (name) {} |
| 26 |
qname (const std::string& ns, const std::string& name) |
| 27 |
: ns_ (ns), name_ (name) {} |
| 28 |
qname (const std::string& ns, |
| 29 |
const std::string& name, |
| 30 |
const std::string& prefix) |
| 31 |
: ns_ (ns), name_ (name), prefix_ (prefix) {} |
| 32 |
|
| 33 |
const std::string& namespace_ () const {return ns_;} |
| 34 |
const std::string& name () const {return name_;} |
| 35 |
const std::string& prefix () const {return prefix_;} |
| 36 |
|
| 37 |
std::string& namespace_ () {return ns_;} |
| 38 |
std::string& name () {return name_;} |
| 39 |
std::string& prefix () {return prefix_;} |
| 40 |
|
| 41 |
// Printable representation in the [<namespace>#]<name> form. |
| 42 |
// |
| 43 |
std::string |
| 44 |
string () const; |
| 45 |
|
| 46 |
// Note that comparison operators |
| 47 |
// |
| 48 |
public: |
| 49 |
friend bool |
| 50 |
operator< (const qname& x, const qname& y) |
| 51 |
{ |
| 52 |
return x.ns_ < y.ns_ || (x.ns_ == y.ns_ && x.name_ < y.name_); |
| 53 |
} |
| 54 |
|
| 55 |
friend bool |
| 56 |
operator== (const qname& x, const qname& y) |
| 57 |
{ |
| 58 |
return x.ns_ == y.ns_ && x.name_ == y.name_; |
| 59 |
} |
| 60 |
|
| 61 |
friend bool |
| 62 |
operator!= (const qname& x, const qname& y) |
| 63 |
{ |
| 64 |
return !(x == y); |
| 65 |
} |
| 66 |
|
| 67 |
private: |
| 68 |
std::string ns_; |
| 69 |
std::string name_; |
| 70 |
std::string prefix_; |
| 71 |
}; |
| 72 |
|
| 73 |
LIBCUTL_EXPORT |
| 74 |
std::ostream& |
| 75 |
operator<< (std::ostream&, const qname&); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
#endif // CUTL_XML_QNAME_HXX |