mod_base_visitors.hh

Go to the documentation of this file.
00001 /*
00008  * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
00009  *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
00010  *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
00011  *****************************************************************************/
00012 
00013 #if COMPILING_MODULE
00014 #ifndef MOD_BASE_VISITORS_HH
00015 #define MOD_BASE_VISITORS_HH 1
00016 
00017 namespace mod_base {
00018 
00024 class VisitorFindPartitionNode : public Visitor
00025 {
00026 public:
00027     VisitorFindPartitionNode( Graph& graph, const string& partitionName )
00028     :   Visitor(graph),
00029         mPartitionName(partitionName),
00030         mPartitionNode(NULL_NODE)
00031     {
00032     }
00033 
00034     void Visit( PartitionNode& partitionNode )
00035     {
00036         // Does this PartitionNode have the sought name?
00037         if ( partitionNode.GetName() == mPartitionName )
00038         {
00039             // Found match, stop traversing.
00040             mPartitionNode = &partitionNode;
00041             Stop();
00042         }
00043     }
00044 
00046     PartitionNode::Ptr GetPartitionNode( void )
00047     {
00048         return mPartitionNode;
00049     }
00050 
00051 private:
00052     const string        mPartitionName;
00053     PartitionNode::Ptr  mPartitionNode;
00054 };
00055 
00062 template<typename NODE>
00063 class VisitorFindNode : public Visitor
00064 {
00065 public:
00066     VisitorFindNode( Graph& graph, const string& partitionName )
00067     :   Visitor(graph),
00068         mNode(NULL_NODE)
00069     {
00070         // Find partition node (visitor-within-a-visitor).
00071         VisitorFindPartitionNode visitorFindPartitionNode( graph, partitionName );
00072         graph.Traverse( visitorFindPartitionNode );
00073         const PartitionNode::Ptr partitionNode = visitorFindPartitionNode.GetPartitionNode();
00074 
00075         // Was partition found?
00076         if ( partitionNode != NULL_NODE )
00077         {
00078             // Traversal will start at this PartitionNode.
00079             SetRootNode( partitionNode );
00080         }
00081         else
00082         {
00083             // Don't traverse.
00084             Stop();
00085         }
00086     }
00087 
00088     void Visit( NODE& node )
00089     {
00090         // Stop at the first type of node.
00091         mNode = &node;
00092         Stop();
00093     }
00094 
00096     typename NODE::Ptr GetNode( void )
00097     {
00098         return mNode;
00099     }
00100 
00101 private:
00102     typename NODE::Ptr  mNode;  // matching node
00103 };
00104 
00105 } // namespace mod_base
00106 
00107 #endif // MOD_BASE_VISITORS_HH
00108 #endif // COMPILING_MODULE
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:12 2007