SPRAAK
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Public Member Functions | Data Fields | Protected Attributes
SprDT Class Reference
+ Inheritance diagram for SprDT:
+ Collaboration diagram for SprDT:

Public Member Functions

virtual int read1 (const SprDT *restrict dt, SprStream *restrict fd, void *restrict dst)
 
virtual ssize_t readN (const SprDT *restrict dt, SprStream *restrict fd, void *restrict dst, size_t Nel)
 
virtual ssize_t readNi (const SprDT *restrict dt, SprStream *restrict fd, void *restrict dst, size_t Nel, size_t offs_next)
 
virtual int write1 (const SprDT *restrict dt, SprStream *restrict fd, const void *restrict src)
 
virtual int writeN (const SprDT *restrict dt, SprStream *restrict fd, const void *restrict src, size_t Nel)
 
virtual int writeNi (const SprDT *restrict dt, SprStream *restrict fd, const void *restrict src, size_t Nel, size_t offs_next)
 
virtual ssize_t skipN (const SprDT *restrict dt, SprStream *restrict fd, size_t Nel)
 
virtual SprDTRead1Func get_read1_func (const SprDT *dt, const SprStream *fd)
 
virtual SprDTReadNFunc get_readN_func (const SprDT *dt, const SprStream *fd)
 
virtual SprDTReadNiFunc get_readNi_func (const SprDT *dt, const SprStream *fd)
 
virtual SprDTWrite1Func get_write1_func (const SprDT *dt, const SprStream *fd)
 
virtual SprDTWriteNFunc get_writeN_func (const SprDT *dt, const SprStream *fd)
 
virtual SprDTWriteNiFunc get_writeNi_func (const SprDT *dt, const SprStream *fd)
 
virtual SprDTSkipNFunc get_skipN_func (const SprDT *dt, const SprStream *fd)
 
virtual char * str_cvt (const SprDT *restrict dt, void *restrict dst, const char *restrict str)
 
virtual void * cpy (const SprDT *dt, void *dst, const void *src)
 
virtual void free (const SprDT *restrict dt, void *restrict ptr)
 
virtual SprDynStr str (const SprDT *restrict dt, const void *restrict src)
 
virtual ssize_t print (const SprDT *restrict dt, SprStream *restrict fd, const void *restrict src)
 
virtual void * cvt1 (const SprDT *dt_dst, void *restrict dst, const SprDT *dt_src, const void *restrict src)
 
virtual void * cvtN (const SprDT *dt_dst, void *restrict dst, const SprDT *dt_src, const void *restrict src, size_t Nel)
 
virtual void * cvtNsi (const SprDT *dt_dst, void *restrict dst, const SprDT *dt_src, const void *restrict src, size_t Nel, size_t offs_src_next)
 
virtual void * cvtNdi (const SprDT *dt_dst, void *restrict dst, const SprDT *dt_src, const void *restrict src, size_t Nel, size_t offs_dst_next)
 
virtual void * cvtNsdi (const SprDT *dt_dst, void *restrict dst, const SprDT *dt_src, const void *restrict src, size_t Nel, size_t offs_src_next, size_t offs_dst_next)
 
virtual SprDTCvt1Func get_cvt1_func (const SprDT *dt_dst, const SprDT *dt_src, SprDTCvtAux **aux_data)
 
virtual SprDTCvtNFunc get_cvtN_func (const SprDT *dt_dst, const SprDT *dt_src, SprDTCvtAux **aux_data)
 
virtual SprDTCvtNsiFunc get_cvtNsi_func (const SprDT *dt_dst, const SprDT *dt_src, SprDTCvtAux **aux_data)
 
virtual SprDTCvtNsiFunc get_cvtNdi_func (const SprDT *dt_dst, const SprDT *dt_src, SprDTCvtAux **aux_data)
 
