Polaris: TopSortNode.h Source File

TopSortNode.h

Go to the documentation of this file.
00001 #ifndef _TOPSORTNODE_H
00002 #define _TOPSORTNODE_H
00003 ///
00004 #ifdef POLARIS_GNU_PRAGMAS
00005 #pragma interface
00006 #endif
00007 ///
00008 #include "ClassNames.h"
00009 ///
00010 /// \class TopSortNode 
00011 /// \brief 
00012 /// A TopSortNode is used to store information during the topological sort
00013 /// used in the TopSorter class.  For more information, see documentation
00014 /// for the TopSorter class.
00015 ///
00016 ///  node dependency arc: source -> target
00017 ///
00018 class TopSortNode : public Listable {
00019 protected:
00020     StringElem _key_name;    ///< The key for the data in this class
00021 
00022     int _number_pointing_at_me; ///< The number of nodes pointing at this node
00023     int _number_I_point_at;     ///< The number of nodes this node points at
00024 
00025     List<StringElem> _source_list; ///< The list of nodes I point at (have arcs with me as source)
00026     List<StringElem> _target_list; ///< The list of nodes that point to me (have arcs with me as target)
00027     List<StringElem> _release_list; ///< The list of nodes whose targets have all been processed by this point
00028 
00029 public:
00030     TopSortNode( StringElem & name );
00031 
00032     ~TopSortNode( ) {
00033     ///< Nothing else to do
00034     };
00035 
00036     StringElem & key() const;
00037 
00038     virtual Listable *listable_clone() const {
00039     return (Listable *) clone();
00040     };
00041 
00042     virtual TopSortNode *clone() const {
00043     return new TopSortNode( this->key() );
00044     };
00045 
00046     void inc_sources();
00047     void inc_targets();
00048 
00049     void dec_sources();
00050     void dec_targets();
00051 
00052     int number_sources();
00053     int number_targets();
00054 
00055     void add_to_target_list( StringElem & othername );
00056     void add_to_source_list( StringElem & othername );
00057 
00058     List<StringElem> & release_list();
00059     List<StringElem> & target_list();
00060     List<StringElem> & source_list();
00061 
00062     ///< This one is to satisfy Listable
00063     virtual void    print(ostream & o) const {
00064     o << "( " << _key_name << ":" << _number_pointing_at_me << " pointing to me: ";
00065     
00066     Iterator<StringElem> s_iter = _source_list;
00067     if (s_iter.valid()) {
00068         o << s_iter.current();
00069 
00070         for (++s_iter;
00071          s_iter.valid();
00072          ++s_iter)
00073         {
00074             o << "," << s_iter.current();
00075         }
00076     }
00077 
00078     o << ";  I point at: ";
00079     Iterator<StringElem> t_iter = _target_list;
00080     if (t_iter.valid()) {
00081         o << t_iter.current();
00082 
00083         for (++t_iter;
00084          t_iter.valid();
00085          ++t_iter)
00086         {
00087             o << "," << t_iter.current();
00088         }
00089     }
00090     o << ")";
00091     };
00092 
00093     friend ostream & operator << (ostream & o, const TopSortNode & dbn) {
00094     dbn.print(o);
00095     return o;
00096     };
00097 };
00098 
00099 #endif
00100 
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:15 2005