ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
ChimeraTK::FixedPointConverter< RawType > Class Template Reference

The fixed point converter provides conversion functions between a user type and up to 32 bit fixed point (signed or unsigned). More...

#include <FixedPointConverter.h>

+ Inheritance diagram for ChimeraTK::FixedPointConverter< RawType >:

Classes

struct  vectorToCooked_impl
 
struct  vectorToCooked_impl< std::string, RAW_ITERATOR, COOKED_ITERATOR >
 

Public Member Functions

 FixedPointConverter (std::string variableName, unsigned int nBits=32, int fractionalBits=0, bool isSignedFlag=true)
 The constructor defines the conversion factor.
 
template<typename UserType >
RawType toRaw (UserType cookedValue) const
 Conversion function from type T to fixed point.
 
template<typename UserType , typename RAW_ITERATOR , typename COOKED_ITERATOR >
void vectorToCooked (const RAW_ITERATOR &raw_begin, const RAW_ITERATOR &raw_end, const COOKED_ITERATOR &cooked_begin) const
 Conversion function from fixed-point values to type T.
 
template<typename UserType >
UserType scalarToCooked (RawType const &raw) const
 Inefficient convenience function for converting a single value to cooked.
 
unsigned int getNBits () const
 Read back the number of bits the converter is using.
 
int getFractionalBits () const
 Read back the fractional bits the converter is using.
 
bool isSigned () const
 Read back wether the conversion is using signed values.
 
bool operator== (const FixedPointConverter &other) const
 Compare two fixed point converters.
 
bool operator!= (const FixedPointConverter &other) const
 

Detailed Description

template<typename RawType>
class ChimeraTK::FixedPointConverter< RawType >

The fixed point converter provides conversion functions between a user type and up to 32 bit fixed point (signed or unsigned).

Definition at line 31 of file FixedPointConverter.h.

Constructor & Destructor Documentation

◆ FixedPointConverter()

template<typename RawType >
ChimeraTK::FixedPointConverter< RawType >::FixedPointConverter ( std::string  variableName,
unsigned int  nBits = 32,
int  fractionalBits = 0,
bool  isSignedFlag = true 
)
explicit

The constructor defines the conversion factor.

Parameters
variableNameThe name of the variable. It is used in case an exception is thrown which significantly simplifies the debugging.
nBitsThe number of total bits must not exceed 32.
fractionalBitsThe number of fractional bits can range from -1024+nBits to 1021-nBits (in case of a double user type). For integer user types, no fractional bits are allowed.
isSignedFlagFlag whether the most significant bit is interpreted as sign bit. Negative numbers are interpreted as two's complement number of the respective number of bits (i.e. in signed 6 bit, 0 fractional bits 0x3F is -1)

Definition at line 497 of file FixedPointConverter.h.

Member Function Documentation

◆ getFractionalBits()

template<typename RawType >
int ChimeraTK::FixedPointConverter< RawType >::getFractionalBits ( ) const
inline

Read back the fractional bits the converter is using.

Definition at line 101 of file FixedPointConverter.h.

◆ getNBits()

template<typename RawType >
unsigned int ChimeraTK::FixedPointConverter< RawType >::getNBits ( ) const
inline

Read back the number of bits the converter is using.

Definition at line 98 of file FixedPointConverter.h.

◆ isSigned()

template<typename RawType >
bool ChimeraTK::FixedPointConverter< RawType >::isSigned ( ) const
inline

Read back wether the conversion is using signed values.

Definition at line 104 of file FixedPointConverter.h.

◆ operator!=()

template<typename RawType >
bool ChimeraTK::FixedPointConverter< RawType >::operator!= ( const FixedPointConverter< RawType > &  other) const
inline

Definition at line 111 of file FixedPointConverter.h.

◆ operator==()

template<typename RawType >
bool ChimeraTK::FixedPointConverter< RawType >::operator== ( const FixedPointConverter< RawType > &  other) const
inline

Compare two fixed point converters.

The variable name is ignored in this comparison.

Definition at line 108 of file FixedPointConverter.h.

◆ scalarToCooked()

template<typename RawType >
template<typename UserType >
UserType ChimeraTK::FixedPointConverter< RawType >::scalarToCooked ( RawType const &  raw) const
inline

Inefficient convenience function for converting a single value to cooked.

Definition at line 91 of file FixedPointConverter.h.

◆ toRaw()

template<typename RawType >
template<typename UserType >
RawType ChimeraTK::FixedPointConverter< RawType >::toRaw ( UserType  cookedValue) const

Conversion function from type T to fixed point.

This conversion usually will introduce rounding errors due to this limited resolution of the fixed point number compared to the double. In case of a high number of fractional bits this can mean that the most significant digits are cut and only the 'noise' in the less significant bits is represented.

Definition at line 341 of file FixedPointConverter.h.

◆ vectorToCooked()

template<typename RawType >
template<typename UserType , typename RAW_ITERATOR , typename COOKED_ITERATOR >
void ChimeraTK::FixedPointConverter< RawType >::vectorToCooked ( const RAW_ITERATOR &  raw_begin,
const RAW_ITERATOR &  raw_end,
const COOKED_ITERATOR &  cooked_begin 
) const
inline

Conversion function from fixed-point values to type T.

The two vectors passed must be of equal size (i.e. cookedValues must already be properly allocated).

Definition at line 64 of file FixedPointConverter.h.


The documentation for this class was generated from the following file: