LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
DataNode.hpp
Go to the documentation of this file.
1 
7 #ifndef LLU_CONTAINERS_ITERATORS_DATANODE_HPP
8 #define LLU_CONTAINERS_ITERATORS_DATANODE_HPP
9 
10 #include <type_traits>
11 
13 #include "LLU/TypedMArgument.h"
14 
15 namespace LLU {
16 
21  template<typename T>
22  class DataNode {
23  static constexpr bool isGeneric = std::is_same_v<T, Argument::TypedArgument>;
24  static_assert(Argument::WrapperQ<T>, "DataNode type is not a valid MArgument wrapper type.");
25 
26  public:
31  explicit DataNode(DataStoreNode dsn);
32 
37  explicit DataNode(GenericDataNode gn);
38 
43  T& value() {
44  return nodeArg;
45  }
46 
51  const T& value() const {
52  return nodeArg;
53  }
54 
60  std::string_view name() const {
61  return node.name();
62  }
63 
68  bool hasNext() const {
69  return static_cast<bool>(node.next());
70  }
71 
77  return node.next();
78  }
79 
84  MArgumentType type() noexcept {
85  return node.type();
86  }
87 
93  template <std::size_t N>
94  decltype(auto) get() {
95  static_assert(N < 2, "Bad structure binding attempt to a DataNode.");
96  if constexpr (N == 0) {
97  return name();
98  } else {
99  return (nodeArg);
100  }
101  }
102 
103  private:
104  GenericDataNode node {};
105  T nodeArg;
106  };
107 
108  /* Definitions od DataNode methods */
109  template<typename T>
110  DataNode<T>::DataNode(DataStoreNode dsn) : DataNode(GenericDataNode {dsn}) {}
111 
112  template<typename T>
114  if (!node) {
116  }
117  if constexpr (isGeneric) {
118  nodeArg = std::move(node.value());
119  } else{
120  nodeArg = std::move(node.as<T>());
121  }
122  }
123 
124 
125 }/* namespace LLU */
126 
127 namespace std {
128  template<typename T>
129  class tuple_size<LLU::DataNode<T>> : public std::integral_constant<std::size_t, 2> {};
130 
131  template<std::size_t N, typename T>
132  class tuple_element<N, LLU::DataNode<T>> {
133  public:
134  using type = decltype(std::declval<LLU::DataNode<T>>().template get<N>());
135  };
136 }
137 
138 #endif // LLU_CONTAINERS_ITERATORS_DATANODE_HPP
LLU::DataNode
Wrapper over DataStoreNode structure from LibraryLink.
Definition: DataNode.hpp:22
LLU::DataNode::value
T & value()
Get node value.
Definition: DataNode.hpp:43
LLU
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
TypedMArgument.h
LLU::DataNode::get
decltype(auto) get()
Get N-th element of DataNode in a tuple-like way.
Definition: DataNode.hpp:94
LLU::ErrorName::DLNullRawNode
const std::string DLNullRawNode
DataStoreNode passed to Node wrapper was null.
LLU::GenericDataNode
Basic wrapper over DataStoreNode, provides class-like interface and conversion of the underlying valu...
Definition: Iterators/DataStore.hpp:22
DataStore.hpp
Definition and implementation of generic DataStore wrapper.
LLU::GenericDataNode::name
std::string_view name() const noexcept
Get node name.
Definition: DataStore.cpp:20
LLU::GenericDataNode::next
GenericDataNode next() const noexcept
Get GenericDataNode wrapper over the next node.
Definition: DataStore.cpp:12
LLU::GenericDataNode::type
MArgumentType type() const noexcept
Get type of the node value.
Definition: DataStore.cpp:16
LLU::DataNode::type
MArgumentType type() noexcept
Get the actual type of node value.
Definition: DataNode.hpp:84
LLU::ErrorManager::throwException
static void throwException(const std::string &errorName, T &&... args)
Throw exception with given name.
Definition: ErrorManager.h:199
LLU::MArgumentType
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
LLU::DataNode::next
GenericDataNode next() const
Get next node as GenericDataNode (because the next node may not necessarily have value of type T)
Definition: DataNode.hpp:76
LLU::DataNode::DataNode
DataNode(DataStoreNode dsn)
Create DataNode from raw DataStoreNode structure.
Definition: DataNode.hpp:110
LLU::DataNode::hasNext
bool hasNext() const
Check if this node has a successor.
Definition: DataNode.hpp:68
LLU::DataNode::value
const T & value() const
Get node value.
Definition: DataNode.hpp:51
LLU::DataNode::name
std::string_view name() const
Get node name.
Definition: DataNode.hpp:60