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 <list>
00034 #include <iostream>
00035 #include "CollectionSerializers.h"
00036 #include "StrUtil.h"
00037 #include "mace_constants.h"
00038
00039 #ifndef _MACE_LIST_H
00040 #define _MACE_LIST_H
00041
00047 namespace mace {
00048
00054
00055 template<class T, class Serial = SerializeList<T>, class Alloc = std::allocator<T> >
00056 class list : public std::list<T, Alloc>, public virtual Serial, public PrintPrintable {
00057
00058 BOOST_CLASS_REQUIRE2(Serial, Serializer, boost, ConvertibleConcept);
00059
00060 public:
00061 typedef typename std::list<T, Alloc> baseType;
00062 typedef typename baseType::iterator iterator;
00063 typedef typename baseType::const_iterator const_iterator;
00064 typedef typename baseType::size_type size_type;
00065
00066 list() : baseType() {
00067 }
00068
00069 list(size_type n) : baseType(n) {
00070 }
00071
00072 list(size_type n, const T& t) : baseType(n, t) {
00073 }
00074
00075 list(const std::list<T, Alloc>& v) : baseType(v) {
00076 }
00077
00078 virtual ~list() { }
00079
00081 void resize(size_t sz) {
00082 baseType::resize(sz);
00083 }
00084
00086 size_t size() const {
00087 return baseType::size();
00088 }
00089
00091 void add(const T& t) {
00092 return baseType::push_back(t);
00093 }
00094
00096 const std::string& getTypeName() const {
00097 const char* types[] = { "T", "Serial", "Alloc", 0 };
00098 static const StrUtilNamespace::StdStringList myTypes = StrUtilNamespace::getTypeFromTemplate(__PRETTY_FUNCTION__, types);
00099 return myTypes[0];
00100 }
00101
00102 void print(PrintNode& pr, const std::string& name) const {
00103 mace::printList(pr, name, "list<" + getTypeName() + ">", this->begin(),
00104 this->end());
00105 }
00106
00107 void print(std::ostream& out) const {
00108 if(mace::PRINT_TYPE_NAMES) {
00109 out << "list<"<< this->getTypeName() <<">";
00110 }
00111 printList(out, this->begin(), this->end());
00112 }
00113
00114 void printState(std::ostream& out) const {
00115 if(mace::PRINT_TYPE_NAMES) {
00116 out << "list<"<<this->getTypeName() <<">";
00117 }
00118 printListState(out, this->begin(), this->end());
00119 }
00120
00121 private:
00122 class v_iterator : public _SerializeList<T>::iterator {
00123 private:
00124 iterator i;
00125 iterator end;
00126
00127 public:
00128 bool isValid() {
00129 return i != end;
00130 }
00131 void next() {
00132 ASSERT(i != end);
00133 i++;
00134 }
00135 T& getValue() {
00136 return *i;
00137 }
00138
00139 v_iterator(iterator beg, iterator end) : i(beg), end(end) {}
00140 ~v_iterator() {}
00141 };
00142
00143 class v_const_iterator : public _SerializeList<T>::const_iterator {
00144 private:
00145 const_iterator i;
00146 const_iterator end;
00147
00148 public:
00149 bool isValid() {
00150 return i != end;
00151 }
00152 void next() {
00153 ASSERT(i != end);
00154 i++;
00155 }
00156 const T& getValue() {
00157 return *i;
00158 }
00159
00160 v_const_iterator(const_iterator beg, const_iterator end) : i(beg), end(end) {}
00161 ~v_const_iterator() {}
00162 };
00163
00164 protected:
00165 typename _SerializeList<T>::iterator* getIterator() {
00166 return new v_iterator(this->begin(), this->end());
00167 }
00168 typename _SerializeList<T>::const_iterator* getIterator() const {
00169 return new v_const_iterator(this->begin(), this->end());
00170 }
00171
00172 };
00173
00176 }
00177 #endif // _MACE_LIST_H