ALBA
albaStorageElement.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaStorageElement
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 __albaStorageElement_h__
17#define __albaStorageElement_h__
18
19#include "albaDefines.h"
20#include <vector>
21//----------------------------------------------------------------------------
22// forward declarations :
23//----------------------------------------------------------------------------
24class albaStorage;
25class albaStorable;
26class albaMatrix;
27class albaString;
28class albaObject;
29
30
45class ALBA_EXPORT albaStorageElement
46{
47public:
49
51 virtual const char *GetName()=0;
52
56 virtual void SetAttribute(const char *name,const char *value)=0;
57 void SetAttribute(const char *name,const albaID value);
58 void SetAttribute(const char *name,const double value);
59
61 virtual bool GetAttribute(const char *name,albaString &value)=0;
62
66 bool GetAttributeAsDouble(const char *name,double &value);
67
71 bool GetAttributeAsInteger(const char *name,albaID &value);
72
74 albaString UpgradeAttribute(const char *attribute);
75
76 virtual int StoreText(const char *name, const char *text)=0;
77 virtual int StoreMatrix(const char *name,const albaMatrix *matrix)=0;
78 virtual int StoreVectorN(const char *name, double *comps,int num)=0;
79 virtual int StoreVectorN(const char *name, int *comps,int num)=0;
80 virtual int StoreVectorN(const char *name, const std::vector<double> &comps,int num)=0;
81 virtual int StoreVectorN(const char *name, const std::vector<int> &comps,int num)=0;
83 virtual int StoreVectorN(const char *name, const std::vector<albaString> &comps,int num,const char *tag)=0;
84
86 //virtual int StoreData(const char *name, const char *data, const int size)=0;
88 //virtual int StoreData16(const char *name, const short *data, const int size)=0;
90 //virtual int StoreData32(const char *name, const long *data, const int size)=0;
91
93 //virtual int RestoreData(const char *name, char *data, const int size)=0;
95 //virtual int RestoreData16(const char *name,short *data, const int size)=0;
97 //virtual int RestoreData32(const char *name,long *data, const int size)=0;
98
99 int RestoreMatrix(const char *name,albaMatrix *matrix);
100 int RestoreVectorN(const char *name,double *comps,unsigned int num);
101 int RestoreVectorN(const char *name,int *comps,unsigned int num);
102 int RestoreVectorN(const char *name,std::vector<double> &comps,unsigned int num);
103 int RestoreVectorN(const char *name,std::vector<int> &comps,unsigned int num);
105 int RestoreVectorN(const char *name,std::vector<albaString> &comps,unsigned int num,const char *tag);
106 int RestoreText(const char *name,char *&buffer);
107 int RestoreText(const char *name,albaString &buffer);
108
109
110 virtual int RestoreMatrix(albaMatrix *matrix)=0;
111 virtual int RestoreVectorN(double *comps,unsigned int num)=0;
112 virtual int RestoreVectorN(int *comps,unsigned int num)=0;
113 virtual int RestoreVectorN(std::vector<double> &comps,unsigned int num)=0;
114 virtual int RestoreVectorN(std::vector<int> &comps,unsigned int num)=0;
116 virtual int RestoreVectorN(std::vector<albaString> &comps,unsigned int num,const char *tag)=0;
117 virtual int RestoreText(albaString &buffer)=0;
118
119 virtual int RestoreText(char *&buffer);
120
121 int StoreDouble(const char *name,const double &value);
122 int RestoreDouble(const char *name,double &value);
123 int RestoreDouble(double &value);
124
125 int StoreInteger(const char *name, const int &value);
126 int RestoreInteger(const char *name,int &value);
127 int RestoreInteger(int &value);
128
136 int RestoreObject(const char *name,albaStorable * object);
137
139 albaObject *RestoreObject(const char *name);
140
143
149 albaStorageElement *StoreObject(const char *name,albaObject *object);
150
153 virtual int StoreObjectVector(const char *name,const std::vector<albaObject *> &vector,const char *items_name="Item");
154
156 virtual int RestoreObjectVector(const char *name,std::vector<albaObject *> &vector,const char *items_name="Item");
157
159 virtual int RestoreObjectVector(albaStorageElement *element,std::vector<albaObject *> &vector,const char *items_name="Item");
160
162 albaStorage *GetStorage() {return m_Storage;}
163
165 albaStorageElement *GetParent() {return m_Parent;}
166
170 virtual albaStorageElement *AppendChild(const char *name) = 0;
171
173 virtual albaStorageElement *FindNestedElement(const char *name);
174
175 typedef std::vector<albaStorageElement *> ChildrenVector;
176
181
184 virtual bool GetNestedElementsByName(const char *name,std::vector<albaStorageElement *> &list);
185
186protected:
189
191 albaStorageElement *StoreObject(const char *name,albaStorable *storable, const char *type_name);
192
193 void SetStorage(albaStorage *storage) {m_Storage = storage;}
194 void SetParent(albaStorageElement *element) {m_Parent = element;}
195
198 std::vector<albaStorageElement *> *m_Children;
199};
200#endif // _albaStorageElement_h_
long albaID
type for IDs inside ALBA
Definition: albaDefines.h:58
albaMatrix - Time stamped 4x4 Matrix.
Definition: albaMatrix.h:44
Abstract superclass for all ALBA classes implementing RTTI APIs.
Definition: albaObject.h:38
albaStorable is an interface for serializable objects.
Definition: albaStorable.h:41
Abstract class representing the interface for the unit of information stored in the storage.
virtual int RestoreText(char *&buffer)
albaStorageElement(albaStorageElement *parent, albaStorage *storage)
elements can be created only by means of AppendChild() or FindNestedElement()
virtual void SetAttribute(const char *name, const char *value)=0
Set an attribute of this element.
virtual int RestoreVectorN(std::vector< double > &comps, unsigned int num)=0
int RestoreVectorN(const char *name, std::vector< int > &comps, unsigned int num)
int RestoreVectorN(const char *name, std::vector< albaString > &comps, unsigned int num, const char *tag)
restore a vector of strings from an XML element, where single items are stored in "tag" sub elements
albaStorageElement * m_Parent
the parent element in the hierarchy
void SetParent(albaStorageElement *element)
albaStorage * m_Storage
storage who created this element
int RestoreDouble(const char *name, double &value)
virtual albaStorageElement * AppendChild(const char *name)=0
Create a new child element and return its pointer.
std::vector< albaStorageElement * > * m_Children
children elements
virtual int StoreVectorN(const char *name, double *comps, int num)=0
int RestoreVectorN(const char *name, int *comps, unsigned int num)
virtual ChildrenVector & GetChildren()=0
Return the list of children.
int RestoreVectorN(const char *name, std::vector< double > &comps, unsigned int num)
virtual int StoreVectorN(const char *name, const std::vector< albaString > &comps, int num, const char *tag)=0
store a vector of strings into an XML element, and stores single items in "tag" sub elements
int RestoreVectorN(const char *name, double *comps, unsigned int num)
virtual int StoreVectorN(const char *name, const std::vector< int > &comps, int num)=0
virtual bool GetNestedElementsByName(const char *name, std::vector< albaStorageElement * > &list)
Return the list of all children with a given name.
int RestoreInteger(const char *name, int &value)
albaStorageElement * GetParent()
return a pointer to the parent element, i.e.
virtual bool GetAttribute(const char *name, albaString &value)=0
Return an attribute value given its name.
virtual int RestoreVectorN(int *comps, unsigned int num)=0
int RestoreInteger(int &value)
int RestoreText(const char *name, char *&buffer)
std::vector< albaStorageElement * > ChildrenVector
int StoreInteger(const char *name, const int &value)
albaStorageElement * StoreObject(const char *name, albaObject *object)
Used for storing a albaObjects.
virtual int StoreVectorN(const char *name, int *comps, int num)=0
bool GetAttributeAsDouble(const char *name, double &value)
Return an attribute value given its name, converting it to double.
int RestoreObject(const char *name, albaStorable *object)
Function to try restoring a albaObject from a albaStorageElement.
albaStorageElement * StoreObject(const char *name, albaStorable *storable, const char *type_name)
commodity function to store a storable object creating on the fly the element to store it inside.
virtual int RestoreVectorN(std::vector< int > &comps, unsigned int num)=0
virtual int StoreText(const char *name, const char *text)=0
virtual int RestoreMatrix(albaMatrix *matrix)=0
virtual int RestoreObjectVector(const char *name, std::vector< albaObject * > &vector, const char *items_name="Item")
Restore a vector of objects.
albaObject * RestoreObject()
Restore object from given element.
int RestoreDouble(double &value)
virtual const char * GetName()=0
get the name of this element.
bool GetAttributeAsInteger(const char *name, albaID &value)
Return an attribute value given its name, converting it to integer.
virtual int StoreMatrix(const char *name, const albaMatrix *matrix)=0
int RestoreText(const char *name, albaString &buffer)
virtual int StoreObjectVector(const char *name, const std::vector< albaObject * > &vector, const char *items_name="Item")
Store a vector of objects.
virtual int RestoreText(albaString &buffer)=0
albaString UpgradeAttribute(const char *attribute)
Used to upgrade attribute value from previous MSF file version.
int StoreDouble(const char *name, const double &value)
void SetStorage(albaStorage *storage)
virtual int RestoreObjectVector(albaStorageElement *element, std::vector< albaObject * > &vector, const char *items_name="Item")
Restore a vector of objects.
albaObject * RestoreObject(const char *name)
Restore object from given element.
virtual int StoreVectorN(const char *name, const std::vector< double > &comps, int num)=0
virtual int RestoreVectorN(double *comps, unsigned int num)=0
virtual albaStorageElement * FindNestedElement(const char *name)
Find a nested element by Name.
int RestoreMatrix(const char *name, albaMatrix *matrix)
Store 8bit binary data.
virtual ~albaStorageElement()
void SetAttribute(const char *name, const albaID value)
void SetAttribute(const char *name, const double value)
albaStorage * GetStorage()
return a pointer to the storage who created this element
virtual int RestoreVectorN(std::vector< albaString > &comps, unsigned int num, const char *tag)=0
restore a vector of strings from an XML element, where single items are stored in "tag" sub elements
Abstract class for an abject mastering the storing/restoring of objects This is an abstract class pro...
Definition: albaStorage.h:48
albaString - performs common string operations on c-strings.
Definition: albaString.h:43