/usr/include/ismrmrd/meta.h is in libismrmrd-dev 1.3.3-1build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | /**
* @file meta.h
* @defgroup meta Meta Attributes API
* @{
*/
#ifndef ISMRMRDMETA_H
#define ISMRMRDMETA_H
#include "ismrmrd/export.h"
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stdexcept>
#include <stdio.h>
namespace ISMRMRD
{
/*
The serialized version of the structues would look like this
<?xml version="1.0"?>
<ismrmrdMeta>
<!-- String value type -->
<meta>
<name>parameter1</name>
<value>value_string</value>
</meta>
<!-- Integer value type -->
<meta>
<name>parameter1</name>
<value>677797</value>
</meta>
<!-- Arrays can have mixed value types -->
<meta>
<name>parameter1</name>
<value>1.456</value>
<value>66797</value>
<value>hsjdhaks</value>
</meta>
</ismrmrdMeta>
*/
/**
This class can represent a meta data value of any
type and it guarantees that any value will have a
representation as any type.
The class uses std::string internally to store the
string representation of the value but this std::string
is never exposed on the class interface and so it should not
need to be exported in Windows. For now, this class can be header only.
*/
class MetaValue
{
public:
/** Default construtor */
MetaValue()
{
set(0L);
}
///Null terminated string constructor
MetaValue(const char* s)
{
set(s);
}
///Long constructor
MetaValue(long l)
{
set(l);
}
///Long constructor
MetaValue(double d)
{
set(d);
}
///Assignment operator for string
MetaValue& operator=(const char * s)
{
set(s);
return *this;
}
///Assignment operator for long
MetaValue& operator=(long l)
{
set(l);
return *this;
}
///Assignment operator for double
MetaValue& operator=(double d)
{
set(d);
return *this;
}
///Get the ingeter representation of the value
long as_long() const
{
return l_;
}
///Get the floating point representation of the value
double as_double() const
{
return d_;
}
///get the C string representation of the value
const char* as_str() const
{
return s_.c_str();
}
protected:
long l_;
double d_;
std::string s_;
void set(const char* s)
{
s_ = std::string(s);
sscanf(s_.c_str(),"%ld",&l_);
sscanf(s_.c_str(),"%lf",&d_);
}
void set(long l)
{
l_ = l;
d_ = static_cast<double>(l_);
std::stringstream strstream;
strstream << l_;
strstream >> s_;
}
void set(double d)
{
d_ = d;
l_ = static_cast<long>(d_);
std::stringstream strstream;
strstream << d_;
strstream >> s_;
}
};
class MetaContainer;
EXPORTISMRMRD void deserialize(const char* xml, MetaContainer& h);
EXPORTISMRMRD void serialize(MetaContainer& h, std::ostream& o);
/// Meta Container
class MetaContainer
{
typedef std::map< std::string, std::vector<MetaValue> > map_t;
friend void serialize(MetaContainer& h, std::ostream& o);
public:
MetaContainer()
{
}
/**
This function sets the parameter with name @name to
value @value. The set function assumes the parameter
will have a single value and wipes out any array that might be there.
There is an @append function for appending to an existing array.
*/
template <class T> void set(const char* name, T value)
{
MetaValue v(value);
map_[std::string(name)] = std::vector<MetaValue>(1,value);
}
template <class T> void append(const char* name, T value)
{
map_t::iterator it = map_.find(std::string(name));
if (it == map_.end()) {
set(name, value);
} else {
MetaValue v(value);
it->second.push_back(v);
}
}
/// Return number of values of a particular parameter
size_t length(const char* name) const
{
map_t::const_iterator it = map_.find(std::string(name));
if (it != map_.end()) {
return it->second.size();
}
return 0;
}
/// Return value number @index of the parameter @name as long
long as_long(const char* name, size_t index = 0) const
{
return value(name,index).as_long();
}
/// Return value number @index of the parameter @name as double
double as_double(const char* name, size_t index = 0) const
{
return value(name,index).as_double();
}
/// Return value number @index of the parameter @name as string
const char* as_str(const char* name, size_t index = 0) const
{
return value(name,index).as_str();
}
const MetaValue& value(const char* name, size_t index = 0) const
{
map_t::const_iterator it = map_.find(std::string(name));
if (it == map_.end()) {
throw std::runtime_error("Attempting to access unkown parameter");
}
if (index >= it->second.size()) {
throw std::runtime_error("Attempting to access indexed value out of bounds");
}
return it->second[index];
}
bool empty()
{
return map_.empty();
}
protected:
map_t map_;
};
//Template function instantiations
/*
template void MetaContainer::set<const char*>(const char* name, const char* value);
template void MetaContainer::set<long>(const char* name, long value);
template void MetaContainer::set<double>(const char* name, double);
template void MetaContainer::append<const char*>(const char* name, const char* value);
template void MetaContainer::append<long>(const char* name, long value);
template void MetaContainer::append<double>(const char* name, double);
*/
}
/** @} */
#endif //ISMRMRDMETA_H
|