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