00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _FIELDINFOLIST_HPP
00016 #define _FIELDINFOLIST_HPP
00017
00018 #include "IndexTypes.hpp"
00019 #include "lemur-platform.h"
00020 #include "Exception.hpp"
00021
00022 namespace lemur
00023 {
00024 namespace api
00025 {
00026
00028
00038 class FieldInfo {
00039 public:
00040 int begin;
00041 int end;
00042 int id;
00043 int ordinal;
00044 int parentOrdinal;
00045 INT64 number;
00046
00047 inline FieldInfo() {}
00048
00049 inline FieldInfo(int _begin, int _end, int _id, INT64 _number=0, int _ordinal=0, int _parentOrdinal=0) :
00050 begin(_begin), end(_end), id(_id),
00051 ordinal(_ordinal), parentOrdinal(_parentOrdinal), number(_number) { }
00052
00053 inline FieldInfo(const FieldInfo &c) :
00054 begin(c.begin), end(c.end), id(c.id),
00055 ordinal(c.ordinal), parentOrdinal(c.parentOrdinal), number(c.number) { }
00056
00057
00058 };
00059
00060
00062
00069 class FieldInfoList {
00070 public:
00071 virtual ~FieldInfoList() {}
00072
00073 protected:
00074
00076 virtual FieldInfo* newElement() const { return new FieldInfo(); }
00078 virtual FieldInfo* getElement(FieldInfo* elem, POS_T position) const =0;
00081 virtual void assignElement(FieldInfo* to, FieldInfo* from) const { *to = *from; }
00083 virtual POS_T beginPosition() const =0;
00085 virtual POS_T endPosition() const =0;
00087 virtual POS_T nextPosition(POS_T position) const =0;
00088
00089 public:
00090
00092 virtual void startIteration()=0;
00093
00095 virtual bool hasMore()const=0;
00096
00098 virtual FieldInfo *nextEntry()const=0;
00099
00101 virtual int size()=0;
00102
00104 virtual FieldInfo* operator[] (int index)=0;
00105
00106
00108 class iterator : std::iterator<std::input_iterator_tag, FieldInfo> {
00109 public:
00110 iterator() : list(NULL), position(0), current(NULL) {}
00111 iterator(const iterator& other) {
00112 list = other.list;
00113 position = other.position;
00114 if ((list) && (other.current) ) {
00115 current = list->newElement();
00116 list->assignElement(current, other.current);
00117 } else {
00118 current = NULL;
00119 }
00120 }
00121 iterator(const FieldInfoList* til, POS_T pos) : list(til), position(pos) {
00122 if (list) {
00123 if (position != list->endPosition()) {
00124 current = list->newElement();
00125 current = list->getElement(current, position);
00126 } else {
00127 current = NULL;
00128 }
00129 }
00130 }
00131
00132 ~iterator() {
00133 delete(current);
00134 }
00135
00136 FieldInfo& operator*() { return *current; }
00137 FieldInfo* operator->() { return current; }
00138 iterator& operator++() {
00139 position = list->nextPosition(position);
00140 if (position != list->endPosition())
00141 current = list->getElement(current, position);
00142 return *this;
00143 }
00144
00145 iterator& operator++(int) {
00146 return operator++();
00147 }
00148 bool operator==(const iterator& other) const {
00149 return (list == other.list) && (position == other.position);
00150 }
00151 bool operator!=(const iterator& other) const {
00152 return (list != other.list) || (position != other.position);
00153 }
00154 iterator& operator=(const iterator& other) {
00155 list = other.list;
00156 position = other.position;
00157 if ((list) && (other.current)) {
00158 if (!current)
00159 current = list->newElement();
00160 list->assignElement(current, other.current);
00161 } else {
00162 delete(current);
00163 current=NULL;
00164 }
00165 return *this;
00166 }
00169 void seek(POS_T pos) {
00170 position = pos;
00171 if (position != list->endPosition()) {
00172 if (!current)
00173 current = list->newElement();
00174 current = list->getElement(current, position);
00175 } else {
00176 delete(current);
00177 current = NULL;
00178 }
00179 }
00180
00181 protected:
00182 const FieldInfoList* list;
00183 POS_T position;
00184 FieldInfo* current;
00185 };
00186
00187 iterator& begin() const {
00188 iterator it(this, beginPosition());
00189 itbegin = it;
00190 return itbegin;
00191 }
00192 iterator& end() const {
00193 iterator it(this, endPosition());
00194 itend = it;
00195 return itend;
00196 }
00197
00198 protected:
00199 mutable FieldInfoList::iterator itbegin;
00200 mutable FieldInfoList::iterator itend;
00201 friend class iterator;
00202 };
00203 }
00204 }
00205
00206
00207 #endif