Files

170 lines
3.1 KiB
C++

// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
//
// This software owned by Onix Solutions Limited [OnixS] and is
// protected by copyright law and international copyright treaties.
//
// Access to and use of the software is governed by the terms of the applicable
// OnixS Software Services Agreement (the Agreement) and Customer end user license
// agreements granting a non-assignable, non-transferable and non-exclusive license
// to use the software for it's own data processing purposes under the terms defined
// in the Agreement.
//
// Except as otherwise granted within the terms of the Agreement, copying or
// reproduction of any part of this source code or associated reference material
// to any other location for further reproduction or redistribution, and any
// amendments to this copyright notice, are expressly prohibited.
//
// Any reproduction or redistribution for sale or hiring of the Software not in
// accordance with the terms of the Agreement is a violation of copyright law.
//
#pragma once
#include <cstddef>
#include <OnixS/CME/MDH/Integral.h>
ONIXS_CMEMDH_NAMESPACE_BEGIN
/// Alias for Byte.
typedef UInt8 Byte;
/// Alias for Word.
typedef UInt16 Word;
/// Alias for Double Word.
typedef UInt32 DWord;
/// Alias for Quad Word.
typedef UInt64 QWord;
//
/// Casts data of source type to the data
/// of target type using C casting rules.
template
<
typename Target,
typename Source
>
inline Target c_cast(Source src)
{
return (Target)src;
}
/// Makes pointer as opaque one.
template
<
typename Type
>
inline
void*
toOpaquePtr(Type* ptr)
{
return static_cast<void*>(ptr);
}
/// Makes pointer as opaque one.
template
<
typename Type
>
inline
const void*
toOpaquePtr(
const Type* ptr)
{
return static_cast<const void*>(ptr);
}
/// Reinterprets pointer to one
/// referencing to byte block.
template
<
typename Type
>
inline
Byte*
toByteBlock(
Type* ptr)
{
return
static_cast
<Byte*>
(toOpaquePtr(ptr));
}
/// Reinterprets pointer to one
/// referencing to byte block.
template
<
typename Type
>
inline
const Byte*
toByteBlock(
const Type* ptr)
{
return
static_cast
<const Byte*>
(toOpaquePtr(ptr));
}
/// Advances given pointer to a given offset (distance) in bytes.
template
<
typename Type
>
inline
Type*
advanceByBytes(
Type* pointer,
ptrdiff_t distance)
{
return
reinterpret_cast<Type*>
(
toByteBlock(pointer) + distance
);
}
/// Returns pointer which is lower than
/// given one to a given number of bytes.
template
<
typename Type
>
inline
Type*
advanceBackByBytes(
Type* pointer,
ptrdiff_t distance)
{
return
reinterpret_cast<Type*>
(
toByteBlock(pointer) - distance
);
}
/// Returns distance in bytes between two pointers.
template
<
typename Left,
typename Right
>
inline
ptrdiff_t
byteDistance(
Left* left,
Right* right)
{
return (
toByteBlock(left) -
toByteBlock(right)
);
}
ONIXS_CMEMDH_NAMESPACE_END