Line |
Branch |
Exec |
Source |
1 |
|
|
/***************************************************************************** |
2 |
|
|
* |
3 |
|
|
* $Id$ |
4 |
|
|
* |
5 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
6 |
|
|
* |
7 |
|
|
* This file is part of the pdserv library. |
8 |
|
|
* |
9 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
11 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
12 |
|
|
* your option) any later version. |
13 |
|
|
* |
14 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
15 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 |
|
|
* License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
21 |
|
|
* |
22 |
|
|
*****************************************************************************/ |
23 |
|
|
|
24 |
|
|
#ifndef DIRECTORYNODE_H |
25 |
|
|
#define DIRECTORYNODE_H |
26 |
|
|
|
27 |
|
|
#include <string> |
28 |
|
|
#include <queue> |
29 |
|
|
#include <map> |
30 |
|
|
|
31 |
|
|
namespace PdServ { |
32 |
|
|
class Session; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
namespace MsrProto { |
36 |
|
|
|
37 |
|
|
class Variable; |
38 |
|
|
class XmlElement; |
39 |
|
|
|
40 |
|
|
class DirectoryNode { |
41 |
|
|
public: |
42 |
|
|
DirectoryNode(DirectoryNode* parent = 0, |
43 |
|
|
const std::string& name = std::string()); |
44 |
|
|
virtual ~DirectoryNode(); |
45 |
|
|
|
46 |
|
|
void list(PdServ::Session *, XmlElement& parent, |
47 |
|
|
const std::string& path, size_t pos, bool hex, |
48 |
|
|
bool derived) const; |
49 |
|
|
std::string path() const; |
50 |
|
|
|
51 |
|
|
void dump() const; |
52 |
|
|
|
53 |
|
|
// Method on a parent to insert a node |
54 |
|
|
void insert(DirectoryNode* node, const std::string& path); |
55 |
|
|
|
56 |
|
|
// Method on a parent to insert a node at a specific position |
57 |
|
|
void pathInsert(Variable* node, const std::string& path); |
58 |
|
|
void traditionalPathInsert(Variable* node, |
59 |
|
|
const std::string& path, |
60 |
|
|
char& hidden, char& persistent); |
61 |
|
|
|
62 |
|
|
DirectoryNode* create(const std::string& name); |
63 |
|
|
|
64 |
|
|
const DirectoryNode* find(const std::string&, size_t pos) const; |
65 |
|
|
|
66 |
|
|
protected: |
67 |
|
|
|
68 |
|
|
virtual bool hasChildren(const Variable* parent) const; |
69 |
|
|
|
70 |
|
270 |
size_t childCount() const { |
71 |
|
270 |
return children.size(); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
// Insert the last node as a leaf |
75 |
|
|
virtual void insertLeaf(DirectoryNode* child); |
76 |
|
|
|
77 |
|
|
// Method on parent to adopt a child |
78 |
|
|
void adopt(DirectoryNode* child, const std::string& path); |
79 |
|
|
|
80 |
|
|
// Method on a node to set the name and ancestory |
81 |
|
|
void rename(const std::string* name, DirectoryNode* parent); |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
private: |
85 |
|
|
DirectoryNode * parent; |
86 |
|
|
const std::string* name; |
87 |
|
|
|
88 |
|
|
typedef std::map<std::string, DirectoryNode*> ChildMap; |
89 |
|
|
ChildMap children; |
90 |
|
|
|
91 |
|
|
typedef std::queue<std::string> DirQ; |
92 |
|
|
void insert(Variable* node, DirQ&); |
93 |
|
|
|
94 |
|
|
bool isRoot() const; |
95 |
|
|
static std::string split(const std::string& path, size_t& pos); |
96 |
|
|
}; |
97 |
|
|
|
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
#endif // DIRECTORYNODE_H |
101 |
|
|
|