aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/jinja2cpp/src/out_stream.h
blob: 8e3f001ba97cf1ebd055a1f698e138f3a2d9ec9b (plain) (blame)
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
#ifndef JINJA2CPP_SRC_OUT_STREAM_H
#define JINJA2CPP_SRC_OUT_STREAM_H

#include "internal_value.h"

#include <functional>
#include <iostream>
#include <sstream>

namespace jinja2
{
class OutStream
{
public:
    struct StreamWriter
    {
        virtual ~StreamWriter() {}

        virtual void WriteBuffer(const void* ptr, size_t length) = 0;
        virtual void WriteValue(const InternalValue &val) = 0;
    };

    OutStream(std::function<StreamWriter*()> writerGetter)
        : m_writerGetter(std::move(writerGetter))
    {}

    void WriteBuffer(const void* ptr, size_t length)
    {
        m_writerGetter()->WriteBuffer(ptr, length);
    }

    void WriteValue(const InternalValue& val)
    {
        m_writerGetter()->WriteValue(val);
    }

private:
    std::function<StreamWriter*()> m_writerGetter;
};

} // namespace jinja2

#endif // JINJA2CPP_SRC_OUT_STREAM_H