YACDB
Yet Another C(rappy) Database
record.h File Reference

A structure for handling data of unknown type. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for record.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  record
 Handles the general record type that abstracts away from the actual type of the data. More...
 

Macros

#define LAST_RECORD_TYPE   7
 The last member of record_type. More...
 

Enumerations

enum  record_type {
  RECORD_TYPE_NULL = 0 , RECORD_TYPE_CHAR = 1 , RECORD_TYPE_SHORT = 2 , RECORD_TYPE_INT = 3 ,
  RECORD_TYPE_LONG = 4 , RECORD_TYPE_FLOAT = 5 , RECORD_TYPE_0 = 6 , RECORD_TYPE_1 = 7
}
 The type stored inside the record. More...
 

Functions

size_t record_size (struct record *record)
 The size of the data stored in the record in bytes.
 
size_t record_type_size (char type)
 
int record_get_char (struct record *record, char **buffer)
 
int record_get_string (struct record *record, char **buffer)
 
int record_get_short (struct record *record, short *buffer)
 
int record_get_long (struct record *record, long *buffer)
 
int * record_get_int (struct record *record, int *buffer)
 
float * record_get_float (struct record *record, float *buffer)
 
struct recordrecord_from_char (char *data)
 Creates a pointer to a record from a ::char. More...
 
struct recordrecord_from_short (short *data)
 Creates a pointer to a record from a short. More...
 
struct recordrecord_from_int (int *data)
 Creates a pointer to a record from an int. More...
 
struct recordrecord_from_long (long *data)
 Creates a pointer to a record from a long. More...
 
struct recordrecord_from_float (float *data)
 Creates a pointer to a record from a float. More...
 
struct recordrecord_from_string (char **data)
 Creates a pointer to a record from a string. More...
 
int compress_records (struct record **records, size_t nb_records, size_t *size, void **buffer)
 Takes a list of records and returns a single buffer that is the concatenation of all the records. More...
 
struct recordextract_record (void *buffer, size_t n)
 Extracts the nth record from a compressed group of records. More...
 
int replace_record (void **buffer, size_t *size, size_t n, struct record *record)
 Replaces the nth record from a compressed group of records. More...
 
int compare_r (struct record *r1, struct record *r2)
 Compares 2 records r1 r2. More...
 
void free_record (struct record *record)
 

Detailed Description

A structure for handling data of unknown type.

Author
Jack Royer
Date
2022-05-29

Macro Definition Documentation

◆ LAST_RECORD_TYPE

#define LAST_RECORD_TYPE   7

The last member of record_type.

It is used to determine the size of strings.

Enumeration Type Documentation

◆ record_type

The type stored inside the record.

Currently, the only supported record types are:

  • null
  • int (char, short, int, long)
  • float
  • string

A string is stored with any record type greater than LAST_RECORD_TYPE. The value of the type determines the size of the string.

Enumerator
RECORD_TYPE_0 
Deprecated:
causes issues with comparisons
RECORD_TYPE_1 
Deprecated:
causes issues with comparisons

Function Documentation

◆ compare_r()

int compare_r ( struct record r1,
struct record r2 
)

Compares 2 records r1 r2.

Returns
0 if r1 == r2, -1 if r1 < r2, 1 if r1 > r2.
Exceptions
returns2 if r1 and r2 are of different types

◆ compress_records()

int compress_records ( struct record **  records,
size_t  nb_records,
size_t *  size,
void **  buffer 
)

Takes a list of records and returns a single buffer that is the concatenation of all the records.

Parameters
recordsThe array of records to compress
nb_recordsThe size of the array
sizeThe final size of the buffer
bufferThe buffer to be written to
Exceptions
Returns-1 if an error occured.

◆ extract_record()

struct record * extract_record ( void *  buffer,
size_t  n 
)

Extracts the nth record from a compressed group of records.

Exceptions
ReturnsNULL if an error occured.

◆ record_from_char()

struct record * record_from_char ( char *  data)

Creates a pointer to a record from a ::char.

Exceptions
ReturnsNULL if an error occured.

◆ record_from_float()

struct record * record_from_float ( float *  data)

Creates a pointer to a record from a float.

Exceptions
ReturnsNULL if an error occured.

◆ record_from_int()

struct record * record_from_int ( int *  data)

Creates a pointer to a record from an int.

Exceptions
ReturnsNULL if an error occured.

◆ record_from_long()

struct record * record_from_long ( long *  data)

Creates a pointer to a record from a long.

Exceptions
ReturnsNULL if an error occured.

◆ record_from_short()

struct record * record_from_short ( short *  data)

Creates a pointer to a record from a short.

Exceptions
ReturnsNULL if an error occured.

◆ record_from_string()

struct record * record_from_string ( char **  data)

Creates a pointer to a record from a string.

Exceptions
ReturnsNULL if an error occured.

◆ record_get_float()

float * record_get_float ( struct record record,
float *  buffer 
)
Todo:
TODO: implement

◆ record_get_int()

int * record_get_int ( struct record record,
int *  buffer 
)
Todo:
TODO: implement

◆ replace_record()

int replace_record ( void **  buffer,
size_t *  size,
size_t  n,
struct record record 
)

Replaces the nth record from a compressed group of records.

The buffer as well as the size will be modified (if needed).

Exceptions
Returns-1 if an error occured.