Orcus
xml_namespace.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #ifndef INCLUDED_ORCUS_XML_NAMESPACE_MANAGER_HPP
9 #define INCLUDED_ORCUS_XML_NAMESPACE_MANAGER_HPP
10 
11 #include "types.hpp"
12 
13 #include <ostream>
14 #include <memory>
15 
16 namespace orcus {
17 
18 class xmlns_context;
19 class pstring;
20 struct xmlns_repository_impl;
21 struct xmlns_context_impl;
22 
27 class ORCUS_PSR_DLLPUBLIC xmlns_repository
28 {
29  friend class xmlns_context;
30 
31  struct impl;
32  std::unique_ptr<impl> mp_impl;
33 
34  xmlns_id_t intern(const pstring& uri);
35 
36  xmlns_repository(const xmlns_repository&); // disabled
37  xmlns_repository& operator= (const xmlns_repository&); // disabled
38 
39  size_t get_index(xmlns_id_t ns_id) const;
40 
41 public:
44 
57  void add_predefined_values(const xmlns_id_t* predefined_ns);
58 
59  xmlns_context create_context();
60 
68  xmlns_id_t get_identifier(size_t index) const;
69 
70  std::string get_short_name(xmlns_id_t ns_id) const;
71  std::string get_short_name(size_t index) const;
72 };
73 
82 class ORCUS_PSR_DLLPUBLIC xmlns_context
83 {
84  friend class xmlns_repository;
85 
86  struct impl;
87  std::unique_ptr<impl> mp_impl;
88 
89  xmlns_context(); // disabled
91 public:
92  xmlns_context(const xmlns_context& r);
93  ~xmlns_context();
94 
95  xmlns_id_t push(const pstring& key, const pstring& uri);
96  void pop(const pstring& key);
97 
105  xmlns_id_t get(const pstring& key) const;
106 
115  size_t get_index(xmlns_id_t ns_id) const;
116 
130  std::string get_short_name(xmlns_id_t ns_id) const;
131 
141  pstring get_alias(xmlns_id_t ns_id) const;
142 
143  std::vector<xmlns_id_t> get_all_namespaces() const;
144 
145  void dump(std::ostream& os) const;
146 };
147 
148 }
149 
150 #endif
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::xmlns_context
Definition: xml_namespace.hpp:82
orcus::pstring
Definition: pstring.hpp:24
orcus::xmlns_repository
Definition: xml_namespace.hpp:27