CiftiLib
A C++ library for CIFTI-2 and CIFTI-1 files
MetaData.h
1 #ifndef __METADATA_H__
2 #define __METADATA_H__
3 
4 /*LICENSE_START*/
5 /*
6  * Copyright (c) 2014, Washington University School of Medicine
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 
32 #include "Common/AString.h"
33 
34 #include "Common/XmlAdapter.h"
35 
36 #include <stdint.h>
37 
38 #include <map>
39 #include <stdexcept>
40 #include <vector>
41 
42 namespace cifti {
43 
44 class MetaData {
45 
46 public:
47  MetaData();
48 
49 public:
50  MetaData(const MetaData& o);
51 
52  MetaData& operator=(const MetaData& o);
53 
54  bool operator==(const MetaData& rhs) const;
55 
56  bool operator!=(const MetaData& rhs) const { return !((*this) == rhs); }
57 
58  virtual ~MetaData();
59 
60 private:
61  void copyHelper(const MetaData& o);
62 
63  void initializeMembersMetaData();
64 
65 public:
66  void clear();
67 
68  void append(const MetaData& smd);
69 
70  void replace(const MetaData& smd);
71 
72  void set(const AString& name, const AString& value);
73 
74  void setInt(const AString& name, const int32_t value);
75 
76  void setFloat(const AString& name, const float value);
77 
78  void replaceWithMap(const std::map<AString, AString>& map);
79 
80  std::map<AString, AString> getAsMap() const;
81 
82  void remove(const AString& name);
83 
84  bool exists(const AString& name) const;
85 
86  AString get(const AString& name) const;
87 
88  int32_t getInt(const AString& name, bool& ok) const;
89 
90  float getFloat(const AString& name, bool& ok) const;
91 
92  std::vector<AString> getAllMetaDataNames() const;
93 
94  void writeCiftiXML1(XmlWriter& xmlWriter) const;
95  void writeCiftiXML2(XmlWriter& xmlWriter) const;//for style, and in case it changes
96  void readCiftiXML1(XmlReader& xml);
97  void readCiftiXML2(XmlReader& xml);
98 
99 private:
100  void readEntry(XmlReader& xml);
101 
102  void replaceName(const AString& oldName,
103  const AString& newName);
104 
105 public:
106 
107 private:
109  std::map<AString, AString> metadata;
110  typedef std::map<AString, AString>::iterator MetaDataIterator;
111  typedef std::map<AString, AString>::const_iterator MetaDataConstIterator;
112 
113 };
114 
115 } // namespace
116 
117 #endif // __METADATA_H__
cifti::MetaData::replace
void replace(const MetaData &smd)
Definition: MetaData.cxx:113
cifti::MetaData
Definition: MetaData.h:44
cifti::MetaData::append
void append(const MetaData &smd)
Definition: MetaData.cxx:97
cifti::MetaData::remove
void remove(const AString &name)
Definition: MetaData.cxx:200
cifti::MetaData::set
void set(const AString &name, const AString &value)
Definition: MetaData.cxx:127
cifti::MetaData::replaceWithMap
void replaceWithMap(const std::map< AString, AString > &map)
Definition: MetaData.cxx:178
cifti::MetaData::getInt
int32_t getInt(const AString &name, bool &ok) const
Definition: MetaData.cxx:249
cifti::MetaData::getAsMap
std::map< AString, AString > getAsMap() const
Definition: MetaData.cxx:187
cifti::MetaData::setFloat
void setFloat(const AString &name, const float value)
Definition: MetaData.cxx:163
cifti::MetaData::getAllMetaDataNames
std::vector< AString > getAllMetaDataNames() const
Definition: MetaData.cxx:287
cifti::MetaData::clear
void clear()
Definition: MetaData.cxx:84
cifti::MetaData::setInt
void setInt(const AString &name, const int32_t value)
Definition: MetaData.cxx:148
cifti::MetaData::get
AString get(const AString &name) const
Definition: MetaData.cxx:231
cifti::MetaData::getFloat
float getFloat(const AString &name, bool &ok) const
Definition: MetaData.cxx:269
cifti
namespace for all CiftiLib functionality
Definition: CiftiBrainModelsMap.h:42
cifti::MetaData::exists
bool exists(const AString &name) const
Definition: MetaData.cxx:213