CMS 3D CMS Logo

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 <boost/iterator_adaptors.hpp>
9 #include <boost/iterator/transform_iterator.hpp>
10 #include <boost/iterator/counting_iterator.hpp>
11 
12 // Function for testing SmallWORMDict
13 namespace test {
14  namespace SmallWORMDict {
15  int test();
16  }
17 } // namespace test
18 
19 namespace cond {
20 
25  class SmallWORMDict {
26  friend int test::SmallWORMDict::test();
27 
28  public:
29  SmallWORMDict();
31 
32  struct Frame {
33  Frame() : b(nullptr) {}
34  Frame(char const* ib, unsigned int il, unsigned int iind) : b(ib), l(il), ind(iind) {}
35  char const* b;
36  unsigned int l;
37  unsigned int ind;
38  };
39 
40  struct IterHelp {
41  typedef Frame result_type;
42  IterHelp() : v(nullptr) {}
43  IterHelp(SmallWORMDict const& iv) : v(&iv) {}
44 
45  result_type const& operator()(int i) const {
46  int k = (0 == i) ? 0 : v->m_index[i - 1];
47  return frame(&v->m_data[k], v->m_index[i] - k, i);
48  }
49 
50  Frame const& frame(char const* b, unsigned int l, unsigned int ind) const {
51  f.b = b;
52  f.l = l;
53  f.ind = ind;
54  return f;
55  }
56 
57  private:
58  SmallWORMDict const* v;
59  mutable Frame f;
60  };
61 
62  friend struct IterHelp;
63 
64  typedef boost::transform_iterator<IterHelp, boost::counting_iterator<int> > const_iterator;
65 
67  return boost::make_transform_iterator(boost::counting_iterator<int>(0), IterHelp(*this));
68  }
69 
70  const_iterator end() const {
71  return boost::make_transform_iterator(boost::counting_iterator<int>(size()), 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 
98  };
99 
100 } // namespace cond
101 
102 #endif
SmallWORMDict const * v
Definition: SmallWORMDict.h:58
const_iterator end() const
Definition: SmallWORMDict.h:70
size_t size() const
int32_t *__restrict__ iv
SOAFrame< float > Frame
std::vector< unsigned int > m_index
Definition: SmallWORMDict.h:95
friend struct IterHelp
Definition: SmallWORMDict.h:62
Frame const & frame(char const *b, unsigned int l, unsigned int ind) const
Definition: SmallWORMDict.h:50
result_type const & operator()(int i) const
Definition: SmallWORMDict.h:45
std::vector< char > m_data
Definition: SmallWORMDict.h:94
const_iterator begin() const
Definition: SmallWORMDict.h:66
Frame operator[](int i) const
Definition: SmallWORMDict.h:74
IterHelp(SmallWORMDict const &iv)
Definition: SmallWORMDict.h:43
const_iterator find(std::string const &s) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: SmallWORMDict.h:64
double b
Definition: hdecay.h:118
#define COND_SERIALIZABLE
Definition: Serializable.h:39
size_t index(std::string const &s) const
Definition: plugin.cc:23
Frame(char const *ib, unsigned int il, unsigned int iind)
Definition: SmallWORMDict.h:34
ib
Definition: cuy.py:661