Inferno  0.2
coupling.hpp
Go to the documentation of this file.
00001 #ifndef COUPLING_HPP
00002 #define COUPLING_HPP
00003 
00004 #include "common/common.hpp"
00005 #include "node/node.hpp"
00006 #include "conjecture.hpp"
00007 #include <set> 
00008 
00009 // Base class for coupling keys; this deals with individual node matches, and also with stars
00010 // by means of pointing "root" at a SubCollection or SubSequence
00011 class CompareReplace;
00012 struct Key
00013 {
00014   virtual ~Key(){}  // be a virtual hierarchy
00015   TreePtr<Node> root; // Input program node for this coupling
00016   TreePtr<Node> replace_pattern; // Pattern node for this coupling TODO rename to just pattern
00017   Conjecture::Choice *governing_choice;
00018   int governing_offset;
00019 };
00020 
00021 class CouplingKeys
00022 {
00023 // TODO const-correctness, so master can be const. Means using find() etc instead of []
00024 // when we only want to look - this will make things faster too I suspect
00025 public:
00026   CouplingKeys();
00027   /// Key a node to a pattern (generates a default key structure)
00028     void DoKey( TreePtr<Node> x, TreePtr<Node> pattern, Conjecture::Choice *gc=NULL, int go=0 );
00029     /// Key some key to a pattern - key is supplied by user, can be subclass of Key
00030     void DoKey( shared_ptr<Key> key, TreePtr<Node> pattern, Conjecture::Choice *gc=NULL, int go=0 );
00031     /// Get the node to which a pattern was keyed, or NULL if pattern has not been keyed
00032     TreePtr<Node> GetCoupled( TreePtr<Node> pattern );                  
00033     /// Get the key for a given pattern, or NULL if pattern has not been keyed
00034     shared_ptr<Key> GetKey( TreePtr<Node> pattern );  
00035     /// Get all the keys in set form
00036     Set< TreePtr<Node> > GetAllKeys();    
00037     /// Provide a pointer to another (read-only) instance of this class that will 
00038     /// be merged for the purposes of searching, but will not recieve new couplings 
00039     void SetMaster( CouplingKeys *m );        
00040     /// Clear the couplings
00041     void Clear();
00042 private:
00043   Map< TreePtr<Node>, shared_ptr<Key> > keys_map;
00044   CouplingKeys *master; 
00045 };
00046 
00047 #endif