]> git.armaanb.net Git - gen-shell.git/blob - src/libshared/src/Tree.h
added install instructions
[gen-shell.git] / src / libshared / src / Tree.h
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2010 - 2017, Paul Beckingham, Federico Hernandez.
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included
13 // in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 //
23 // http://www.opensource.org/licenses/mit-license.php
24 //
25 ////////////////////////////////////////////////////////////////////////////////
26
27 #ifndef INCLUDED_TREE
28 #define INCLUDED_TREE
29
30 #include <map>
31 #include <vector>
32 #include <string>
33 #include <memory>
34
35 class Tree;
36
37 class Tree
38 {
39 public:
40   void addBranch (std::shared_ptr <Tree>);
41   void removeBranch (std::shared_ptr <Tree>);
42   void removeAllBranches ();
43   void replaceBranch (std::shared_ptr <Tree>, std::shared_ptr <Tree>);
44
45   void attribute (const std::string&, const std::string&);
46   void attribute (const std::string&, const int);
47   void attribute (const std::string&, const double);
48   std::string attribute (const std::string&);
49   void removeAttribute (const std::string&);
50
51   void enumerate (std::vector <std::shared_ptr <Tree>>& all) const;
52
53   bool hasTag (const std::string&) const;
54   void tag (const std::string&);
55   void unTag (const std::string&);
56   int countTags () const;
57
58   int count () const;
59
60   std::shared_ptr <Tree> find (const std::string&);
61
62   std::string dump () const;
63
64 private:
65   std::string dumpNode (const std::shared_ptr <Tree>, int) const;
66
67 public:
68   std::string                          _name       {"Unknown"};  // Name.
69   std::vector <std::shared_ptr <Tree>> _branches   {};           // Children.
70   std::map <std::string, std::string>  _attributes {};           // Attributes (name->value).
71   std::vector <std::string>            _tags       {};           // Tags (tag, tag ...).
72 };
73
74 #endif
75
76 ////////////////////////////////////////////////////////////////////////////////