Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Pipes/Dependency.h

00001 # ifndef __dependency_h
00002 # define __dependency_h
00003 
00004 // This class (partly) helps booking the dependency relationship in the 
00005 // pipe graph. Actually the dependencis can be viewed as directed edges
00006 // in the graph.
00007 // The following code is not guarenteed to work on multi-derived classes, 
00008 // since a re-interpret cast will have to be used.
00009 // And semaphores must be added if used under multithread settings
00010 
00011 class DependencyUnit {
00012  protected:
00013   struct Node {
00014     DependencyUnit ** dependency ;
00015     Node * next ;
00016 
00017     Node( DependencyUnit ** u, Node * n = 0 ) : dependency(u), next(n) {}
00018     ~Node() { delete next ; }
00019   } *head, **tail ;
00020 
00021   // Functions in the following 'protected' section are supposed to be 
00022   // overridden.
00023  protected:
00024 
00025   // This must be overridden, to return a new copy of the object itself.
00026   // In smalltalk this can be done solely in the parent class, 
00027   // e.g. ^new (self class), but in C++ I can't figure out a way doing
00028   // so without the help of the derived class.
00029 
00030   virtual DependencyUnit * duplicate(void) const = 0 ;
00031     // e.g. { return new ClassName(*this) ; }
00032     // Here ClassName is the name of the derived class.
00033     // Be sure that dependency is correctly set up.
00034 
00035   // This may be overridden, to set dependencies (i.e. via addDependency()).
00036   // However, be sure to call it as well as in all constructors of the 
00037   // derived class when appropriate, since overriding functions will not be
00038   // calls during construction of the base class.
00039   
00040   virtual void setDependency(void) {}
00041 
00042  private:
00043 
00044   DependencyUnit * replica ;
00045   bool copying ;
00046 
00047   void precopy(void);
00048   void docopy(void);
00049   void postcopy(void);
00050 
00051  public:
00052 
00053   // This is the deep copy function using overridden duplicate.
00054   // It's not supposed to be overridden in most cases.
00055 
00056   virtual DependencyUnit * copy(void);
00057 
00058  public:
00059 
00060   DependencyUnit() : 
00061     head(0), tail(&head), replica(0), copying(false) { setDependency(); }
00062   DependencyUnit(const DependencyUnit& u ) : // no default copy constructor
00063     head(0), tail(&head), replica(0), copying(false) { setDependency(); }
00064 
00065   void addDependency( DependencyUnit ** u ) 
00066     { *tail = new Node(u,0); tail = &((*tail)->next); }
00067   void removeDependency( DependencyUnit ** u );
00068   void removeAllDependency(void) { delete head ; head = 0 ; tail = &head ; }
00069   virtual ~DependencyUnit() { removeAllDependency(); }
00070 };
00071 
00072 
00073 # endif //__dependency_h

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000