GDCM  2.2.6
TestByteSwap.cxx

This is a C++ example on how to use gdcm::ByteSwap

/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "gdcmTypes.h"
#include "gdcmSwapCode.h"
#include "gdcmByteSwap.h"
#include <string.h> // memcpy
int myfunc()
{
char vl_str[4];
const char raw[] = "\000\000\000\004";
memcpy(vl_str, raw, 4);
uint32_t vl;
memcpy(&vl, vl_str, 4);
if( vl != 0x00000004 )
{
std::cerr << std::hex << "vl: " << vl << std::endl;
return 1;
}
if( vl != 0x00000004 )
{
std::cerr << std::hex << "vl: " << vl << std::endl;
return 1;
}
std::cout << std::hex << "vl: " << vl << std::endl;
if( vl != 0x4000000 )
{
return 1;
}
return 0;
}
int TestByteSwap(int , char *[])
{
{
}
{
}
{
return 1;
}
std::cout << "sc: " << sc << std::endl;
uint16_t t = 0x1234;
{
if( t != 0x3412 )
{
std::cerr << std::hex << "t: " << t << std::endl;
return 1;
}
// ok test pass rest value to old one
t = 0x1234;
}
else if ( sc == gdcm::SwapCode::LittleEndian )
{
if( t != 0x1234 )
{
std::cerr << std::hex << "t: " << t << std::endl;
return 1;
}
}
union { char n[2]; uint16_t tn; } u16;
memcpy(u16.n, &t, 2 );
uint16_t tn = u16.tn;
{
if( tn != 0x3412 )
{
std::cerr << std::hex << "tn: " << tn << std::endl;
return 1;
}
// ok test pass rest value to old one
t = 0x1234;
}
else if ( sc == gdcm::SwapCode::LittleEndian )
{
if( tn != 0x1234 )
{
std::cerr << std::hex << "tn: " << tn << std::endl;
return 1;
}
}
tn = u16.tn;
{
if( tn != 0x3412 )
{
std::cerr << std::hex << "tn: " << tn << std::endl;
return 1;
}
}
else if ( sc == gdcm::SwapCode::BigEndian )
{
if( tn != 0x1234 )
{
std::cerr << std::hex << "tn: " << tn << std::endl;
return 1;
}
}
if( myfunc() )
{
return 1;
}
uint16_t array[] = { 0x1234 };
if ( array[0] != 0x3412 )
{
return 1;
}
return 0;
}

Generated on Sat Dec 21 2013 05:56:16 for GDCM by doxygen 1.8.5
SourceForge.net Logo