LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
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 <lsst/tr1/unordered_map.h>
57 #include <list>
58 #include <string>
59 #include <typeinfo>
60 #include <vector>
61 
62 #include "boost/any.hpp"
63 #include "boost/shared_ptr.hpp"
65 
66 namespace lsst {
67 namespace daf {
68 
69 namespace persistence {
70  class PropertyListFormatter;
71 } // namespace lsst::daf::persistence
72 
73 
74 namespace base {
75 
76 #if defined(__ICC)
77 #pragma warning (push)
78 #pragma warning (disable: 444)
79 #endif
80 
81 class PropertyList : public PropertySet {
82 public:
83 // Typedefs
84  typedef boost::shared_ptr<PropertyList> Ptr;
85  typedef boost::shared_ptr<PropertyList const> ConstPtr;
86 
87 // Constructors
88  PropertyList(void);
89  virtual ~PropertyList(void);
90 
91 // Accessors
92  virtual PropertySet::Ptr deepCopy(void) const;
93  // Returns a PropertySet::Ptr pointing to a new deep copy of the
94  // PropertyList.
95 
96  template <typename T> T get(std::string const& name) const;
97  // Note that the type must be explicitly specified for this template:
98  // int i = propertyList.get<int>("foo");
99  template <typename T>
100  T get(std::string const& name, T const& defaultValue) const;
101  // Returns the provided default value if the name does not exist.
102  template <typename T>
103  std::vector<T> getArray(std::string const& name) const;
104 
105  std::string const& getComment(std::string const& name) const;
106  std::vector<std::string> getOrderedNames(void) const;
107 
108  std::list<std::string>::const_iterator begin(void) const;
109  std::list<std::string>::const_iterator end(void) const;
110 
111  // Use this for debugging, not for serialization/persistence.
112  virtual std::string toString(bool topLevelOnly = false,
113  std::string const& indent = "") const;
114 
115 // Modifiers
116  template <typename T> void set(
117  std::string const& name, T const& value, bool inPlace=true);
118  void set(
119  std::string const& name, PropertySet::Ptr const& value,
120  bool inPlace=true);
121  template <typename T> void set(
122  std::string const& name, std::vector<T> const& value,
123  bool inPlace=true);
124  void set(
125  std::string const& name, char const* value, bool inPlace=true);
126  template <typename T> void add(
127  std::string const& name, T const& value, bool inPlace=true);
128  template <typename T> void add(
129  std::string const& name, std::vector<T> const& value,
130  bool inPlace=true);
131  void add(
132  std::string const& name, char const* value, bool inPlace=true);
133 
134  template <typename T> void set(
135  std::string const& name, T const& value,
136  std::string const& comment, bool inPlace=true);
137  template <typename T> void set(
138  std::string const& name, std::vector<T> const& value,
139  std::string const& comment, bool inPlace=true);
140  void set(
141  std::string const& name, char const* value,
142  std::string const& comment, bool inPlace=true);
143  template <typename T> void add(
144  std::string const& name, T const& value,
145  std::string const& comment, bool inPlace=true);
146  template <typename T> void add(
147  std::string const& name, std::vector<T> const& value,
148  std::string const& comment, bool inPlace=true);
149  void add(
150  std::string const& name, char const* value,
151  std::string const& comment, bool inPlace=true);
152 
153  template <typename T> void set(
154  std::string const& name, T const& value,
155  char const* comment, bool inPlace=true) {
156  set(name, value, std::string(comment), inPlace);
157  }
158  template <typename T> void set(
159  std::string const& name, std::vector<T> const& value,
160  char const* comment, bool inPlace=true) {
161  set(name, value, std::string(comment), inPlace);
162  }
163  void set(
164  std::string const& name, char const* value,
165  char const* comment, bool inPlace=true) {
166  set(name, value, std::string(comment), inPlace);
167  }
168  template <typename T> void add(
169  std::string const& name, T const& value,
170  char const* comment, bool inPlace=true) {
171  add(name, value, std::string(comment), inPlace);
172  }
173  template <typename T> void add(
174  std::string const& name, std::vector<T> const& value,
175  char const* comment, bool inPlace=true) {
176  add(name, value, std::string(comment), inPlace);
177  }
178  void add(
179  std::string const& name, char const* value,
180  char const* comment, bool inPlace=true) {
181  add(name, value, std::string(comment), inPlace);
182  }
183 
184  virtual void copy(std::string const& dest, PropertySet::ConstPtr source,
185  std::string const& name) {
186  copy(dest, source, name, true);
187  }
188  virtual void combine(PropertySet::ConstPtr source) {
189  combine(source, true);
190  }
191 
192  virtual void copy(std::string const& dest, PropertySet::ConstPtr source,
193  std::string const& name, bool inPlace);
194  virtual void combine(PropertySet::ConstPtr source, bool inPlace);
195 
196  virtual void remove(std::string const& name);
197 
198 private:
199  LSST_PERSIST_FORMATTER(lsst::daf::persistence::PropertyListFormatter)
200 
201  typedef std::tr1::unordered_map<std::string, std::string> CommentMap;
202 
203  virtual void _set(std::string const& name,
204  boost::shared_ptr< std::vector<boost::any> > vp);
205  virtual void _moveToEnd(std::string const& name);
206  virtual void _commentOrderFix(
207  std::string const& name, std::string const& comment, bool inPlace);
208 
209  CommentMap _comments;
210  std::list<std::string> _order;
211 };
212 
213 #if defined(__ICC)
214 #pragma warning (pop)
215 #endif
216 
217 }}} // namespace lsst::daf::base
218 
219 #endif
boost::shared_ptr< PropertyList const > ConstPtr
Definition: PropertyList.h:85
void add(std::string const &name, std::vector< T > const &value, char const *comment, bool inPlace=true)
Definition: PropertyList.h:173
std::string const & getComment(std::string const &name) const
table::Key< std::string > name
Definition: ApCorrMap.cc:71
std::tr1::unordered_map< std::string, std::string > CommentMap
Definition: PropertyList.h:201
std::vector< T > getArray(std::string const &name) const
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
virtual void copy(std::string const &dest, PropertySet::ConstPtr source, std::string const &name)
Definition: PropertyList.h:184
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
void set(std::string const &name, char const *value, char const *comment, bool inPlace=true)
Definition: PropertyList.h:163
boost::shared_ptr< PropertySet const > ConstPtr
Definition: PropertySet.h:91
std::list< std::string >::const_iterator begin(void) const
virtual void _moveToEnd(std::string const &name)
void set(std::string const &name, T const &value, bool inPlace=true)
bool any(CoordinateExpr< N > const &expr)
Return true if any elements are true.
std::list< std::string > _order
Definition: PropertyList.h:210
boost::shared_ptr< PropertyList > Ptr
Definition: PropertyList.h:84
virtual void _set(std::string const &name, boost::shared_ptr< std::vector< boost::any > > vp)
std::vector< std::string > getOrderedNames(void) const
std::list< std::string >::const_iterator end(void) const
void add(std::string const &name, char const *value, char const *comment, bool inPlace=true)
Definition: PropertyList.h:178
#define LSST_PERSIST_FORMATTER(formatter...)
Definition: Persistable.h:98
virtual std::string toString(bool topLevelOnly=false, std::string const &indent="") const
void add(std::string const &name, T const &value, char const *comment, bool inPlace=true)
Definition: PropertyList.h:168
Class for storing generic metadata.
Definition: PropertySet.h:82
virtual void _commentOrderFix(std::string const &name, std::string const &comment, bool inPlace)
void set(std::string const &name, std::vector< T > const &value, char const *comment, bool inPlace=true)
Definition: PropertyList.h:158
Interface for PropertySet class.
void add(std::string const &name, T const &value, bool inPlace=true)
virtual PropertySet::Ptr deepCopy(void) const
Definition: PropertyList.cc:72
void set(std::string const &name, T const &value, char const *comment, bool inPlace=true)
Definition: PropertyList.h:153
virtual void combine(PropertySet::ConstPtr source)
Definition: PropertyList.h:188