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

# namespaces.h

Go to the documentation of this file.

    00001 /* -*- c++ -*- */
    00002 #ifndef AKAXISO2_FRAMEWORK_NAMESPACES_H__
    00003 #define AKAXISO2_FRAMEWORK_NAMESPACES_H__
    00004
    00010 #include <akaxiso2/framework/types.h>
    00011 #include <akaxiso2/util/mutex.h>
    00012 #include <map>
    00013 #include <vector>
    00014
    00015 namespace aka2 {
    00016
    00028   void xmlns(const std::string &prefix, const std::string &uri);
    00029
    00035   const std::string &get_namespace_uri(const std::string &prefix);
    00036
    00037   const std::string &get_namespace_uri(const id_type ns_id);
    00038
    00044   const std::string &get_prefix(const std::string &uri);
    00045
    00046   const std::string &get_prefix(const id_type &ns_id);
    00047   const id_type get_namespace_id(const std::string &uri);
    00048   const id_type get_prefix_id(const std::string &prefix);
    00049
    00050
    00051   class namespace_map {
    00052     typedef std::map<id_type, std::string> urimap_type;
    00053     typedef std::map<std::string, id_type> idmap_type;
    00054
    00055   public:
    00056     namespace_map(id_type initial_id = 1) : current_id_(initial_id) {}
    00057     const id_type register_namespace_uri(const std::string &uri);
    00058     const std::string &get_namespace_uri(const id_type id) const;
    00059     const id_type get_namespace_id(const std::string &uri) const;
    00060     bool is_uri_registered(const std::string &uri) const;
    00061
    00062     // Used for system globals.
    00063     void initialize();
    00064
    00065     void clear();
    00066
    00067   private:
    00068     id_type current_id_;
    00069     urimap_type urimap_;
    00070     idmap_type idmap_;
    00071   };
    00072
    00073
    00074   class any_namespace_map : public namespace_map {
    00075   public:
    00076     any_namespace_map() : namespace_map(0x8000) {}
    00077     const std::string &get_namespace_uri(const id_type id) const;
    00078     const id_type get_namespace_id(const std::string &uri);
    00079     bool is_uri_registered(const std::string &uri) const;
    00080
    00081     void clear();
    00082   private:
    00083     mutable mutex mutex_;
    00084   };
    00085
    00086
    00087   class any_prefix_cache {
    00088   public:
    00089     any_prefix_cache(const std::string &prefix = "tmpns") : prefix_(prefix) { }
    00090     const std::string &get_prefix(id_type nsid) const;
    00091     void clear();
    00092   private:
    00093     std::string prefix_;
    00094     mutable std::vector<std::string> cache_;
    00095   };
    00096
    00097
    00101   class prefix_map {
    00102     typedef std::vector<std::string> prefixes;
    00103     typedef std::vector<id_type> id_stack;
    00104
    00105     // URI -> prefix mapping.
    00106     typedef std::map<id_type, prefixes> prefixmap_type;
    00107     // Preix is unique, but some prefixes may be associated with the same id.
    00108     typedef std::map<std::string, id_stack> idmap_type;
    00109   public:
    00110     typedef prefixmap_type::const_iterator const_iterator;
    00111
    00112     prefix_map();
    00113     const_iterator begin() const { return prefixmap_.begin(); }
    00114     const_iterator end() const { return prefixmap_.end(); }
    00115
    00127     void assign_prefix(const std::string &prefix, const std::string &uri);
    00133     void clear_prefix(const std::string &prefix);
    00134
    00135     const id_type get_prefix_id(const std::string &prefix) const;
    00136     const std::string &get_prefix(const id_type id) const;
    00137
    00138     static void initialize();
    00139     void clear();
    00140
    00141   private:
    00142     static bool is_prefix_xml(const std::string &prefix);
    00143     static std::string xml_prefix_;
    00144     prefixmap_type prefixmap_;
    00145     any_prefix_cache any_cache_;
    00146     idmap_type idmap_;
    00147   };
    00148
    00149 } // namespace aka2
    00150
    00151 #endif