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
VytU
Unsigned 32-bit integer
VytI
Signed 32-bit integer
VytZ
Unsigned 64-bit integer
VytF
32-bit floating point value
vyt_alloc
(re)allocate memory in current frame
vyt_raise
raises allocation of memory to previous frame
VtlMem
Resizable allocated memory
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_die
write line to std error and exit program.
vyt_nat
converts string to natural number
Details
VYT_CBEGIN()
macros to write extern "C" block
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
x
y
vector addition
vector subtraction
struct Vyt?Rect
Rectangle
left
top
width
height
struct Vyt?Trans2
2d transformation matrix
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.
vyt_die( ... )
write line to std error and exit program.
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
return
The formatted string
VytZ vyt_stamp()
milliseconds passed since epoch
VytU vyt_stamp_diff()
milliseconds passed since last call to
vyt_stamp_diff