Bayeux  3.4.1
Core Foundation library for SuperNEMO
urn_query_service.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2017-03-07
4  * Last modified: 2018-03-23
5  *
6  * License:
7  *
8  * Copyright (C) 2017-2018 Francois Mauger <mauger@lpccaen.in2p3.fr>
9  *
10  * This program 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 (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  * Description:
26  *
27  * URN query service.
28  *
29  */
30 
31 #ifndef DATATOOLS_URN_QUERY_SERVICE_H
32 #define DATATOOLS_URN_QUERY_SERVICE_H
33 
34 // Standard Library:
35 #include <string>
36 #include <map>
37 #include <set>
38 
39 // Third party:
40 #include <boost/noncopyable.hpp>
41 
42 // This project:
43 #include <datatools/base_service.h>
44 #include <datatools/urn_info.h>
45 
46 namespace datatools {
47 
48  class urn_db_service;
49  class urn_to_path_resolver_service;
50  class dependency_graph;
51 
56  , private boost::noncopyable
57  {
58  public:
59 
62 
64  virtual ~urn_query_service();
65 
67  virtual bool is_initialized() const;
68 
70  virtual int initialize(const datatools::properties & config_,
71  datatools::service_dict_type & services_);
72 
74  virtual int reset();
75 
77  virtual void tree_dump(std::ostream & out = std::clog,
78  const std::string & title = "",
79  const std::string & indent = "",
80  bool inherit = false) const;
81 
83  bool check_urn_info(const std::string & urn_,
84  const std::string & category_ = "") const;
85 
87  bool find_urn_info(std::vector<std::string> & urn_list_,
88  const std::string & urn_db_regex_ = "",
89  const std::string & urn_regex_ = "",
90  const std::string & urn_category_regex_ = "",
91  bool clear_ = true) const;
92 
94  const urn_info & get_urn_info(const std::string & urn_) const;
95 
97  bool find_urn_to_path(std::vector<std::string> & urn_path_list_,
98  const std::string & urn_resolver_regex_ = "",
99  const std::string & urn_regex_ = "",
100  const std::string & urn_category_regex_ = "",
101  const std::string & urn_mime_regex_ = "",
102  bool clear_ = true) const;
103 
105  bool check_urn_to_path(const std::string & urn_) const;
106 
109  bool resolve_urn_to_path(const std::string & urn_,
110  std::string & category_,
111  std::string & mime_,
112  std::string & path_) const;
113 
115  bool get_urn_to_path(const std::string & urn_,
116  std::string & category_,
117  std::string & mime_,
118  std::string & path_) const;
119 
121  bool has_db(const std::string & name_) const;
122 
124  bool has_db(const urn_db_service &) const;
125 
127  const urn_db_service & get_db(const std::string & name_) const;
128 
130  void build_list_of_dbs(std::set<std::string> & dbs_) const;
131 
133  void add_db(const urn_db_service &);
134 
136  void add_db(const urn_db_service &, const std::string & name_);
137 
139  void remove_db(const urn_db_service &);
140 
142  void remove_db(const std::string & name_);
143 
145  bool has_path_resolver(const std::string & name_) const;
146 
148  void build_list_of_path_resolvers(std::set<std::string> & prs_) const;
149 
152 
154  const urn_to_path_resolver_service & get_path_resolver(const std::string & name_) const;
155 
158 
161  const std::string & name_);
162 
165 
167  void remove_path_resolver(const std::string & name_);
168 
170  const dependency_graph & get_dependency_graph() const;
171 
174 
175  private:
176 
177  void _build_dependency_graph_();
178 
179  void _dependency_graph_process_db(const urn_db_service * db_,
180  std::set<const urn_db_service*> & processed_dbs_);
181 
182  private:
183 
184  // Management:
185  bool _initialized_ = false;
186 
187  // Private implementation:
188  struct pimpl_type;
189  std::unique_ptr<pimpl_type> _pimpl_;
190  std::unique_ptr<dependency_graph> _dg_ptr_;
191 
192  // Service registration
194 
195  };
196 
197 } // end of namespace datatools
198 
199 #endif // DATATOOLS_URN_QUERY_SERVICE_H
200 
201 // Local Variables: --
202 // mode: c++ --
203 // c-file-style: "gnu" --
204 // tab-width: 2 --
205 // End: --
urn_query_service()
Default constructor.
A service which allows queries about URNs thanks to embedded specialized dictionaries of URN informat...
Definition: urn_query_service.h:54
void build_list_of_path_resolvers(std::set< std::string > &prs_) const
Build the list of URN path resolvers.
virtual void tree_dump(std::ostream &out=std::clog, const std::string &title="", const std::string &indent="", bool inherit=false) const
Smart print.
bool has_db(const std::string &name_) const
Check if an URN database with given name is registered.
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
const dependency_graph & get_dependency_graph() const
Return the auto-build dependency graph associated to the service.
virtual int initialize(const datatools::properties &config_, datatools::service_dict_type &services_)
Initialize the service from a list of properties.
#define DATATOOLS_SERVICE_REGISTRATION_INTERFACE(SERVICE_CLASS_NAME)
Definition: base_service.h:152
const urn_info & get_urn_info(const std::string &urn_) const
Return a registered URN info.
virtual int reset()
Reset.
void add_db(const urn_db_service &)
Register an URN database.
const urn_db_service & get_db(const std::string &name_) const
Return an URN db service with a given name.
void remove_path_resolver(const urn_to_path_resolver_service &)
Unregister an URN path resolver.
URN to file path resolver service.
Definition: urn_to_path_resolver_service.h:53
Dependency graph.
Definition: dependency_graph.h:64
A service with a dictionary of URN informations.
Definition: urn_db_service.h:142
void build_list_of_dbs(std::set< std::string > &dbs_) const
Build the list of URN databases.
void add_path_resolver(const urn_to_path_resolver_service &)
Register an URN path resolver.
bool check_urn_info(const std::string &urn_, const std::string &category_="") const
Check if an URN information is defined.
virtual ~urn_query_service()
Destructor.
const urn_to_path_resolver_service & get_path_resolver(const std::string &name_) const
Return an URN path resolver service with a given name.
bool has_path_resolver(const std::string &name_) const
Check if an URN path resolver with given name is registered.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
bool check_urn_to_path(const std::string &urn_) const
Check if URN is associated to a path.
bool find_urn_info(std::vector< std::string > &urn_list_, const std::string &urn_db_regex_="", const std::string &urn_regex_="", const std::string &urn_category_regex_="", bool clear_=true) const
Build a list of URNs with requested URN and category patterns.
bool find_urn_to_path(std::vector< std::string > &urn_path_list_, const std::string &urn_resolver_regex_="", const std::string &urn_regex_="", const std::string &urn_category_regex_="", const std::string &urn_mime_regex_="", bool clear_=true) const
Build a list of URNs associated to path with requested URN and category patterns.
virtual bool is_initialized() const
Check initialization status.
void remove_db(const urn_db_service &)
Unregister an URN database.
bool resolve_urn_to_path(const std::string &urn_, std::string &category_, std::string &mime_, std::string &path_) const
A class documenting an object addressed by its unique URN and linked to other objects (also addressed...
Definition: urn_info.h:71
bool get_urn_to_path(const std::string &urn_, std::string &category_, std::string &mime_, std::string &path_) const
Return the informations associated to a URN to path association.
void update_dependency_graph()
Return the auto-build dependency graph associated to the service.
A dictionary of arbitrary properties.
Definition: properties.h:125