DetectorGraph  2.0
vertex.hpp
Go to the documentation of this file.
1 // Copyright 2017 Nest Labs, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef DETECTORGRAPH_INCLUDE_VERTEX_HPP_
16 #define DETECTORGRAPH_INCLUDE_VERTEX_HPP_
17 
18 #include "dglogging.hpp"
19 
20 #if defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
21 // LITE_BEGIN
22 #include "detectorgraphliteconfig.hpp"
24 // LITE_END
25 #else
26 // FULL_BEGIN
27 #include <list>
28 #include <typeinfo>
29 // FULL_END
30 #endif
31 
32 namespace DetectorGraph
33 {
34 /**
35  * @brief Define behaviors of a vertex in a graph
36  */
37 class Vertex
38 {
39 public:
40 #if defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
42 #else
43  typedef std::list<Vertex*> VertexPtrContainer;
44 #endif
45 
47  virtual ~Vertex() {}
48  virtual void ProcessVertex() = 0;
49  /**
50  * @brief Enum used for topological sort & traverse context keeping
51  */
53  {
57  };
58 
59  /**
60  * @ brief Enum used to identify the type of Vertex on a Detector Graph
61  */
63  {
67  };
68 
69  virtual VertexType GetVertexType() const = 0;
70 
72  {
73  return mState;
74  }
75 
76  void SetState(VertexSearchState aNewState)
77  {
78  mState = aNewState;
79  }
80 
81  void InsertEdge(Vertex* aVertex)
82  {
83  mOutEdges.push_back(aVertex);
84 #if !defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
85  aVertex->mInEdges.push_back(this);
86 #endif
87 #if defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_INSTRUMENT_RESOURCE_USAGE)
88  DG_LOG("Added Edge (total=%u)", mOutEdges.size());
89 #endif
90  }
91 
92  void RemoveEdge(Vertex* aVertex)
93  {
94 #if !defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
95  mOutEdges.remove(aVertex);
96  aVertex->mInEdges.remove(this);
97 #endif
98  }
99 
100  VertexPtrContainer& GetOutEdges()
101  {
102  return mOutEdges;
103  }
104 
105  void MarkFutureEdge(Vertex* aVertex)
106  {
107 #if !defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
108  mFutureOutEdges.push_back(aVertex);
109  aVertex->mFutureInEdges.push_back(this);
110 #endif
111  }
112 
113 #if !defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
114  // FULL_BEGIN
115 public:
116  VertexPtrContainer& GetInEdges()
117  {
118  return mInEdges;
119  }
120 
121  VertexPtrContainer& GetFutureOutEdges()
122  {
123  return mFutureOutEdges;
124  }
125 
126  VertexPtrContainer& GetFutureInEdges()
127  {
128  return mFutureInEdges;
129  }
130 
131  // This uses RTTI only for clarity purposes. And could potentially be removed.
132  // LCOV_EXCL_START
133  const char * GetName() const
134  {
135  return typeid(*this).name();
136  }
137  // LCOV_EXCL_STOP
138  // FULL_END
139 #endif
140 
141 protected:
143  VertexPtrContainer mOutEdges;
144 
145 #if !defined(BUILD_FEATURE_DETECTORGRAPH_CONFIG_LITE)
146  VertexPtrContainer mInEdges;
147  VertexPtrContainer mFutureOutEdges;
148  VertexPtrContainer mFutureInEdges;
149 #endif
150 };
151 
152 } // namespace DetectorGraph
153 
154 #endif // DETECTORGRAPH_INCLUDE_VERTEX_HPP_
VertexPtrContainer mOutEdges
Definition: vertex.hpp:143
void InsertEdge(Vertex *aVertex)
Definition: vertex.hpp:81
VertexSearchState mState
Definition: vertex.hpp:142
VertexPtrContainer & GetInEdges()
Definition: vertex.hpp:116
VertexSearchState
Enum used for topological sort & traverse context keeping.
Definition: vertex.hpp:52
VertexPtrContainer & GetFutureOutEdges()
Definition: vertex.hpp:121
virtual void ProcessVertex()=0
void MarkFutureEdge(Vertex *aVertex)
Definition: vertex.hpp:105
const char * GetName() const
Definition: vertex.hpp:133
VertexPtrContainer mFutureInEdges
Definition: vertex.hpp:148
void DG_LOG(const char *aLogString,...)
Definition: dglogging.cpp:22
void RemoveEdge(Vertex *aVertex)
Definition: vertex.hpp:92
VertexPtrContainer & GetOutEdges()
Definition: vertex.hpp:100
VertexPtrContainer & GetFutureInEdges()
Definition: vertex.hpp:126
VertexSearchState GetState() const
Definition: vertex.hpp:71
VertexPtrContainer mFutureOutEdges
Definition: vertex.hpp:147
virtual VertexType GetVertexType() const =0
VertexPtrContainer mInEdges
Definition: vertex.hpp:146
virtual ~Vertex()
Definition: vertex.hpp:47
void SetState(VertexSearchState aNewState)
Definition: vertex.hpp:76
std::list< Vertex * > VertexPtrContainer
Definition: vertex.hpp:43
Define behaviors of a vertex in a graph.
Definition: vertex.hpp:37