Endian: Rename endian_io.hpp -> endian_binary_stream.hpp for consistency. Add binary_stream_test, miscellaneous polish.

git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@51783 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
bemandawes committed 2009-03-15 13:28:43 +00:00
1 parent 815bdaabcd
commit 8ddc12967c
9 files changed
+543 -135

No files matched your search

+21 -4
View File
@@ -1,6 +1,6 @@
// boost/binary_stream.hpp ----------------------------------------------------------//
// Copyright Beman Dawes, 2009
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
@@ -16,10 +16,28 @@
#include <cstring> // for strlen
#include <cwchar> // for wcslen
// unformatted binary (as opposed to formatted character-set) input and output
// Caution: Use only on streams opened with filemode std::ios_base::binary. Thus
// unformatted binary I/O should not be with the standard streams (cout, cin, etc.)
// since they are opened in text mode. Use on text streams may produce incorrect
// results, such as insertion of unwanted characters or premature end-of-file.
// For example, on Windows 0x0D would become 0x0D, 0x0A.
// Caution: When mixing formatted (i.e. operator << or >>) and unformatted (i.e.
// operator <= or >=) be aware that << and >> take precedence over <= and >=. Use
// parentheses to force correct order of evaluation. For example:
//
// my_stream << foo <= bar; // no parentheses needed
// (my_stream <= foo) << bar; // parentheses required
// This implementation uses reinterpret_cast<>() when needed to convert one pointer
// type to another. See 5.2.10 [expr.reinterpret.cast], Reinterpret cast, para 7.
namespace boost
{
// binary input and output for built-in types
// built-in types ------------------------------------------------------------------//
// omission of bool and void* is deliberate; any semantics would be questionable
@@ -98,7 +116,7 @@ namespace boost
inline std::istream& operator>=(std::istream& is, wchar_t& v)
{ return is.read( reinterpret_cast<char*>(&v), sizeof(v) ); }
// binary input and output for strings
// strings -------------------------------------------------------------------------//
inline std::ostream& operator<=(std::ostream& os, const char* p)
{ return os.write( p, std::strlen(p)+1 ); }
@@ -124,7 +142,6 @@ namespace boost
{ return os.write( reinterpret_cast<const char*>(s.c_str()), (s.size()+1)*sizeof(wchar_t) ); }
// TODO: provide input function
} // namespace boost
#endif // BOOST_BINARY_STREAM_HPP