forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableContainer.h
More file actions
76 lines (55 loc) · 1.85 KB
/
VariableContainer.h
File metadata and controls
76 lines (55 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License
/*
* Implementation of the UCs B05 - B06
*/
#ifndef MO_VARIABLECONTAINER_H
#define MO_VARIABLECONTAINER_H
#include <MicroOcpp/Version.h>
#if MO_ENABLE_V201
#include <memory>
#include <MicroOcpp/Model/Variables/Variable.h>
#include <MicroOcpp/Core/FilesystemAdapter.h>
#include <MicroOcpp/Core/Memory.h>
namespace MicroOcpp {
class VariableContainer {
public:
~VariableContainer();
virtual size_t size() = 0;
virtual Variable *getVariable(size_t i) = 0;
virtual Variable *getVariable(const ComponentId& component, const char *variableName) = 0;
virtual bool commit();
};
class VariableContainerNonOwning : public VariableContainer, public MemoryManaged {
private:
Vector<Variable*> variables;
public:
VariableContainerNonOwning();
size_t size() override;
Variable *getVariable(size_t i) override;
Variable *getVariable(const ComponentId& component, const char *variableName) override;
bool add(Variable *variable);
};
class VariableContainerOwning : public VariableContainer, public MemoryManaged {
private:
Vector<std::unique_ptr<Variable>> variables;
std::shared_ptr<FilesystemAdapter> filesystem;
char *filename = nullptr;
uint16_t trackWriteCount = 0;
bool checkWriteCountUpdated();
bool loaded = false;
public:
VariableContainerOwning();
~VariableContainerOwning();
size_t size() override;
Variable *getVariable(size_t i) override;
Variable *getVariable(const ComponentId& component, const char *variableName) override;
bool add(std::unique_ptr<Variable> variable);
bool enablePersistency(std::shared_ptr<FilesystemAdapter> filesystem, const char *filename);
bool load(); //load variables from flash
bool commit() override;
};
} //end namespace MicroOcpp
#endif //MO_ENABLE_V201
#endif