Bond
 
Loading...
Searching...
No Matches
stdio_output_stream.h
1// Copyright (c) Microsoft. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4#pragma once
5
6#include <bond/core/config.h>
7
8#include "output_buffer.h"
9
10#include <bond/core/blob.h>
11
12#include <stdio.h>
13#include <stdint.h>
14
15namespace bond
16{
17
18class StdioOutputStream
19{
20public:
21 StdioOutputStream(FILE* file)
22 : _file(file)
23 {}
24
25 template<typename T>
26 void Write(const T& value)
27 {
28 Write(&value, sizeof(value));
29 }
30
31 void Write(const blob& buffer)
32 {
33 Write(buffer.data(), buffer.length());
34 }
35
36 void Write(const void* value, uint32_t size)
37 {
38 fwrite(value, size, 1, _file);
39 }
40
41protected:
42 FILE* _file;
43};
44
45
46// Returns a default OutputBuffer since StdioOutputStream is not capable
47// of holding a memory buffer.
48inline OutputBuffer CreateOutputBuffer(const StdioOutputStream& /*other*/)
49{
50 return OutputBuffer();
51}
52
53}
namespace bond
Definition: apply.h:17
OutputMemoryStream OutputBuffer
Type alias for memory backed output stream using std::allocator.
Definition: output_buffer.h:386