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 #ifndef _EYEDB_COLL_IMPL_H
00026 #define _EYEDB_COLL_IMPL_H
00027
00028 #include "IndexImpl.h"
00029 #include <assert.h>
00030
00031 namespace eyedb {
00032
00033 class CollImpl : public gbxObject {
00034
00035 public:
00036 enum Type {
00037 Unknown = 0,
00038 HashIndex = 1,
00039 BTreeIndex = 2,
00040 NoIndex = 3
00041 };
00042
00043 CollImpl() : impl_type(Unknown), idximpl(0), dataspace(0),
00044 impl_hints(0), impl_hints_cnt(0) { }
00045
00046 CollImpl(CollImpl::Type impl_type, const Dataspace *dataspace = 0,
00047 const int impl_hints[] = 0,
00048 unsigned int impl_hints_cnt = 0,
00049 unsigned int keycount_or_degree = 0,
00050 BEMethod_C *mth = 0) :
00051 impl_type(impl_type), dataspace(dataspace) {
00052 if (impl_type == HashIndex ||
00053 impl_type == BTreeIndex) {
00054 IndexImpl::Type idxtype = (impl_type == HashIndex ?
00055 IndexImpl::Hash : IndexImpl::BTree);
00056 idximpl = new IndexImpl(idxtype, dataspace, keycount_or_degree, mth,
00057 impl_hints, impl_hints_cnt);
00058 this->impl_hints = 0;
00059 this->impl_hints_cnt = 0;
00060 }
00061 else {
00062 idximpl = 0;
00063 this->impl_hints_cnt = impl_hints_cnt;
00064 this->impl_hints = new int[impl_hints_cnt];
00065 memcpy(this->impl_hints, impl_hints, sizeof(int) * impl_hints_cnt);
00066 }
00067 }
00068
00069 CollImpl(const IndexImpl *_idximpl) : idximpl(_idximpl), dataspace(0),
00070 impl_hints(0), impl_hints_cnt(0) {
00071 if (!idximpl) {
00072 impl_type = NoIndex;
00073 }
00074 else if (idximpl->getType() == IndexImpl::Hash) {
00075 impl_type = HashIndex;
00076 }
00077 else if (idximpl->getType() == IndexImpl::BTree) {
00078 impl_type = BTreeIndex;
00079 }
00080 else {
00081 impl_type = Unknown;
00082 }
00083 }
00084
00085 CollImpl(CollImpl::Type impl_type, const IndexImpl *_idximpl) :
00086 impl_type(impl_type), idximpl(_idximpl), dataspace(0),
00087 impl_hints(0), impl_hints_cnt(0) {
00088
00089 if (!idximpl) {
00090 assert(impl_type == NoIndex ||
00091 impl_type == Unknown);
00092 }
00093 else if (idximpl->getType() == IndexImpl::Hash) {
00094 assert(impl_type == HashIndex);
00095 }
00096 else if (idximpl->getType() == IndexImpl::BTree) {
00097 assert(impl_type == BTreeIndex);
00098 }
00099 else {
00100 assert(0);
00101 }
00102 }
00103
00104 CollImpl::Type getType() const {return impl_type;}
00105 const IndexImpl *getIndexImpl() const {return idximpl;}
00106
00107 void setType(CollImpl::Type impl_type) {this->impl_type = impl_type;}
00108 void setIndexImpl(const IndexImpl *idximpl) {this->idximpl = idximpl;}
00109
00110 int *getImplHints(unsigned int &impl_hints_cnt) const {
00111 impl_hints_cnt = this->impl_hints_cnt;
00112 return impl_hints;
00113 }
00114
00115 bool compare(const CollImpl *collimpl) const {
00116 if (impl_type != collimpl->impl_type) {
00117 return false;
00118 }
00119
00120 if (impl_type == NoIndex) {
00121
00122
00123
00124 }
00125 else {
00126 if ((idximpl == NULL && collimpl->idximpl != NULL) ||
00127 (idximpl != NULL && collimpl->idximpl == NULL)) {
00128 return false;
00129 }
00130
00131 if (idximpl != NULL && collimpl->idximpl != NULL) {
00132 return (bool)idximpl->compare(collimpl->idximpl);
00133 }
00134 }
00135
00136 return true;
00137 }
00138
00139 CollImpl *clone() const;
00140
00141 ~CollImpl() {
00142 delete [] impl_hints;
00143 }
00144
00145 private:
00146 Type impl_type;
00147 const IndexImpl *idximpl;
00148 const Dataspace *dataspace;
00149 int *impl_hints;
00150 unsigned int impl_hints_cnt;
00151 };
00152 }
00153
00154 #endif