Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/search_action is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_search_action
0005 #define tools_sg_search_action
0006 
0007 #include "action"
0008 
0009 #include <vector>
0010 
0011 namespace tools {
0012 namespace sg {
0013   class node;
0014 }}
0015 
0016 namespace tools {
0017 namespace sg {
0018 
0019 class search_action : public action {
0020   TOOLS_ACTION(search_action,tools::sg::search_action,action)
0021 public:
0022   search_action(std::ostream& a_out)
0023   :parent(a_out)
0024   ,m_what(search_node_of_class)
0025   ,m_stop_at_first(false)
0026   ,m_node(0) //not owner
0027 
0028   ,m_done(false)
0029   {}
0030   virtual ~search_action(){}
0031 public:
0032   search_action(const search_action& a_from)
0033   :parent(a_from)
0034   ,m_what(a_from.m_what)
0035   ,m_stop_at_first(a_from.m_stop_at_first)
0036   ,m_class(a_from.m_class)
0037   ,m_node(a_from.m_node)
0038 
0039   ,m_done(false)
0040   {}
0041   search_action& operator=(const search_action& a_from){
0042     parent::operator=(a_from);
0043     if(&a_from==this) return *this;
0044     m_what = a_from.m_what;
0045     m_stop_at_first = a_from.m_stop_at_first;
0046     m_class = a_from.m_class;
0047     m_node = a_from.m_node;
0048     reset();
0049     return *this;
0050   }
0051 public:
0052   void reset() {
0053     m_done = false;
0054     m_objs.clear();
0055     m_path.clear();
0056     m_paths.clear();
0057   }
0058 
0059   enum search_what {
0060     search_node_of_class = 0,
0061     search_path_to_node = 1,
0062     search_path_to_node_of_class = 2
0063   };
0064   search_what what() const {return m_what;}
0065   void set_what(search_what a_v) {m_what = a_v;}
0066 
0067   void set_done(bool a_value) {m_done = a_value;}
0068   bool done() const {return m_done;}
0069 
0070   bool stop_at_first() const {return m_stop_at_first;}
0071   void set_stop_at_first(bool a_v) {m_stop_at_first = a_v;}
0072 
0073   //////////////////////////////////////////////////////////
0074   /// search_node_of_class : ///////////////////////////////
0075   //////////////////////////////////////////////////////////
0076   //NOTE : result of a search is not necessary a sg::node.
0077   //       (For exa in ioda::main, could be a base_button).
0078   void add_obj(void* a_obj) {m_objs.push_back(a_obj);}
0079   const std::vector<void*>& objs() const {return m_objs;}
0080 
0081   void set_class(const std::string& a_class) {m_class = a_class;}
0082   const std::string& sclass() const {return m_class;}
0083 
0084   //////////////////////////////////////////////////////////
0085   /// search_path_to_node : ////////////////////////////////
0086   //////////////////////////////////////////////////////////
0087   void set_node(sg::node* a_v) {m_node = a_v;}
0088   sg::node* node() const {return m_node;}
0089 
0090   void path_push(sg::node* a_v) {m_path.push_back(a_v);}
0091   void path_pop() {m_path.pop_back();}
0092 
0093   typedef std::vector<sg::node*> path_t;
0094   const path_t& path() const {return m_path;}
0095   //path_t path() {return m_path;}
0096   void clear_path() {m_path.clear();}
0097 
0098   bool do_path() const {
0099     if(m_what==search_action::search_path_to_node) return true;
0100     if(m_what==search_action::search_path_to_node_of_class) return true;
0101     return false;
0102   }
0103 
0104   //////////////////////////////////////////////////////////
0105   /// search_path_to_node_of_class : ///////////////////////
0106   //////////////////////////////////////////////////////////
0107   void add_path(const path_t& a_p) {m_paths.push_back(a_p);}
0108 
0109   typedef std::vector<path_t> paths_t;
0110   const paths_t& paths() const {return m_paths;}
0111 
0112 protected:
0113   search_what m_what;
0114   bool m_stop_at_first;
0115 
0116   //search_node_of_class :
0117   std::string m_class;
0118   std::vector<void*> m_objs;
0119 
0120   //search_path_to_node :
0121   sg::node* m_node; //not owner.
0122   path_t m_path;
0123 
0124   //search_path_to_node_of_class :
0125   std::vector<path_t> m_paths;
0126 
0127   bool m_done;
0128 };
0129 
0130 }}
0131 
0132 #endif