g4tools  5.4.0
search_action
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_search_action
5 #define tools_sg_search_action
6 
7 #include "action"
8 
9 #include <vector>
10 
11 namespace tools {
12 namespace sg {
13  class node;
14 }}
15 
16 namespace tools {
17 namespace sg {
18 
19 class search_action : public action {
21 public:
22  search_action(std::ostream& a_out)
23  :parent(a_out)
25  ,m_stop_at_first(false)
26  ,m_node(0) //not owner
27 
28  ,m_done(false)
29  {}
30  virtual ~search_action(){}
31 public:
33  :parent(a_from)
34  ,m_what(a_from.m_what)
36  ,m_class(a_from.m_class)
37  ,m_node(a_from.m_node)
38 
39  ,m_done(false)
40  {}
42  parent::operator=(a_from);
43  if(&a_from==this) return *this;
44  m_what = a_from.m_what;
46  m_class = a_from.m_class;
47  m_node = a_from.m_node;
48  reset();
49  return *this;
50  }
51 public:
52  void reset() {
53  m_done = false;
54  m_objs.clear();
55  m_path.clear();
56  m_paths.clear();
57  }
58 
59  enum search_what {
63  };
64  search_what what() const {return m_what;}
65  void set_what(search_what a_v) {m_what = a_v;}
66 
67  void set_done(bool a_value) {m_done = a_value;}
68  bool done() const {return m_done;}
69 
70  bool stop_at_first() const {return m_stop_at_first;}
71  void set_stop_at_first(bool a_v) {m_stop_at_first = a_v;}
72 
76  //NOTE : result of a search is not necessary a sg::node.
77  // (For exa in ioda::main, could be a base_button).
78  void add_obj(void* a_obj) {m_objs.push_back(a_obj);}
79  const std::vector<void*>& objs() const {return m_objs;}
80 
81  void set_class(const std::string& a_class) {m_class = a_class;}
82  const std::string& sclass() const {return m_class;}
83 
87  void set_node(sg::node* a_v) {m_node = a_v;}
88  sg::node* node() const {return m_node;}
89 
90  void path_push(sg::node* a_v) {m_path.push_back(a_v);}
91  void path_pop() {m_path.pop_back();}
92 
93  typedef std::vector<sg::node*> path_t;
94  const path_t& path() const {return m_path;}
95  //path_t path() {return m_path;}
96  void clear_path() {m_path.clear();}
97 
98  bool do_path() const {
101  return false;
102  }
103 
107  void add_path(const path_t& a_p) {m_paths.push_back(a_p);}
108 
109  typedef std::vector<path_t> paths_t;
110  const paths_t& paths() const {return m_paths;}
111 
112 protected:
115 
116  //search_node_of_class :
117  std::string m_class;
118  std::vector<void*> m_objs;
119 
120  //search_path_to_node :
121  sg::node* m_node; //not owner.
123 
124  //search_path_to_node_of_class :
125  std::vector<path_t> m_paths;
126 
127  bool m_done;
128 };
129 
130 }}
131 
132 #endif
tools::sg::search_action::set_stop_at_first
void set_stop_at_first(bool a_v)
Definition: search_action:71
tools::sg::search_action::m_stop_at_first
bool m_stop_at_first
Definition: search_action:114
tools::sg::search_action::m_objs
std::vector< void * > m_objs
Definition: search_action:118
tools::sg::action
Definition: action:19
tools::sg::search_action::stop_at_first
bool stop_at_first() const
Definition: search_action:70
tools::sg::search_action::search_path_to_node
@ search_path_to_node
Definition: search_action:61
tools::sg::search_action::~search_action
virtual ~search_action()
Definition: search_action:30
tools::sg::search_action::set_what
void set_what(search_what a_v)
Definition: search_action:65
tools::sg::node
Definition: node:28
tools::sg::search_action::done
bool done() const
Definition: search_action:68
tools::sg::search_action::sclass
const std::string & sclass() const
Definition: search_action:82
tools::sg::search_action::m_class
std::string m_class
Definition: search_action:117
action
tools::sg::search_action::path
const path_t & path() const
Definition: search_action:94
tools::sg::search_action::set_done
void set_done(bool a_value)
Definition: search_action:67
tools::sg::search_action::search_node_of_class
@ search_node_of_class
Definition: search_action:60
tools::sg::search_action::path_push
void path_push(sg::node *a_v)
Definition: search_action:90
tools::sg::search_action::m_paths
std::vector< path_t > m_paths
Definition: search_action:125
tools::sg::search_action::m_done
bool m_done
Definition: search_action:127
tools::sg::search_action::m_path
path_t m_path
Definition: search_action:122
tools::sg::search_action::add_path
void add_path(const path_t &a_p)
search_path_to_node_of_class : ///////////////////////
Definition: search_action:107
tools::sg::search_action::what
search_what what() const
Definition: search_action:64
tools::sg::search_action::set_node
void set_node(sg::node *a_v)
search_path_to_node : ////////////////////////////////
Definition: search_action:87
tools::sg::search_action::paths_t
std::vector< path_t > paths_t
Definition: search_action:109
tools::sg::search_action::search_path_to_node_of_class
@ search_path_to_node_of_class
Definition: search_action:62
tools::sg::search_action::do_path
bool do_path() const
Definition: search_action:98
TOOLS_ACTION
#define TOOLS_ACTION(a__class, a__sclass, a__parent)
Definition: action:60
tools::sg::search_action::operator=
search_action & operator=(const search_action &a_from)
Definition: search_action:41
tools::sg::search_action::path_pop
void path_pop()
Definition: search_action:91
tools::sg::search_action::path_t
std::vector< sg::node * > path_t
Definition: search_action:93
tools::sg::search_action
Definition: search_action:19
tools::sg::search_action::clear_path
void clear_path()
Definition: search_action:96
tools::sg::search_action::objs
const std::vector< void * > & objs() const
Definition: search_action:79
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::search_action::search_action
search_action(const search_action &a_from)
Definition: search_action:32
tools::sg::search_action::paths
const paths_t & paths() const
Definition: search_action:110
tools::sg::search_action::m_what
search_what m_what
Definition: search_action:113
tools::sg::search_action::add_obj
void add_obj(void *a_obj)
search_node_of_class : ///////////////////////////////
Definition: search_action:78
tools::sg::search_action::search_what
search_what
Definition: search_action:59
tools::sg::search_action::search_action
search_action(std::ostream &a_out)
Definition: search_action:22
tools::sg::search_action::node
sg::node * node() const
Definition: search_action:88
tools::sg::search_action::reset
void reset()
Definition: search_action:52
tools::sg::search_action::set_class
void set_class(const std::string &a_class)
Definition: search_action:81
tools::sg::search_action::m_node
sg::node * m_node
Definition: search_action:121