Passwordfile library  3.1.4
C++ library to read/write passwords from/to encrypted files
entry.h
Go to the documentation of this file.
1 #ifndef ENTRY_H
2 #define ENTRY_H
3 
4 #include "./field.h"
5 
6 #include <c++utilities/conversion/types.h>
7 
8 #include <iostream>
9 #include <list>
10 #include <string>
11 #include <vector>
12 
13 namespace Io {
14 
18 enum class EntryType : int {
19  Node,
20  Account
21 };
22 
23 class NodeEntry;
24 
26  friend class NodeEntry;
27 
28 public:
29  virtual ~Entry();
30  Entry &operator=(const Entry &other) = delete;
31  virtual EntryType type() const = 0;
32  const std::string &label() const;
33  void setLabel(const std::string &label);
34  void makeLabelUnique();
35  NodeEntry *parent() const;
36  void setParent(NodeEntry *parent, int index = -1);
37  int index() const;
38  bool isIndirectChildOf(NodeEntry *entry) const;
39  std::list<std::string> path() const;
40  void path(std::list<std::string> &res) const;
41  virtual void make(std::ostream &stream) const = 0;
42  virtual Entry *clone() const = 0;
43  static Entry *parse(std::istream &stream);
44  static bool denotesNodeEntry(byte version);
45 
46 protected:
47  Entry(const std::string &label = std::string(), NodeEntry *parent = nullptr);
48  Entry(const Entry &other);
49 
50 private:
51  std::string m_label;
52  NodeEntry *m_parent;
53  int m_index;
54 
55 protected:
56  std::string m_extendedData;
57 };
58 
62 inline const std::string &Entry::label() const
63 {
64  return m_label;
65 }
66 
72 inline void Entry::setLabel(const std::string &label)
73 {
74  m_label = label;
75  makeLabelUnique();
76 }
77 
82 inline NodeEntry *Entry::parent() const
83 {
84  return m_parent;
85 }
86 
90 inline int Entry::index() const
91 {
92  return m_index;
93 }
94 
96  friend class Entry;
97 
98 public:
99  NodeEntry();
100  NodeEntry(const std::string &label, NodeEntry *parent = nullptr);
101  NodeEntry(std::istream &stream);
102  NodeEntry(const NodeEntry &other);
103  ~NodeEntry();
104 
105  virtual EntryType type() const;
106  const std::vector<Entry *> &children() const;
107  void deleteChildren(int begin, int end);
108  void replaceChild(size_t at, Entry *newChild);
109  Entry *entryByPath(std::list<std::string> &path, bool includeThis = true, EntryType *creationType = nullptr);
110  bool isExpandedByDefault() const;
111  void setExpandedByDefault(bool expandedByDefault);
112  virtual void make(std::ostream &stream) const;
113  virtual NodeEntry *clone() const;
114 
115 private:
116  std::vector<Entry *> m_children;
117  bool m_expandedByDefault;
118 };
119 
121 {
122  return EntryType::Node;
123 }
124 
125 inline const std::vector<Entry *> &NodeEntry::children() const
126 {
127  return m_children;
128 }
129 
131 {
132  return m_expandedByDefault;
133 }
134 
135 inline void NodeEntry::setExpandedByDefault(bool expandedByDefault)
136 {
137  m_expandedByDefault = expandedByDefault;
138 }
139 
140 inline bool Entry::denotesNodeEntry(byte version)
141 {
142  return (version & 0x80) == 0;
143 }
144 
146 public:
147  AccountEntry();
148  AccountEntry(const std::string &label, NodeEntry *parent = nullptr);
149  AccountEntry(std::istream &stream);
150  AccountEntry(const AccountEntry &other);
151  ~AccountEntry();
152 
153  virtual EntryType type() const;
154  const std::vector<Field> &fields() const;
155  std::vector<Field> &fields();
156  virtual void make(std::ostream &stream) const;
157  virtual AccountEntry *clone() const;
158 
159 private:
160  std::vector<Field> m_fields;
161 };
162 
164 {
165  return EntryType::Account;
166 }
167 
168 inline const std::vector<Field> &AccountEntry::fields() const
169 {
170  return m_fields;
171 }
172 
173 inline std::vector<Field> &AccountEntry::fields()
174 {
175  return m_fields;
176 }
177 }
178 
179 #endif // ENTRY_H
NodeEntry * parent() const
Returns the parent entry.
Definition: entry.h:82
The NodeEntry class acts as parent for other entries.
Definition: entry.h:95
const std::string & label() const
Returns the label.
Definition: entry.h:62
void setLabel(const std::string &label)
Sets the label.
Definition: entry.h:72
bool isExpandedByDefault() const
Definition: entry.h:130
virtual EntryType type() const
Returns the type of the entry.
Definition: entry.h:163
Contains all IO related classes.
int index() const
Returns the index of the entry within its parent.
Definition: entry.h:90
std::string m_extendedData
Definition: entry.h:56
The exception that is thrown when a parsing error occurs.
Definition: entry.h:145
#define PASSWORD_FILE_EXPORT
Marks the symbol to be exported by the passwordfile library.
static bool denotesNodeEntry(byte version)
Definition: entry.h:140
const std::vector< Entry * > & children() const
Definition: entry.h:125
const std::vector< Field > & fields() const
Definition: entry.h:168
EntryType
Specifies the entry type.
Definition: entry.h:18
void setExpandedByDefault(bool expandedByDefault)
Definition: entry.h:135
virtual EntryType type() const
Returns the type of the entry.
Definition: entry.h:120
Instances of the Entry class form a hierarchic data strucutre used to store account information...
Definition: entry.h:25