00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <vector>
00034 #include "CollectionSerializers.h"
00035 #include "StrUtil.h"
00036 #include "mace_constants.h"
00037
00038 #ifndef _MACE_ARRAY_H
00039 #define _MACE_ARRAY_H
00040
00046 namespace mace {
00047
00053
00054
00058 template<class T, int size, class Serial = SerializeArray<T>, class Alloc = std::allocator<T> >
00059 class array : public std::vector<T, Alloc>, public virtual Serial, public PrintPrintable {
00060
00061 BOOST_CLASS_REQUIRE2(Serial, Serializer, boost, ConvertibleConcept);
00062
00063 public:
00064 typedef typename std::vector<T, Alloc> baseType;
00065 typedef typename baseType::iterator iterator;
00066 typedef typename baseType::const_iterator const_iterator;
00067 typedef typename baseType::size_type size_type;
00068
00069 array() : baseType(size) {
00070 }
00071
00072 array(const T& t) : baseType(size, t) {
00073 }
00074
00075 array(const array<T, size, Serial, Alloc>& v) : baseType(v) {
00076 }
00077
00078 virtual ~array() { }
00079
00081 const std::string& getTypeName() const {
00082 const char* types[] = { "T", "int size", "Alloc", 0 };
00083 static const StrUtilNamespace::StdStringList myTypes = StrUtilNamespace::getTypeFromTemplate(__PRETTY_FUNCTION__, types);
00084 return myTypes[0];
00085 }
00086
00087 void print(std::ostream& out) const {
00088 if(mace::PRINT_TYPE_NAMES) {
00089 out << "array<"<< this->getTypeName() << "," << size << ">";
00090 }
00091 printList(out, this->begin(), this->end());
00092 }
00093 void printState(std::ostream& out) const {
00094 if(mace::PRINT_TYPE_NAMES) {
00095 out << "array<"<< this->getTypeName() << "," << size << ">";
00096 }
00097 printListState(out, this->begin(), this->end());
00098 }
00099
00100 private:
00101 class v_iterator : public _SerializeArray<T>::iterator {
00102 private:
00103 iterator i;
00104 iterator end;
00105
00106 public:
00107 bool isValid() {
00108 return i != end;
00109 }
00110 void next() {
00111 ASSERT(i != end);
00112 i++;
00113 }
00114 T& getValue() {
00115 return *i;
00116 }
00117
00118 v_iterator(iterator beg, iterator end) : i(beg), end(end) {}
00119 ~v_iterator() {}
00120 };
00121
00122 class v_const_iterator : public _SerializeArray<T>::const_iterator {
00123 private:
00124 const_iterator i;
00125 const_iterator end;
00126
00127 public:
00128 bool isValid() {
00129 return i != end;
00130 }
00131 void next() {
00132 ASSERT(i != end);
00133 i++;
00134 }
00135 const T& getValue() {
00136 return *i;
00137 }
00138
00139 v_const_iterator(const_iterator beg, const_iterator end) : i(beg), end(end) {}
00140 ~v_const_iterator() {}
00141 };
00142
00143 protected:
00144 typename _SerializeArray<T>::iterator* getIterator() {
00145 return new v_iterator(this->begin(), this->end());
00146 }
00147 typename _SerializeArray<T>::const_iterator* getIterator() const {
00148 return new v_const_iterator(this->begin(), this->end());
00149 }
00150 };
00151
00154 }
00155 #endif // _MACE_ARRAY_H