diff --git a/boost/binary_stream.hpp b/boost/binary_stream.hpp new file mode 100644 index 0000000..1dedebd --- /dev/null +++ b/boost/binary_stream.hpp @@ -0,0 +1,138 @@ +// boost/binary_stream.hpp ----------------------------------------------------------// + +// Copyright Beman Dawes, 2009 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See documentation at http://www.boost.org/libs/utility + +#ifndef BOOST_BINARY_STREAM_HPP +#define BOOST_BINARY_STREAM_HPP + +#include +#include + +namespace boost +{ + + // binary output for built-in types + + // omission of bool is deliberate; semantics undecided + inline std::ostream& operator<=(std::ostream& os, short v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, unsigned short v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, int v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, unsigned int v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, long v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, unsigned long v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, long long v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, unsigned long long v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, float v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, double v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, long double v) + { return os.write( reinterpret_cast(&v), sizeof(v) ); } + inline std::ostream& operator<=(std::ostream& os, const void* p) + { return os.write( static_cast(p), sizeof(p) ); } + inline std::ostream& operator<=(std::ostream& os, char c) + { return os.put( c ); } + inline std::ostream& operator<=(std::ostream& os, signed char c) + { return os.put( c ); } + inline std::ostream& operator<=(std::ostream& os, unsigned char c) + { return os.put( c ); } + inline std::ostream& operator<=(std::ostream& os, const char* p) + { return os.write( p, std::strlen(p)+1 ); } + inline std::ostream& operator<=(std::ostream& os, const signed char* p) + { return os.write( static_cast(p), std::strlen(p)+1 ); } + inline std::ostream& operator<=(std::ostream& os, const unsigned char* p) + { return os.write( static_cast(p), std::strlen(p)+1 ); } + + +//// 27.6.2.6 Formatted output: +//basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)); +//basic_ostream& operator<<(basic_ios& (*pf)(basic_ios&)); +//basic_ostream& operator<<(ios_base& (*pf)(ios_base&)); +//basic_ostream& operator<<(bool n); +//basic_ostream& operator<<(short n); +//basic_ostream& operator<<(unsigned short n); +//basic_ostream& operator<<(int n); +//basic_ostream& operator<<(unsigned int n); +//basic_ostream& operator<<(long n); +//basic_ostream& operator<<(unsigned long n); +//basic_ostream& operator<<(long long n); +//basic_ostream& operator<<(unsigned long long n); +//basic_ostream& operator<<(float f); +//basic_ostream& operator<<(double f); +//basic_ostream& operator<<(long double f); +//basic_ostream& operator<<(const void* p); +//basic_ostream& operator<<(basic_streambuf* sb); +// +//// 27.6.2.6.4 character inserters +//template +//basic_ostream& operator<<(basic_ostream&, charT); +//template +//basic_ostream& operator<<(basic_ostream&&, charT); +//template +//basic_ostream& operator<<(basic_ostream&, char); +//template +//basic_ostream& operator<<(basic_ostream&&, char); +//template +//basic_ostream& operator<<(basic_ostream&, char); +//template +//basic_ostream& operator<<(basic_ostream&&, char); +// +//// signed and unsigned +//template +//basic_ostream& operator<<(basic_ostream&, signed char); +//template +//basic_ostream& operator<<(basic_ostream&&, signed char); +//template +//basic_ostream& operator<<(basic_ostream&, unsigned char); +//template +//basic_ostream& operator<<(basic_ostream&&, unsigned char); +// +//template +//basic_ostream& operator<<(basic_ostream&, const charT*); +//template +//basic_ostream& operator<<(basic_ostream&&, const charT*); +//template +//basic_ostream& operator<<(basic_ostream&, const char*); +//template +//basic_ostream& operator<<(basic_ostream&&, const char*); +//template +//basic_ostream& operator<<(basic_ostream&, const char*); +//template +//basic_ostream& operator<<(basic_ostream&&, const char*); +// +//// signed and unsigned +//template +//basic_ostream& operator<<(basic_ostream&, const signed char*); +//template +//basic_ostream& operator<<(basic_ostream&&, const signed char*); +//template +//basic_ostream& operator<<(basic_ostream&, const unsigned char*); +//template +//basic_ostream& operator<<(basic_ostream&&, const unsigned char*); +// +//// 21.3.8.9: inserters and extractors +//template +//basic_istream& operator>>(basic_istream&& is, basic_string& str); +//template +//basic_ostream& operator<<(basic_ostream&& os, const basic_string& str); +//template +//basic_istream& getline(basic_istream&& is, basic_string& str, charT delim); +//template +//basic_istream& getline(basic_istream&& is, basic_string& str); + +} // namespace boost + +#endif // BOOST_BINARY_STREAM_HPP