Bayeux  3.4.1
Core Foundation library for SuperNEMO
urn_info.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2017-03-06
4  * Last modified: 2017-03-06
5  *
6  * License:
7  *
8  * Copyright (C) 2017 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 information node structure.
28  *
29  */
30 
31 #ifndef DATATOOLS_URN_INFO_H
32 #define DATATOOLS_URN_INFO_H
33 
34 // Standard Library:
35 #include <string>
36 #include <vector>
37 #include <map>
38 
39 // Datatools:
41 #include <datatools/i_tree_dump.h>
42 #include <datatools/properties.h>
43 
44 namespace datatools {
45 
71  class urn_info
74  {
75  public:
76 
78  typedef std::map<std::string, std::vector<std::string> > component_topic_dict_type;
79 
101  static bool validate_urn(const std::string &);
102 
104  static bool validate_category(const std::string &);
105 
107  static bool validate_topic(const std::string &);
108 
110  static const std::string & anonymous_topic();
111 
113  urn_info();
114 
116  urn_info(const std::string & urn_,
117  const std::string & category_,
118  const std::string & description_ = "");
119 
121  virtual ~urn_info();
122 
124  bool is_valid() const;
125 
127 
150  void initialize(const properties &);
151 
153  void reset();
154 
156  void set_urn(const std::string & urn_);
157 
159  const std::string & get_urn() const;
160 
162  bool has_category() const;
163 
165  void set_category(const std::string & category_);
166 
168  const std::string & get_category() const;
169 
171  void set_description(const std::string & description_);
172 
174  bool has_description() const;
175 
177  const std::string & get_description() const;
178 
180  void lock();
181 
183  void unlock();
184 
186  bool is_locked() const;
187 
189  void remove_all_components();
190 
192  bool has_component(const std::string & comp_urn_) const;
193 
195  bool has_component_in_topic(const std::string & comp_urn_,
196  const std::string & comp_topic_) const;
197 
199  void add_component(const std::string & comp_urn_,
200  const std::string & comp_topic_ = "");
201 
203  void remove_component(const std::string & comp_urn_);
204 
206  bool has_components() const;
207 
209  std::size_t get_number_of_components() const;
210 
212  std::size_t get_number_of_components_by_topic(const std::string & comp_topic_) const;
213 
215  std::string get_component(const std::string & comp_topic_, int rank_ = 0) const;
216 
218  bool has_topic(const std::string & comp_topic_) const;
219 
221  const std::vector<std::string> &
222  get_components_by_topic(const std::string & comp_topic_) const;
223 
225  void build_topics(std::vector<std::string> &) const;
226 
228  std::vector<std::string> get_topics() const;
229 
231  virtual void tree_dump(std::ostream& out = std::clog,
232  const std::string& title = "",
233  const std::string& indent = "",
234  bool inherit = false) const;
235 
237  bool operator<(const urn_info & other_) const;
238 
239  private:
240 
241  // Management:
242  bool _locked_ = false;
243 
244  // Configuration:
245  std::string _urn_;
246  std::string _category_;
247  std::string _description_;
248  component_topic_dict_type _components_;
249 
252 
253  };
254 
255 } // end of namespace datatools
256 
257 #endif // DATATOOLS_URN_INFO_H
258 
259 // Local Variables: --
260 // mode: c++ --
261 // c-file-style: "gnu" --
262 // tab-width: 2 --
263 // End: --
void unlock()
Unlock the record.
void set_urn(const std::string &urn_)
Set the URN.
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
const std::string & get_category() const
Return the category.
const std::string & get_description() const
Return the description.
void remove_component(const std::string &comp_urn_)
Remove an URN component.
void set_category(const std::string &category_)
Set the category.
const std::string & get_urn() const
Return the URN.
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
#define DATATOOLS_SERIALIZATION_DECLARATION_ADVANCED(ClassName)
Definition: i_serializable.h:371
bool has_components() const
Check if URN components are set.
bool is_valid() const
Check validity.
void lock()
Lock the record.
std::string get_component(const std::string &comp_topic_, int rank_=0) const
Return the URN component with given topic at given rank.
void initialize(const properties &)
Initialize.
urn_info()
Default constructor.
virtual ~urn_info()
Destructor.
std::map< std::string, std::vector< std::string > > component_topic_dict_type
Dictionary of list of components addressed by topic.
Definition: urn_info.h:78
bool has_topic(const std::string &comp_topic_) const
Check if a given component topic is defined.
bool is_locked() const
Check lock flag.
virtual void tree_dump(std::ostream &out=std::clog, const std::string &title="", const std::string &indent="", bool inherit=false) const
Main interface method for smart dump.
bool has_component_in_topic(const std::string &comp_urn_, const std::string &comp_topic_) const
Check if a component exists in a given topic.
void set_description(const std::string &description_)
Set the description.
void build_topics(std::vector< std::string > &) const
Build the current list of component topics.
void add_component(const std::string &comp_urn_, const std::string &comp_topic_="")
Add an URN component given its topic.
std::size_t get_number_of_components_by_topic(const std::string &comp_topic_) const
Return the number of URN components with given topic.
bool has_category() const
Check if category is set.
static const std::string & anonymous_topic()
Return the anonymous topic.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
std::vector< std::string > get_topics() const
Return the current list of component topics.
static bool validate_topic(const std::string &)
Validate a topic name.
static bool validate_category(const std::string &)
Validate a category name.
bool has_description() const
Check if the description is set.
bool has_component(const std::string &comp_urn_) const
Check if a component exists.
bool operator<(const urn_info &other_) const
Basic comparison with respect to the URN name.
void remove_all_components()
Remove all components.
const std::vector< std::string > & get_components_by_topic(const std::string &comp_topic_) const
Return the components associated to a given topic.
A class documenting an object addressed by its unique URN and linked to other objects (also addressed...
Definition: urn_info.h:71
std::size_t get_number_of_components() const
Return the total number of URN components.
void reset()
Clear the URN info.
A dictionary of arbitrary properties.
Definition: properties.h:125
static bool validate_urn(const std::string &)