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 
4 #include<vector>
5 #include<string>
6 #include<algorithm>
7 #include<numeric>
8 #include<exception>
9 #include <boost/bind.hpp>
10 #include <boost/iterator_adaptors.hpp>
11 #include <boost/iterator/transform_iterator.hpp>
12 #include <boost/iterator/counting_iterator.hpp>
13 
14 
15 namespace cond {
16 
21  class SmallWORMDict {
22  public:
23  SmallWORMDict();
25 
26  struct Frame {
27  Frame(): b(0){}
28  Frame(char const * ib,
29  unsigned int il,
30  unsigned int iind) :
31  b(ib),l(il),ind(iind){}
32  char const * b;
33  unsigned int l;
34  unsigned int ind;
35  };
36 
37  struct IterHelp {
38  typedef Frame result_type;
39  IterHelp() : v(0){}
40  IterHelp(SmallWORMDict const & iv) : v(&iv){}
41 
42  result_type const & operator()(int i) const {
43  int k = (0==i) ? 0 : v->m_index[i-1];
44  return frame(&v->m_data[k], v->m_index[i]-k, i);
45  }
46 
47  Frame const & frame(char const * b,
48  unsigned int l,
49  unsigned int ind) const {
50  f.b = b; f.l=l; f.ind=ind;
51  return f;
52  }
53 
54  private:
55  SmallWORMDict const * v;
56  mutable Frame f;
57  };
58 
59  friend struct IterHelp;
60 
61  typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > const_iterator;
62 
63 
65  return boost::make_transform_iterator(boost::counting_iterator<int>(0),
66  IterHelp(*this));
67  }
68 
69  const_iterator end() const {
70  return boost::make_transform_iterator(boost::counting_iterator<int>(size()),
71  IterHelp(*this));
72  }
73 
74  Frame operator[](int i) const {
75  int k = (0==i) ? 0 : m_index[i-1];
76  return Frame(&m_data[k], m_index[i]-k, i);
77  }
78 
79  const_iterator find(std::string const & s) const;
80 
81  const_iterator find(char const * s) const;
82 
83  // constructror from config
84  explicit SmallWORMDict(std::vector<std::string> const & idict);
85 
86  // find location of a word
87  size_t index(std::string const & s) const;
88 
89  size_t index(char const * s) const;
90 
91  size_t size() const;
92 
93  private:
94  std::vector<char> m_data;
95  std::vector<unsigned int> m_index;
96  };
97 
98 
99 }
100 
101 #endif
size_t index(std::string const &s) const
int i
Definition: DBlmapReader.cc:9
SmallWORMDict const * v
Definition: SmallWORMDict.h:55
int ib
Definition: cuy.py:660
const_iterator end() const
Definition: SmallWORMDict.h:69
std::vector< unsigned int > m_index
Definition: SmallWORMDict.h:95
friend struct IterHelp
Definition: SmallWORMDict.h:59
const_iterator begin() const
Definition: SmallWORMDict.h:64
result_type const & operator()(int i) const
Definition: SmallWORMDict.h:42
Frame operator[](int i) const
Definition: SmallWORMDict.h:74
const_iterator find(std::string const &s) const
Frame const & frame(char const *b, unsigned int l, unsigned int ind) const
Definition: SmallWORMDict.h:47
std::vector< char > m_data
Definition: SmallWORMDict.h:94
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: SmallWORMDict.h:61
int k[5][pyjets_maxn]
IterHelp(SmallWORMDict const &iv)
Definition: SmallWORMDict.h:40
double b
Definition: hdecay.h:120
size_t size() const
Frame(char const *ib, unsigned int il, unsigned int iind)
Definition: SmallWORMDict.h:28