00001 #ifndef LUX_INDEX_ATTRINDEXARRAY_H 00002 #define LUX_INDEX_ATTRINDEXARRAY_H 00003 00004 #include "lux/lux.h" 00005 #include "lux/storage/storage_engine.h" 00006 #include "lux/document/document_definition.pb.h" 00007 #include <string> 00008 #include <set> 00009 00010 #ifdef HAVE_TR1_MEMORY 00011 #include <tr1/memory> 00012 #elif HAVE_BOOST_SHARED_PTR_HPP 00013 #include <boost/shared_ptr.hpp> 00014 #endif 00015 00016 namespace Lux { 00017 00018 class Document; 00019 00020 template <class T> 00021 struct less_attr_name : public std::binary_function <T, T, bool> { 00022 bool operator() (const T& t1, const T& t2) const { 00023 return t1.attr_name < t2.attr_name; 00024 } 00025 }; 00026 00030 struct AttrIndexEngine { 00031 AttrIndexEngine(const std::string &attr_name_, 00032 Config::Field::AttrIndexType attr_type_, uint32_t attr_size_); 00033 AttrIndexEngine(const std::string &attr_name_); 00034 bool open(const std::string file, db_flags_t open_params_); 00035 bool close(void); 00036 00037 std::string attr_name; 00038 Config::Field::AttrIndexType attr_type; 00039 uint32_t attr_size; 00040 #ifdef HAVE_TR1_MEMORY 00041 std::tr1::shared_ptr<LuxArrayStorage> engine; 00042 #elif HAVE_BOOST_SHARED_PTR_HPP 00043 boost::shared_ptr<LuxBtreeStorage> engine; 00044 #endif 00045 }; 00046 00047 typedef std::set< AttrIndexEngine, 00048 less_attr_name<AttrIndexEngine> > engine_set; 00049 typedef engine_set::iterator engine_set_itr; 00050 00054 class AttrIndexArray { 00055 public: 00056 AttrIndexArray(Config::Document &doc_config); 00057 ~AttrIndexArray() {} 00058 bool open(std::string storage_dir, db_flags_t open_params); 00059 bool close(void); 00060 bool add(const Document *doc); 00061 bool add(const Document &doc); 00062 bool get(AttrIndexEngine &aie); 00063 00064 private: 00065 engine_set engine_set_; 00066 Config::Document doc_config_; 00067 }; 00068 } 00069 00070 #endif