Passwordfile library 5.0.12
C++ library to read/write passwords from/to encrypted files
Loading...
Searching...
No Matches
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
9namespace Io {
10
11enum class FieldType : int { Normal, Password };
12
13class AccountEntry;
14
16public:
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
32private:
33 std::string m_name;
34 std::string m_value;
35 FieldType m_type;
36 AccountEntry *m_tiedAccount;
37
38protected:
39 std::string m_extendedData;
40};
41
43 : m_type(FieldType::Normal)
44 , m_tiedAccount(nullptr)
45{
46}
47
51inline bool Field::isEmpty() const
52{
53 return m_name.empty() && m_value.empty();
54}
55
59inline const std::string &Field::name() const
60{
61 return m_name;
62}
63
67inline void Field::setName(const std::string &name)
68{
69 m_name = name;
70}
71
75inline const std::string &Field::value() const
76{
77 return m_value;
78}
79
83inline void Field::setValue(const std::string &value)
84{
85 m_value = value;
86}
87
91inline FieldType Field::type() const
92{
93 return m_type;
94}
95
99inline void Field::setType(FieldType type)
100{
101 m_type = type;
102}
103
108{
109 return m_tiedAccount;
110}
111
115inline 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.
Definition global.h:14
Contains all IO related classes.
FieldType
Definition field.h:11