-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodejw.h
executable file
·142 lines (127 loc) · 3.23 KB
/
nodejw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef NODEJW
#define NODEJW
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <string>
#include "basenode_jw.h"
using std::cin;
using std::cout;
using std::ostream;
//testing
using std::istream;
using std::stringstream;
using std::string;
enum NODEJW_ERROR {NODE_VALUE_NOT_SET};
template <typename T>
class nodeJW:public baseNodeJW{
public:
//nodeJW();
nodeJW(T input = T());
nodeJW(const nodeJW &other);
nodeJW& operator=(const baseNodeJW &other);
~nodeJW(){
delete (T*)getValue();
}
bool operator<(const baseNodeJW &x) const;
bool operator<=(const baseNodeJW &x) const;
bool operator>(const baseNodeJW &x) const;
bool operator>=(const baseNodeJW &x) const;
bool operator==(const baseNodeJW &x) const;
bool operator!=(const baseNodeJW &x) const;
inline T getData(){
return *(T*) getValue();
}
template <typename U>
friend
ostream& operator<<(ostream& out, const nodeJW<U> &theNode);
template <typename U>
friend
istream& operator>>(istream& in, nodeJW<U> &theNode);
protected:
//string type;
private:
void copy(const baseNodeJW *other);
};
template <typename T>
nodeJW<T>::nodeJW(T input){
setValue(new T(input));
};
template <typename T>
nodeJW<T>::nodeJW(const nodeJW<T> &other){
copy(&other);
}
template <typename T>
void nodeJW<T>::copy(const baseNodeJW* other)
{
*(T*)getValue() = *(T*)(other->getValue());
}
template <typename T>
nodeJW<T>& nodeJW<T>::operator=(const baseNodeJW &other){
if(this!=&other)
copy(&other);
return *this;
}
template <typename T>
bool nodeJW<T>::operator<(const baseNodeJW &x) const{
return *(T*)getValue()<*(T*)x.getValue();
}
template <typename T>
bool nodeJW<T>::operator<=(const baseNodeJW &x) const{
return *(T*)getValue()<=*(T*)x.getValue();
}
template <typename T>
bool nodeJW<T>::operator>(const baseNodeJW &x) const{
return *(T*)getValue()>*(T*)x.getValue();
}
template <typename T>
bool nodeJW<T>::operator>=(const baseNodeJW &x) const{
return *(T*)getValue()>=*(T*)x.getValue();
}
template <typename T>
bool nodeJW<T>::operator==(const baseNodeJW &x) const{
return *(T*)getValue()==*(T*)x.getValue();
}
template <typename T>
bool nodeJW<T>::operator!=(const baseNodeJW &x) const{
return *(T*)getValue()!=*(T*)x.getValue();
}
template <typename U>
ostream& operator<<(ostream& out, const nodeJW<U> &theNode)
{
if(&out == &cout)
out<<"value: "<<theNode.getData();
else{
out<<"["<<theNode.getData()<<"]";
}
return out;
}
template <typename U>
istream& operator>>(istream& in, nodeJW<U> &theNode)
{
if(&in == &cin)
{
string line;
cout << "Value: ";
getline (cin,line);
stringstream ss(line);
ss >> *(U*)theNode.getValue();
ss.str(std::string());
ss.clear();
}
else
{
string line;
getline(in,line,']');
if(line.size()!=0){
line.erase(0,1);
line.erase(line.size(),1);
stringstream ss;
ss >> *(U*)theNode.getValue();
ss.clear();
}
}
return in;
};
#endif // NODEJW