virtual SprDTCvtNsdiFunc get_cvtNsdi_func (const SprDT *dt_dst, const SprDT *dt_src, SprDTCvtAux **aux_data)
 
virtual void reserve_dt (SprDT *restrict dt)
 
virtual void release_dt (SprDT *restrict dt)
 

Data Fields

base::< SprObjectinterface_
 
int dsize
 
unsigned int dalign
 
int dsize_packed
 

Protected Attributes

unsigned int flags
 
const char * desc_str
 

Detailed Description

SprDT is the base class for all types that describe data types in the SPRAAK system.

The date atype descriptor type. For more info, see datatype.c

Member Function Documentation

virtual int SprDT::read1 ( const SprDT *restrict  dt,
SprStream *restrict  fd,
void *restrict  dst 
)
virtual

Read a single data element from the given stream fd. The binary data is written to dst. It is the callers responsability to assure that dst is large enough to contain the whole data element.

Returns
(-1) on error and 0 on success.
Note
When the read fails, a simple check of fd->eof allows the caller to distinguish between read errors and an end-of-file condition. An additional check if fd->buf_rptr equals fd->buf_end allows the caller to check for partial data when encountering an error or an end-of-file condition.

Reimplemented in SprDT_ET.

virtual ssize_t SprDT::readN ( const SprDT *restrict  dt,
SprStream *restrict  fd,
void *restrict  dst,
size_t  Nel 
)
virtual

Read Nel data elements from the given stream fd. The binary data is written to dst. It is the callers responsability to assure that dst is large enough to contain all Nel data elements.

Returns
0 if all requested elements were read successfully and the number of elements short of Nel otherwise.
Note
When not all elements were read, a simple check of fd->eof allows the caller to distinguish between read errors and an end-of-file condition. An additional check if fd->buf_rptr equals fd->buf_end allows the caller to check for partial data when encountering an error or an end-of-file condition.

Reimplemented in SprDT_ET.

virtual ssize_t SprDT::readNi ( const SprDT *restrict  dt,
SprStream *restrict  fd,
void *restrict  dst,
size_t  Nel,
size_t  offs_next 
)
virtual

Read Nel data elements from the given stream fd. The binary data is written to dst in an interleaved fashion, i.e. the 2nd elements is written to (char*)dst+<offs_next) and so on. It is the callers responsability to assure that dst is large enough to contain all Nel data elements.

Returns
0 if all requested elements were read successfully and the number of elements short of Nel otherwise.
Note
When not all elements were read, a simple check of fd->eof allows the caller to distinguish between read errors and an end-of-file condition. An additional check if fd->buf_rptr equals fd->buf_end allows the caller to check for partial data when encountering an error or an end-of-file condition.

Reimplemented in SprDT_ET.

virtual int SprDT::write1 ( const SprDT *restrict  dt,
SprStream *restrict  fd,
const void *restrict  src 
)
virtual

Write a single data element of which the binary data can be found at address src to the given stream fd.

Returns
(-1) on error and 0 on success.

Reimplemented in SprDT_ET.

virtual int SprDT::writeN ( const SprDT *restrict  dt,
SprStream *restrict  fd,
const void *restrict  src,
size_t  Nel 
)
virtual

Write the Nel data elements located at address src and upwards to the given stream fd.

Returns
0 if all requested elements were written successfully and -1 otherwise.

Reimplemented in SprDT_ET.

virtual int SprDT::writeNi ( const SprDT *restrict  dt,
SprStream *restrict  fd,
const void *restrict  src,
size_t  Nel,
size_t  offs_next 
)
virtual

Write the Nel data elements located at address src and upwards to the given stream fd. The source elements are stored in an interleaved fashion in memory, i.e. the 2nd elements is located at (char*)src+<offs_next) and so on.

Returns
0 if all requested elements were written successfully and -1 otherwise.

Reimplemented in SprDT_ET.

virtual ssize_t SprDT::skipN ( const SprDT *restrict  dt,
SprStream *restrict  fd,
size_t  Nel 
)
virtual

