27namespace shamrock::solvergraph {
30 class INode :
public std::enable_shared_from_this<INode>,
34 std::vector<std::shared_ptr<IEdge>> ro_edges;
36 std::vector<std::shared_ptr<IEdge>> rw_edges;
41 INode(
const INode &) =
delete;
45 INode(INode &&) noexcept = default;
48 INode &operator=(INode &&) noexcept = default;
51 inline std::shared_ptr<INode>
getptr_shared() {
return shared_from_this(); }
53 inline std::weak_ptr<INode>
getptr_weak() {
return weak_from_this(); }
56 inline std::vector<std::shared_ptr<IEdge>> &
get_ro_edges() {
return ro_edges; }
58 inline std::vector<std::shared_ptr<IEdge>> &
get_rw_edges() {
return rw_edges; }
94 auto &edge = ro_edges.at(slot);
96 auto ptr = std::dynamic_pointer_cast<T>(edge);
98 return std::cref(*ptr);
101 if (is_null_opt_edge(edge)) {
106 shambase::format(
"Edge is not from the requested type: {}", slot));
112 auto &edge = rw_edges.at(slot);
114 auto ptr = std::dynamic_pointer_cast<T>(edge);
116 return std::cref(*ptr);
119 if (is_null_opt_edge(edge)) {
124 shambase::format(
"Edge is not from the requested type: {}", slot));
168 std::string node_info = shambase::format(
"Node info :\n");
169 node_info += shambase::format(
" - Node type : {}\n",
typeid(*this).name());
170 node_info += shambase::format(
" - Node UUID : {}\n",
get_uuid());
171 node_info += shambase::format(
" - Node label : {}\n",
_impl_get_label());
173 auto append_edges_info = [&](
const char *title,
const auto &edges) {
174 node_info += shambase::format(
" - {}: {}\n", title, edges.size());
175 for (
const auto &edge : edges) {
176 const auto &e = *edge;
177 node_info += shambase::format(
178 " - Edge ptr = {}, uuid = {}, label = {},\n type = {} \n",
179 static_cast<void *
>(edge.get()),
186 append_edges_info(
"Node Read Only edges", ro_edges);
187 append_edges_info(
"Node Read Write edges", rw_edges);
211 for (
auto e : ro_edges) {
214 this->ro_edges = new_ro_edges;
215 for (
auto e : ro_edges) {
221 for (
auto e : rw_edges) {
224 this->rw_edges = new_rw_edges;
225 for (
auto e : rw_edges) {
232 for (
auto &in : ro_edges) {
239 for (
auto &out : rw_edges) {
248 std::string edge_str =
"";
249 for (
auto &in : ro_edges) {
250 edge_str += shambase::format(
251 "e_{} -> n_{} [style=\"dashed\", color=green];\n",
254 edge_str += shambase::format(
255 "e_{} [label=\"{}\",shape=rect, style=filled];\n", in->get_uuid(), in->get_label());
257 for (
auto &out : rw_edges) {
258 edge_str += shambase::format(
259 "n_{} -> e_{} [style=\"dashed\", color=red];\n", this->
get_uuid(), out->get_uuid());
260 edge_str += shambase::format(
261 "e_{} [label=\"{}\",shape=rect, style=filled];\n",
266 return shambase::format(
"{}{}", node_str, edge_str);
270 return shambase::format(
"n_{}", this->
get_uuid());
273 return shambase::format(
"n_{}", this->
get_uuid());
278#define INODE_DECL_RO(type, name) const type &name;
279#define INODE_DECL_RW(type, name) type & name;
280#define INODE_PARAM_RO(type, name) const std::shared_ptr<type> &name,
281#define INODE_PARAM_RW(type, name) const std::shared_ptr<type> &name,
282#define INODE_PUSH_RO1(type, name) name,
283#define INODE_PUSH_RW1(type, name)
284#define INODE_PUSH_RO2(type, name)
285#define INODE_PUSH_RW2(type, name) name,
286#define INODE_GET_RO(type, name) get_ro_edge<type>(ro++),
287#define INODE_GET_RW(type, name) get_rw_edge<type>(rw++),
289#define INODE_DECL_RO_OPTIONAL(type, name) \
290 const std::optional<std::reference_wrapper<const type>> name;
291#define INODE_DECL_RW_OPTIONAL(type, name) const std::optional<std::reference_wrapper<type>> name;
292#define INODE_PARAM_RO_OPTIONAL(type, name) const std::optional<std::shared_ptr<type>> &name,
293#define INODE_PARAM_RW_OPTIONAL(type, name) const std::optional<std::shared_ptr<type>> &name,
294#define INODE_PUSH_RO1_OPTIONAL(type, name) shamrock::solvergraph::obsfucate_null_opt_edge(name),
295#define INODE_PUSH_RW1_OPTIONAL(type, name)
296#define INODE_PUSH_RO2_OPTIONAL(type, name)
297#define INODE_PUSH_RW2_OPTIONAL(type, name) shamrock::solvergraph::obsfucate_null_opt_edge(name),
298#define INODE_GET_RO_OPTIONAL(type, name) get_ro_edge_optional<type>(ro++),
299#define INODE_GET_RW_OPTIONAL(type, name) get_rw_edge_optional<type>(rw++),
301#define EXPAND_NODE_EDGES(EDGES) \
304 EDGES(INODE_DECL_RO, INODE_DECL_RW) \
307 inline void set_edges( \
308 EDGES(INODE_PARAM_RO, INODE_PARAM_RW) SourceLocation loc = SourceLocation{}) { \
309 __shamrock_log_callsite(loc); \
311 __internal_set_ro_edges({EDGES(INODE_PUSH_RO1, INODE_PUSH_RW1)}); \
312 __internal_set_rw_edges({EDGES(INODE_PUSH_RO2, INODE_PUSH_RW2)}); \
315 inline Edges get_edges() { \
318 return Edges{EDGES(INODE_GET_RO, INODE_GET_RW)}; \
321#define EXPAND_NODE_EDGES_OPTIONAL(EDGES) \
324 EDGES(INODE_DECL_RO, INODE_DECL_RW, INODE_DECL_RO_OPTIONAL, INODE_DECL_RW_OPTIONAL) \
327 inline void set_edges( \
328 EDGES(INODE_PARAM_RO, INODE_PARAM_RW, INODE_PARAM_RO_OPTIONAL, INODE_PARAM_RW_OPTIONAL) \
329 SourceLocation loc = SourceLocation{}) { \
330 __shamrock_log_callsite(loc); \
332 __internal_set_ro_edges({EDGES( \
333 INODE_PUSH_RO1, INODE_PUSH_RW1, INODE_PUSH_RO1_OPTIONAL, INODE_PUSH_RW1_OPTIONAL)}); \
334 __internal_set_rw_edges({EDGES( \
335 INODE_PUSH_RO2, INODE_PUSH_RW2, INODE_PUSH_RO2_OPTIONAL, INODE_PUSH_RW2_OPTIONAL)}); \
338 inline Edges get_edges() { \
342 EDGES(INODE_GET_RO, INODE_GET_RW, INODE_GET_RO_OPTIONAL, INODE_GET_RW_OPTIONAL)}; \
A class that provides unique identifiers (UUID) to instances.
void evaluate()
Evaluate the node.
INode & operator=(const INode &)=delete
would violate shared_from_this() & unique UUID
std::vector< std::shared_ptr< IEdge > > & get_ro_edges()
Get the read only edges.
virtual std::string _impl_get_dot_graph_node_start() const
get the dot graph of the node start
void on_edge_ro_edges(Func &&f)
Apply a function to the read only edges.
T & get_rw_edge(int slot)
Get a read write edge and cast it to the type T.
INode(INode &&) noexcept=default
would violate shared_from_this() & unique UUID
void __internal_set_rw_edges(std::vector< std::shared_ptr< IEdge > > new_rw_edges)
Set the read write edges.
virtual ~INode()
Destructor (virtual) & reset the edges.
std::string get_dot_graph_node_start()
Get the id of the node start in the dot graph.
std::string get_tex_partial()
Get the TeX of the node partial.
std::weak_ptr< INode > getptr_weak()
Get a weak pointer to this node.
std::optional< std::reference_wrapper< const T > > get_ro_edge_optional(int slot)
Get a read only edge and cast it to the type T, return an optional.
std::string get_tex()
Get the TeX of the node.
virtual void _impl_evaluate_internal()=0
evaluate the node
IEdge & get_rw_edge_base(int slot)
Get a reference to a read write edge and cast it to the type IEdge.
void on_edge_rw_edges(Func &&f)
Apply a function to the read write edges.
std::string get_dot_graph()
Get the dot graph of the node (Currently only an alias to get_dot_graph_partial).
std::shared_ptr< INode > getptr_shared()
Get a shared pointer to this node.
std::string get_label() const
Get the label of the node.
virtual std::string print_node_info() const
print the node info
void __internal_set_ro_edges(std::vector< std::shared_ptr< IEdge > > new_ro_edges)
Set the read only edges.
std::string get_dot_graph_partial()
Get the dot graph of the subgraph corresponding to the node.
std::string get_dot_graph_node_end()
Get the id of the node end in the dot graph.
std::optional< std::reference_wrapper< T > > get_rw_edge_optional(int slot)
Get a read write edge and cast it to the type T, return an optional.
virtual std::string _impl_get_label() const =0
get the label of the node
const T & get_ro_edge(int slot)
Get a read only edge and cast it to the type T.
virtual std::string _impl_get_dot_graph_partial() const
get the dot graph of the node partial
std::vector< std::shared_ptr< IEdge > > & get_rw_edges()
Get the read write edges.
virtual std::string _impl_get_tex() const =0
get the tex of the node
virtual std::string _impl_get_dot_graph_node_end() const
get the dot graph of the node end
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
This file contains the definition for the stacktrace related functionality.