Conversion.h
Classes
- Conversion -- A class with general conversion definitions (full description)
Interface
- Public Members
- typedef unsigned int ValueFunction (void* to, const void* from, unsigned int nvalues)
- typedef void* ByteFunction (void* to, const void* from, unsigned int nbytes)
- static unsigned int boolToBit (void* to, const void* from, unsigned int nvalues)
- static void boolToBit (void* to, const void* from, unsigned int startBit, unsigned int nvalues)
- static unsigned int bitToBool (void* to, const void* from, unsigned int nvalues)
- static void bitToBool (void* to, const void* from, unsigned int startBit, unsigned int nvalues)
- static unsigned int valueCopy (void* to, const void* from, unsigned int nbytes)
- static ByteFunction* getmemcpy()
- static void* mymemcpy (void* to, const void* from, unsigned int nbytes)
Review Status
- Reviewed By:
- Friso Olnon
- Date Reviewed:
- 1996/11/06
- Programs:
- Tests:
Synopsis
This class contains the general definitions for the Conversion classes.
-
It defines the signature for the functions converting from input
to output format (e.g. from local to canonical format). There is
a version where the number of values is given and a version where
the number of bytes is given. The latter is there to be able to use
memcpy as a conversion function (which will often be the case).
Note that the signatures only differ in return value.
-
It defines functions to convert Bools to bits and vice-versa.
These are used elsewhere to store Bools as space efficient as possible.
Note that these functions are machine independent (they work on little
and big endian machines).
-
It defines a private version of memcpy for compilers having a
different signature for memcpy (e.g. ObjectCenter and DEC-Alpha).
Static functions in the classes
CanonicalConversion,
VAXConversion, and
IBMConversion convert data
from/to canonical, VAX, and IBM/360 format, resp..
Classes derived from
DataConversion
provide the same functionality in a polymorphic way.
Motivation
This provides a common place for definitions used elsewhere.
It also provides a uniform interface to memcpy.
Member Description
typedef unsigned int ValueFunction (void* to, const void* from, unsigned int nvalues)
Define the signature of a function converting nvalues
values from internal to external format or vice-versa.
These functions are used in the IO framework
, but are also used in the table system.
Examples of such conversions are:
- local <-> canonical (when storing in canonical format)
- local <-> local (when storing in local format)
- binary <-> ASCII
It returns the number of bytes in external format.
(For example the ToLocal/FromLocal functions in class
CanonicalConversion
return the number of bytes in canonical format).
typedef void* ByteFunction (void* to, const void* from, unsigned int nbytes)
Define the signature of a function converting from one
format to another providing the number of bytes.
It returns the to pointer (similar to memcpy).
(For example the byteTo/FromLocalXXX functions in class
CanonicalConversion.
static unsigned int boolToBit (void* to, const void* from, unsigned int nvalues)
static void boolToBit (void* to, const void* from, unsigned int startBit, unsigned int nvalues)
Convert a stream of Bools to output format (as bits).
The variable startBit (0-relative) indicates
where to start in the to buffer.
static unsigned int bitToBool (void* to, const void* from, unsigned int nvalues)
static void bitToBool (void* to, const void* from, unsigned int startBit, unsigned int nvalues)
Convert a stream of Bools to output format (as bits).
The variable startBit (0-relative) indicates
where to start in the from buffer.
static unsigned int valueCopy (void* to, const void* from, unsigned int nbytes)
Copy a value using memcpy.
It differs from memcpy in the return value.
This version has the ValueFunction signature,
but it expects as input the number of bytes.
static ByteFunction* getmemcpy()
Get a pointer to the memcpy function.
static void* mymemcpy (void* to, const void* from, unsigned int nbytes)
A placeholder for the ObjectCenter or DEC-alpha memcpy or 64bit SGI
Also added this for HPUX11 (2b provided in the makedefs)
(because they do not use an unsigned int for nbytes).