Passwordfile library  3.1.4
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 { Normal, Password };
12 
13 class AccountEntry;
14 
16 public:
17  Field(AccountEntry *tiedAccount, const std::string &name = std::string(), const std::string &value = std::string());
18  Field(AccountEntry *tiedAccount, std::istream &stream);
19 
20  bool isEmpty() const;
21  const std::string &name() const;
22  void setName(const std::string &name);
23  const std::string &value() const;
24  void setValue(const std::string &value);
25  FieldType type() const;
26  void setType(FieldType type);
27  AccountEntry *tiedAccount() const;
28  void make(std::ostream &stream) const;
29  static bool isValidType(int number);
30 
31 private:
32  std::string m_name;
33  std::string m_value;
34  FieldType m_type;
35  AccountEntry *m_tiedAccount;
36 
37 protected:
38  std::string m_extendedData;
39 };
40 
44 inline bool Field::isEmpty() const
45 {
46  return m_name.empty() && m_value.empty();
47 }
48 
52 inline const std::string &Field::name() const
53 {
54  return m_name;
55 }
56 
60 inline void Field::setName(const std::string &name)
61 {
62  m_name = name;
63 }
64 
68 inline const std::string &Field::value() const
69 {
70  return m_value;
71 }
72 
76 inline void Field::setValue(const std::string &value)
77 {
78  m_value = value;
79 }
80 
84 inline FieldType Field::type() const
85 {
86  return m_type;
87 }
88 
92 inline void Field::setType(FieldType type)
93 {
94  m_type = type;
95 }
96 
101 {
102  return m_tiedAccount;
103 }
104 
108 inline bool Field::isValidType(int number)
109 {
110  return number >= 0 && number <= 1;
111 }
112 }
113 
114 #endif // FIELD_H
void setName(const std::string &name)
Sets the name.
Definition: field.h:60
static bool isValidType(int number)
Returns whether the specified number is a valid field type.
Definition: field.h:108
void setValue(const std::string &value)
Sets the value.
Definition: field.h:76
bool isEmpty() const
Returns an indication whether the entry is empty.
Definition: field.h:44
const std::string & value() const
Returns the value.
Definition: field.h:68
Contains all IO related classes.
FieldType type() const
Returns the type.
Definition: field.h:84
The Field class holds field information which consists of a name and a value and is able to serialize...
Definition: field.h:15
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.
void setType(FieldType type)
Sets the type.
Definition: field.h:92
std::string m_extendedData
Definition: field.h:38
FieldType
Definition: field.h:11
AccountEntry * tiedAccount() const
Returns the tied account.
Definition: field.h:100
const std::string & name() const
Returns the name.
Definition: field.h:52