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