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
15#include <cstdio>
16#include <stdexcept>
17
18namespace msgpack {
19
23
24class fbuffer {
25public:
26 explicit fbuffer(FILE* file) : m_file(file) { }
27
28public:
29 void write(const char* buf, unsigned int len)
30 {
31 if (1 != fwrite(buf, len, 1, m_file)) {
32 throw std::runtime_error("fwrite() failed");
33 }
34 }
35
36 FILE* file() const
37 {
38 return m_file;
39 }
40
41#if defined(MSGPACK_USE_CPP03)
42private:
43 fbuffer(const fbuffer&);
44 fbuffer& operator=(const fbuffer&);
45#else // defined(MSGPACK_USE_CPP03)
46 fbuffer(const fbuffer&) = delete;
47 fbuffer& operator=(const fbuffer&) = delete;
48#endif // defined(MSGPACK_USE_CPP03)
49
50private:
51 FILE* m_file;
52};
53
55} // MSGPACK_API_VERSION_NAMESPACE(v1)
57
58} // namespace msgpack
59
60#endif // MSGPACK_V1_FBUFFER_HPP
Definition fbuffer.hpp:24
FILE * file() const
Definition fbuffer.hpp:36
fbuffer & operator=(const fbuffer &)=delete
fbuffer(FILE *file)
Definition fbuffer.hpp:26
void write(const char *buf, unsigned int len)
Definition fbuffer.hpp:29
fbuffer(const fbuffer &)=delete
Definition adaptor_base.hpp:15
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:58