Go to the documentation of this file.
11 #ifndef CONFIG_GRAPH_H___
12 #define CONFIG_GRAPH_H___
26 inline auto printDotID(std::ostream& os,
const std::string&
id) -> std::ostream& {
28 if (
id.empty() ||
id ==
"."
29 ||
id ==
"node" ||
id ==
"edge" ||
id ==
"graph"
30 ||
id ==
"digraph" ||
id ==
"subgraph" ||
id ==
"strict") {
31 return os <<
'"' <<
id <<
'"';
35 if (std::all_of(
id.
begin(),
id.
end(), [&](
const auto& c){
36 return std::isalnum(c) || c ==
'_';
37 }) && not std::isdigit(*
id.
begin())) {
43 for (std::ptrdiff_t i = 0; i != (std::ptrdiff_t)
id.size(); ++i) {
44 if (
id[i] ==
'"') os <<
'\\';
91 typename VertexList = std::vector<std::pair<std::string,ConfigStore>>,
92 typename EdgeList = std::vector<NameNameConfigStore>
95 std::string graph_name_ = {},
ConfigStore graph_attributes_ = {},
96 VertexList vertices_ = {},
EdgeList edges_ = {}
101 for (
const auto& v : vertices_) {
insert(std::move(v.first), std::move(v.second)); }
102 for (
const auto& e : edges_) {
link(
insert(std::move(e.name1)).first,
103 insert(std::move(e.name2)).first, std::move(e.cs)); }
157 std::vector<VertexID> result;
158 for (
const auto& e :
outEdges(v)) { result.push_back(e.target); }
174 auto vid = VertexID{
name };
175 auto it_and_is_new =
vertices.insert({vid, {}});
176 if (it_and_is_new.second) {
177 it_and_is_new.first->second = std::move(vertex_attrs);
179 set_all(it_and_is_new.first->second, std::move(vertex_attrs));
193 if (fo ==
target) { edge_count += 1; }
195 auto edge_id = EdgeID{
source, std::move(
target), edge_count };
197 edges.emplace(edge_id, std::move(edge_attrs));
206 const auto print_attribute_list = [](
auto& os,
const auto& attrs) ->
auto& {
207 if (attrs.empty()) {
return os; }
209 bool first_iter =
true;
210 for (
const auto& kv : attrs) {
211 if (not first_iter) { os <<
", "; }
225 print_attribute_list(os,
attributes(v)) <<
";\n";
231 print_attribute_list(os,
attributes(e)) <<
";\n";
250 return std::tie(this->
id) < std::tie(rhs.
id);
253 return std::tie(this->
id) == std::tie(rhs.
id);
266 return std::tie(this->source, this->target, this->
id)
270 return std::tie(this->source, this->target, this->
id)
290 std::map<EdgeID,ConfigStore>
edges = {};
auto fanout(const VertexID &v) const
const ConfigStore & attributes(const VertexID &v) const
friend auto operator<<(std::ostream &os, const DotIDPrinter &rhs) -> std::ostream &
friend std::ostream & operator<<(std::ostream &os, const EdgeID &e)
auto begin(const SingleItemImmutableSet< VertexID > &siis)
auto printDotID(std::ostream &os, const std::string &id) -> std::ostream &
ConfigGraph(std::string graph_name_={}, ConfigStore graph_attributes_={}, VertexList vertices_={}, EdgeList edges_={})
tuple_get_range< 1, Range > make_second_of_pair_range(Range &&r)
tuple_get_range< 0, Range > make_first_of_pair_range(Range &&r)
auto outEdges(const VertexID &v) const
void setGraphAttributes(const ConfigStore &attrs)
auto dotIDPrinter(T &t) -> DotIDPrinter< T >
bool operator<(const EdgeID &rhs) const
ConfigStore graph_attributes
const std::string & name(const VertexID &v) const
VertexID(std::string id_)
auto make_iterator_range(BIter &&b, EIter &&e)
std::multimap< MRRG::NodeDescriptor, MRRG::NodeDescriptor > EdgeList
const ConfigStore & graphAttributes() const &
const ConfigStore & attributes(const EdgeID &e) const
void setGraphAttributes(ConfigStore &&attrs)
std::pair< VertexID, bool > insert(std::string name, ConfigStore vertex_attrs={})
EdgeID link(VertexID source, VertexID target, ConfigStore edge_attrs={})
std::map< VertexID, ConfigStore > vertices
EdgeID(VertexID source, VertexID target, int id)
std::ptrdiff_t numVertices() const
auto end(const SingleItemImmutableSet< VertexID > &siis)
const VertexID & source(const EdgeID &e) const
ConfigStore & set_all(ConfigStore &into, const ConfigStore &from)
const VertexID & target(const EdgeID &e) const
friend std::ostream & operator<<(std::ostream &os, const VertexID &v)
const std::string & graphName() const &
bool operator==(const EdgeID &rhs) const
std::ostream & printDot(std::ostream &os) const
bool operator<(const VertexID &rhs) const
friend bool operator==(const ConfigGraph &lhs, const ConfigGraph &rhs)
std::map< EdgeID, ConfigStore > edges
bool operator==(const VertexID &rhs) const
std::multimap< VertexID, EdgeID > out_edges
void setGraphName(std::string &&s)
std::ptrdiff_t numEdges() const
friend std::ostream & operator<<(std::ostream &os, const ConfigGraph &cs)
VertexID target(EdgeID &&e) const
void setGraphName(const std::string &s)
VertexID source(EdgeID &&e) const