lsst.daf.base  13.0-2-g167564e+10
PropertyList.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
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
13  * (at your option) any later version.
14  *
15  * This program 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 LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_DAF_BASE_PROPERTYLIST
26 #define LSST_DAF_BASE_PROPERTYLIST
27 
56 #include <list>
57 #include <memory>
58 #include <string>
59 #include <typeinfo>
60 #include <unordered_map>
61 #include <vector>
62 
63 #include "boost/any.hpp"
64 
66 
67 namespace lsst {
68 namespace daf {
69 
70 namespace persistence {
71  class PropertyListFormatter;
72 } // namespace lsst::daf::persistence
73 
74 
75 namespace base {
76 
77 #if defined(__ICC)
78 #pragma warning (push)
79 #pragma warning (disable: 444)
80 #endif
81 
82 class PropertyList : public PropertySet {
83 public:
84 // Typedefs
85  typedef std::shared_ptr<PropertyList> Ptr;
86  typedef std::shared_ptr<PropertyList const> ConstPtr;
87 
88 // Constructors
89  PropertyList(void);
90  virtual ~PropertyList(void);
91 
92 // Accessors
93  virtual PropertySet::Ptr deepCopy(void) const;
94  // Returns a PropertySet::Ptr pointing to a new deep copy of the
95  // PropertyList.
96 
97  template <typename T> T get(std::string const& name) const;
98  // Note that the type must be explicitly specified for this template:
99  // int i = propertyList.get<int>("foo");
100  template <typename T>
101  T get(std::string const& name, T const& defaultValue) const;
102  // Returns the provided default value if the name does not exist.
103  template <typename T>
104  std::vector<T> getArray(std::string const& name) const;
105 
106  std::string const& getComment(std::string const& name) const;
107  std::vector<std::string> getOrderedNames(void) const;
108 
109  std::list<std::string>::const_iterator begin(void) const;
110  std::list<std::string>::const_iterator end(void) const;
111 
112  // Use this for debugging, not for serialization/persistence.
113  virtual std::string toString(bool topLevelOnly = false,
114  std::string const& indent = "") const;
115 
116 // Modifiers
117  template <typename T> void set(
118  std::string const& name, T const& value);
119  void set(
120  std::string const& name, PropertySet::Ptr const& value);
121  template <typename T> void set(
122  std::string const& name, std::vector<T> const& value);
123  void set(
124  std::string const& name, char const* value);
125  template <typename T> void add(
126  std::string const& name, T const& value);
127  template <typename T> void add(
128  std::string const& name, std::vector<T> const& value);
129  void add(
130  std::string const& name, char const* value);
131 
132  template <typename T> void set(
133  std::string const& name, T const& value,
134  std::string const& comment);
135  template <typename T> void set(
136  std::string const& name, std::vector<T> const& value,
137  std::string const& comment);
138  void set(
139  std::string const& name, char const* value,
140  std::string const& comment);
141  template <typename T> void add(
142  std::string const& name, T const& value,
143  std::string const& comment);
144  template <typename T> void add(
145  std::string const& name, std::vector<T> const& value,
146  std::string const& comment);
147  void add(
148  std::string const& name, char const* value,
149  std::string const& comment);
150 
151  template <typename T> void set(
152  std::string const& name, T const& value,
153  char const* comment) {
154  set(name, value, std::string(comment));
155  }
156  template <typename T> void set(
157  std::string const& name, std::vector<T> const& value,
158  char const* comment) {
159  set(name, value, std::string(comment));
160  }
161  void set(
162  std::string const& name, char const* value,
163  char const* comment) {
164  set(name, value, std::string(comment));
165  }
166  template <typename T> void add(
167  std::string const& name, T const& value,
168  char const* comment) {
169  add(name, value, std::string(comment));
170  }
171  template <typename T> void add(
172  std::string const& name, std::vector<T> const& value,
173  char const* comment) {
174  add(name, value, std::string(comment));
175  }
176  void add(
177  std::string const& name, char const* value,
178  char const* comment) {
179  add(name, value, std::string(comment));
180  }
181 
182  virtual void copy(std::string const& dest, PropertySet::ConstPtr source,
183  std::string const& name);
184  virtual void combine(PropertySet::ConstPtr source);
185 
186  virtual void remove(std::string const& name);
187 
188 private:
189  LSST_PERSIST_FORMATTER(lsst::daf::persistence::PropertyListFormatter)
190 
191  typedef std::unordered_map<std::string, std::string> CommentMap;
192 
193  virtual void _set(std::string const& name,
194  std::shared_ptr< std::vector<boost::any> > vp);
195  virtual void _moveToEnd(std::string const& name);
196  virtual void _commentOrderFix(
197  std::string const& name, std::string const& comment);
198 
199  CommentMap _comments;
200  std::list<std::string> _order;
201 };
202 
203 #if defined(__ICC)
204 #pragma warning (pop)
205 #endif
206 
207 }}} // namespace lsst::daf::base
208 
209 #endif
std::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:85
Class for storing ordered metadata with comments.
Definition: PropertyList.h:82
std::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:86
std::shared_ptr< PropertyList const > ConstPtr
Definition: PropertyList.h:86
Definition: Citizen.h:35
std::shared_ptr< PropertyList > Ptr
Definition: PropertyList.h:85
void add(std::string const &name, std::vector< T > const &value, char const *comment)
Definition: PropertyList.h:171
void add(std::string const &name, char const *value, char const *comment)
Definition: PropertyList.h:176
Class for storing generic metadata.
Definition: PropertySet.h:82
#define LSST_PERSIST_FORMATTER(formatter...)
Macro used to connect the persistable class with the Formatter and boost::serialization.
Definition: Persistable.h:98
Interface for PropertySet class.
void add(std::string const &name, T const &value, char const *comment)
Definition: PropertyList.h:166