forked from jdnc/nao-robots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.h
67 lines (55 loc) · 1.9 KB
/
Module.h
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
#ifndef MODULE_NNIRD0YI
#define MODULE_NNIRD0YI
#include <string>
#include <vector>
#include <iostream>
#include <memory/MemoryBlock.h>
#include <memory/Memory.h>
#include <memory/TextLogger.h>
#include <memory/FrameInfoBlock.h>
class Module {
public:
Module ();
void init(Memory *memory, TextLogger* tl);
virtual void initSpecificModule() {};
void updateModuleMemory(Memory *memory);
// Did all required blocks load
bool isMemorySatisfied() { return memory_satisfied_; };
protected:
void requiresMemoryBlock(const std::string &name);
void providesMemoryBlock(const std::string &name);
virtual void specifyMemoryDependency() = 0;
virtual void specifyMemoryBlocks() = 0;
Memory *memory_; // Should go private once we remove bhuman walk module
TextLogger* textlogger;
protected:
template <class T>
void getMemoryBlock(T *&ptr, const std::string &name){
for (unsigned int i = 0; i < required_blocks_.size(); i++) {
if (required_blocks_[i] == name) {
bool ok = memory_->getBlockByName(ptr,name);
if (!ok) memory_satisfied_ = false;
return;
}
}
std::cerr << "Module::getMemoryBlock - ERROR: tried to get a memory block that was not required: " << name << std::endl;
return;
}
template <class T>
void getOrAddMemoryBlock(T *&ptr, const std::string &name) {
for (unsigned int i = 0; i < required_blocks_.size(); i++) {
if (required_blocks_[i] == name) {
bool ok = memory_->getOrAddBlockByName(ptr,name);
if (!ok) memory_satisfied_ = false;
return;
}
}
std::cerr << "Module::getMemoryBlock - ERROR: tried to get a memory block that was not required: " << name << std::endl;
return;
}
private:
std::vector<std::string> required_blocks_;
std::vector<std::string> provided_blocks_;
bool memory_satisfied_; // Have all required blocks loaded
};
#endif /* end of include guard: MODULE_NNIRD0YI */