GNodeVisitor.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef sofa_simulation_treeGNodeVisitor_h
00037 #define sofa_simulation_treeGNodeVisitor_h
00038
00039 #include <sofa/simulation/common/Visitor.h>
00040 #include <sofa/simulation/tree/GNode.h>
00041
00042 namespace sofa {
00043
00044 namespace simulation {
00045
00046 namespace tree {
00047
00053 class GNodeVisitor : public sofa::simulation::Visitor
00054 {
00055 public:
00056 GNodeVisitor();
00057
00058 ~GNodeVisitor();
00059
00061 virtual Result processNodeTopDown(GNode* ) { return RESULT_CONTINUE; }
00062
00064 virtual void processNodeBottomUp(GNode* ) { }
00065
00068 virtual Result processNodeTopDown(GNode* node, LocalStorage*) { return processNodeTopDown(node); }
00069
00072 virtual void processNodeBottomUp(GNode* node, LocalStorage*) { processNodeBottomUp(node); }
00073
00075 virtual Result processNodeTopDown(simulation::Node* node)
00076 {
00077 GNode* g = dynamic_cast<GNode*>(node);
00078 if (!g)
00079 {
00080 std::cerr << "GNodeVisitor: node is not a GNode !\n";
00081 return RESULT_PRUNE;
00082 }
00083 else
00084 {
00085 return processNodeTopDown(g);
00086 }
00087 }
00088
00090 virtual void processNodeBottomUp(simulation::Node* node)
00091 {
00092 GNode* g = dynamic_cast<GNode*>(node);
00093 if (!g)
00094 {
00095 std::cerr << "GNodeVisitor: node is not a GNode !\n";
00096 }
00097 else
00098 {
00099 processNodeBottomUp(g);
00100 }
00101 }
00102
00104 template < class Act, class Container, class Object >
00105 void for_each(Act* action, GNode* node, const Container& list, void (Act::*fn)(GNode*, Object*))
00106 {
00107 if (node->getLogTime())
00108 {
00109 const std::string category = getCategoryName();
00110 ctime_t t0 = node->startTime();
00111 for (typename Container::iterator it=list.begin(); it != list.end(); ++it)
00112 {
00113 (action->*fn)(node, *it);
00114 t0 = node->endTime(t0, category, *it);
00115 }
00116 }
00117 else
00118 {
00119 for (typename Container::iterator it=list.begin(); it != list.end(); ++it)
00120 {
00121 (action->*fn)(node, *it);
00122 }
00123 }
00124 }
00125
00127 template < class Act, class Container, class Object >
00128 Visitor::Result for_each_r(Act* action, GNode* node, const Container& list, Visitor::Result (Act::*fn)(GNode*, Object*))
00129 {
00130 Visitor::Result res = Visitor::RESULT_CONTINUE;
00131 if (node->getLogTime())
00132 {
00133 const std::string category = getCategoryName();
00134 ctime_t t0 = node->startTime();
00135 for (typename Container::iterator it=list.begin(); it != list.end(); ++it)
00136 {
00137 res = (action->*fn)(node, *it);
00138 t0 = node->endTime(t0, category, *it);
00139 }
00140 }
00141 else
00142 {
00143 for (typename Container::iterator it=list.begin(); it != list.end(); ++it)
00144 {
00145 res = (action->*fn)(node, *it);
00146 }
00147 }
00148 return res;
00149 }
00150
00151 };
00152
00153 }
00154
00155 }
00156
00157 }
00158
00159 #endif