Hideaki Tai / msgpack-embedded

Dependents:   hello_message_pack

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fbuffer.hpp Source File

fbuffer.hpp

00001 //
00002 // MessagePack for C++ FILE* buffer adaptor
00003 //
00004 // Copyright (C) 2013 Vladimir Volodko
00005 //
00006 //    Distributed under the Boost Software License, Version 1.0.
00007 //    (See accompanying file LICENSE_1_0.txt or copy at
00008 //    http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 #ifndef MSGPACK_FBUFFER_HPP__
00011 #define MSGPACK_FBUFFER_HPP__
00012 
00013 #include "msgpack/versioning.hpp"
00014 
00015 #include <cstdio>
00016 #include <stdexcept>
00017 
00018 namespace msgpack {
00019 
00020 /// @cond
00021 MSGPACK_API_VERSION_NAMESPACE(v1) {
00022 /// @endcond
00023 
00024 class fbuffer {
00025 public:
00026     explicit fbuffer(FILE* file) : m_file(file) { }
00027 
00028 public:
00029     void write(const char* buf, unsigned int len)
00030     {
00031         if (1 != fwrite(buf, len, 1, m_file)) {
00032             throw std::runtime_error("fwrite() failed");
00033         }
00034     }
00035 
00036     FILE* file() const
00037     {
00038         return m_file;
00039     }
00040 
00041 #if defined(MSGPACK_USE_CPP03)
00042 private:
00043     fbuffer(const fbuffer&);
00044     fbuffer& operator=(const fbuffer&);
00045 #else  // defined(MSGPACK_USE_CPP03)
00046     fbuffer(const fbuffer&) = delete;
00047     fbuffer& operator=(const fbuffer&) = delete;
00048 #endif // defined(MSGPACK_USE_CPP03)
00049 
00050 private:
00051     FILE* m_file;
00052 };
00053 
00054 /// @cond
00055 }  // MSGPACK_API_VERSION_NAMESPACE(v1)
00056 /// @endcond
00057 
00058 }  // namespace msgpack
00059 
00060 #endif /* msgpack/fbuffer.hpp */