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