1 // This is brl/bbas/bgrl2/bgrl2_vertex.h 2 #ifndef bgrl2_vertex_h_ 3 #define bgrl2_vertex_h_ 4 //: 5 // \file 6 // \brief A templated vertex class for a generic graph 7 // \author Amir Tamrakar 8 // \date February 30, 2005 9 // 10 // The vertex contains sets of incoming and outgoing 11 // edges to other vertices in the graph 12 // 13 // \verbatim 14 // Modifications 15 // Amir Tamrakar Feb 30, 2005 Initial version. 16 // \endverbatim 17 18 #include <list> 19 #include <iostream> 20 #ifdef _MSC_VER 21 # include <vcl_msvc_warnings.h> 22 #endif 23 #include <vbl/vbl_ref_count.h> 24 #include <vbl/vbl_smart_ptr.h> 25 26 //: A vertex in a graph 27 template<class E> 28 class bgrl2_vertex : public vbl_ref_count 29 { 30 protected: 31 typedef vbl_smart_ptr<E> E_sptr; 32 33 public: 34 typedef typename std::list<E_sptr>::iterator edge_iterator; 35 36 //: Constructor bgrl2_vertex()37 bgrl2_vertex() : vbl_ref_count(), out_edges_(), in_edges_() {} 38 39 //: Destructor 40 ~bgrl2_vertex() override= default; 41 42 //: returns all outgoing edges of this vertex out_edges()43 const std::list<E_sptr>& out_edges() { return out_edges_; } 44 45 //: returns all incoming edges of this vertex in_edges()46 const std::list<E_sptr>& in_edges() { return in_edges_; } 47 48 //: Returns an iterator to the beginning of the set of incoming edges in_edges_begin()49 edge_iterator in_edges_begin() { return in_edges_.begin(); } 50 51 //: Returns an iterator to the end of the list of incoming edges in_edges_end()52 edge_iterator in_edges_end() { return in_edges_.end(); } 53 54 //: Returns an iterator to the beginning of the set of outgoing edges out_edges_begin()55 edge_iterator out_edges_begin() { return out_edges_.begin(); } 56 57 //: Returns an iterator to the end of the list of outgoing edges out_edges_end()58 edge_iterator out_edges_end() { return out_edges_.end(); } 59 60 //: Returns the total number of edges at this vertex degree()61 int degree() const { return this->in_degree() + this->out_degree(); } 62 63 //: Returns the number of incoming edges to this vertex in_degree()64 unsigned int in_degree() const { return in_edges_.size(); } 65 66 //: Returns the number of outgoing edges to this vertex out_degree()67 unsigned int out_degree() const { return out_edges_.size(); } 68 69 //: add an edge to the incoming edge list of this node add_incoming_edge(E_sptr e)70 void add_incoming_edge(E_sptr e) { in_edges_.push_back(e); } 71 72 //: add an edge to the outgoing edge list of this node add_outgoing_edge(E_sptr e)73 void add_outgoing_edge(E_sptr e) { out_edges_.push_back(e); } 74 75 //: delete an edge incident on this node 76 bool del_edge(E_sptr e); 77 78 //: delete an edge from the incoming edge list 79 bool del_in_edge(E_sptr e); 80 81 //: delete an edge from the outgoing edge list 82 bool del_out_edge(E_sptr e); 83 84 //: delete all edges 85 void del_all_edges(); 86 87 //: delete all the incoming edges 88 void del_all_in_edges(); 89 90 //: delete all the outgoing edges 91 void del_all_out_edges(); 92 93 //: Print an ascii summary to the stream 94 virtual void print_summary(std::ostream &os) const; 95 96 protected: 97 98 //: The pointers to outgoing edges 99 std::list<E_sptr> out_edges_; 100 101 //: The pointers to incoming edges 102 std::list<E_sptr> in_edges_; 103 }; 104 105 #endif // bgrl2_vertex_h_ 106