Skip Nel elements in the input stream fd.

Returns
0 if all requested elements were skipped successfully, the number of elements short of Nel when encountering an EOF, and (-1) on encountering an error (even if some elements were skipped).

Reimplemented in SprDT_EnumT, and SprDT_ET.

virtual SprDTRead1Func SprDT::get_read1_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to read a single data element of the type dt from the stream fd. This function behaves identically to the SprDT::read1() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual SprDTReadNFunc SprDT::get_readN_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to read N data element of the type dt from the stream fd. This function behaves identically to the SprDT::readN() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual SprDTReadNiFunc SprDT::get_readNi_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to read N data element of the type dt from the stream fd in an interleaved fashion. This function behaves identically to the SprDT::readNi() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual SprDTWrite1Func SprDT::get_write1_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to write a single data element of the type dt to the stream fd. This function behaves identically to the SprDT::write1() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual SprDTWriteNFunc SprDT::get_writeN_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to write N data element of the type dt to the stream fd. This function behaves identically to the SprDT::writeN() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual SprDTWriteNiFunc SprDT::get_writeNi_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to write N data element of the type dt to the stream fd in an interleaved fashion. This function behaves identically to the SprDT::writeNi() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual SprDTSkipNFunc SprDT::get_skipN_func ( const SprDT dt,
const SprStream fd 
)
virtual

Find a function to skip N data element of the type dt in the stream fd. This function behaves identically to the SprDT::skipN() method, but is typically faster since the mode of the stream (BIN, BINSWAP, ASCII) is known in advance.

Returns
The requested function pointer.

Reimplemented in SprDT_ET.

virtual char* SprDT::str_cvt ( const SprDT *restrict  dt,
void *restrict  dst,
const char *restrict  str 
)
virtual

Convert to the initial part of the dst to a data element of this type. The binary data is written to dst. Leading space is ignored. The conversion stops at the first character that does not fit the data type.

Returns
The address of the first character not belonging to this data type or (NULL) if the conversion failed.
Note
This method does not issue a warning when the conversion fails!
virtual void* SprDT::cpy ( const SprDT dt,
void *  dst,
const void *  src 
)
virtual

Copy the item *src of type dt to *dst (same type).

Returns
dst on success and NULL on failure.

Reimplemented in SprDT_EnumT.

virtual void SprDT::free ( const SprDT *restrict  dt,
void *restrict  ptr 
)
virtual

Release all memory associated to the object of type dt located at address ptr.

Note
This method typically equals NULL (and hence cannot be called) since most types do not allocate their own memory. So check the dt->free_fp pointer before calling this method!
virtual SprDynStr SprDT::str ( const SprDT *restrict  dt,
const void *restrict  src 
)
virtual

Convert the data element of type dt and for which the binary data can be found at address src to a dynamic string.

Returns
The dynamic string or NULL on failure.
virtual ssize_t SprDT::print ( const SprDT *restrict  dt,
SprStream *restrict  fd,
const void *restrict  src 
)
virtual

Print the data element of type dt and for which the binary data can be found at address src to the stream fd.

Returns
The number of bytes written or (-1) on failure.
virtual void* SprDT::cvt1 ( const SprDT dt_dst,
void *restrict  dst,
const SprDT dt_src,
const void *restrict  src 
)
virtual

Convert the single data element *src of the type dt_src to a data element of the type dt_dst and write the result to *dst.

Returns
The pointer dst if successfull and NULL otherwise.
Parameters
dt_dstData type of dst.
dstLocation where the converted data will be written. It is the callers responsability to assure that dst is large enough to contain the data.
dt_srcData type of src.
srcThe data that must be converted.
virtual void* SprDT::cvtN ( const SprDT dt_dst,
void *restrict  dst,
const SprDT dt_src,
const void *restrict  src,
size_t  Nel 
)
virtual

