MessagePack for C++
Loading...
Searching...
No Matches
fbuffer.hpp
Go to the documentation of this file.
1//
2// MessagePack for C++ FILE* buffer adaptor
3//
4// Copyright (C) 2013 Vladimir Volodko
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10#ifndef MSGPACK_V1_FBUFFER_HPP
11#define MSGPACK_V1_FBUFFER_HPP
12
14#include "msgpack/assert.hpp"
15
16#include <cstdio>
17#include <stdexcept>
18
19namespace msgpack {
20
24
25class fbuffer {
26public:
27 explicit fbuffer(FILE* file) : m_file(file) { }
28
29public:
30 void write(const char* buf, unsigned int len)
31 {
32 MSGPACK_ASSERT(buf || len == 0);
33 if (!buf) return;
34 if (1 != fwrite(buf, len, 1, m_file)) {
35 throw std::runtime_error("fwrite() failed");
36 }
37 }
38
39 FILE* file() const
40 {
41 return m_file;
42 }
43
44#if defined(MSGPACK_USE_CPP03)
45private:
46 fbuffer(const fbuffer&);
47 fbuffer& operator=(const fbuffer&);
48#else // defined(MSGPACK_USE_CPP03)
49 fbuffer(const fbuffer&) = delete;
50 fbuffer& operator=(const fbuffer&) = delete;
51#endif // defined(MSGPACK_USE_CPP03)
52
53private:
54 FILE* m_file;
55};
56
58} // MSGPACK_API_VERSION_NAMESPACE(v1)
60
61} // namespace msgpack
62
63#endif // MSGPACK_V1_FBUFFER_HPP
#define MSGPACK_ASSERT
Definition assert.hpp:22
Definition fbuffer.hpp:25
FILE * file() const
Definition fbuffer.hpp:39
fbuffer & operator=(const fbuffer &)=delete
fbuffer(FILE *file)
Definition fbuffer.hpp:27
void write(const char *buf, unsigned int len)
Definition fbuffer.hpp:30
fbuffer(const fbuffer &)=delete
Definition adaptor_base.hpp:15
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66