barry: Your go-to motif accountant  0.0-1
Full enumeration of sample space and fast count of sufficient statistics for binary arrays
rules-bones.hpp
Go to the documentation of this file.
1 #ifndef BARRY_RULES_BONES_HPP
2 #define BARRY_RULES_BONES_HPP 1
3 
4 template <typename Array_Type, typename Data_Type>
5 bool rule_fun_default(const Array_Type * array, size_t i, size_t j, Data_Type * dat) {
6  return false;
7 }
8 
19 template<typename Array_Type = BArray<>, typename Data_Type = bool>
20 class Rule {
21 
22 private:
24  Data_Type dat;
25 
26  std::string name = "";
27  std::string desc = "";
28 
29 public:
30 
41  Rule() : fun(rule_fun_default<Array_Type,Data_Type>) {};
44  Data_Type dat_,
45  std::string name_ = "",
46  std::string desc_ = ""
47  ) : fun(fun_), dat(dat_), name(name_), desc(desc_) {};
49 
50  ~Rule() {};
51 
52  Data_Type & D();
53 
54  bool operator()(const Array_Type & a, size_t i, size_t j);
55 
56  std::string & get_name();
57  std::string & get_description();
58 
59  std::string get_name() const;
60  std::string get_description() const;
61 
62 };
63 
70 template<typename Array_Type, typename Data_Type>
71 class Rules {
72 
73 private:
74  std::vector< Rule<Array_Type,Data_Type> > data;
75 
76 public:
77  Rules() {};
78 
79  Rules(const Rules<Array_Type,Data_Type> & rules_);
81 
82  ~Rules() {};
83 
84  size_t size() const noexcept {
85  return data.size();
86  };
87 
95  void add_rule(
97  Data_Type data_,
98  std::string name_ = "",
99  std::string description_ = ""
100  );
102 
113  bool operator()(const Array_Type & a, size_t i, size_t j);
114 
124  void get_seq(
125  const Array_Type & a,
126  std::vector< size_t > * free,
127  std::vector< size_t > * locked = nullptr
128  );
129 
130  std::vector< std::string > get_names() const;
131  std::vector< std::string > get_descriptions() const;
132 
133  // Iterator
134  typename std::vector< Rule<Array_Type,Data_Type> >::iterator begin() {
135  return data.begin();
136  };
137  typename std::vector< Rule<Array_Type,Data_Type> >::iterator end() {
138  return data.end();
139  };
140 
141 };
142 
143 
144 #endif
Rule for determining if a cell should be included in a sequence.
Definition: rules-bones.hpp:20
bool operator()(const Array_Type &a, size_t i, size_t j)
Definition: rules-meat.hpp:43
Data_Type & D()
Read/Write access to the data.
Definition: rules-meat.hpp:37
Rule(Rule_fun_type< Array_Type, Data_Type > fun_, Data_Type dat_, std::string name_="", std::string desc_="")
Definition: rules-bones.hpp:42
std::string & get_description()
Definition: rules-meat.hpp:54
std::string & get_name()
Definition: rules-meat.hpp:48
Vector of objects of class Rule.
Definition: rules-bones.hpp:71
size_t size() const noexcept
Definition: rules-bones.hpp:84
bool operator()(const Array_Type &a, size_t i, size_t j)
Check whether a given cell is free or locked.
Definition: rules-meat.hpp:101
void add_rule(Rule< Array_Type, Data_Type > rule)
Definition: rules-meat.hpp:72
std::vector< std::string > get_descriptions() const
Definition: rules-meat.hpp:180
void get_seq(const Array_Type &a, std::vector< size_t > *free, std::vector< size_t > *locked=nullptr)
Computes the sequence of free and locked cells in an BArray.
Definition: rules-meat.hpp:117
std::vector< std::string > get_names() const
Definition: rules-meat.hpp:167
std::vector< Rule< Array_Type, Data_Type > >::iterator end()
Rules< Array_Type, Data_Type > operator=(const Rules< Array_Type, Data_Type > &rules_)
Definition: rules-meat.hpp:19
std::vector< Rule< Array_Type, Data_Type > >::iterator begin()
Data_Type &&counter_ desc(std::move(counter_.desc))
Move constructor.
Data_Type &&counter_ name(std::move(counter_.name))
Data_Type fun
Data_Type &&counter_ data(std::move(counter_.data))
Data_Type fun_
Data_Type Counter_fun_type< Array_Type, Data_Type > Hasher_fun_type< Array_Type, Data_Type > Data_Type std::string std::string desc_
Data_Type Counter_fun_type< Array_Type, Data_Type > Hasher_fun_type< Array_Type, Data_Type > Data_Type std::string name_
size_t size_t j
size_t i
Data_Type &&counter_ noexcept
Data_Type Counter_fun_type< Array_Type, Data_Type > Hasher_fun_type< Array_Type, Data_Type > Data_Type data_
bool rule_fun_default(const Array_Type *array, size_t i, size_t j, Data_Type *dat)
Definition: rules-bones.hpp:5
std::function< bool(const Array_Type &, size_t, size_t, Data_Type &)> Rule_fun_type
Definition: typedefs.hpp:190