| CXXGraph 0.4.0 CXXGraph is a header only, that manages the Graphs and it's algorithm in C++

Node.hpp
1 /***********************************************************/
2 /*** ______ ____ ______ _ ***/
3 /*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
4 /*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
5 /*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
6 /*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
7 /*** |_| ***/
8 /***********************************************************/
9 /*** Header-Only C++ Library for Graph ***/
10 /*** Representation and Algorithms ***/
11 /***********************************************************/
12 /*** Author: ZigRazor ***/
13 /*** E-Mail: zigrazor@gmail.com ***/
14 /***********************************************************/
15 /*** Collaboration: ----------- ***/
16 /***********************************************************/
17 /*** License: MPL v2.0 ***/
18 /***********************************************************/
19
20
21 #ifndef __CXXGRAPH_NODE_H__
22 #define __CXXGRAPH_NODE_H__
23
24 #pragma once
25 #include <iostream>
26 #include <openssl/sha.h>
27 #include <iomanip>
28
29
30 namespace CXXGRAPH
31 {
32 template <typename T>
33 class Node;
34 template <typename T>
35 std::ostream &operator<<(std::ostream &os, const Node<T> &node);
36 template <typename T>
37 class Node
38 {
39 private:
40 std::size_t id = 0;
41 std::string userId = "";
42 T data;
43 void setId(std::string_view);
44
45 public:
46 Node(std::string_view, const T &data);
47 ~Node() = default;
48 const std::size_t &getId() const;
49 const std::string &getUserId() const;
50 const T &getData() const;
51 //operator
52 bool operator==(const Node<T> &b) const;
53 bool operator<(const Node<T> &b) const;
54 friend std::ostream &operator<<<>(std::ostream &os, const Node<T> &node);
55 };
56
57 template <typename T>
58 Node<T>::Node(std::string_view id, const T &data)
59 {
60 this->userId = id;
61 // the userid is set as sha512 hash of the user provided id
62 setId(id);
63 this->data = data;
64 }
65
66 template <typename T>
67 void Node<T>::setId(std::string_view inpId)
68 {
69 //const unsigned char* userId = reinterpret_cast<const unsigned char *>((*inpId).c_str() );
70 //unsigned char obuf[64];
71 //unsigned long long obuf[8];
72 //SHA512(userId, (*inpId).length(), reinterpret_cast<unsigned char*>(obuf));
91 this->id = std::hash<std::string_view>{}(inpId);
92
93 }
94
95 template <typename T>
96 const std::size_t &Node<T>::getId() const
97 {
98 return id;
99 }
100
101 template <typename T>
102 const std::string &Node<T>::getUserId() const
103 {
104 return userId;
105 }
106
107 template <typename T>
108 const T &Node<T>::getData() const
109 {
110 return data;
111 }
112
113 template <typename T>
114 bool Node<T>::operator==(const Node<T> &b) const
115 {
116 return (this->id == b.id && this->data == b.data);
117 }
118
119 template <typename T>
120 bool Node<T>::operator<(const Node<T> &b) const
121 {
122 return (this->id < b.id);
123 }
124
125
126 //ostream overload
127 template <typename T>
128 std::ostream &operator<<(std::ostream &os, const Node<T> &node)
129 {
130 os << "Node: {\n"
131 << " Id:\t" << node.userId << "\n Data:\t" << node.data << "\n}";
132 return os;
133 }
134 }
135
136 #endif // __CXXGRAPH_NODE_H__
CXXGRAPH::Node
Definition: Node.hpp:38