ALBA
albaTagArray.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaTagArray
5 Authors: Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaTagArray_h
17#define __albaTagArray_h
18//----------------------------------------------------------------------------
19// includes :
20//----------------------------------------------------------------------------
21#include "albaAttribute.h"
22#include "albaTagItem.h"
23#include <map>
24#include <string>
25
26#ifdef ALBA_EXPORTS
27#include "albaDllMacros.h"
28EXPORT_STL_MAP(ALBA_EXPORT,std::string,albaTagItem);
29#endif
30
36class ALBA_EXPORT albaTagArray : public albaAttribute
37{
38public:
41
43
44
45 void operator=(const albaTagArray &a);
46
47 bool operator==(const albaTagArray &a) const;
48
50 //albaTagItem &operator [](const char *name);
51
53 //const albaTagItem &operator [](const char *name) const;
54
57 albaTagItem *GetTag(const char *name);
58
61 bool GetTag(const char *name,albaTagItem &item);
62
65 bool IsTagPresent(const char *name);
66
71 void SetTag(const albaTagItem &value);
72
77 void SetTag(const char *name, const char *value,int type=ALBA_MISSING_TAG);
78
82 void SetTag(const char *name, double value);
83
84
86 void DeleteTag(const char *name);
87
90 void GetTagList(std::vector<std::string> &list);
91
95 bool Equals(const albaTagArray *array) const;
96
98 void DeepCopy(const albaTagArray *a);
99
100 void DeepCopy(const albaAttribute *a);
101
105 void GetTagsByType(int type, std::vector<albaTagItem *> &array);
106
108 int GetNumberOfTags() const;
109
110 typedef std::map<std::string,albaTagItem> mmuTagsMap;
111
113 mmuTagsMap *GetTagsContainer() {return &m_Tags;}
114
116 virtual void Print(std::ostream& os, const int tabs=0) const;
117
118protected:
119
120 virtual int InternalStore(albaStorageElement *parent);
122
123
125};
126
127//-------------------------------------------------------------------------
128template <class TType>
129inline TType albaRestoreNumericFromTag(albaTagArray *array,const char *name, TType &variable, TType unset_value, TType default_value)
130//-------------------------------------------------------------------------
131{
132 if (variable==unset_value)
133 {
134 if (albaTagItem *item=array->GetTag(name))
135 {
136 variable = item->GetValueAsDouble();
137 }
138 else
139 {
140 variable = default_value;
141 }
142 }
143
144 return variable;
145}
146
147//-------------------------------------------------------------------------
148template <class TType>
149inline TType albaRestoreStringFromTag(albaTagArray *array,const char *name, TType &variable, const char *unset_value, const char *default_value)
150//-------------------------------------------------------------------------
151{
152 if (variable==unset_value)
153 {
154 if (albaTagItem *item=array->GetTag(name))
155 {
156 variable = item->GetValue();
157 }
158 else
159 {
160 variable = default_value;
161 }
162 }
163
164 return variable;
165}
166
167
168#endif
169
#define EXPORT_STL_MAP(declspec_, K_, V_)
Definition: albaDllMacros.h:90
TType albaRestoreNumericFromTag(albaTagArray *array, const char *name, TType &variable, TType unset_value, TType default_value)
Definition: albaTagArray.h:129
TType albaRestoreStringFromTag(albaTagArray *array, const char *name, TType &variable, const char *unset_value, const char *default_value)
Definition: albaTagArray.h:149
@ ALBA_MISSING_TAG
Definition: albaTagItem.h:36
An abstract class for objects representing an attribute for albaVMEs.
Definition: albaAttribute.h:34
void operator=(const albaAttribute &a)
attributes must define a copy rule
Abstract class representing the interface for the unit of information stored in the storage.
An attribute used to store an associtive array of <key,value> pairs, where value is multi component.
Definition: albaTagArray.h:37
void GetTagList(std::vector< std::string > &list)
Return the list of Tag names as an array of strings.
int GetNumberOfTags() const
return the number of tags stored in this object
std::map< std::string, albaTagItem > mmuTagsMap
Definition: albaTagArray.h:110
bool GetTag(const char *name, albaTagItem &item)
Get a particular tag item.
bool IsTagPresent(const char *name)
return true if the give TAG exists.
void DeepCopy(const albaTagArray *a)
copy the content of another array
mmuTagsMap m_Tags
Definition: albaTagArray.h:124
void DeleteTag(const char *name)
Remove an item from the array.
void SetTag(const albaTagItem &value)
This function searches for an item with same Tag name of the given one and if it doesn't exist append...
bool Equals(const albaTagArray *array) const
Compare two tag arrays.
void SetTag(const char *name, double value)
This function searches for an item with given name and if it doesn't exist append a new one to the Ar...
albaTagItem * GetTag(const char *name)
provide access to vector items.
virtual void Print(std::ostream &os, const int tabs=0) const
dump tags stored into this array
virtual int InternalStore(albaStorageElement *parent)
This is called by Store() and must be reimplemented by subclasses.
void GetTagsByType(int type, std::vector< albaTagItem * > &array)
Search the tag array for tags of a given type and put in the array pointers to them
bool operator==(const albaTagArray &a) const
mmuTagsMap * GetTagsContainer()
return the container of the tags stored in this attribute
Definition: albaTagArray.h:113
albaTypeMacro(albaTagArray, albaAttribute) void operator
attributes must define a copy rule
virtual int InternalRestore(albaStorageElement *node)
This is called by Restore() and must be reimplemented by subclasses The element from which the object...
void SetTag(const char *name, const char *value, int type=ALBA_MISSING_TAG)
This function searches for an item with given name and if it doesn't exist append a new one to the Ar...
void DeepCopy(const albaAttribute *a)
copy the content of the given attribute.
an utility class for storing <key-type-array of values> information.
Definition: albaTagItem.h:47