Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
Functions | |
void | setmem (void *mem, const void *value, unsigned value_size, size_t num_elem) |
Similar to memset, but accepts values larger than 1 char. | |
long | filesize (FILE *filp) |
Get size of file (if it is a regular file) | |
long | filesize (std::ifstream &str) |
Get size of file (if it is a regular file) | |
void | byteswap (void *data, unsigned value_size, size_t num_elem) |
Swap byte order (e.g. change from big-endian to little-endian) | |
static uint16_t | swap_bytes (uint16_t value) |
static uint32_t | swap_bytes (uint32_t value) |
static uint64_t | swap_bytes (uint64_t value) |
void | byteswap2 (void *data, size_t num_elem) |
Alternate byteswap optimized for 2-byte values. | |
void | byteswap4 (void *data, size_t num_elem) |
Alternate byteswap optimized for 4-byte values. | |
void | byteswap8 (void *data, size_t num_elem) |
Alternate byteswap optimized for 8-byte values. | |
bool | little_endian () |
Check if platform is little-endian. | |
bool | big_endian () |
Check if platform is big-endian. | |
template<typename T > | |
void | byteswap (T *data, size_t num_elem) |
Type-specific byte swap. | |
Variables | |
const uint64_t | m64b1 = 0xFF |
const uint64_t | m64b2 = m64b1 << 8 |
const uint64_t | m64b3 = m64b1 << 16 |
const uint64_t | m64b4 = m64b1 << 24 |
const uint64_t | m64b5 = m64b1 << 32 |
const uint64_t | m64b6 = m64b1 << 40 |
const uint64_t | m64b7 = m64b1 << 48 |
bool moab::SysUtil::big_endian | ( | ) | [inline] |
Check if platform is big-endian.
Check if platform is big-endian (least significant byte at lowest memory address.)
Definition at line 61 of file SysUtil.hpp.
Referenced by moab::ReadSTL::load_file(), and moab::WriteSTL::write_file().
{ const unsigned one = 1; return !( ( (char*)&one )[sizeof( unsigned ) - 1] ); }
void moab::SysUtil::byteswap | ( | void * | data, |
unsigned | value_size, | ||
size_t | num_elem | ||
) |
Swap byte order (e.g. change from big-endian to little-endian)
Reverse byte order or array of values.
data | Pointer to beginning of memory block to modify |
values_size | Size of one value |
num_elem | Number of values of size 'value_size' in 'data' |
Definition at line 57 of file SysUtil.cpp.
Referenced by moab::ReadSTL::binary_read_triangles(), moab::WriteSTL::binary_write_triangles(), and byteswap().
{ char* mem = reinterpret_cast< char* >( data ); char* const end = mem + value_size * num_elem; for( ; mem < end; mem += value_size ) { unsigned i = 0, j = value_size - 1; while( i < j ) std::swap( mem[i++], mem[j--] ); } }
void moab::SysUtil::byteswap | ( | T * | data, |
size_t | num_elem | ||
) | [inline] |
Type-specific byte swap.
Definition at line 85 of file SysUtil.hpp.
References byteswap(), byteswap2(), byteswap4(), byteswap8(), and T.
void moab::SysUtil::byteswap2 | ( | void * | data, |
size_t | num_elem | ||
) |
Alternate byteswap optimized for 2-byte values.
Definition at line 128 of file SysUtil.cpp.
References swap_bytes().
Referenced by byteswap().
{ uint16_t* mem = reinterpret_cast< uint16_t* >( data ); uint16_t* end = mem + num_elem; for( ; mem < end; ++mem ) *mem = swap_bytes( *mem ); }
void moab::SysUtil::byteswap4 | ( | void * | data, |
size_t | num_elem | ||
) |
Alternate byteswap optimized for 4-byte values.
Definition at line 136 of file SysUtil.cpp.
References swap_bytes().
Referenced by byteswap().
{ uint32_t* mem = reinterpret_cast< uint32_t* >( data ); uint32_t* end = mem + num_elem; for( ; mem < end; ++mem ) *mem = swap_bytes( *mem ); }
void moab::SysUtil::byteswap8 | ( | void * | data, |
size_t | num_elem | ||
) |
Alternate byteswap optimized for 8-byte values.
Definition at line 144 of file SysUtil.cpp.
References swap_bytes().
Referenced by byteswap().
{ if( sizeof( void* ) >= 8 ) { uint64_t* mem = reinterpret_cast< uint64_t* >( data ); uint64_t* end = mem + num_elem; for( ; mem < end; ++mem ) *mem = swap_bytes( *mem ); } else { uint32_t* mem = reinterpret_cast< uint32_t* >( data ); uint32_t* end = mem + 2 * num_elem; for( ; mem < end; mem += 2 ) { uint32_t tmp = swap_bytes( mem[0] ); mem[0] = swap_bytes( mem[1] ); mem[1] = tmp; } } }
long moab::SysUtil::filesize | ( | FILE * | filp | ) |
Get size of file (if it is a regular file)
Get size of regular file.
Definition at line 27 of file SysUtil.cpp.
References length().
Referenced by moab::ReadSTL::binary_read_triangles().
long moab::SysUtil::filesize | ( | std::ifstream & | str | ) |
Get size of file (if it is a regular file)
Get size of regular file.
Definition at line 42 of file SysUtil.cpp.
References length().
bool moab::SysUtil::little_endian | ( | ) | [inline] |
Check if platform is little-endian.
Check if platform is little-endian (least significant byte at highest memory address.)
Definition at line 50 of file SysUtil.hpp.
Referenced by moab::ReadSTL::binary_read_triangles(), moab::WriteSTL::binary_write_triangles(), moab::ReadSTL::load_file(), and moab::WriteSTL::write_file().
{ const unsigned one = 1; return !*( (char*)&one ); }
void moab::SysUtil::setmem | ( | void * | mem, |
const void * | value, | ||
unsigned | value_size, | ||
size_t | num_elem | ||
) |
Similar to memset, but accepts values larger than 1 char.
Set block of memory to repeating copies of a sequene of bytes.
mem | Pointer to start of memory block to initialize |
value | Byte sequence to initialize mem with |
value_size | Size of 'value' |
num_elem | Size of 'mem' as a multiple of value_size (the number of copies of 'value' to write into 'mem'.) |
Definition at line 15 of file SysUtil.cpp.
Referenced by moab::DenseTag::clear_data(), moab::SequenceData::create_data(), moab::MeshTag::get_data(), moab::DenseTag::get_data(), moab::VarLenDenseTag::get_data(), moab::SparseTag::get_data(), and moab::WriteVtk::write_tag().
{ if( !num_elem ) return; char* array = reinterpret_cast< char* >( mem ); memcpy( array, value, value_size ); size_t count; for( count = 1; count * 2 < num_elem; count *= 2 ) memcpy( array + count * value_size, array, count * value_size ); memcpy( array + count * value_size, array, ( num_elem - count ) * value_size ); }
static uint16_t moab::SysUtil::swap_bytes | ( | uint16_t | value | ) | [inline, static] |
Definition at line 69 of file SysUtil.cpp.
Referenced by moab::ReadSTL::binary_read_triangles(), moab::WriteSTL::binary_write_triangles(), byteswap2(), byteswap4(), and byteswap8().
{
return ( value >> 8 ) | ( value << 8 );
}
static uint32_t moab::SysUtil::swap_bytes | ( | uint32_t | value | ) | [inline, static] |
Definition at line 74 of file SysUtil.cpp.
{ return ( ( value /*& (uint32_t)0xFF000000*/ ) >> 24 ) | ( ( value & (uint32_t)0x00FF0000 ) >> 8 ) | ( ( value & (uint32_t)0x0000FF00 ) << 8 ) | ( ( value /*& (uint32_t)0X000000FF*/ ) << 24 ); }
static uint64_t moab::SysUtil::swap_bytes | ( | uint64_t | value | ) | [inline, static] |
Definition at line 89 of file SysUtil.cpp.
const uint64_t moab::SysUtil::m64b1 = 0xFF |
Definition at line 80 of file SysUtil.cpp.
const uint64_t moab::SysUtil::m64b2 = m64b1 << 8 |
Definition at line 81 of file SysUtil.cpp.
Referenced by swap_bytes().
const uint64_t moab::SysUtil::m64b3 = m64b1 << 16 |
Definition at line 82 of file SysUtil.cpp.
Referenced by swap_bytes().
const uint64_t moab::SysUtil::m64b4 = m64b1 << 24 |
Definition at line 83 of file SysUtil.cpp.
Referenced by swap_bytes().
const uint64_t moab::SysUtil::m64b5 = m64b1 << 32 |
Definition at line 84 of file SysUtil.cpp.
Referenced by swap_bytes().
const uint64_t moab::SysUtil::m64b6 = m64b1 << 40 |
Definition at line 85 of file SysUtil.cpp.
Referenced by swap_bytes().
const uint64_t moab::SysUtil::m64b7 = m64b1 << 48 |
Definition at line 86 of file SysUtil.cpp.
Referenced by swap_bytes().