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 struct xmlns_repository_impl;
20 struct xmlns_context_impl;
21 
26 class ORCUS_PSR_DLLPUBLIC xmlns_repository
27 {
28  friend class xmlns_context;
29 
30  struct impl;
31  std::unique_ptr<impl> mp_impl;
32 
33  xmlns_id_t intern(std::string_view uri);
34 
35  xmlns_repository(const xmlns_repository&); // disabled
36  xmlns_repository& operator= (const xmlns_repository&); // disabled
37 
38  size_t get_index(xmlns_id_t ns_id) const;
39 
40 public:
43 
56  void add_predefined_values(const xmlns_id_t* predefined_ns);
57 
58  xmlns_context create_context();
59 
67  xmlns_id_t get_identifier(size_t index) const;
68 
69  std::string get_short_name(xmlns_id_t ns_id) const;
70  std::string get_short_name(size_t index) const;
71 };
72 
81 class ORCUS_PSR_DLLPUBLIC xmlns_context
82 {
83  friend class xmlns_repository;
84 
85  struct impl;
86  std::unique_ptr<impl> mp_impl;
87 
89 public:
90  xmlns_context();
92  xmlns_context(const xmlns_context& r);
93  ~xmlns_context();
94 
95  xmlns_context& operator= (const xmlns_context& r);
96  xmlns_context& operator= (xmlns_context&& r);
97 
98  xmlns_id_t push(std::string_view key, std::string_view uri);
99  void pop(std::string_view key);
100 
108  xmlns_id_t get(std::string_view key) const;
109 
118  size_t get_index(xmlns_id_t ns_id) const;
119 
133  std::string get_short_name(xmlns_id_t ns_id) const;
134 
144  std::string_view get_alias(xmlns_id_t ns_id) const;
145 
146  std::vector<xmlns_id_t> get_all_namespaces() const;
147 
148  void dump(std::ostream& os) const;
149 
153  void dump_state(std::ostream& os) const;
154 
155  void swap(xmlns_context& other) noexcept;
156 };
157 
158 }
159 
160 #endif
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: xml_namespace.hpp:82
xmlns_id_t get(std::string_view key) const
size_t get_index(xmlns_id_t ns_id) const
std::string get_short_name(xmlns_id_t ns_id) const
void dump_state(std::ostream &os) const
std::string_view get_alias(xmlns_id_t ns_id) const
Definition: xml_namespace.hpp:27
void add_predefined_values(const xmlns_id_t *predefined_ns)
xmlns_id_t get_identifier(size_t index) const