libdballe 9.6
value.h
1#ifndef DBALLE_VALUE_H
2#define DBALLE_VALUE_H
3
4#include <dballe/fwd.h>
5#include <wreport/varinfo.h>
6#include <memory>
7#include <iosfwd>
8
9namespace wreport {
10struct Var;
11}
12
13namespace dballe {
14
18class Value
19{
20protected:
21 wreport::Var* m_var = nullptr;
22
23public:
24 Value() = default;
25 Value(const Value& o);
26 Value(Value&& o) : m_var(o.m_var) { o.m_var = nullptr; }
27
29 Value(const wreport::Var& var);
30
32 Value(std::unique_ptr<wreport::Var>&& var) : m_var(var.release()) {}
33
34 ~Value();
35
36 Value& operator=(const Value& o);
37 Value& operator=(Value&& o);
38
39 bool operator==(const Value& o) const;
40 bool operator!=(const Value& o) const;
41
42 const wreport::Var* get() const { return m_var; }
43 wreport::Var* get() { return m_var; }
44
45 const wreport::Var* operator->() const { return m_var; }
46 wreport::Var* operator->() { return m_var; }
47
48 const wreport::Var& operator*() const { return *m_var; }
49 wreport::Var& operator*() { return *m_var; }
50
53
55 void reset(const wreport::Var& var);
56
58 void reset(std::unique_ptr<wreport::Var>&& var);
59
61 std::unique_ptr<wreport::Var> release();
62
64 void print(FILE* out) const;
65};
66
67
71struct DBValue : public Value
72{
73 using Value::Value;
74
76 int data_id = MISSING_INT;
77
78 DBValue() = default;
79 DBValue(const DBValue& o) = default;
80 DBValue(DBValue&& o) = default;
81
83 DBValue(int data_id, const wreport::Var& var)
84 : Value(var), data_id(data_id) {}
85
87 DBValue(int data_id, std::unique_ptr<wreport::Var>&& var)
88 : Value(std::move(var)), data_id(data_id) {}
89
90 DBValue& operator=(const DBValue&) = default;
91 DBValue& operator=(DBValue&&) = default;
92
93 bool operator==(const DBValue& o) const;
94 bool operator!=(const DBValue& o) const;
95
97 void print(FILE* out) const;
98};
99
100std::ostream& operator<<(std::ostream&, const Value&);
101std::ostream& operator<<(std::ostream&, const DBValue&);
102
103}
104
105#endif
Container for a wreport::Var pointer.
Definition: value.h:19
void print(FILE *out) const
Print the contents of this Value.
Value(std::unique_ptr< wreport::Var > &&var)
Construct from a wreport::Var, taking ownership of it.
Definition: value.h:32
void reset(const wreport::Var &var)
Fill from a wreport::Var.
Value(const wreport::Var &var)
Construct from a wreport::Var.
void reset(std::unique_ptr< wreport::Var > &&var)
Fill from a wreport::Var, taking ownership of it.
wreport::Varcode code() const
Return the varcode of the variable, or 0 if no variable has been set.
std::unique_ptr< wreport::Var > release()
Return the Var pointer, setting the Value to undefined.
uint16_t Varcode
Container for a wreport::Var pointer, and its database ID.
Definition: value.h:72
int data_id
Database ID of the value.
Definition: value.h:76
void print(FILE *out) const
Print the contents of this Value.
DBValue(int data_id, std::unique_ptr< wreport::Var > &&var)
Construct from a wreport::Var, taking ownership of it.
Definition: value.h:87
DBValue(int data_id, const wreport::Var &var)
Construct from a wreport::Var.
Definition: value.h:83