MUQ  0.4.3
Attributes.h
Go to the documentation of this file.
1 #ifndef ATTRIBUTES_H
2 #define ATTRIBUTES_H
3 
5 
6 #include <map>
7 #include <string>
8 
9 namespace muq
10 {
11 
12 namespace Utilities
13 {
14 
15 
16 class Attribute
17 {
18 
19 public:
20 
21  Attribute(){};
22 
23  Attribute(std::shared_ptr<HDF5File> file_,
24  std::string const& path_,
25  std::string const& name_) : file(file_),
26  path(path_),
27  name(name_){};
28 
29  virtual ~Attribute(){};
30 
31 
33  // conversions FROM other types
36  Attribute& operator=(ScalarType val)
37  {
38  assert(file);
39  file->WriteScalarAttribute(path, name, val);
40  return *this;
41  }
42 
43  template<typename ScalarType, int fixedRows>
44  Attribute& operator=(Eigen::Matrix<ScalarType, fixedRows, 1> const& val)
45  {
46  assert(file);
47  file->WriteVectorAttribute(path, name, val);
48  return *this;
49  }
50 
51  Attribute& operator=(std::string const& val);
52 
54  // conversions TO other types
57  operator ScalarType() const
58  {
59  assert(file);
60 
61  return file->GetScalarAttribute<ScalarType>(path,name);
62  };
63 
64  template<typename ScalarType>
65  operator Eigen::Matrix<ScalarType, Eigen::Dynamic, 1>() const
66  {
67  assert(file);
68  return file->GetVectorAttribute<ScalarType>(path,name);
69  };
70 
71  operator std::string() const;
72 
73 private:
74 
75  std::shared_ptr<HDF5File> file;
76 
77  std::string path; // the path into the HDF5 file
78  std::string name; // the name of the attribute
79 
80 };
81 
83 {
84 
85 public:
86 
88 
89  AttributeList(std::shared_ptr<HDF5File> file_,
90  std::string const& path_) : file(file_),
91  path(path_){};
92 
93  Attribute& operator[](std::string const& attrName);
94 
95 
96 private:
97  std::map<std::string, Attribute> attributes;
98 
99  std::shared_ptr<HDF5File> file;
100 
101  std::string path;
102 };
103 
104 } // namespace Utilities
105 } // namespace muq
106 
107 #endif
Attribute & operator[](std::string const &attrName)
Definition: Attributes.cpp:19
std::shared_ptr< HDF5File > file
Definition: Attributes.h:99
AttributeList(std::shared_ptr< HDF5File > file_, std::string const &path_)
Definition: Attributes.h:89
std::map< std::string, Attribute > attributes
Definition: Attributes.h:97
std::shared_ptr< HDF5File > file
Definition: Attributes.h:75
Attribute(std::shared_ptr< HDF5File > file_, std::string const &path_, std::string const &name_)
Definition: Attributes.h:23
Attribute & operator=(ScalarType val)
Definition: Attributes.h:36
Attribute & operator=(Eigen::Matrix< ScalarType, fixedRows, 1 > const &val)
Definition: Attributes.h:44
int int FloatType value
Definition: json.h:15223