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
80 void DeleteTag(const char *name);
81
84 void GetTagList(std::vector<std::string> &list);
85
89 bool Equals(const albaTagArray *array) const;
90
92 void DeepCopy(const albaTagArray *a);
93
94 void DeepCopy(const albaAttribute *a);
95
99 void GetTagsByType(int type, std::vector<albaTagItem *> &array);
100
102 int GetNumberOfTags() const;
103
104 typedef std::map<std::string,albaTagItem> mmuTagsMap;
105
107 mmuTagsMap *GetTagsContainer() {return &m_Tags;}
108
110 virtual void Print(std::ostream& os, const int tabs=0) const;
111
112protected:
113
114 virtual int InternalStore(albaStorageElement *parent);
116
117
119};
120
121//-------------------------------------------------------------------------
122template <class TType>
123inline TType albaRestoreNumericFromTag(albaTagArray *array,const char *name, TType &variable, TType unset_value, TType default_value)
124//-------------------------------------------------------------------------
125{
126 if (variable==unset_value)
127 {
128 if (albaTagItem *item=array->GetTag(name))
129 {
130 variable = item->GetValueAsDouble();
131 }
132 else
133 {
134 variable = default_value;
135 }
136 }
137
138 return variable;
139}
140
141//-------------------------------------------------------------------------
142template <class TType>
143inline TType albaRestoreStringFromTag(albaTagArray *array,const char *name, TType &variable, const char *unset_value, const char *default_value)
144//-------------------------------------------------------------------------
145{
146 if (variable==unset_value)
147 {
148 if (albaTagItem *item=array->GetTag(name))
149 {
150 variable = item->GetValue();
151 }
152 else
153 {
154 variable = default_value;
155 }
156 }
157
158 return variable;
159}
160
161
162#endif
163
#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:123
TType albaRestoreStringFromTag(albaTagArray *array, const char *name, TType &variable, const char *unset_value, const char *default_value)
Definition: albaTagArray.h:143
@ 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:104
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:118
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.
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:107
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