libUTL++
Graph.h
1 #pragma once
2 
4 
5 #include <libutl/TCollection.h>
6 #include <libutl/RBtree.h>
7 #include <libutl/Vertex.h>
8 
10 
11 UTL_NS_BEGIN;
12 
14 
34 
36 class Graph : public TCollection<Vertex>, protected FlagsMI
37 {
39 
40 public:
46  Graph(bool owner, bool directed = true)
47  {
48  setCollection(new RBtree(owner));
49  _start = nullptr;
50  setDirected(directed);
51  }
52 
53  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
54 
56  void
58  {
59  super::clear();
60  _start = nullptr;
61  }
62 
64 
65 
66  bool
67  isDirected() const
68  {
69  return getFlag(flg_directed);
70  }
71 
73  void
74  setDirected(bool directed)
75  {
76  setFlag(flg_directed, directed);
77  }
78 
80  Vertex*
81  getStart() const
82  {
83  return _start;
84  }
85 
87  void
88  setStart(Vertex* start)
89  {
90  _start = start;
91  }
93 
95 
96 
102  bool addEdge(const Object& lhsKey, const Object& rhsKey);
103 
110  bool removeEdge(const Object& lhsKey, const Object& rhsKey);
112 private:
113  enum flg_t
114  {
115  flg_directed
116  };
117  void
118  init()
119  {
120  setCollection(new RBtree(true));
121  _start = nullptr;
122  setDirected(true);
123  }
124  void
125  deInit()
126  {
127  }
128 
129 private:
130  Vertex* _start;
131 };
132 
134 
135 UTL_NS_END;
void setDirected(bool directed)
Set the directed flag.
Definition: Graph.h:74
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
void setStart(Vertex *start)
Set the start vertex.
Definition: Graph.h:88
void deInit()
De-initialize UTL++.
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Graph vertex.
Definition: Vertex.h:32
Mix-in to provide 64-bits for space-efficient storage of up to 64 boolean flags.
Definition: FlagsMI.h:25
Red/black tree.
Definition: RBtree.h:37
Graph (directed or undirected).
Definition: Graph.h:36
Templated proxy for Collection.
Definition: TCollection.h:29
void clear()
Remove all vertices, clear the start vertex.
Definition: Graph.h:57
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Stream I/O abstraction.
Definition: Stream.h:68
Vertex * getStart() const
Return the start vertex.
Definition: Graph.h:81
Root of UTL++ class hierarchy.
Definition: Object.h:52
void init()
Initialize UTL++.
Graph(bool owner, bool directed=true)
Constructor.
Definition: Graph.h:46
bool isDirected() const
Get the directed flag.
Definition: Graph.h:67