Passwordfile library  5.0.6
C++ library to read/write passwords from/to encrypted files
field.h
Go to the documentation of this file.
1 #ifndef PASSWORD_FILE_IO_FIELD_H
2 #define PASSWORD_FILE_IO_FIELD_H
3 
4 #include "../global.h"
5 
6 #include <iostream>
7 #include <string>
8 
9 namespace Io {
10 
11 enum class FieldType : int { Normal, Password };
12 
13 class AccountEntry;
14 
16 public:
17  Field();
18  Field(AccountEntry *tiedAccount, const std::string &name = std::string(), const std::string &value = std::string());
19  Field(AccountEntry *tiedAccount, std::istream &stream);
20 
21  bool isEmpty() const;
22  const std::string &name() const;
23  void setName(const std::string &name);
24  const std::string &value() const;
25  void setValue(const std::string &value);
26  FieldType type() const;
27  void setType(FieldType type);
28  AccountEntry *tiedAccount() const;
29  void make(std::ostream &stream) const;
30  static bool isValidType(int number);
31 
32 private:
33  std::string m_name;
34  std::string m_value;
35  FieldType m_type;
36  AccountEntry *m_tiedAccount;
37 
38 protected:
39  std::string m_extendedData;
40 };
41 
42 inline Field::Field()
43  : m_type(FieldType::Normal)
44  , m_tiedAccount(nullptr)
45 {
46 }
47 
51 inline bool Field::isEmpty() const
52 {
53  return m_name.empty() && m_value.empty();
54 }
55 
59 inline const std::string &Field::name() const
60 {
61  return m_name;
62 }
63 
67 inline void Field::setName(const std::string &name)
68 {
69  m_name = name;
70 }
71 
75 inline const std::string &Field::value() const
76 {
77  return m_value;
78 }
79 
83 inline void Field::setValue(const std::string &value)
84 {
85  m_value = value;
86 }
87 
91 inline FieldType Field::type() const
92 {
93  return m_type;
94 }
95 
99 inline void Field::setType(FieldType type)
100 {
101  m_type = type;
102 }
103 
108 {
109  return m_tiedAccount;
110 }
111 
115 inline bool Field::isValidType(int number)
116 {
117  return number >= 0 && number <= 1;
118 }
119 } // namespace Io
120 
121 #endif // PASSWORD_FILE_IO_FIELD_H
The exception that is thrown when a parsing error occurs.
Definition: entry.h:170
The Field class holds field information which consists of a name and a value and is able to serialize...
Definition: field.h:15
void setName(const std::string &name)
Sets the name.
Definition: field.h:67
void setValue(const std::string &value)
Sets the value.
Definition: field.h:83
const std::string & name() const
Returns the name.
Definition: field.h:59
Field()
Definition: field.h:42
static bool isValidType(int number)
Returns whether the specified number is a valid field type.
Definition: field.h:115
const std::string & value() const
Returns the value.
Definition: field.h:75
void setType(FieldType type)
Sets the type.
Definition: field.h:99
bool isEmpty() const
Returns an indication whether the entry is empty.
Definition: field.h:51
FieldType type() const
Returns the type.
Definition: field.h:91
AccountEntry * tiedAccount() const
Returns the tied account.
Definition: field.h:107
std::string m_extendedData
Definition: field.h:39
#define PASSWORD_FILE_EXPORT
Marks the symbol to be exported by the passwordfile library.
Contains all IO related classes.
FieldType
Definition: field.h:11