Convert data elements src[0...Nel-1] of the type dt_src to data elements of the type dt_dst and write the result to dst[0...Nel-1].

Returns
The pointer &dst[Nel] if successfull and NULL otherwise.
Parameters
dt_dstData type of dst.
dstLocation where the converted data will be written. It is the callers responsability to assure that dst is large enough to contain the data.
dt_srcData type of src.
srcThe data that must be converted.
NelNumber of elements to convert.
virtual void* SprDT::cvtNsi ( const SprDT dt_dst,
void *restrict  dst,
const SprDT dt_src,
const void *restrict  src,
size_t  Nel,
size_t  offs_src_next 
)
virtual

Convert data elements *src, *(src+<offs_src_next), ... *(src+(Nel-1)*offs_src_next) of the type dt_src to data elements of the type dt_dst and write the result to dst[0...Nel-1].

Returns
The pointer &dst[Nel] if successfull and NULL otherwise.
Parameters
dt_dstData type of dst.
dstLocation where the converted data will be written. It is the callers responsability to assure that dst is large enough to contain the data.
dt_srcData type of src.
srcThe data that must be converted.
NelNumber of elements to convert.
offs_src_nextOffset of the next element in the source data. The destination data is consecutive.
virtual void* SprDT::cvtNdi ( const SprDT dt_dst,
void *restrict  dst,
const SprDT dt_src,
const void *restrict  src,
size_t  Nel,
size_t  offs_dst_next 
)
virtual

Convert data elements src[0...Nel-1] of the type dt_src to data elements of the type dt_dst and write the result to *dst, *(dst+<offs_dst_next), ... *(dst+(Nel-1)*offs_dst_next)

Returns
The pointer (dst+Nel*offs_dst_next) if successfull and NULL otherwise.
Parameters
dt_dstData type of dst.
dstLocation where the converted data will be written. It is the callers responsability to assure that dst is large enough to contain the data.
dt_srcData type of src.
srcThe data that must be converted.
NelNumber of elements to convert.
offs_dst_nextOffset of the next element in the destination data.
virtual void* SprDT::cvtNsdi ( const SprDT dt_dst,
void *restrict  dst,
const SprDT dt_src,
const void *restrict  src,
size_t  Nel,
size_t  offs_src_next,
size_t  offs_dst_next 
)
virtual

Convert data elements *src, *(src+<offs_src_next), ... *(src+(Nel-1)*offs_src_next) of the type dt_src to data elements of the type dt_dst and write the result to *dst, *(dst+<offs_dst_next), ... *(dst+(Nel-1)*offs_dst_next)

Returns
The pointer (dst+Nel*offs_dst_next) if successfull and NULL otherwise.
Parameters
dt_dstData type of dst.
dstLocation where the converted data will be written. It is the callers responsability to assure that dst is large enough to contain the data.
dt_srcData type of src.
srcThe data that must be converted.
NelNumber of elements to convert.
offs_src_nextOffset of the next element in the source data. The destination data is consecutive.
offs_dst_nextOffset of the next element in the destination data.
virtual SprDTCvt1Func SprDT::get_cvt1_func ( const SprDT dt_dst,
const SprDT dt_src,
SprDTCvtAux **  aux_data 
)
virtual

Find a function to convert a single data element of the type dt_src to a data element of the type dt_dst. If needed, some auxilary data needed for the conversion will be returned via aux_data. If all conversions are done, this auxilary data must be freed using aux_data->free_routine().

Returns
A pointer to a function that will do the requested convertion or (NULL) if no such function exists.
virtual SprDTCvtNFunc SprDT::get_cvtN_func ( const SprDT dt_dst,
const SprDT dt_src,
SprDTCvtAux **  aux_data 
)
virtual

Find a function to convert a vector of data elements of the type dt_src to a vector of data elements of the type dt_dst. If needed, some auxilary data needed for the conversion will be returned via aux_data. If all conversions are done, this auxilary data must be freed using aux_data->free_routine().

