fbuffer.hpp
Go to the documentation of this file.
//
// MessagePack for C++ FILE* buffer adaptor
//
// Copyright (C) 2013 Vladimir Volodko
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_V1_FBUFFER_HPP
#define MSGPACK_V1_FBUFFER_HPP
#include "msgpack/v1/fbuffer_decl.hpp"
#include <cstdio>
#include <stdexcept>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class fbuffer {
public:
explicit fbuffer(FILE* file) : m_file(file) { }
public:
void write(const char* buf, unsigned int len)
{
if (1 != fwrite(buf, len, 1, m_file)) {
throw std::runtime_error("fwrite() failed");
}
}
FILE* file() const
{
return m_file;
}
#if defined(MSGPACK_USE_CPP03)
private:
fbuffer(const fbuffer&);
fbuffer& operator=(const fbuffer&);
#else // defined(MSGPACK_USE_CPP03)
fbuffer(const fbuffer&) = delete;
fbuffer& operator=(const fbuffer&) = delete;
#endif // defined(MSGPACK_USE_CPP03)
private:
FILE* m_file;
};
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_FBUFFER_HPP
msgpack::fbuffer::operator=
fbuffer & operator=(const fbuffer &)=delete
fbuffer_decl.hpp
msgpack
Definition: adaptor_base.hpp:15
msgpack::fbuffer
Definition: fbuffer.hpp:24
msgpack::fbuffer::file
FILE * file() const
Definition: fbuffer.hpp:36
msgpack::fbuffer::write
void write(const char *buf, unsigned int len)
Definition: fbuffer.hpp:29
msgpack::fbuffer::fbuffer
fbuffer(FILE *file)
Definition: fbuffer.hpp:26
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58