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 <deque>
00034 #include <string>
00035 #include "CollectionSerializers.h"
00036 #include "mace_constants.h"
00037 #include "StrUtilNamespace.h"
00038
00039 #ifndef _MACE_DEQUE_H
00040 #define _MACE_DEQUE_H
00041
00047 namespace mace {
00048
00054
00055 template<class T, class Serial = SerializeList<T>, class Alloc = std::allocator<T> >
00056 class deque : public std::deque<T, Alloc>, public virtual Serial, public PrintPrintable {
00057
00058 BOOST_CLASS_REQUIRE2(Serial, Serializer, boost, ConvertibleConcept);
00059
00060 public:
00061 typedef typename std::deque<T, Alloc> baseType;
00062 typedef typename baseType::size_type size_type;
00063 typedef typename baseType::iterator iterator;
00064 typedef typename baseType::const_iterator const_iterator;
00065
00066 deque() : baseType() {
00067 }
00068
00069 deque(size_type n) : baseType(n) {
00070 }
00071
00072 deque(size_type n, const T& t) : baseType(n, t) {
00073 }
00074
00075 deque(const std::deque<T, Alloc>& d) : baseType(d) {
00076 }
00077
00078 virtual ~deque() { }
00079
00081
00084 bool contains(const T& t) const {
00085 for (const_iterator i = this->begin(); i != this->end(); i++) {
00086 if (*i == t) {
00087 return true;
00088 }
00089 }
00090 return false;
00091 }
00092
00094 iterator erase(iterator pos) {
00095 return baseType::erase(pos);
00096 }
00097
00099 size_t erase(const T& t) {
00100 size_t r = 0;
00101 iterator i = this->begin();
00102 while (i != this->end()) {
00103 if (*i == t) {
00104 i = this->erase(i);
00105 r++;
00106 }
00107 else {
00108 i++;
00109 }
00110 }
00111 return r;
00112 }
00113
00115 void resize(size_t sz) {
00116 baseType::resize(sz);
00117 }
00118
00120 size_t size() const {
00121 return baseType::size();
00122 }
00123
00125 const std::string& getTypeName() const {
00126 const char* types[] = { "T", "Serial", "Alloc", 0 };
00127 static const StrUtilNamespace::StdStringList myTypes = StrUtilNamespace::getTypeFromTemplate(__PRETTY_FUNCTION__, types);
00128 return myTypes[0];
00129 }
00130
00131 void print(std::ostream& out) const {
00132 if(mace::PRINT_TYPE_NAMES) {
00133 out << "deque<"<< this->getTypeName() << ">";
00134 }
00135 printList(out, this->begin(), this->end());
00136 }
00137
00138 void print(PrintNode& pr, const std::string& name) const {
00139 mace::printList(pr, name, "deque<" + getTypeName() + ">", this->begin(),
00140 this->end());
00141 }
00142
00143 void printState(std::ostream& out) const {
00144 if(mace::PRINT_TYPE_NAMES) {
00145 out << "deque<"<< this->getTypeName() << ">";
00146 }
00147 printListState(out, this->begin(), this->end());
00148 }
00149
00150 private:
00151 class v_iterator : public _SerializeList<T>::iterator {
00152 private:
00153 iterator i;
00154 iterator end;
00155
00156 public:
00157 bool isValid() {
00158 return i != end;
00159 }
00160 void next() {
00161 ASSERT(i != end);
00162 i++;
00163 }
00164 T& getValue() {
00165 return *i;
00166 }
00167
00168 v_iterator(iterator beg, iterator end) : i(beg), end(end) {}
00169 ~v_iterator() {}
00170 };
00171
00172 class v_const_iterator : public _SerializeList<T>::const_iterator {
00173 private:
00174 const_iterator i;
00175 const_iterator end;
00176
00177 public:
00178 bool isValid() {
00179 return i != end;
00180 }
00181 void next() {
00182 ASSERT(i != end);
00183 i++;
00184 }
00185 const T& getValue() {
00186 return *i;
00187 }
00188
00189 v_const_iterator(const_iterator beg, const_iterator end) : i(beg), end(end) {}
00190 ~v_const_iterator() {}
00191 };
00192
00193 protected:
00194 typename _SerializeList<T>::iterator* getIterator() {
00195 return new v_iterator(this->begin(), this->end());
00196 }
00197 typename _SerializeList<T>::const_iterator* getIterator() const {
00198 return new v_const_iterator(this->begin(), this->end());
00199 }
00200 };
00201
00204 }
00205
00206 #endif // _MACE_DEQUE_H