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
42namespace cifti {
43
44class MetaData {
45
46public:
47 MetaData();
48
49public:
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
60private:
61 void copyHelper(const MetaData& o);
62
63 void initializeMembersMetaData();
64
65public:
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
99private:
100 void readEntry(XmlReader& xml);
101
102 void replaceName(const AString& oldName,
103 const AString& newName);
104
105public:
106
107private:
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__
Definition: MetaData.h:44
void set(const AString &name, const AString &value)
Definition: MetaData.cxx:127
void setInt(const AString &name, const int32_t value)
Definition: MetaData.cxx:148
int32_t getInt(const AString &name, bool &ok) const
Definition: MetaData.cxx:249
void replaceWithMap(const std::map< AString, AString > &map)
Definition: MetaData.cxx:178
void replace(const MetaData &smd)
Definition: MetaData.cxx:113
void clear()
Definition: MetaData.cxx:84
void append(const MetaData &smd)
Definition: MetaData.cxx:97
void remove(const AString &name)
Definition: MetaData.cxx:200
void setFloat(const AString &name, const float value)
Definition: MetaData.cxx:163
std::vector< AString > getAllMetaDataNames() const
Definition: MetaData.cxx:287
bool exists(const AString &name) const
Definition: MetaData.cxx:213
float getFloat(const AString &name, bool &ok) const
Definition: MetaData.cxx:269
AString get(const AString &name) const
Definition: MetaData.cxx:231
std::map< AString, AString > getAsMap() const
Definition: MetaData.cxx:187
namespace for all CiftiLib functionality
Definition: CiftiBrainModelsMap.h:42