Bayeux  3.4.1
Core Foundation library for SuperNEMO
urn_to_path_resolver_service.h
Go to the documentation of this file.
1 //
5 // Copyright (c) 2017 by Francois Mauger <mauger@lpccaen.in2p3.fr>
6 // Copyright (c) 2017 by Université de Caen
7 //
8 // This file is part of Bayeux/datatools.
9 //
10 // Bayeux/datatools is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Bayeux/datatools is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Bayeux/datatools. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef DATATOOLS_URN_TO_PATH_RESOLVER_SERVICE_H
24 #define DATATOOLS_URN_TO_PATH_RESOLVER_SERVICE_H
25 
26 // Standard Library
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include <iostream>
31 #include <set>
32 
33 // This project
34 #include <datatools/properties.h>
35 #include <datatools/base_service.h>
36 #include <datatools/urn_to_path.h>
37 
38 namespace datatools {
39 
55  {
56  public:
57 
59  static const std::set<std::string> & default_known_categories();
60 
61  // \brief Resolver map entry
62  //
63  // The category is a string which documents the type of informations accessible
64  // from the path. Default set of values supports:
65  // - "data" : generic data
66  // - "configuration" : set of configuration parameters (configuration file)
67  // - "graphics" : graphical information (icons, images...)
68  // - "archive" : a container for other resources (tar, zip...)
69  // - "log" : logging informations
70  // struct resolver_entry {
71  // std::string urn; //!< URN representation
72  // std::string category; //!< Resource file category
73  // std::string path; //!< Resource path (may be a filesystem path or any kind of URL)
74  // std::string mime; //!< MIME type
75  // };
76  // \brief Resolver map entry
78 
80  typedef std::map<std::string, resolver_entry> urn_lookup_table_type;
81 
84 
87 
89  void add_known_category(const std::string & cat_);
90 
92  void remove_known_category(const std::string & cat_);
93 
96 
98  const std::set<std::string> & get_known_categories() const;
99 
101  bool is_allow_overloading() const;
102 
104  void set_allow_overloading(bool);
105 
107  void add_map(const std::string &);
108 
110  virtual bool is_initialized() const;
111 
113  virtual int initialize(const datatools::properties & config_,
114  datatools::service_dict_type & services_);
115 
117  virtual int reset();
118 
120  virtual void tree_dump(std::ostream& out = std::clog,
121  const std::string & title = "",
122  const std::string & indent = "",
123  bool inherit = false) const;
124 
126  void load_map(const std::string & map_filename_);
127 
129  bool urn_is_known(const std::string & urn_) const;
130 
132  std::string resolve(const std::string & urn_) const;
133 
135  void add_entry(const std::string & urn_,
136  const std::string & category_,
137  const datatools::properties & infos_);
138 
140  void add_entry(const std::string & urn_,
141  const std::string & category_,
142  const std::string & path_,
143  const std::string & mime_ = "");
144 
146  void remove(const std::string & urn_);
147 
149  std::size_t size() const;
150 
152  const resolver_entry & get_entry(const std::string & urn_) const;
153 
155  const std::string & get_category(const std::string & urn_) const;
156 
158  const std::string & get_path(const std::string & urn_) const;
159 
161  const std::string & get_mime(const std::string & urn_) const;
162 
164  void print_lookup_table(std::ostream & = std::clog, const uint32_t flags_ = 0) const;
165 
168 
170  void kernel_push(const std::string & = "");
171 
173  void kernel_pop();
174 
176  bool is_kernel_pushed() const;
177 
178  private:
179 
180  void _init_();
181 
182  void _reset_();
183 
184  private:
185 
186  // Management:
187  bool _initialized_ = false;
188 
189  // Configuration:
190  bool _allow_overloading_ = false;
191  std::vector<std::string> _map_filenames_;
192  std::set<std::string> _known_categories_;
193 
194  // Private data:
195  urn_lookup_table_type _urn_lookup_table_;
196 
198 
199  };
200 
201 }
202 
203 #endif // DATATOOLS_URN_TO_PATH_RESOLVER_SERVICE_H
204 
205 // Local Variables: --
206 // mode: c++ --
207 // c-file-style: "gnu" --
208 // tab-width: 2 --
209 // End: --
virtual bool is_initialized() const
Check initialization status.
void remove(const std::string &urn_)
Remove an entry.
std::map< std::string, service_entry_ptr > service_dict_type
Type alias for a flat dictionary of service entries.
Definition: service_tools.h:196
The base service class.
Definition: base_service.h:68
void kernel_pop()
Remove from system.
virtual void tree_dump(std::ostream &out=std::clog, const std::string &title="", const std::string &indent="", bool inherit=false) const
Smart print.
void add_known_category(const std::string &cat_)
Add a known catagory.
void add_map(const std::string &)
Add a map file.
#define DATATOOLS_SERVICE_REGISTRATION_INTERFACE(SERVICE_CLASS_NAME)
Definition: base_service.h:152
bool is_kernel_pushed() const
Check if the service is pushed (registered) in the kernel.
void kernel_push(const std::string &="")
Add to system.
void remove_known_category(const std::string &cat_)
Remove a known catagory.
std::size_t size() const
Return the size of the lookup table.
const std::string & get_category(const std::string &urn_) const
Return the category associated to a given URN.
static const std::set< std::string > & default_known_categories()
Return the default list of known categories.
void add_entry(const std::string &urn_, const std::string &category_, const datatools::properties &infos_)
Add entry in the URN path lockup table.
const std::set< std::string > & get_known_categories() const
Return the known categories.
std::string resolve(const std::string &urn_) const
Return the path associated to a given URN.
URN to file path resolver service.
Definition: urn_to_path_resolver_service.h:53
const resolver_entry & get_entry(const std::string &urn_) const
Return the entry associated to a given URN.
virtual ~urn_to_path_resolver_service()
Destructor.
void set_allow_overloading(bool)
Set the URN overloading flag.
const urn_lookup_table_type & get_urn_lookup_table() const
Return the URN lookup table.
void print_lookup_table(std::ostream &=std::clog, const uint32_t flags_=0) const
Print the URN lookup table.
void clear_known_categories()
Clear known categories.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
urn_to_path resolver_entry
Definition: urn_to_path_resolver_service.h:77
bool is_allow_overloading() const
Check if URN overloading is allowed.
bool urn_is_known(const std::string &urn_) const
Check is a given URN is known.
const std::string & get_path(const std::string &urn_) const
Return the path associated to a given URN.
virtual int initialize(const datatools::properties &config_, datatools::service_dict_type &services_)
Initialize the service from a list of properties.
std::map< std::string, resolver_entry > urn_lookup_table_type
URN to path lookup table.
Definition: urn_to_path_resolver_service.h:80
A class representing the association of an URN to some paths. A path maybe a filesystem path,...
Definition: urn_to_path.h:61
void load_map(const std::string &map_filename_)
Load a URN/path map file.
const std::string & get_mime(const std::string &urn_) const
Return the MIME associated to a given URN.
A dictionary of arbitrary properties.
Definition: properties.h:125