Returns
A pointer to a function that will do the requested convertion or (NULL) if no such function exists.
virtual SprDTCvtNsiFunc SprDT::get_cvtNsi_func ( const SprDT dt_dst,
const SprDT dt_src,
SprDTCvtAux **  aux_data 
)
virtual

Find a function to convert a vector of data elements of the type dt_src to a vector of data elements of the type dt_dst when the source data is stored in an interleaved fashion. If needed, some auxilary data needed for the conversion will be returned via aux_data. If all conversions are done, this auxilary data must be freed using aux_data->free_routine().

Returns
A pointer to a function that will do the requested convertion or (NULL) if no such function exists.
virtual SprDTCvtNsiFunc SprDT::get_cvtNdi_func ( const SprDT dt_dst,
const SprDT dt_src,
SprDTCvtAux **  aux_data 
)
virtual

Find a function to convert a vector of data elements of the type dt_src to a vector of data elements of the type dt_dst when the destination data is stored in an interleaved fashion. If needed, some auxilary data needed for the conversion will be returned via aux_data. If all conversions are done, this auxilary data must be freed using aux_data->free_routine().

Returns
A pointer to a function that will do the requested convertion or (NULL) if no such function exists.
virtual SprDTCvtNsdiFunc SprDT::get_cvtNsdi_func ( const SprDT dt_dst,
const SprDT dt_src,
SprDTCvtAux **  aux_data 
)
virtual

Find a function to convert a vector of data elements of the type dt_src to a vector of data elements of the type dt_dst when both the source and the destination data are stored in an interleaved fashion. If needed, some auxilary data needed for the conversion will be returned via aux_data. If all conversions are done, this auxilary data must be freed using aux_data->free_routine().

Returns
A pointer to a function that will do the requested convertion or (NULL) if no such function exists.
virtual void SprDT::reserve_dt ( SprDT *restrict  dt)
virtual

Some complex data type descriptors (things of the type SprDT) are dynamic allocated, and hence must be released when no longer needed (or reserved when a copy is made). This method will reserve the type description (augment some counter with 1), making sure the dynamic allocated structure will not be freed before a matching SprDT::release_dt() method is called.

Note
Checking if some data type descriptor requires calls to the SprDT::reserve_dt() and SprDT::release_dt() methods can be done in two ways: (1) check the documentation if the type is known, or (2) check if the SPR_DT_REQ_RR flag in dt->flags is set.
The SprDT::reserve_dt() and SprDT::release_dt() methods can be called for any data type descriptor. Those that don't need is, will simply do nothing.
virtual void SprDT::release_dt ( SprDT *restrict  dt)
virtual

Some data type descriptors (things of the type SprDT) are dynamic allocated, and hence must be released when no longer needed (or reserved when a copy is made). This method will releases the type description, i.e. it descreases some counter with 1, and frees the type descriptor when the counter reaches zero.

Note
Checking if some data type descriptor requires calls to the SprDT::reserve_dt() and SprDT::release_dt() methods can be done in two ways: (1) check the documentation if the type is known, or (2) check if the SPR_DT_REQ_RR flag in dt->flags is set.
The SprDT::reserve_dt() and SprDT::release_dt() methods can be called for any data type descriptor. Those that don't need is, will simply do nothing.

Field Documentation

base::<SprObject> SprDT::interface_
int SprDT::dsize

Size of the data when stored in binary format in memory, -1 for variable sized items.

unsigned int SprDT::dalign

Minimal alignment requirement of the data when stored in binary format in memory.

int SprDT::dsize_packed

Size of the data when stored in binary format in a file (elements are not aligned), -1 for variable sized items.

unsigned int SprDT::flags
protected

Flags describing the various properties of the data type.

const char* SprDT::desc_str
protected

Formal description string (or template string) for the data type.