-
Notifications
You must be signed in to change notification settings - Fork 24
/
Sample.Manager.h
65 lines (53 loc) · 1.13 KB
/
Sample.Manager.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
#pragma once
#include <cassert>
#include <iostream>
#include <vector>
#include <utility>
#include "Sample.h"
class SampleManager
{
public:
SampleManager();
virtual ~SampleManager();
void add(const std::string& name, Sample* sample);
void run();
private:
std::vector<std::pair<Sample*, std::string>> m_samples;
};
SampleManager::SampleManager()
{
m_samples.clear();
}
SampleManager::~SampleManager()
{
for (auto& e : m_samples)
{
if (e.first != nullptr)
{
delete e.first;
}
}
m_samples.clear();
}
void SampleManager::add(const std::string& name, Sample* sample)
{
if (sample == nullptr || name.empty())
{
return;
}
m_samples.emplace_back(std::make_pair(sample, name));
}
void SampleManager::run()
{
for (auto& e : m_samples)
{
std::cout << std::endl;
std::cout << "--- [" << e.second << "] ---" << std::endl;
e.first->run();
std::cout << "--- [" << e.second << "] ---" << std::endl;
std::cout << std::endl;
}
}
#define VU_SM_INIT() SampleManager samples
#define VU_SM_ADD_SAMPLE(sample) samples.add(#sample, new sample ## _Sample)
#define VU_SM_RUN() samples.run()