mirror of
https://github.com/boostorg/endian.git
synced 2025-08-02 05:54:31 +02:00
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:
@@ -1,6 +1,6 @@
|
|||||||
// boost/binary_stream.hpp ----------------------------------------------------------//
|
// boost/binary_stream.hpp ----------------------------------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes, 2009
|
// Copyright Beman Dawes 2009
|
||||||
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// See http://www.boost.org/LICENSE_1_0.txt
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
@@ -16,10 +16,28 @@
|
|||||||
#include <cstring> // for strlen
|
#include <cstring> // for strlen
|
||||||
#include <cwchar> // for wcslen
|
#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
|
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
|
// 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)
|
inline std::istream& operator>=(std::istream& is, wchar_t& v)
|
||||||
{ return is.read( reinterpret_cast<char*>(&v), sizeof(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)
|
inline std::ostream& operator<=(std::ostream& os, const char* p)
|
||||||
{ return os.write( p, std::strlen(p)+1 ); }
|
{ 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) ); }
|
{ return os.write( reinterpret_cast<const char*>(s.c_str()), (s.size()+1)*sizeof(wchar_t) ); }
|
||||||
// TODO: provide input function
|
// TODO: provide input function
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // BOOST_BINARY_STREAM_HPP
|
#endif // BOOST_BINARY_STREAM_HPP
|
||||||
|
@@ -1,20 +1,38 @@
|
|||||||
// boost/integer/endian_io.hpp -------------------------------------------------------//
|
// boost/integer/endian_binary_stream.hpp --------------------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes, 2009
|
// Copyright Beman Dawes 2009
|
||||||
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// See http://www.boost.org/LICENSE_1_0.txt
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
// See library home page at http://www.boost.org/libs/endian
|
// See library home page at http://www.boost.org/libs/endian
|
||||||
|
|
||||||
#ifndef BOOST_ENDIAN_IO_HPP
|
#ifndef BOOST_ENDIAN_BINARY_STREAM_HPP
|
||||||
#define BOOST_ENDIAN_IO_HPP
|
#define BOOST_ENDIAN_BINARY_STREAM_HPP
|
||||||
|
|
||||||
#include <boost/integer/endian.hpp>
|
#include <boost/integer/endian.hpp>
|
||||||
#include <boost/utility/enable_if.hpp>
|
#include <boost/utility/enable_if.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <istream>
|
#include <istream>
|
||||||
|
|
||||||
|
// 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
|
namespace boost
|
||||||
{
|
{
|
||||||
namespace integer
|
namespace integer
|
||||||
@@ -98,19 +116,19 @@ namespace boost
|
|||||||
|
|
||||||
template < class Endian >
|
template < class Endian >
|
||||||
inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
|
inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
|
||||||
operator<<( std::ostream & os, const Endian & e )
|
operator<=( std::ostream & os, const Endian & e )
|
||||||
{
|
{
|
||||||
return os.write( reinterpret_cast<const char*>(&e), sizeof(e) );
|
return os.write( reinterpret_cast<const char*>(&e), sizeof(e) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template < class Endian >
|
template < class Endian >
|
||||||
inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
|
inline typename boost::enable_if< is_endian<Endian>, std::istream & >::type
|
||||||
operator>>( std::ostream & os, const Endian & e )
|
operator>=( std::istream & is, Endian & e )
|
||||||
{
|
{
|
||||||
return os.read( reinterpret_cast<const char*>(&e), sizeof(e) );
|
return is.read( reinterpret_cast<char*>(&e), sizeof(e) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace integer
|
} // namespace integer
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // BOOST_ENDIAN_IO_HPP
|
#endif // BOOST_ENDIAN_BINARY_STREAM_HPP
|
||||||
|
@@ -1,116 +0,0 @@
|
|||||||
// boost/integer/endian_io.hpp -------------------------------------------------------//
|
|
||||||
|
|
||||||
// Copyright Beman Dawes, 2009
|
|
||||||
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// See http://www.boost.org/LICENSE_1_0.txt
|
|
||||||
|
|
||||||
// See library home page at http://www.boost.org/libs/endian
|
|
||||||
|
|
||||||
#ifndef BOOST_ENDIAN_IO_HPP
|
|
||||||
#define BOOST_ENDIAN_IO_HPP
|
|
||||||
|
|
||||||
#include <boost/integer/endian.hpp>
|
|
||||||
#include <boost/utility/enable_if.hpp>
|
|
||||||
#include <ostream>
|
|
||||||
#include <istream>
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
namespace integer
|
|
||||||
{
|
|
||||||
template< class T > struct is_endian { static const bool value = false; };
|
|
||||||
|
|
||||||
template<> struct is_endian<big8_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big24_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big40_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big48_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big56_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<big64_t> { static const bool value = true; };
|
|
||||||
|
|
||||||
template<> struct is_endian<ubig8_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig24_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig40_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig48_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig56_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ubig64_t> { static const bool value = true; };
|
|
||||||
|
|
||||||
template<> struct is_endian<little8_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little24_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little40_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little48_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little56_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<little64_t> { static const bool value = true; };
|
|
||||||
|
|
||||||
template<> struct is_endian<ulittle8_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle24_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle40_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle48_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle56_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<ulittle64_t> { static const bool value = true; };
|
|
||||||
|
|
||||||
template<> struct is_endian<native8_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native24_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native40_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native48_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native56_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<native64_t> { static const bool value = true; };
|
|
||||||
|
|
||||||
template<> struct is_endian<unative8_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative24_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative40_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative48_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative56_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<unative64_t> { static const bool value = true; };
|
|
||||||
|
|
||||||
# if defined(BOOST_HAS_INT16_T)
|
|
||||||
template<> struct is_endian<aligned_big16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_ubig16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_little16_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_ulittle16_t> { static const bool value = true; };
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(BOOST_HAS_INT32_T)
|
|
||||||
template<> struct is_endian<aligned_big32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_ubig32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_little32_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_ulittle32_t> { static const bool value = true; };
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(BOOST_HAS_INT64_T)
|
|
||||||
template<> struct is_endian<aligned_big64_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_ubig64_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_little64_t> { static const bool value = true; };
|
|
||||||
template<> struct is_endian<aligned_ulittle64_t> { static const bool value = true; };
|
|
||||||
# endif
|
|
||||||
|
|
||||||
template < class Endian >
|
|
||||||
inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
|
|
||||||
operator<<( std::ostream & os, const Endian & e )
|
|
||||||
{
|
|
||||||
return os.write( reinterpret_cast<const char*>(&e), sizeof(e) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template < class Endian >
|
|
||||||
inline typename boost::enable_if< is_endian<Endian>, std::ostream & >::type
|
|
||||||
operator>>( std::ostream & os, const Endian & e )
|
|
||||||
{
|
|
||||||
return os.read( reinterpret_cast<const char*>(&e), sizeof(e) );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace integer
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#endif // BOOST_ENDIAN_IO_HPP
|
|
@@ -8,7 +8,7 @@
|
|||||||
// See library home page at http://www.boost.org/libs/endian
|
// See library home page at http://www.boost.org/libs/endian
|
||||||
|
|
||||||
#include <boost/integer/endian.hpp>
|
#include <boost/integer/endian.hpp>
|
||||||
#include <boost/integer/endian_io.hpp>
|
#include <boost/integer/endian_binary_stream.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
@@ -1,13 +1,12 @@
|
|||||||
// binary_test.cpp -------------------------------------------------------------------//
|
// binary_stream_test.cpp ------------------------------------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes, 2009
|
// Copyright Beman Dawes 2009
|
||||||
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// See http://www.boost.org/LICENSE_1_0.txt
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
#include <boost/binary_stream.hpp>
|
#include <boost/binary_stream.hpp>
|
||||||
#include <boost/cstdint.hpp>
|
#include <string>
|
||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
@@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "endian_hello_world", "endia
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "binary_stream_test", "binary_stream_test\binary_stream_test.vcproj", "{1382D085-FF3F-4573-8709-E10D3D74D620}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "binary_stream_test", "binary_stream_test\binary_stream_test.vcproj", "{1382D085-FF3F-4573-8709-E10D3D74D620}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "endian_binary_stream_test", "endian_binary_stream_test\endian_binary_stream_test.vcproj", "{AD46E04C-C1E1-446E-8D5F-E11B6C438181}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Win32 = Debug|Win32
|
Debug|Win32 = Debug|Win32
|
||||||
@@ -49,6 +51,10 @@ Global
|
|||||||
{1382D085-FF3F-4573-8709-E10D3D74D620}.Debug|Win32.Build.0 = Debug|Win32
|
{1382D085-FF3F-4573-8709-E10D3D74D620}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
{1382D085-FF3F-4573-8709-E10D3D74D620}.Release|Win32.ActiveCfg = Release|Win32
|
{1382D085-FF3F-4573-8709-E10D3D74D620}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
{1382D085-FF3F-4573-8709-E10D3D74D620}.Release|Win32.Build.0 = Release|Win32
|
{1382D085-FF3F-4573-8709-E10D3D74D620}.Release|Win32.Build.0 = Release|Win32
|
||||||
|
{AD46E04C-C1E1-446E-8D5F-E11B6C438181}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
|
{AD46E04C-C1E1-446E-8D5F-E11B6C438181}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
|
{AD46E04C-C1E1-446E-8D5F-E11B6C438181}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
|
{AD46E04C-C1E1-446E-8D5F-E11B6C438181}.Release|Win32.Build.0 = Release|Win32
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@@ -0,0 +1,195 @@
|
|||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="9.00"
|
||||||
|
Name="endian_binary_stream_test"
|
||||||
|
ProjectGUID="{AD46E04C-C1E1-446E-8D5F-E11B6C438181}"
|
||||||
|
RootNamespace="endian_binary_stream_test"
|
||||||
|
Keyword="Win32Proj"
|
||||||
|
TargetFrameworkVersion="196613"
|
||||||
|
>
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"
|
||||||
|
/>
|
||||||
|
</Platforms>
|
||||||
|
<ToolFiles>
|
||||||
|
</ToolFiles>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||||
|
IntermediateDirectory="$(ConfigurationName)"
|
||||||
|
ConfigurationType="1"
|
||||||
|
InheritedPropertySheets="..\common.vsprops"
|
||||||
|
CharacterSet="1"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||||
|
MinimalRebuild="true"
|
||||||
|
BasicRuntimeChecks="3"
|
||||||
|
RuntimeLibrary="3"
|
||||||
|
UsePrecompiledHeader="0"
|
||||||
|
WarningLevel="3"
|
||||||
|
DebugInformationFormat="4"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
LinkIncremental="2"
|
||||||
|
GenerateDebugInformation="true"
|
||||||
|
SubSystem="1"
|
||||||
|
TargetMachine="1"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManifestTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAppVerifierTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||||
|
IntermediateDirectory="$(ConfigurationName)"
|
||||||
|
ConfigurationType="1"
|
||||||
|
InheritedPropertySheets="..\common.vsprops"
|
||||||
|
CharacterSet="1"
|
||||||
|
WholeProgramOptimization="1"
|
||||||
|
>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="2"
|
||||||
|
EnableIntrinsicFunctions="true"
|
||||||
|
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||||
|
RuntimeLibrary="2"
|
||||||
|
EnableFunctionLevelLinking="true"
|
||||||
|
UsePrecompiledHeader="0"
|
||||||
|
WarningLevel="3"
|
||||||
|
DebugInformationFormat="3"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
LinkIncremental="1"
|
||||||
|
GenerateDebugInformation="true"
|
||||||
|
SubSystem="1"
|
||||||
|
OptimizeReferences="2"
|
||||||
|
EnableCOMDATFolding="2"
|
||||||
|
TargetMachine="1"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCALinkTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManifestTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXDCMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCBscMakeTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCFxCopTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAppVerifierTool"
|
||||||
|
/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"
|
||||||
|
/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="Source Files"
|
||||||
|
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||||
|
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath="..\..\endian_binary_stream_test.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Header Files"
|
||||||
|
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||||
|
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||||
|
>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Resource Files"
|
||||||
|
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||||
|
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||||
|
>
|
||||||
|
</Filter>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
289
libs/integer/test/endian_binary_stream_test.cpp
Normal file
289
libs/integer/test/endian_binary_stream_test.cpp
Normal file
@@ -0,0 +1,289 @@
|
|||||||
|
// endian_binary_stream_test.cpp -----------------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright Beman Dawes 2009
|
||||||
|
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/integer/endian_binary_stream.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
using namespace boost;
|
||||||
|
using namespace boost::integer;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
int errors = 0;
|
||||||
|
|
||||||
|
void verify( bool x, const char * file, int line )
|
||||||
|
{
|
||||||
|
if ( x ) return;
|
||||||
|
++errors;
|
||||||
|
cout << file << "(" << line << ") : error: predicate is false\n" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BOOST_VERIFY(predicate) verify( predicate, __FILE__, __LINE__ )
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::stringstream ss( std::ios_base::in | std::ios_base::out | std::ios_base::binary );
|
||||||
|
|
||||||
|
// big tests
|
||||||
|
|
||||||
|
big8_t big8_t_1(0x01), big8_t_2;
|
||||||
|
ss <= big8_t_1;
|
||||||
|
ss >= big8_t_2;
|
||||||
|
BOOST_VERIFY( big8_t_1 == big8_t_2 );
|
||||||
|
|
||||||
|
big16_t big16_t_1(0x0102), big16_t_2;
|
||||||
|
ss <= big16_t_1;
|
||||||
|
ss >= big16_t_2;
|
||||||
|
BOOST_VERIFY( big16_t_1 == big16_t_2 );
|
||||||
|
|
||||||
|
big24_t big24_t_1(0x010203L), big24_t_2;
|
||||||
|
ss <= big24_t_1;
|
||||||
|
ss >= big24_t_2;
|
||||||
|
BOOST_VERIFY( big24_t_1 == big24_t_2 );
|
||||||
|
|
||||||
|
big32_t big32_t_1(0x01020304L), big32_t_2;
|
||||||
|
ss <= big32_t_1;
|
||||||
|
ss >= big32_t_2;
|
||||||
|
BOOST_VERIFY( big32_t_1 == big32_t_2 );
|
||||||
|
|
||||||
|
big40_t big40_t_1(0x0102030405LL), big40_t_2;
|
||||||
|
ss <= big40_t_1;
|
||||||
|
ss >= big40_t_2;
|
||||||
|
BOOST_VERIFY( big40_t_1 == big40_t_2 );
|
||||||
|
|
||||||
|
big48_t big48_t_1(0x010203040506LL), big48_t_2;
|
||||||
|
ss <= big48_t_1;
|
||||||
|
ss >= big48_t_2;
|
||||||
|
BOOST_VERIFY( big48_t_1 == big48_t_2 );
|
||||||
|
|
||||||
|
big56_t big56_t_1(0x01020304050607LL), big56_t_2;
|
||||||
|
ss <= big56_t_1;
|
||||||
|
ss >= big56_t_2;
|
||||||
|
BOOST_VERIFY( big56_t_1 == big56_t_2 );
|
||||||
|
|
||||||
|
big64_t big64_t_1(0x0102030405060808LL), big64_t_2;
|
||||||
|
ss <= big64_t_1;
|
||||||
|
ss >= big64_t_2;
|
||||||
|
BOOST_VERIFY( big64_t_1 == big64_t_2 );
|
||||||
|
|
||||||
|
// ubig tests
|
||||||
|
|
||||||
|
ubig8_t ubig8_t_1(0x01), ubig8_t_2;
|
||||||
|
ss <= ubig8_t_1;
|
||||||
|
ss >= ubig8_t_2;
|
||||||
|
BOOST_VERIFY( ubig8_t_1 == ubig8_t_2 );
|
||||||
|
|
||||||
|
ubig16_t ubig16_t_1(0x0102), ubig16_t_2;
|
||||||
|
ss <= ubig16_t_1;
|
||||||
|
ss >= ubig16_t_2;
|
||||||
|
BOOST_VERIFY( ubig16_t_1 == ubig16_t_2 );
|
||||||
|
|
||||||
|
ubig24_t ubig24_t_1(0x010203L), ubig24_t_2;
|
||||||
|
ss <= ubig24_t_1;
|
||||||
|
ss >= ubig24_t_2;
|
||||||
|
BOOST_VERIFY( ubig24_t_1 == ubig24_t_2 );
|
||||||
|
|
||||||
|
ubig32_t ubig32_t_1(0x01020304L), ubig32_t_2;
|
||||||
|
ss <= ubig32_t_1;
|
||||||
|
ss >= ubig32_t_2;
|
||||||
|
BOOST_VERIFY( ubig32_t_1 == ubig32_t_2 );
|
||||||
|
|
||||||
|
ubig40_t ubig40_t_1(0x0102030405LL), ubig40_t_2;
|
||||||
|
ss <= ubig40_t_1;
|
||||||
|
ss >= ubig40_t_2;
|
||||||
|
BOOST_VERIFY( ubig40_t_1 == ubig40_t_2 );
|
||||||
|
|
||||||
|
ubig48_t ubig48_t_1(0x010203040506LL), ubig48_t_2;
|
||||||
|
ss <= ubig48_t_1;
|
||||||
|
ss >= ubig48_t_2;
|
||||||
|
BOOST_VERIFY( ubig48_t_1 == ubig48_t_2 );
|
||||||
|
|
||||||
|
ubig56_t ubig56_t_1(0x01020304050607LL), ubig56_t_2;
|
||||||
|
ss <= ubig56_t_1;
|
||||||
|
ss >= ubig56_t_2;
|
||||||
|
BOOST_VERIFY( ubig56_t_1 == ubig56_t_2 );
|
||||||
|
|
||||||
|
ubig64_t ubig64_t_1(0x0102030405060808LL), ubig64_t_2;
|
||||||
|
ss <= ubig64_t_1;
|
||||||
|
ss >= ubig64_t_2;
|
||||||
|
BOOST_VERIFY( ubig64_t_1 == ubig64_t_2 );
|
||||||
|
|
||||||
|
// little tests
|
||||||
|
|
||||||
|
little8_t little8_t_1(0x01), little8_t_2;
|
||||||
|
ss <= little8_t_1;
|
||||||
|
ss >= little8_t_2;
|
||||||
|
BOOST_VERIFY( little8_t_1 == little8_t_2 );
|
||||||
|
|
||||||
|
little16_t little16_t_1(0x0102), little16_t_2;
|
||||||
|
ss <= little16_t_1;
|
||||||
|
ss >= little16_t_2;
|
||||||
|
BOOST_VERIFY( little16_t_1 == little16_t_2 );
|
||||||
|
|
||||||
|
little24_t little24_t_1(0x010203L), little24_t_2;
|
||||||
|
ss <= little24_t_1;
|
||||||
|
ss >= little24_t_2;
|
||||||
|
BOOST_VERIFY( little24_t_1 == little24_t_2 );
|
||||||
|
|
||||||
|
little32_t little32_t_1(0x01020304L), little32_t_2;
|
||||||
|
ss <= little32_t_1;
|
||||||
|
ss >= little32_t_2;
|
||||||
|
BOOST_VERIFY( little32_t_1 == little32_t_2 );
|
||||||
|
|
||||||
|
little40_t little40_t_1(0x0102030405LL), little40_t_2;
|
||||||
|
ss <= little40_t_1;
|
||||||
|
ss >= little40_t_2;
|
||||||
|
BOOST_VERIFY( little40_t_1 == little40_t_2 );
|
||||||
|
|
||||||
|
little48_t little48_t_1(0x010203040506LL), little48_t_2;
|
||||||
|
ss <= little48_t_1;
|
||||||
|
ss >= little48_t_2;
|
||||||
|
BOOST_VERIFY( little48_t_1 == little48_t_2 );
|
||||||
|
|
||||||
|
little56_t little56_t_1(0x01020304050607LL), little56_t_2;
|
||||||
|
ss <= little56_t_1;
|
||||||
|
ss >= little56_t_2;
|
||||||
|
BOOST_VERIFY( little56_t_1 == little56_t_2 );
|
||||||
|
|
||||||
|
little64_t little64_t_1(0x0102030405060808LL), little64_t_2;
|
||||||
|
ss <= little64_t_1;
|
||||||
|
ss >= little64_t_2;
|
||||||
|
BOOST_VERIFY( little64_t_1 == little64_t_2 );
|
||||||
|
|
||||||
|
// ulittle tests
|
||||||
|
|
||||||
|
ulittle8_t ulittle8_t_1(0x01), ulittle8_t_2;
|
||||||
|
ss <= ulittle8_t_1;
|
||||||
|
ss >= ulittle8_t_2;
|
||||||
|
BOOST_VERIFY( ulittle8_t_1 == ulittle8_t_2 );
|
||||||
|
|
||||||
|
ulittle16_t ulittle16_t_1(0x0102), ulittle16_t_2;
|
||||||
|
ss <= ulittle16_t_1;
|
||||||
|
ss >= ulittle16_t_2;
|
||||||
|
BOOST_VERIFY( ulittle16_t_1 == ulittle16_t_2 );
|
||||||
|
|
||||||
|
ulittle24_t ulittle24_t_1(0x010203L), ulittle24_t_2;
|
||||||
|
ss <= ulittle24_t_1;
|
||||||
|
ss >= ulittle24_t_2;
|
||||||
|
BOOST_VERIFY( ulittle24_t_1 == ulittle24_t_2 );
|
||||||
|
|
||||||
|
ulittle32_t ulittle32_t_1(0x01020304L), ulittle32_t_2;
|
||||||
|
ss <= ulittle32_t_1;
|
||||||
|
ss >= ulittle32_t_2;
|
||||||
|
BOOST_VERIFY( ulittle32_t_1 == ulittle32_t_2 );
|
||||||
|
|
||||||
|
ulittle40_t ulittle40_t_1(0x0102030405LL), ulittle40_t_2;
|
||||||
|
ss <= ulittle40_t_1;
|
||||||
|
ss >= ulittle40_t_2;
|
||||||
|
BOOST_VERIFY( ulittle40_t_1 == ulittle40_t_2 );
|
||||||
|
|
||||||
|
ulittle48_t ulittle48_t_1(0x010203040506LL), ulittle48_t_2;
|
||||||
|
ss <= ulittle48_t_1;
|
||||||
|
ss >= ulittle48_t_2;
|
||||||
|
BOOST_VERIFY( ulittle48_t_1 == ulittle48_t_2 );
|
||||||
|
|
||||||
|
ulittle56_t ulittle56_t_1(0x01020304050607LL), ulittle56_t_2;
|
||||||
|
ss <= ulittle56_t_1;
|
||||||
|
ss >= ulittle56_t_2;
|
||||||
|
BOOST_VERIFY( ulittle56_t_1 == ulittle56_t_2 );
|
||||||
|
|
||||||
|
ulittle64_t ulittle64_t_1(0x0102030405060808LL), ulittle64_t_2;
|
||||||
|
ss <= ulittle64_t_1;
|
||||||
|
ss >= ulittle64_t_2;
|
||||||
|
BOOST_VERIFY( ulittle64_t_1 == ulittle64_t_2 );
|
||||||
|
|
||||||
|
// native tests
|
||||||
|
|
||||||
|
native8_t native8_t_1(0x01), native8_t_2;
|
||||||
|
ss <= native8_t_1;
|
||||||
|
ss >= native8_t_2;
|
||||||
|
BOOST_VERIFY( native8_t_1 == native8_t_2 );
|
||||||
|
|
||||||
|
native16_t native16_t_1(0x0102), native16_t_2;
|
||||||
|
ss <= native16_t_1;
|
||||||
|
ss >= native16_t_2;
|
||||||
|
BOOST_VERIFY( native16_t_1 == native16_t_2 );
|
||||||
|
|
||||||
|
native24_t native24_t_1(0x010203L), native24_t_2;
|
||||||
|
ss <= native24_t_1;
|
||||||
|
ss >= native24_t_2;
|
||||||
|
BOOST_VERIFY( native24_t_1 == native24_t_2 );
|
||||||
|
|
||||||
|
native32_t native32_t_1(0x01020304L), native32_t_2;
|
||||||
|
ss <= native32_t_1;
|
||||||
|
ss >= native32_t_2;
|
||||||
|
BOOST_VERIFY( native32_t_1 == native32_t_2 );
|
||||||
|
|
||||||
|
native40_t native40_t_1(0x0102030405LL), native40_t_2;
|
||||||
|
ss <= native40_t_1;
|
||||||
|
ss >= native40_t_2;
|
||||||
|
BOOST_VERIFY( native40_t_1 == native40_t_2 );
|
||||||
|
|
||||||
|
native48_t native48_t_1(0x010203040506LL), native48_t_2;
|
||||||
|
ss <= native48_t_1;
|
||||||
|
ss >= native48_t_2;
|
||||||
|
BOOST_VERIFY( native48_t_1 == native48_t_2 );
|
||||||
|
|
||||||
|
native56_t native56_t_1(0x01020304050607LL), native56_t_2;
|
||||||
|
ss <= native56_t_1;
|
||||||
|
ss >= native56_t_2;
|
||||||
|
BOOST_VERIFY( native56_t_1 == native56_t_2 );
|
||||||
|
|
||||||
|
native64_t native64_t_1(0x0102030405060808LL), native64_t_2;
|
||||||
|
ss <= native64_t_1;
|
||||||
|
ss >= native64_t_2;
|
||||||
|
BOOST_VERIFY( native64_t_1 == native64_t_2 );
|
||||||
|
|
||||||
|
// unative tests
|
||||||
|
|
||||||
|
unative8_t unative8_t_1(0x01), unative8_t_2;
|
||||||
|
ss <= unative8_t_1;
|
||||||
|
ss >= unative8_t_2;
|
||||||
|
BOOST_VERIFY( unative8_t_1 == unative8_t_2 );
|
||||||
|
|
||||||
|
unative16_t unative16_t_1(0x0102), unative16_t_2;
|
||||||
|
ss <= unative16_t_1;
|
||||||
|
ss >= unative16_t_2;
|
||||||
|
BOOST_VERIFY( unative16_t_1 == unative16_t_2 );
|
||||||
|
|
||||||
|
unative24_t unative24_t_1(0x010203L), unative24_t_2;
|
||||||
|
ss <= unative24_t_1;
|
||||||
|
ss >= unative24_t_2;
|
||||||
|
BOOST_VERIFY( unative24_t_1 == unative24_t_2 );
|
||||||
|
|
||||||
|
unative32_t unative32_t_1(0x01020304L), unative32_t_2;
|
||||||
|
ss <= unative32_t_1;
|
||||||
|
ss >= unative32_t_2;
|
||||||
|
BOOST_VERIFY( unative32_t_1 == unative32_t_2 );
|
||||||
|
|
||||||
|
unative40_t unative40_t_1(0x0102030405LL), unative40_t_2;
|
||||||
|
ss <= unative40_t_1;
|
||||||
|
ss >= unative40_t_2;
|
||||||
|
BOOST_VERIFY( unative40_t_1 == unative40_t_2 );
|
||||||
|
|
||||||
|
unative48_t unative48_t_1(0x010203040506LL), unative48_t_2;
|
||||||
|
ss <= unative48_t_1;
|
||||||
|
ss >= unative48_t_2;
|
||||||
|
BOOST_VERIFY( unative48_t_1 == unative48_t_2 );
|
||||||
|
|
||||||
|
unative56_t unative56_t_1(0x01020304050607LL), unative56_t_2;
|
||||||
|
ss <= unative56_t_1;
|
||||||
|
ss >= unative56_t_2;
|
||||||
|
BOOST_VERIFY( unative56_t_1 == unative56_t_2 );
|
||||||
|
|
||||||
|
unative64_t unative64_t_1(0x0102030405060808LL), unative64_t_2;
|
||||||
|
ss <= unative64_t_1;
|
||||||
|
ss >= unative64_t_2;
|
||||||
|
BOOST_VERIFY( unative64_t_1 == unative64_t_2 );
|
||||||
|
|
||||||
|
cout << errors << " error(s) detected\n";
|
||||||
|
return errors;
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
// endian_test.cpp ---------------------------------------------------------//
|
// endian_test.cpp ---------------------------------------------------------//
|
||||||
|
|
||||||
// Copyright Beman Dawes, 1999-2008
|
// Copyright Beman Dawes 1999-2008
|
||||||
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// See http://www.boost.org/LICENSE_1_0.txt
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
Reference in New Issue
Block a user