22 #ifndef _DescriptionAttributes_hxx_
23 #define _DescriptionAttributes_hxx_
47 : _attributeName(attributeName) {}
49 : _scopeName(scopeName), _attributeName(attributeName) {}
56 storage.
Store(scopeAttribute);
59 storage.
Store(nameAttribute);
68 const std::string &
GetName()
const {
return _attributeName; }
70 const std::string &
GetScope()
const {
return _scopeName; }
73 virtual void *
Allocate(
unsigned size)
const = 0;
75 virtual void Deallocate(
void * data)
const = 0;
77 virtual void Insert(
void * data,
unsigned pos)
const = 0;
79 virtual void Remove(
void * data,
unsigned pos)
const = 0;
82 virtual void XmlDumpData(
Storage & storage,
const void * data,
unsigned size )
const = 0;
90 template <
typename TypeToCheck>
93 if (
typeid(TypeToCheck)==
TypeInfo())
return;
94 std::ostringstream os;
95 os <<
"Attribute '" << _scopeName <<
":" << _attributeName
96 <<
"' has been used as type '" <<
typeid(TypeToCheck).name()
97 <<
"' but it really was of type '" <<
TypeInfo().name() <<
"'";
103 virtual const std::type_info &
TypeInfo()
const = 0;
105 std::string _scopeName;
106 std::string _attributeName;
114 template <
typename AttributeType>
120 Attribute(
const std::string & scopeName,
const std::string & attributeName)
125 return new std::vector<DataType>(size);
129 delete (std::vector<DataType>*)data;
131 virtual void Insert(
void * data,
unsigned pos)
const
133 std::vector<DataType> * vector = (std::vector<DataType> *) data;
134 vector->insert(vector->begin()+pos,
DataType());
136 virtual void Remove(
void * data,
unsigned pos)
const
138 std::vector<DataType> * vector = (std::vector<DataType> *) data;
139 vector->erase(vector->begin()+pos);
144 storage.
Store(nameAdapter);
145 const std::vector<DataType> * vector = (
const std::vector<DataType> *) data;
146 XmlDumpConcreteData(storage,&(*vector)[0],size,(
DataType*)0);
152 storage.
Load(nameAdapter);
154 (
"The schema expected an attribute named '" +
GetScope() +
":" +
GetName() +
155 "' but the XML file contained '" +
GetScope() +
":" + name +
"'").c_str());
156 std::vector<DataType> * vector = (std::vector<DataType> *) data;
157 XmlRestoreConcreteData(storage,&(*vector)[0],size,(
DataType*)0);
162 std::string type = XmlTypeId(typeDiscriminator, typeDiscriminator);
164 storage.
Store(typeAttribute);
167 template <
typename T>
168 std::string XmlTypeId(
const T * realType,
void * discriminator )
const
171 return typeid(T).name();
173 template <
typename T>
174 std::string XmlTypeId(
const T * realType, Component * discriminator )
const
177 return dummy.GetClassName();
179 template <
typename T>
180 std::string XmlTypeId(
const T * realType,
float * discriminator )
const
184 template <
typename T>
185 std::string XmlTypeId(
const T * realType, std::string * discriminator )
const
189 template <
typename T>
190 void XmlDumpConcreteData(Storage & storage,
const T * data,
unsigned size,
void * discriminator )
const
192 XMLArrayAdapter<DataType> dataAdapter((
DataType*)data, size);
193 storage.Store(dataAdapter);
195 template <
typename T>
196 void XmlDumpConcreteData(Storage & storage,
const T * data,
unsigned size, Component * discriminator )
const
198 for (
unsigned i=0 ; i < size ; i++ )
200 XMLComponentAdapter componentAdapter(data[i],data[i].
GetClassName(),
true);
201 storage.Store(componentAdapter);
204 template <
typename T>
205 void XmlRestoreConcreteData(Storage & storage, T * data,
unsigned size,
void * discriminator )
const
207 XMLArrayAdapter<DataType> dataAdapter(data, size);
208 storage.Load(dataAdapter);
210 template <
typename T>
211 void XmlRestoreConcreteData(Storage & storage, T * data,
unsigned size, Component * discriminator )
const
213 for (
unsigned i=0 ; i < size ; i++ )
215 XMLComponentAdapter componentAdapter(data[i],data[i].
GetClassName(),
true);
216 storage.Load(componentAdapter);
230 #endif// _DescriptionAttributes_hxx_