mirror of
https://github.com/boostorg/endian.git
synced 2025-07-30 12:37:24 +02:00
Add use_cases.cpp
This commit is contained in:
73
example/use_cases.cpp
Normal file
73
example/use_cases.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// endian/example/uses_cases.cpp -----------------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright Beman Dawes 2014
|
||||||
|
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
#define _SCL_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
|
#include <boost/endian/detail/disable_warnings.hpp>
|
||||||
|
|
||||||
|
#define BOOST_ENDIAN_LOG
|
||||||
|
#include <boost/endian/types.hpp>
|
||||||
|
#include <boost/endian/buffers.hpp>
|
||||||
|
#include <boost/detail/lightweight_main.hpp>
|
||||||
|
#include <boost/detail/lightweight_test.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// Maximize chance of name clashes for testing purposes
|
||||||
|
using namespace boost::endian;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
//using boost::int8_t;
|
||||||
|
//using boost::uint8_t;
|
||||||
|
//using boost::int16_t;
|
||||||
|
//using boost::uint16_t;
|
||||||
|
//using boost::int32_t;
|
||||||
|
//using boost::uint32_t;
|
||||||
|
//using boost::int64_t;
|
||||||
|
//using boost::uint64_t;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
|
int cpp_main(int, char *[])
|
||||||
|
{
|
||||||
|
cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl;
|
||||||
|
|
||||||
|
big_int32_t i1(1), i2(2), i3;
|
||||||
|
big_buf32_t b1(1), b2(2), b3;
|
||||||
|
|
||||||
|
cout << "endian buffer tests" << endl;
|
||||||
|
cout << "compute\n";
|
||||||
|
i3 = i1 + 5;
|
||||||
|
cout << "test\n";
|
||||||
|
BOOST_TEST(i3 == 6);
|
||||||
|
cout << "compute\n";
|
||||||
|
i3 = i1 + i2;
|
||||||
|
cout << "test\n";
|
||||||
|
BOOST_TEST(i3 == 3);
|
||||||
|
|
||||||
|
cout << "endian integer tests" << endl;
|
||||||
|
cout << "compute\n";
|
||||||
|
b3 = b1 + 5;
|
||||||
|
cout << "test\n";
|
||||||
|
BOOST_TEST(b3 == 6);
|
||||||
|
cout << "compute\n";
|
||||||
|
b3 = b1 + b2;
|
||||||
|
cout << "test\n";
|
||||||
|
BOOST_TEST(b3 == 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return ::boost::report_errors();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include <boost/endian/detail/disable_warnings_pop.hpp>
|
@ -481,8 +481,8 @@ int cpp_main(int, char * [])
|
|||||||
|
|
||||||
// variations to detect ambiguities
|
// variations to detect ambiguities
|
||||||
|
|
||||||
u1 + 5;
|
be::little_uint32_t u3 = u1 + 5;
|
||||||
u1 + 5u;
|
u3 = u1 + 5u;
|
||||||
|
|
||||||
if (u1 == 5)
|
if (u1 == 5)
|
||||||
{}
|
{}
|
||||||
@ -496,10 +496,10 @@ int cpp_main(int, char * [])
|
|||||||
u2 = u1 + 5u;
|
u2 = u1 + 5u;
|
||||||
|
|
||||||
// one more wrinkle
|
// one more wrinkle
|
||||||
be::little_uint16_t u3(3);
|
be::little_uint16_t u4(3);
|
||||||
u3 = 3;
|
u4 = 3;
|
||||||
std::clog << "\nu2 = u1 + u3\n";
|
std::clog << "\nu2 = u1 + u4\n";
|
||||||
u2 = u1 + u3;
|
u2 = u1 + u4;
|
||||||
std::clog << "\n";
|
std::clog << "\n";
|
||||||
|
|
||||||
be::endian_log = false;
|
be::endian_log = false;
|
||||||
|
@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "loop_time_test", "loop_time
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buffer_test", "buffer_test\buffer_test.vcxproj", "{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "buffer_test", "buffer_test\buffer_test.vcxproj", "{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "uses_cases", "uses_cases\uses_cases.vcxproj", "{36BF451A-EAEF-4140-92E4-6EA461A26107}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Win32 = Debug|Win32
|
Debug|Win32 = Debug|Win32
|
||||||
@ -125,6 +127,12 @@ Global
|
|||||||
{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}.Release|Win32.ActiveCfg = Release|Win32
|
{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}.Release|Win32.Build.0 = Release|Win32
|
{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}.Release|Win32.Build.0 = Release|Win32
|
||||||
{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}.Release|x64.ActiveCfg = Release|Win32
|
{BFB68CF4-EB92-4E5C-9694-A939496C5CDE}.Release|x64.ActiveCfg = Release|Win32
|
||||||
|
{36BF451A-EAEF-4140-92E4-6EA461A26107}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||||
|
{36BF451A-EAEF-4140-92E4-6EA461A26107}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
|
{36BF451A-EAEF-4140-92E4-6EA461A26107}.Debug|x64.ActiveCfg = Debug|Win32
|
||||||
|
{36BF451A-EAEF-4140-92E4-6EA461A26107}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
|
{36BF451A-EAEF-4140-92E4-6EA461A26107}.Release|Win32.Build.0 = Release|Win32
|
||||||
|
{36BF451A-EAEF-4140-92E4-6EA461A26107}.Release|x64.ActiveCfg = Release|Win32
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
88
test/msvc/uses_cases/uses_cases.vcxproj
Normal file
88
test/msvc/uses_cases/uses_cases.vcxproj
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="14.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>{36BF451A-EAEF-4140-92E4-6EA461A26107}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>uses_cases</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v140</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v140</PlatformToolset>
|
||||||
|
<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" />
|
||||||
|
<Import Project="..\common.props" />
|
||||||
|
</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" />
|
||||||
|
<Import Project="..\common.props" />
|
||||||
|
</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>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</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>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\..\example\use_cases.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
Reference in New Issue
Block a user