vytools.h

VyTools is a C and C++ library which makes often used tasks easier.
The vytools.h header is for the C part. It contains some fixed-size basic types, often used structures, basic string and stream handling and a resizable buffer.
If compiled with a C++ compiler, all the declarations are in the vytc namespace

Contents

VYT_CBEGIN macros to write extern "C" block
VytPtr Typeless pointer
VytStr C string
VytU Unsigned 32-bit integer
VytI Signed 32-bit integer
VytZ Unsigned 64-bit integer
VytF 32-bit floating point value
Vyt?Vec2 2 coordinate vector
Vyt?Rect Rectangle
Vyt?Trans2 2d transformation matrix
VytStream Any stream type
vyt_alloc (re)allocate memory in current frame
vyt_frame open new frame or close current
vyt_raise raises allocation of memory to previous frame
VtlMem Resizable allocated memory
VytStreamOp Custom read or write operation
vyt_fread fread as VytStreamOp
vyt_fread_part fread as VytStreamOp, can read less than full block
vyt_fwrite fwrite as VytStreamOp
vyt_mread memory copy from (VytPtr *)stream to mem
vyt_mwrite memory copy form mem to (VytPtr *)stream
vyt_block_op write or read a complete block using VytStreamOp.
vyt_read_skip skip reading bytes.
vyt_ewrite write line to std error.
vyt_die write line to std error and exit program.
vyt_nat converts string to natural number
vyt_same same strings (NULL proof)
vyt_sprintf format string (uses static buffer)
vyt_stamp milliseconds passed since epoch
vyt_stamp_diff milliseconds passed since last call to vyt_stamp_diff

Details

VYT_CBEGIN()
macros to write extern "C" block
VytPtr
Typeless pointer
VytStr
C string
VytU
Unsigned 32-bit integer
VytI
Signed 32-bit integer
VytZ
Unsigned 64-bit integer
VytF
32-bit floating point value
struct Vyt?Vec2
2 coordinate vector
VYT_VEC2( t )
x
y
vector addition
vector subtraction
struct Vyt?Rect
Rectangle
VYT_RECT( t )
left
top
width
height
struct Vyt?Trans2
2d transformation matrix
VYT_TRANS2( t )
sx
rx
ry
sy
dx
dy
VytStream
Any stream type
VytPtr vyt_alloc( VytPtr old, VytU size )
(re)allocate memory in current frame
void vyt_frame( bool openNew )
open new frame or close current if called with true, creates a new frame to remember allocations if called with false, frees all vyt_alloc-ed memory in the frame and destroys frame itself
VytPtr vyt_raise( VytPtr )
raises allocation of memory to previous frame dies if there is no previous frame
VtlMem
Resizable allocated memory
VytU (* VytStreamOp)( VytStream stream, VytPtr mem, VytU size )
Custom read or write operation
stream Pointer to the stream
mem Pointer to data
size Number of bytes to read or write
return Number of bytes successfully read or written
VytU vyt_fread( VytStream stream, VytPtr mem, VytU size )
fread as VytStreamOp
VytU vyt_fread_part( VytStream stream, VytPtr mem, VytU size )
fread as VytStreamOp, can read less than full block
VytU vyt_fwrite( VytStream stream, VytPtr mem, VytU size )
fwrite as VytStreamOp
VytU vyt_mread( VytStream stream, VytPtr mem, VytU size )
memory copy from (VytPtr *)stream to mem
VytU vyt_mwrite( VytStream stream, VytPtr mem, VytU size )
memory copy form mem to (VytPtr *)stream
bool vyt_block_op( VytStream stream, VytStreamOp op, VytPtr mem, VytU size )
write or read a complete block using VytStreamOp. Keeps calling op until size is reached or 0 is returned
stream Pointer to the stream
op The read or write operation
mem Pointer to data
size Total number of bytes to write
return true if all size bytes are read or written
bool vyt_read_skip( VytStream stream, VytStreamOp read, VytU size )
skip reading bytes. Calls read without using the data read
stream Pointer to the stream
read The read or write operation
size Total number of bytes to skip
return true if all size bytes are skipped
vyt_ewrite( ... )
write line to std error.
... Arguments as in printf
vyt_die( ... )
write line to std error and exit program.
... Arguments as in printf
bool vyt_nat( VytStr s, VytU * nat )
converts string to natural number
s The string
nat Number is returned here
return true on success
bool vyt_same( VytStr a, VytStr b )
same strings (NULL proof)
a First string
b Second string
return true if both are NULL or the two are the same
VytStr vyt_sprintf( VytStr fmt, ... )
format string (uses static buffer)
fmt Format string
... printf arguments
return The formatted string
VytZ vyt_stamp()
milliseconds passed since epoch
VytU vyt_stamp_diff()
milliseconds passed since last call to vyt_stamp_diff