-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStaticVariant.cpp
More file actions
64 lines (52 loc) · 1.59 KB
/
StaticVariant.cpp
File metadata and controls
64 lines (52 loc) · 1.59 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
// ===========================================================================
// StaticVariant.cpp // class StaticTextProcessor
// ===========================================================================
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <memory>
#include "RenderListStrategy.h"
#include "RenderHtmlListStrategy.h"
#include "RenderMarkdownListStrategy.h"
#include "RenderTextProcessor.h"
template <typename LS>
class StaticTextProcessor
{
private:
std::ostringstream m_oss;
std::unique_ptr<LS> m_listStrategy;
public:
StaticTextProcessor()
{
m_listStrategy = std::make_unique<LS>();
}
void clear() {
m_oss.str("");
m_oss.clear();
}
void appendList(const std::vector <std::string> items)
{
m_listStrategy->start(m_oss);
for (auto& item : items)
m_listStrategy->add(m_oss, item);
m_listStrategy->end(m_oss);
}
std::string toString() const {
return m_oss.str();
}
};
void test_render_app_statically()
{
// 'markdown' strategy
StaticTextProcessor<RenderMarkdownListStrategy> tpMarkdown;
tpMarkdown.appendList({ "foo", "bar", "baz" });
std::cout << tpMarkdown.toString() << std::endl;
// 'html' strategy
StaticTextProcessor<RenderHtmlListStrategy> tpHtml;
tpHtml.appendList({ "FOO", "BAR", "BAZ" });
std::cout << tpHtml.toString() << std::endl;
}
// ===========================================================================
// End-of-File
// ===========================================================================