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