26namespace shamrock::solvergraph {
29 class INode :
public std::enable_shared_from_this<INode>,
33 std::vector<std::shared_ptr<IEdge>> ro_edges;
35 std::vector<std::shared_ptr<IEdge>> rw_edges;
52 inline std::weak_ptr<INode>
getptr_weak() {
return weak_from_this(); }
55 inline std::vector<std::shared_ptr<IEdge>> &
get_ro_edges() {
return ro_edges; }
57 inline std::vector<std::shared_ptr<IEdge>> &
get_rw_edges() {
return rw_edges; }
129 std::string node_info = shambase::format(
"Node info :\n");
130 node_info += shambase::format(
" - Node type : {}\n",
typeid(*this).name());
131 node_info += shambase::format(
" - Node UUID : {}\n",
get_uuid());
132 node_info += shambase::format(
" - Node label : {}\n",
_impl_get_label());
134 auto append_edges_info = [&](
const char *title,
const auto &edges) {
135 node_info += shambase::format(
" - {}: {}\n", title, edges.size());
136 for (
const auto &edge : edges) {
137 const auto &e = *edge;
138 node_info += shambase::format(
139 " - Edge ptr = {}, uuid = {}, label = {},\n type = {} \n",
140 static_cast<void *
>(edge.get()),
147 append_edges_info(
"Node Read Only edges", ro_edges);
148 append_edges_info(
"Node Read Write edges", rw_edges);
172 for (
auto e : ro_edges) {
175 this->ro_edges = new_ro_edges;
176 for (
auto e : ro_edges) {
182 for (
auto e : rw_edges) {
185 this->rw_edges = new_rw_edges;
186 for (
auto e : rw_edges) {
193 for (
auto &in : ro_edges) {
200 for (
auto &out : rw_edges) {
209 std::string edge_str =
"";
210 for (
auto &in : ro_edges) {
211 edge_str += shambase::format(
212 "e_{} -> n_{} [style=\"dashed\", color=green];\n",
215 edge_str += shambase::format(
216 "e_{} [label=\"{}\",shape=rect, style=filled];\n", in->get_uuid(), in->get_label());
218 for (
auto &out : rw_edges) {
219 edge_str += shambase::format(
220 "n_{} -> e_{} [style=\"dashed\", color=red];\n", this->
get_uuid(), out->get_uuid());
221 edge_str += shambase::format(
222 "e_{} [label=\"{}\",shape=rect, style=filled];\n",
227 return shambase::format(
"{}{}", node_str, edge_str);
231 return shambase::format(
"n_{}", this->
get_uuid());
234 return shambase::format(
"n_{}", this->
get_uuid());
239#define INODE_DECL_RO(type, name) const type &name;
240#define INODE_DECL_RW(type, name) type & name;
241#define INODE_PARAM_RO(type, name) std::shared_ptr<type> name,
242#define INODE_PARAM_RW(type, name) std::shared_ptr<type> name,
243#define INODE_PUSH_RO1(type, name) name,
244#define INODE_PUSH_RW1(type, name)
245#define INODE_PUSH_RO2(type, name)
246#define INODE_PUSH_RW2(type, name) name,
247#define INODE_GET_RO(type, name) get_ro_edge<type>(ro++),
248#define INODE_GET_RW(type, name) get_rw_edge<type>(rw++),
250#define EXPAND_NODE_EDGES(EDGES) \
253 EDGES(INODE_DECL_RO, INODE_DECL_RW) \
256 inline void set_edges( \
257 EDGES(INODE_PARAM_RO, INODE_PARAM_RW) SourceLocation loc = SourceLocation{}) { \
258 __shamrock_log_callsite(loc); \
260 __internal_set_ro_edges({EDGES(INODE_PUSH_RO1, INODE_PUSH_RW1)}); \
261 __internal_set_rw_edges({EDGES(INODE_PUSH_RO2, INODE_PUSH_RW2)}); \
264 inline Edges get_edges() { \
267 return Edges{EDGES(INODE_GET_RO, INODE_GET_RW)}; \
A class that provides unique identifiers (UUID) to instances.
u64 get_uuid() const
Get the uuid of the class.
Inode is node between data edges, takes multiple inputs, multiple outputs.
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::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.
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.
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...
This file contains the definition for the stacktrace related functionality.