00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00024 #ifndef INTELIB_SDBLLIST_HPP_SENTRY
00025 #define INTELIB_SDBLLIST_HPP_SENTRY
00026
00027 #include "iexcept.hpp"
00028 #include "sbacklnk.hpp"
00029 #include "gensref.hpp"
00030
00032 class IntelibX_not_a_doublelist : public IntelibX {
00033 public:
00034 IntelibX_not_a_doublelist(SReference a_param);
00035 };
00036
00038
00042 class SExpressionDoubleList : public SExpression {
00043 SBacklinkRef begin, end;
00044 protected:
00046 SExpressionDoubleList(const IntelibTypeId &t) : SExpression(t) {}
00047 SExpressionDoubleList(const SBacklinkRef &a_begin,
00048 const SBacklinkRef &a_end,
00049 const IntelibTypeId &t)
00050 : SExpression(t), begin(a_begin), end(a_end) {}
00052 ~SExpressionDoubleList() {}
00053 public:
00055 static IntelibTypeId TypeId;
00056
00058 SExpressionDoubleList() : SExpression(TypeId) {}
00059
00061
00067 SExpressionDoubleList(const SBacklinkRef &a_begin,
00068 const SBacklinkRef &a_end)
00069 : SExpression(TypeId), begin(a_begin), end(a_end) {}
00070
00072 const SBacklinkRef& AddToBegin(const SReference &ref);
00074 const SBacklinkRef& AddToEnd(const SReference &ref);
00075
00077 SBacklinkRef GetBegin() const { return begin; }
00079 SBacklinkRef GetEnd() const { return end; }
00080
00082
00092 void Exclude(const SBacklinkRef &from, const SBacklinkRef &thru);
00094
00103 void InsertListAfter(const SBacklinkRef &from,
00104 const SBacklinkRef &left,
00105 const SBacklinkRef &right);
00106
00107 #if INTELIB_TEXT_REPRESENTATIONS == 1
00108 virtual SString TextRepresentation() const;
00109 #endif
00110
00111 class Iterator;
00112 friend class Iterator;
00113
00114 private:
00115 void SetTheOnlyItem(const SReference &ref);
00116 };
00117
00118
00120 typedef GenericSReference<SExpressionDoubleList,IntelibX_not_a_doublelist>
00121 SDoubleListRefBase;
00122
00123
00125 class SDoubleListRef : public SDoubleListRefBase {
00126 public:
00128 SDoubleListRef() {}
00130 SDoubleListRef(SExpressionDoubleList *e) : SDoubleListRefBase(e){}
00132 SDoubleListRef(const SDoubleListRef &e) : SDoubleListRefBase(e){}
00134 SDoubleListRef(const SReference &e) : SDoubleListRefBase(e){}
00136 ~SDoubleListRef() {}
00137
00139 SDoubleListRef& operator,(const SReference &s);
00140 };
00141
00142
00144 class SExpressionDoubleList::Iterator : public SBacklinkRef {
00145 SDoubleListRef master;
00146 public:
00148 Iterator(const SDoubleListRef &m, bool from_end = false)
00149 : SBacklinkRef(
00150 m.GetPtr() ? (from_end ? m->end : m->begin) : SBacklinkRef()
00151 ), master(m) {}
00153 Iterator(SExpressionDoubleList *m, bool from_end = false)
00154 : SBacklinkRef(from_end ? m->end : m->begin), master(m) {}
00155
00157 void SetBegin() { SBacklinkRef::operator=(master->begin); }
00159 void SetEnd() { SBacklinkRef::operator=(master->end); }
00160
00162 void InsertBefore(const SReference& r);
00164 void InsertAfter(const SReference& r);
00166 bool Remove();
00167
00169 bool IsBegin() const { return GetPtr() && (*this)->Prev().IsEmptyList(); }
00171 bool IsEnd() const { return GetPtr() && (*this)->Next().IsEmptyList(); }
00173 bool Exhausted() const { return !GetPtr() || IsEmptyList(); }
00174
00176 const SDoubleListRef& GetMaster() { return master; }
00177 };
00178
00179 inline SDoubleListRef& SDoubleListRef::operator,(const SReference &s)
00180 { (*this)->AddToEnd(s); return *this; }
00181
00183
00188 class SDoubleList : public SDoubleListRef {
00189 public:
00191 SDoubleList() : SDoubleListRef(new SExpressionDoubleList) {}
00192 private:
00193 SDoubleList(const SDoubleList&) {}
00194 void operator=(const SDoubleList&) {}
00195 };
00196
00197
00199
00202 class SDoubleListConstructor {
00203 public:
00204 SDoubleListConstructor() {}
00205 ~SDoubleListConstructor() {}
00206
00208
00209 SDoubleListRef operator |(const SReference &t) const
00210 {
00211 SDoubleListRef r(new SExpressionDoubleList);
00212 r->AddToBegin(t);
00213 return r;
00214 }
00215 };
00216
00217
00219 class SDoubleListRange {
00220 SDoubleListRef master;
00221 SBacklinkRef first, follow;
00222 public:
00224
00228 SDoubleListRange() {}
00229
00231 SDoubleListRange(const SDoubleListRef& a_master)
00232 : master(a_master), first(master->GetBegin()), follow(*PTheEmptyList)
00233 {}
00234
00236
00245 SDoubleListRange(const SDoubleListRef& a_master,
00246 const SBacklinkRef& a_first,
00247 const SBacklinkRef& a_follow)
00248 : master(a_master), first(a_first), follow(a_follow)
00249 {}
00250
00252 SDoubleListRange(const SDoubleListRange& o)
00253 : master(o.master), first(o.first), follow(o.follow)
00254 {}
00255
00257 void operator=(const SDoubleListRange &a)
00258 { master = a.master; first = a.first; follow = a.follow; }
00259
00263 bool IsEmpty() const { return first.GetPtr() == follow.GetPtr(); }
00266 bool Exhausted() const { return first.IsEmptyList(); }
00267
00269
00272 SDoubleListRef Copy() const;
00273
00275 class LeftEndMover {
00276 friend class SDoubleListRange;
00277 SDoubleListRange *master;
00278 LeftEndMover(SDoubleListRange *a_master) : master(a_master) {}
00279 public:
00280 operator SBacklinkRef() const;
00281 SBacklinkRef operator++() const;
00282 SBacklinkRef operator++(int) const;
00283 SBacklinkRef operator--() const;
00284 SBacklinkRef operator--(int) const;
00285 void JumpToFirst() const;
00286 void JumpToLast() const;
00287 void JumpToRightEnd() const;
00289 };
00290 friend class LeftEndMover;
00291
00293 class RightEndMover {
00294 friend class SDoubleListRange;
00295 SDoubleListRange *master;
00296 RightEndMover(SDoubleListRange *a_master) : master(a_master) {}
00297 public:
00298 operator SBacklinkRef() const;
00299 SBacklinkRef operator++() const;
00300 SBacklinkRef operator++(int) const;
00301 SBacklinkRef operator--() const;
00302 SBacklinkRef operator--(int) const;
00303 void JumpToFirst() const;
00304 void JumpToLast() const;
00305 void JumpToLeftEnd() const;
00307 };
00308 friend class RightEndMover;
00309
00311 LeftEndMover LeftEnd() { return LeftEndMover(this); }
00313 RightEndMover RightEnd() { return RightEndMover(this); }
00314
00316 const SDoubleListRef& GetMaster() const { return master; }
00317
00319 SBacklinkRef GetFirst() const;
00321 const SBacklinkRef& GetFollow() const;
00323 SBacklinkRef GetLast() const;
00324
00326
00327 void SetFirst(const SBacklinkRef& r) { first = r; }
00329
00330 void SetFollow(const SBacklinkRef& r) { follow = r; }
00331
00333 SDoubleListRange WhatsBefore() const
00334 { return SDoubleListRange(master, master->GetBegin(), first); }
00336 SDoubleListRange WhatsAfter() const
00337 { return SDoubleListRange(master, follow, *PTheEmptyList); }
00338 };
00339
00340
00341
00342
00343 #endif