contrib/brl/bbas/bgrl/bgrl_edge.h
Go to the documentation of this file.
00001 // This is brl/bbas/bgrl/bgrl_edge.h
00002 #ifndef bgrl_edge_h_
00003 #define bgrl_edge_h_
00004 //:
00005 // \file
00006 // \brief A directed edge in a graph
00007 // \author Matt Leotta, (mleotta@lems.brown.edu)
00008 // \date March 17, 2004
00009 //
00010 // The edge has a pointer to its start and end vertices
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   10-sep-2004 Peter Vanroose Added copy ctor with explicit vbl_ref_count init
00015 // \endverbatim
00016 
00017 #include <vbl/vbl_ref_count.h>
00018 #include <bgrl/bgrl_vertex_sptr.h>
00019 #include <vsl/vsl_binary_io.h>
00020 #include <vcl_string.h>
00021 #include <vcl_iosfwd.h>
00022 
00023 //: Directed edge from one vertex to another
00024 class bgrl_edge : public vbl_ref_count
00025 {
00026  public:
00027   friend class bgrl_vertex;
00028   friend class bgrl_graph;
00029 
00030   // Constructor
00031   bgrl_edge() : from_(NULL), to_(NULL) {}
00032   // Copy constructor
00033   bgrl_edge(bgrl_edge const& e) : vbl_ref_count(), from_(e.from_), to_(e.to_) {}
00034   // Destructor
00035   virtual ~bgrl_edge() {}
00036 
00037   //: Smart pointer to the vertex where this edge originates
00038   bgrl_vertex_sptr from() const { return bgrl_vertex_sptr(from_); }
00039 
00040   //: Smart pointer to the vertex where this edge ends
00041   bgrl_vertex_sptr to() const { return bgrl_vertex_sptr(to_); }
00042 
00043   //: Return a platform independent string identifying the class
00044   virtual vcl_string is_a() const;
00045 
00046   //: Create a copy of the object on the heap.
00047   // The caller is responsible for deletion
00048   virtual bgrl_edge* clone() const;
00049 
00050   //: Binary save self to stream.
00051   void b_write(vsl_b_ostream &os) const;
00052 
00053   //: Binary load self from stream.
00054   void b_read(vsl_b_istream &is);
00055 
00056   //: Print an ascii summary to the stream
00057   void print_summary(vcl_ostream &os) const;
00058 
00059  protected:
00060   //: initialize the edge
00061   virtual void init() {}
00062 
00063   // The following pointers are only used to point back to the vertices
00064   // which own them.  The vertices are responsible for keeping these
00065   // pointers valid.
00066 
00067   //: The starting vertex
00068   // \note This must not be a smart pointer to prevent memory leaks
00069   bgrl_vertex* from_;
00070   //: The ending vertex
00071   // \note This must not be a smart pointer to prevent memory leaks
00072   bgrl_vertex* to_;
00073 };
00074 
00075 
00076 //: Allows derived class to be loaded by base-class pointer
00077 //  A loader object exists which is invoked by calls
00078 //  of the form "vsl_b_read(os,base_ptr)".  This loads derived class
00079 //  objects from the disk, places them on the heap and
00080 //  returns a base class pointer.
00081 //  In order to work the loader object requires
00082 //  an instance of each derived class that might be
00083 //  found.  This function gives the model class to
00084 //  the appropriate loader.
00085 void vsl_add_to_binary_loader(const bgrl_edge& e);
00086 
00087 //: Print an ASCII summary to the stream
00088 // \relatesalso bgrl_edge
00089 void vsl_print_summary(vcl_ostream &os, const bgrl_edge* e);
00090 
00091 #include "bgrl_edge_sptr.h"
00092 
00093 #endif // bgrl_edge_h_