LCOV - code coverage report
Current view: top level - db - db_graph_vertex.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 37 41 90.2 %
Date: 2026-06-04 02:06:09 Functions: 15 15 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef ctrlplane_db_graph_entry_h
       6             : #define ctrlplane_db_graph_entry_h
       7             : 
       8             : #include "db/db_entry.h"
       9             : #include "db/db_graph_base.h"
      10             : 
      11             : class DBGraph;
      12             : class DBGraphEdge;
      13             : class DBGraphVertex;
      14             : 
      15             : namespace boost {
      16             : template <>
      17             : struct is_POD<DBGraphEdge> : public false_type {};
      18             : 
      19             : template <>
      20             : struct is_POD<DBGraphVertex> : public false_type {};
      21             : }
      22             : 
      23             : class DBGraphVertex : public DBEntry {
      24             : public:
      25             :     typedef DBGraphBase::vertex_descriptor Vertex;
      26             :     typedef DBGraphBase::edge_descriptor Edge;
      27             : 
      28     1063560 :     DBGraphVertex() : vertex_id_(NULL), visited_at_(0) { }
      29             : 
      30             :     class adjacency_iterator : public boost::iterator_facade<
      31             :     adjacency_iterator, DBGraphVertex, boost::forward_traversal_tag
      32             :     > {
      33             :     public:
      34             :         adjacency_iterator();
      35             :         adjacency_iterator(DBGraph *graph, Vertex vertex);
      36             :     private:
      37             :         friend class boost::iterator_core_access;
      38     1475742 :         void increment() {
      39     1475742 :             ++iter_;
      40     1475742 :         }
      41     2310942 :         bool equal(const adjacency_iterator &rhs) const {
      42     2310942 :             if (graph_ == NULL) {
      43           0 :                 return (rhs.graph_ == NULL);
      44             :             }
      45     2310942 :             if (rhs.graph_ == NULL) {
      46     2310942 :                 return iter_ == end_;
      47             :             }
      48           0 :             return iter_ == rhs.iter_;
      49             :         }
      50             :         DBGraphVertex &dereference() const;
      51             :         DBGraph *graph_;
      52             :         DBGraphBase::adjacency_iterator iter_;
      53             :         DBGraphBase::adjacency_iterator end_;
      54             :     };
      55             : 
      56             :     class edge_iterator : public boost::iterator_facade<
      57             :     edge_iterator, DBGraphEdge, boost::forward_traversal_tag
      58             :     > {
      59             :     public:
      60             :         edge_iterator();
      61             :         edge_iterator(DBGraph *graph, DBGraphVertex *vertex);
      62             :         DBGraphVertex *target() const;
      63             :     private:
      64             :         friend class boost::iterator_core_access;
      65      742288 :         void increment() {
      66      742288 :             ++iter_;
      67      742288 :         }
      68      931885 :         bool equal(const edge_iterator &rhs) const {
      69      931885 :             if (graph_ == NULL) {
      70           0 :                 return (rhs.graph_ == NULL);
      71             :             }
      72      931885 :             if (rhs.graph_ == NULL) {
      73      931885 :                 return iter_ == end_;
      74             :             }
      75           0 :             return iter_ == rhs.iter_;
      76             :         }
      77             :         DBGraphEdge &dereference() const;
      78             :         DBGraph *graph_;
      79             :         DBGraphVertex *vertex_;
      80             :         DBGraphBase::out_edge_iterator iter_;
      81             :         DBGraphBase::out_edge_iterator end_;
      82             :     };
      83             : 
      84      835200 :     adjacency_iterator begin(DBGraph *graph) {
      85      835200 :         return adjacency_iterator(graph, vertex_id_);
      86             :     }
      87     2310942 :     adjacency_iterator end(DBGraph *graph) {
      88     2310942 :         return adjacency_iterator();
      89             :     }
      90             : 
      91      189597 :     edge_iterator edge_list_begin(DBGraph *graph) {
      92      189597 :         return edge_iterator(graph, this);
      93             :     }
      94      931885 :     edge_iterator edge_list_end(DBGraph *graph) {
      95      931885 :         return edge_iterator();
      96             :     }
      97             : 
      98             :     bool HasAdjacencies(DBGraph *graph) const;
      99             : 
     100      189302 :     void set_vertex(const Vertex &vertex_id) {
     101      189302 :         vertex_id_ = vertex_id;
     102      189302 :     }
     103             : 
     104      189292 :     void VertexInvalidate() {
     105      189292 :         vertex_id_ = NULL;
     106      189292 :     }
     107             : 
     108         264 :     bool IsVertexValid() {
     109         264 :         return (vertex_id_ != NULL);
     110             :     }
     111             : 
     112      892425 :     Vertex vertex() const { return vertex_id_; }
     113             : 
     114         534 :     void set_visited(uint64_t current_graph_walk_num) {
     115         534 :         visited_at_ = current_graph_walk_num;
     116         534 :     }
     117             : 
     118         415 :     bool visited(uint64_t current_graph_walk_num) {
     119         415 :         return (visited_at_ == current_graph_walk_num);
     120             :     }
     121             : 
     122             :     virtual std::string ToString() const = 0;
     123             : 
     124             : private:
     125             :     Vertex vertex_id_;
     126             :     uint64_t visited_at_;
     127             : };
     128             : 
     129             : #endif

Generated by: LCOV version 1.14