Go to the documentation of this file.00001 #ifndef cond_SmallWORMDict_h
00002 #define cond_SmallWORMDict_h
00003
00004 #include<vector>
00005 #include<string>
00006 #include<algorithm>
00007 #include<numeric>
00008 #include<exception>
00009 #include <boost/bind.hpp>
00010 #include <boost/iterator_adaptors.hpp>
00011 #include <boost/iterator/transform_iterator.hpp>
00012 #include <boost/iterator/counting_iterator.hpp>
00013
00014
00015 namespace cond {
00016
00021 class SmallWORMDict {
00022 public:
00023 SmallWORMDict();
00024 ~SmallWORMDict();
00025
00026 struct Frame {
00027 Frame(){}
00028 Frame(char const * ib,
00029 unsigned int il,
00030 unsigned int iind) :
00031 b(ib),l(il),ind(iind){}
00032 char const * b;
00033 unsigned int l;
00034 unsigned int ind;
00035 };
00036
00037 struct IterHelp {
00038 typedef Frame result_type;
00039 IterHelp() : v(0){}
00040 IterHelp(SmallWORMDict const & iv) : v(&iv){}
00041
00042 result_type const & operator()(int i) const {
00043 int k = (0==i) ? 0 : v->m_index[i-1];
00044 return frame(&v->m_data[k], v->m_index[i]-k, i);
00045 }
00046
00047 Frame const & frame(char const * b,
00048 unsigned int l,
00049 unsigned int ind) const {
00050 f.b = b; f.l=l; f.ind=ind;
00051 return f;
00052 }
00053
00054 private:
00055 SmallWORMDict const * v;
00056 mutable Frame f;
00057 };
00058
00059 friend struct IterHelp;
00060
00061 typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > const_iterator;
00062
00063
00064 const_iterator begin() const {
00065 return boost::make_transform_iterator(boost::counting_iterator<int>(0),
00066 IterHelp(*this));
00067 }
00068
00069 const_iterator end() const {
00070 return boost::make_transform_iterator(boost::counting_iterator<int>(size()),
00071 IterHelp(*this));
00072 }
00073
00074 Frame operator[](int i) const {
00075 int k = (0==i) ? 0 : m_index[i-1];
00076 return Frame(&m_data[k], m_index[i]-k, i);
00077 }
00078
00079 const_iterator find(std::string const & s) const;
00080
00081 const_iterator find(char const * s) const;
00082
00083
00084 explicit SmallWORMDict(std::vector<std::string> const & idict);
00085
00086
00087 size_t index(std::string const & s) const;
00088
00089 size_t index(char const * s) const;
00090
00091 size_t size() const;
00092
00093 private:
00094 std::vector<char> m_data;
00095 std::vector<unsigned int> m_index;
00096 };
00097
00098
00099 }
00100
00101 #endif