BRL-CAD
Variable-length Byte Buffers
Collaboration diagram for Variable-length Byte Buffers:

Files

file  vlb.c
 

Data Structures

struct  bu_vlb
 

Macros

#define BU_VLB_NULL   ((struct bu_vlb *)0)
 
#define BU_CK_VLB(_vp)   BU_CKMAG(_vp, BU_VLB_MAGIC, "bu_vlb")
 
#define BU_VLB_INIT(_vp)
 
#define BU_VLB_INIT_ZERO   { BU_VLB_MAGIC, NULL, 0, 0 }
 
#define BU_VLB_IS_INITIALIZED(_vp)   (((struct bu_vlb *)(_vp) != BU_VLB_NULL) && ((_vp)->magic == BU_VLB_MAGIC))
 

Typedefs

typedef struct bu_vlb bu_vlb_t
 

Functions

void bu_vlb_init (struct bu_vlb *vlb)
 
void bu_vlb_initialize (struct bu_vlb *vlb, size_t initialSize)
 
void bu_vlb_write (struct bu_vlb *vlb, unsigned char *start, size_t len)
 
void bu_vlb_reset (struct bu_vlb *vlb)
 
unsigned char * bu_vlb_addr (struct bu_vlb *vlb)
 
size_t bu_vlb_buflen (struct bu_vlb *vlb)
 
void bu_vlb_free (struct bu_vlb *vlb)
 
void bu_vlb_print (struct bu_vlb *vlb, FILE *fd)
 
void bu_pr_vlb (const char *title, const struct bu_vlb *vlb)
 

Detailed Description

Macro Definition Documentation

#define BU_VLB_NULL   ((struct bu_vlb *)0)

Definition at line 51 of file vlb.h.

#define BU_CK_VLB (   _vp)    BU_CKMAG(_vp, BU_VLB_MAGIC, "bu_vlb")

assert the integrity of a bu_vlb struct.

Definition at line 56 of file vlb.h.

#define BU_VLB_INIT (   _vp)
Value:
{ \
(_vp)->magic = BU_VLB_MAGIC; \
(_vp)->buf = NULL; \
(_vp)->bufCapacity = (_vp)->nextByte = 0; \
}
#define BU_VLB_MAGIC
Definition: magic.h:64
oldeumate l2 magic
Definition: nmg_mod.c:3843

initializes a bu_vlb struct without allocating any memory.

Definition at line 61 of file vlb.h.

#define BU_VLB_INIT_ZERO   { BU_VLB_MAGIC, NULL, 0, 0 }

macro suitable for declaration statement initialization of a bu_vlb struct. does not allocate memory.

Definition at line 71 of file vlb.h.

#define BU_VLB_IS_INITIALIZED (   _vp)    (((struct bu_vlb *)(_vp) != BU_VLB_NULL) && ((_vp)->magic == BU_VLB_MAGIC))

returns truthfully whether a bu_vlb struct has been initialized. is not reliable unless the struct has been allocated with BU_ALLOC(), bu_calloc(), or a previous call to bu_vlb_init() or BU_VLB_INIT() has been made.

Definition at line 79 of file vlb.h.

Typedef Documentation

typedef struct bu_vlb bu_vlb_t

Definition at line 50 of file vlb.h.

Function Documentation

void bu_vlb_init ( struct bu_vlb vlb)

Initialize the specified bu_vlb structure and mallocs the initial block of memory.

Parameters
vlbPointer to an uninitialized bu_vlb structure

Definition at line 35 of file vlb.c.

References bu_calloc(), BU_VLB_MAGIC, bu_vlb::buf, bu_vlb::bufCapacity, bu_vlb::magic, bu_vlb::nextByte, and VLB_BLOCK_SIZE.

Referenced by bu_vlb_initialize().

Here is the call graph for this function:

void bu_vlb_initialize ( struct bu_vlb vlb,
size_t  initialSize 
)

Initialize the specified bu_vlb structure and mallocs the initial block of memory with the specified size

Parameters
vlbPointer to an uninitialized bu_vlb structure
initialSizeThe desired initial size of the buffer

Definition at line 45 of file vlb.c.

References bu_calloc(), bu_log(), bu_vlb_init(), BU_VLB_MAGIC, bu_vlb::buf, bu_vlb::bufCapacity, bu_vlb::magic, bu_vlb::nextByte, and UNLIKELY.

Here is the call graph for this function:

void bu_vlb_write ( struct bu_vlb vlb,
unsigned char *  start,
size_t  len 
)

Write some bytes to the end of the bu_vlb structure. If necessary, additional memory will be allocated.

Parameters
vlbPointer to the bu_vlb structure to receive the bytes
startPointer to the first byte to be copied to the bu_vlb structure
lenThe number of bytes to copy to the bu_vlb structure

Definition at line 60 of file vlb.c.

References BU_CKMAG, bu_realloc(), BU_VLB_MAGIC, bu_vlb::buf, bu_vlb::bufCapacity, bu_vlb::nextByte, and VLB_BLOCK_SIZE.

Here is the call graph for this function:

void bu_vlb_reset ( struct bu_vlb vlb)

Reset the bu_vlb counter to the start of its byte array. This essentially ignores any bytes currently in the buffer, but does not free any memory.

Parameters
vlbPointer to the bu_vlb structure to be reset

Definition at line 83 of file vlb.c.

References BU_CKMAG, BU_VLB_MAGIC, and bu_vlb::nextByte.

unsigned char* bu_vlb_addr ( struct bu_vlb vlb)

Get a pointer to the byte array held by the bu_vlb structure

Parameters
vlbPointer to the bu_vlb structure
Returns
A pointer to the byte array contained by the bu_vlb structure

Definition at line 91 of file vlb.c.

References BU_CKMAG, BU_VLB_MAGIC, and bu_vlb::buf.

size_t bu_vlb_buflen ( struct bu_vlb vlb)

Return the number of bytes used in the bu_vlb structure

Parameters
vlbPointer to the bu_vlb structure
Returns
The number of bytes written to the bu_vlb structure

Definition at line 99 of file vlb.c.

References BU_CKMAG, BU_VLB_MAGIC, and bu_vlb::nextByte.

void bu_vlb_free ( struct bu_vlb vlb)

Free the memory allocated for the byte array in the bu_vlb structure. Also uninitializes the structure.

Parameters
vlbPointer to the bu_vlb structure

Definition at line 107 of file vlb.c.

References BU_CKMAG, bu_free(), BU_VLB_MAGIC, bu_vlb::buf, bu_vlb::bufCapacity, bu_vlb::magic, and bu_vlb::nextByte.

Here is the call graph for this function:

void bu_vlb_print ( struct bu_vlb vlb,
FILE *  fd 
)

Write the current byte array from the bu_vlb structure to a file

Parameters
vlbPointer to the bu_vlb structure that is the source of the bytes
fdPointer to a FILE to receive the bytes

Definition at line 121 of file vlb.c.

References BU_CKMAG, BU_VLB_MAGIC, bu_vlb::buf, and bu_vlb::nextByte.

void bu_pr_vlb ( const char *  title,
const struct bu_vlb vlb 
)

Print the bytes set in a variable-length byte array.

Definition at line 134 of file vlb.c.

References BU_CKMAG, bu_log(), BU_VLB_MAGIC, bu_vls_addr(), bu_vls_free(), BU_VLS_INIT_ZERO, bu_vls_printf(), bu_vls_strcat(), bu_vlb::buf, and bu_vlb::nextByte.

Here is the call graph for this function: