Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
ArrayField.h
1 #ifndef ELM_ARRAYFIELD_H
2 #define ELM_ARRAYFIELD_H
3 
4 #include <elm/string.h>
5 #include <elm/serial2/serial.h>
6 
7 
8 
9 
10 #define ARRAYFIELD(name, size) elm::serial2::getArrayField(#name, name, size)
11 
12 namespace elm { namespace serial2 {
13 
14 template <class T>
15 class ArrayField {
16  // private fields
17  const elm::CString name;
18  T *tab;
19  const int &size;
20 
21 public:
22 
23  // Constructor
24  inline ArrayField(elm::CString _name, T *_tab, int &_size) : name(_name), tab(_tab) , size(_size){
25  }
26 
27  // Accessors
28  inline const elm::CString& getName() const {
29  return name;
30  }
31  inline T *value() const {
32  return tab;
33  }
34  inline const int& getSize() const {
35  return size;
36  }
37 };
38 
39 
40 template <class T>
42  return ArrayField<T>(name, tab, size);
43 }
44 
45 
46 
47 
48 
49  template <class T>
50  inline void __serialize(Serializer& s, const ArrayField<T> &field) {
51  s.beginField(field.getName());
53  for (int i = 0; i < field.getSize(); i++) {
54  s.onItem();
55  s.onValue((field.value())[i]);
56  }
57  s.endCompound(field.value());
58  s.endField();
59  }
60 
61  template <class T>
62  inline void __unserialize(Unserializer& s, const ArrayField<T> &field) {
63  s.beginField(field.getName());
65  for (int i = 0; i < field.getSize(); i++) {
66  s.onValue((field.value())[i]);
67  }
68  s.endCompound(field.value());
69  s.endField();
70  }
71 
72 
73  template <class T>
75  __serialize(s, field);
76  return s;
77  }
78 
79  template <class T>
81  __unserialize(s, field);
82  return s;
83  }
84 } }
85 
86 #endif
elm::serial2::__unserialize
void __unserialize(Unserializer &s, const ArrayField< T > &field)
Definition: ArrayField.h:62
elm::serial2::ArrayField::getName
const elm::CString & getName() const
Definition: ArrayField.h:28
elm::serial2::Serializer::onValue
virtual void onValue(const bool &v)=0
elm::serial2::Unserializer::beginField
virtual bool beginField(CString name)=0
elm::serial2::Unserializer::endCompound
virtual void endCompound(void *)=0
elm::serial2::ArrayField
Definition: ArrayField.h:15
elm::serial2::__serialize
void __serialize(Serializer &s, const ArrayField< T > &field)
Definition: ArrayField.h:50
elm::Field::value
V & value(void) const
Definition: rtti.h:39
elm::serial2::Serializer::endField
virtual void endField(void)=0
elm::CString
Definition: CString.h:17
elm::serial2::Serializer::beginCompound
virtual void beginCompound(const void *object)=0
elm::serial2::ArrayField::value
T * value() const
Definition: ArrayField.h:31
elm
Definition: adapter.h:26
elm::serial2::Serializer
Definition: Serializer.h:36
elm::serial2::Unserializer::onValue
virtual void onValue(bool &v)=0
elm::t::size
uint64 size
Definition: arch.h:35
elm::serial2::operator&
Serializer & operator&(Serializer &s, const ArrayField< T > &field)
Definition: ArrayField.h:74
elm::serial2::getArrayField
ArrayField< T > getArrayField(elm::CString name, T *tab, int &size)
Definition: ArrayField.h:41
elm::serial2::ArrayField::ArrayField
ArrayField(elm::CString _name, T *_tab, int &_size)
Definition: ArrayField.h:24
elm::field
Field< T > field(CString name, T &value)
Definition: rtti.h:42
elm::serial2::Serializer::onItem
virtual void onItem(void)=0
elm::serial2::Unserializer
Definition: Unserializer.h:15
elm::serial2::ArrayField::getSize
const int & getSize() const
Definition: ArrayField.h:34
elm::serial2::Serializer::endCompound
virtual void endCompound(const void *)=0
elm::serial2::Unserializer::endField
virtual void endField(void)=0
elm::serial2::Unserializer::beginCompound
virtual bool beginCompound(void *)=0
elm::serial2::Serializer::beginField
virtual void beginField(CString name)=0