Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages

# qname.h

Go to the documentation of this file.

    00001 /* -*- c++ -*- */
    00002 #ifndef AKAXISO2_FRAMEWORK_QNAME_H__
    00003 #define AKAXISO2_FRAMEWORK_QNAME_H__
    00004
    00010 #include <akaxiso2/framework/types.h>
    00011 #include <string>
    00012
    00013 namespace aka2 {
    00014
    00015   class prefix_map;
    00016
    00020   class qname {
    00021   public:
    00022     friend struct qname_less;
    00024     explicit qname() : namespace_id_(empty_token) {}
    00031     explicit qname(const std::string &rawname) { set(rawname); }
    00032
    00033     explicit qname(id_type namespace_id, const std::string &localname) {
    00034       set(namespace_id, localname);
    00035     }
    00036
    00042     void set(const std::string &uri, const std::string &name);
    00043
    00044     void set(const id_type namespace_id, const std::string &name);
    00045
    00052     void set(const std::string &rawname);
    00053
    00054     void set(const std::string &rawname,
    00055              const prefix_map &pfs);
    00056
    00061     bool is_qualified() const { return namespace_id_ != empty_token; }
    00062
    00067     std::string qualified() const;
    00068
    00069     std::string qualified(const prefix_map &pfmap) const;
    00070     const std::string &prefix(const prefix_map &pfs) const;
    00071
    00076     const std::string &prefix() const;
    00077
    00078     const id_type get_namespace_id() const { return namespace_id_; }
    00079
    00084     std::string &local();
    00085
    00090     const std::string &local() const;
    00091
    00092     bool operator ==(const qname &rhs) const {
    00093       return (namespace_id_ == rhs.namespace_id_) && (name_ == rhs.name_);
    00094     }
    00095     bool operator !=(const qname &rhs) const {
    00096       return (namespace_id_ != rhs.namespace_id_) || (name_ != rhs.name_);
    00097     }
    00098
    00103     bool empty() const;
    00104
    00105   private:
    00106     void validate_name() const;
    00107
    00108     id_type namespace_id_;
    00109     std::string name_;
    00110     mutable const char *prefix_cache_;
    00111   };
    00112
    00113   struct qname_less {
    00114     bool operator ()(const qname &lhs, const qname &rhs) const {
    00115       if (lhs.namespace_id_ < rhs.namespace_id_)
    00116         return true;
    00117       else if (lhs.namespace_id_ == rhs.namespace_id_)
    00118         return (lhs.name_ < rhs.name_);
    00119       return false;
    00120     }
    00121   };
    00122
    00123   inline std::ostream & operator <<(std::ostream &ostm, const aka2::qname &name) {
    00124     ostm << name.qualified();
    00125     return ostm;
    00126   }
    00127
    00128   inline bool operator <(const aka2::qname &lhs, const aka2::qname &rhs) {
    00129     return aka2::qname_less()(lhs, rhs);
    00130   }
    00131
    00132 } // namespace aka2
    00133
    00134 #endif