c++文件结构的问题
class Visitor{
public:
virtual ~Visitor() {}
virtual void visitNode(Node*) = 0;
virtual void visitFile(File*) = 0;
virtual void visitDirectory(Directory*) = 0;
virtual void visitLink(Link*) = 0;
protected:
Visitor();
Visitor(const Visitor&);
};
class Link : public Node {
public:
Link(Node*);
//redeclare common Node interface here
Node* getChild(int index);
virtual void accept(Visitor&);
private:
Node* _subject;
};
class Node {
public:
//declare common interface here
void setName(string& name);
const string getName();
//const Protection& getProtection();
//void setProtection(const Protection&);
void setCDate(char* cDate);
char* getCDate();
long size();
void streamIn(istream&);
void streamOut(ostream&);
Node* getChild(int index);
virtual void adopt(Node* child);
virtual void orphan(Node* child);
virtual void accept(Visitor&) = 0;
static void destroy(Node*);
protected:
Node();
Node(const Node&);
virtual ~Node();
virtual bool isWritable() = 0;
private:
string name;
char* cDate;
};
class Directory : public Node {
public:
Directory();
Directory(string path);
//redeclare common interface here
void setName(string& name);
string getName();
void setCDate(char* cDate);
char* getCDate();
long size();
Node* getChild(int index);
virtual void adopt(Node* child); //add children
virtual void orphan(Node* child); //let the subnode be free
virtual void accept(Visitor&);
private:
list<Node*> _nodes; //hold its subnode
string& name;
char* cDate;
};
class File : public Node {
public:
File();
//redeclare common interface here
void setName(string& name);
string& getName();
void setCDate(char* cDate);
char* getCDate();
long size();
virtual void accept(Visitor&);
private:
string& name;
char* cDate;
};