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

Generated by: LCOV version 1.14