forked from boostorg/endian
Set up infrastructure, change to new names, clean up comments.
This commit is contained in:
@ -5,36 +5,21 @@
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef BOOST_ENDIAN_CONVERSION2_HPP
|
||||
#define BOOST_ENDIAN_CONVERSION2_HPP
|
||||
#ifndef BOOST_ENDIAN_CONVERTERS_HPP
|
||||
#define BOOST_ENDIAN_CONVERTERS_HPP
|
||||
|
||||
#include <boost/detail/endian.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
//
|
||||
// This header explores
|
||||
// -- value returning interface approach suggested by Phil Endecott.
|
||||
// -- additional reorder overloads for floating point types as requested by Vicente
|
||||
// Botet and others.
|
||||
// -- reorder implementation approach suggested by tymofey, with avoidance of
|
||||
// undefined behavior as suggested by Giovanni Piero Deretta, and a further
|
||||
// refinement suggested by Pyry Jahkola.
|
||||
// -- general reorder function template to meet requests for UDT support by
|
||||
// Vicente Botet and others.
|
||||
// -- general reorder function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard
|
||||
//
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------- synopsis ---------------------------------------//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian2
|
||||
namespace endian
|
||||
{
|
||||
// reverse byte order (i.e. endianness)
|
||||
// value returning interface approach suggested by Phil Endecott.
|
||||
|
||||
inline int16_t reorder(int16_t x);
|
||||
inline int32_t reorder(int32_t x);
|
||||
@ -43,6 +28,8 @@ namespace endian2
|
||||
inline uint32_t reorder(uint32_t x);
|
||||
inline uint64_t reorder(uint64_t x);
|
||||
|
||||
// additional reorder overloads for floating point types as requested by Vicente
|
||||
// Botet and others.
|
||||
// TODO: Need implementation
|
||||
// TODO: Need to verify the return does not invoke undefined behavior (as might happen
|
||||
// if there are unutterable floating point values, such as happens with the unutterable
|
||||
@ -50,20 +37,23 @@ namespace endian2
|
||||
inline float reorder(float x);
|
||||
inline double reorder(double x);
|
||||
|
||||
// TODO: Would pass by value be better for the following functions?
|
||||
// general reorder function template to meet requests for UDT support by Vicente
|
||||
// Botet and others.
|
||||
template <class T>
|
||||
inline T reorder(T x);
|
||||
|
||||
template <class T>
|
||||
inline T reorder(const T& x);
|
||||
|
||||
template <class T>
|
||||
inline T big(const T& x);
|
||||
inline T big(T x);
|
||||
// Return: x if native endianness is big, otherwise reorder(x);
|
||||
|
||||
template <class T>
|
||||
inline T little(const T& x);
|
||||
inline T little(T x);
|
||||
// Return: x if native endianness is little, otherwise reorder(x);
|
||||
|
||||
//----------------------------------- implementation -----------------------------------//
|
||||
// -- reorder implementation approach suggested by tymofey, with avoidance of
|
||||
// undefined behavior as suggested by Giovanni Piero Deretta, and a further
|
||||
// refinement suggested by Pyry Jahkola.
|
||||
|
||||
inline int16_t reorder(int16_t x)
|
||||
{
|
||||
@ -116,8 +106,10 @@ namespace endian2
|
||||
}
|
||||
|
||||
|
||||
// general reorder function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard
|
||||
template <class T>
|
||||
inline T reorder(const T& x)
|
||||
inline T reorder(T x)
|
||||
{
|
||||
T tmp;
|
||||
std::reverse(
|
||||
@ -147,7 +139,7 @@ namespace endian2
|
||||
# endif
|
||||
}
|
||||
|
||||
} // namespace endian2
|
||||
} // namespace endian
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_CONVERSION2_HPP
|
||||
#endif // BOOST_ENDIAN_CONVERTERS_HPP
|
||||
|
@ -9,12 +9,12 @@
|
||||
|
||||
#include <boost/endian/detail/disable_warnings.hpp>
|
||||
|
||||
#include <boost/endian/conversion2.hpp>
|
||||
#include <boost/endian/converters.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace be = boost::endian2;
|
||||
namespace be = boost::endian;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
81
test/msvc10/converter_test/converter_test.vcxproj
Normal file
81
test/msvc10/converter_test/converter_test.vcxproj
Normal file
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{EAE18F4D-AAF2-4C19-86FB-1144B5BD5993}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>converter_test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user