-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNode.h
73 lines (55 loc) · 1.95 KB
/
Node.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
#ifndef Node_H_12122013
#define Node_H_12122013
/**********************************
Node: base class for composite class Directory and leaf class File
\***********************************/
#include <iosfwd>
#include <string>
#include <exception>
#include <stdexcept>
class Directory;
class Visitor;
class Node { // abstract base class. accept(Visitor&) is pure virtual.
friend class Directory;
public:
class node_logic_error : public std::logic_error {
public:
node_logic_error(const std::string& msg) : std::logic_error(msg) {}
};
public:
static const char directory_separator = '/';
virtual void adopt(Node* p) throw(node_logic_error)
{
throw node_logic_error("This class does not support the add operation");
}
virtual void remove(Node *pnode) throw(node_logic_error, std::invalid_argument)
{
throw node_logic_error("This class does not support the remove operation");
}
virtual Node *getChild(int i) throw(node_logic_error, std::out_of_range)
{
throw node_logic_error("This class does not support the getChild operation");
}
virtual std::string getName() const throw(node_logic_error)
{
throw node_logic_error("This class does not support the getName operation");
}
virtual std::string getDateCreated() const throw(node_logic_error)
{
throw node_logic_error("This class does not support the getDateCreated operation");
}
virtual long getSize() const throw(node_logic_error)
{
throw node_logic_error("This class does not support the getSize operation");
}
virtual void accept(Visitor& v) const = 0; //++ add const version
friend std::ostream& operator<<(std::ostream& ostr, const Node& c);
Node() {};
virtual ~Node() {};
};
inline std::ostream& operator<<(std::ostream& ostr, const Node& c)
{
ostr << std::string("This is class Node\n");
return ostr;
}
#endif