CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SmallWORMDict.h
Go to the documentation of this file.
1 #ifndef cond_SmallWORMDict_h
2 #define cond_SmallWORMDict_h
3 
5 
6 #include<vector>
7 #include<string>
8 #include<algorithm>
9 #include<numeric>
10 #include<exception>
11 #include <boost/bind.hpp>
12 #include <boost/iterator_adaptors.hpp>
13 #include <boost/iterator/transform_iterator.hpp>
14 #include <boost/iterator/counting_iterator.hpp>
15 
16 // Function for testing SmallWORMDict
17 namespace test {
18  namespace SmallWORMDict {
19  int test();
20  }
21 }
22 
23 namespace cond {
24 
29  class SmallWORMDict {
30  friend int test::SmallWORMDict::test();
31 
32  public:
33  SmallWORMDict();
35 
36  struct Frame {
37  Frame(): b(0){}
38  Frame(char const * ib,
39  unsigned int il,
40  unsigned int iind) :
41  b(ib),l(il),ind(iind){}
42  char const * b;
43  unsigned int l;
44  unsigned int ind;
45  };
46 
47  struct IterHelp {
48  typedef Frame result_type;
49  IterHelp() : v(0){}
50  IterHelp(SmallWORMDict const & iv) : v(&iv){}
51 
52  result_type const & operator()(int i) const {
53  int k = (0==i) ? 0 : v->m_index[i-1];
54  return frame(&v->m_data[k], v->m_index[i]-k, i);
55  }
56 
57  Frame const & frame(char const * b,
58  unsigned int l,
59  unsigned int ind) const {
60  f.b = b; f.l=l; f.ind=ind;
61  return f;
62  }
63 
64  private:
65  SmallWORMDict const * v;
66  mutable Frame f;
67  };
68 
69  friend struct IterHelp;
70 
71  typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > const_iterator;
72 
73 
75  return boost::make_transform_iterator(boost::counting_iterator<int>(0),
76  IterHelp(*this));
77  }
78 
79  const_iterator end() const {
80  return boost::make_transform_iterator(boost::counting_iterator<int>(size()),
81  IterHelp(*this));
82  }
83 
84  Frame operator[](int i) const {
85  int k = (0==i) ? 0 : m_index[i-1];
86  return Frame(&m_data[k], m_index[i]-k, i);
87  }
88 
89  const_iterator find(std::string const & s) const;
90 
91  const_iterator find(char const * s) const;
92 
93  // constructror from config
94  explicit SmallWORMDict(std::vector<std::string> const & idict);
95 
96  // find location of a word
97  size_t index(std::string const & s) const;
98 
99  size_t index(char const * s) const;
100 
101  size_t size() const;
102 
103  private:
104  std::vector<char> m_data;
105  std::vector<unsigned int> m_index;
106 
108 };
109 
110 
111 }
112 
113 #endif
size_t index(std::string const &s) const
int i
Definition: DBlmapReader.cc:9
SmallWORMDict const * v
Definition: SmallWORMDict.h:65
int ib
Definition: cuy.py:660
const_iterator end() const
Definition: SmallWORMDict.h:79
std::vector< unsigned int > m_index
friend struct IterHelp
Definition: SmallWORMDict.h:69
const_iterator begin() const
Definition: SmallWORMDict.h:74
result_type const & operator()(int i) const
Definition: SmallWORMDict.h:52
Frame operator[](int i) const
Definition: SmallWORMDict.h:84
const_iterator find(std::string const &s) const
Frame const & frame(char const *b, unsigned int l, unsigned int ind) const
Definition: SmallWORMDict.h:57
std::vector< char > m_data
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: SmallWORMDict.h:71
IterHelp(SmallWORMDict const &iv)
Definition: SmallWORMDict.h:50
double b
Definition: hdecay.h:120
#define COND_SERIALIZABLE
Definition: Serializable.h:38
size_t size() const
Frame(char const *ib, unsigned int il, unsigned int iind)
Definition: SmallWORMDict.h:38