C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
generic_def.h File Reference

Contains Macros that are used for defining psuedo data template functions. More...

#include "typedefs.h"
#include "memory_manager.h"

Go to the source code of this file.

Macros

#define CMPR(T, NAME)
 Template Compare function for default data types. More...
 
#define ASSGN(T, NAME)
 Template Assign memory function for default data types. More...
 
#define SWAP(T, NAME)
 Template Swap function for default data types. More...
 
#define FMT_SPF(T)
 
#define PRINT_GEN(T, NAME)
 Template print function for default data types. More...
 
#define CMPR_IDX(T, NAME)
 Template function for comparing elemts at given indicies of an array for default data types. More...
 
#define SWP_IDX(T, NAME)
 Template function for swaping elemts at given indicies of an array for default data types. More...
 
#define COPY_IDX(T, NAME)
 Template function for copying element to a given index of an array for default data types. More...
 
#define GET_IDX(T, NAME)
 Template function for getting element at a given index of an array for default data types. More...
 
#define GET_IDX_CPY(T, NAME)
 Template function for getting element at a given index of an array for default data types. More...
 

Functions

e_cmpr compare_char (t_gen, t_gen)
 Below routines defined as reference for basic datatypes. More...
 
e_cmpr compare_int (t_gen, t_gen)
 
e_cmpr compare_float (t_gen, t_gen)
 
e_cmpr compare_string (t_gen, t_gen)
 
e_cmpr compare_gen (t_gen, t_gen)
 
t_gen assign_char (char)
 
t_gen assign_int (int)
 
t_gen assign_float (float)
 
t_gen assign_string (char *)
 
t_gen assign_gen (t_gen)
 
void swap_char (t_gen, t_gen)
 
void swap_int (t_gen, t_gen)
 
void swap_float (t_gen, t_gen)
 
void swap_string (t_gen, t_gen)
 
void swap_gen (t_gen, t_gen)
 
void print_char (t_gen)
 
void print_float (t_gen)
 
void print_int (t_gen)
 
void print_str (t_gen)
 
void print_gen (t_gen)
 
e_cmpr compare_idx_char (t_gen, int, int)
 
e_cmpr compare_idx_int (t_gen, int, int)
 
e_cmpr compare_idx_float (t_gen, int, int)
 
void swap_idx_char (t_gen, int, int)
 
void swap_idx_int (t_gen, int, int)
 
void swap_idx_float (t_gen, int, int)
 
void copy_idx_char (t_gen, int, t_gen)
 
void copy_idx_int (t_gen, int, t_gen)
 
void copy_idx_float (t_gen, int, t_gen)
 
t_gen get_idx_char (t_gen, int)
 
t_gen get_idx_int (t_gen, int)
 
t_gen get_idx_float (t_gen, int)
 
t_gen get_idx_char_cpy (t_gen, int)
 
t_gen get_idx_int_cpy (t_gen, int)
 
t_gen get_idx_float_cpy (t_gen, int)
 
e_cmpr gen_cmpr_idx (t_gen x, int idx1, int idx2)
 
void gen_swp_idx (t_gen x, int idx1, int idx2)
 
void gen_cpy_idx (t_gen x, int idx1, t_gen data)
 
t_gen gen_get_idx (t_gen x, int idx1)
 

Detailed Description

Contains Macros that are used for defining psuedo data template functions.

Definition in file generic_def.h.

Macro Definition Documentation

◆ ASSGN

#define ASSGN (   T,
  NAME 
)
Value:
t_gen NAME(T y) \
{\
t_gen x = get_mem(1, sizeof(T));\
*((T*)x) = y;\
return x;\
}
#define get_mem(nmemb, size)
Definition: memory_manager.h:8
void * t_gen
Base Data type used for all data structure and data elements.
Definition: typedefs.h:41

Template Assign memory function for default data types.

Definition at line 24 of file generic_def.h.

◆ CMPR

#define CMPR (   T,
  NAME 
)
Value:
e_cmpr NAME(t_gen x, t_gen y)\
{ \
e_cmpr ret = eEQUAL;\
T tmp = (*((T*)(x))) - (*((T*)(y)));\
if (tmp < 0) \
ret = eLESS;\
else if (tmp > 0)\
ret = eGREAT;\
return ret;\
}
e_cmpr
Custom Compare function return type.
Definition: typedefs.h:34
@ eGREAT
Definition: typedefs.h:37
@ eLESS
Definition: typedefs.h:35
@ eEQUAL
Definition: typedefs.h:36

Template Compare function for default data types.

Definition at line 11 of file generic_def.h.

◆ CMPR_IDX

#define CMPR_IDX (   T,
  NAME 
)
Value:
e_cmpr NAME(t_gen x, int idx1, int idx2)\
{ \
e_cmpr ret = eEQUAL;\
T *arr = ((T*)(x));\
T tmp = arr[idx1] -arr[idx2];\
if (tmp < 0) \
ret = eLESS;\
else if (tmp > 0)\
ret = eGREAT;\
return ret;\
}

Template function for comparing elemts at given indicies of an array for default data types.

Definition at line 70 of file generic_def.h.

◆ COPY_IDX

#define COPY_IDX (   T,
  NAME 
)
Value:
void NAME(t_gen x, int idx1, t_gen data)\
{ \
T *arr = ((T*)(x));\
arr[idx1] = *((T*)(data));\
}

Template function for copying element to a given index of an array for default data types.

Definition at line 92 of file generic_def.h.

◆ FMT_SPF

#define FMT_SPF (   T)
Value:
_Generic((T),\
char: "%c", \
signed char: "%hhd", \
unsigned char: "%hhu", \
signed short: "%hd", \
unsigned short: "%hu", \
signed int: "%d", \
unsigned int: "%u", \
long int: "%ld", \
unsigned long int: "%lu", \
long long int: "%lld", \
unsigned long long int: "%llu", \
float: "%f", \
double: "%f", \
long double: "%Lf", \
char *: "%s", \
void *: "%p")

Defines format specfier depending on type of data used for implementing generic print Note: Requires C11 compiler since it use _Generic

Definition at line 43 of file generic_def.h.

◆ GET_IDX

#define GET_IDX (   T,
  NAME 
)
Value:
t_gen NAME(t_gen x, int idx1)\
{ \
T *arr = ((T*)(x));\
t_gen tmp = &arr[idx1] ;\
return tmp;\
}

Template function for getting element at a given index of an array for default data types.

Definition at line 99 of file generic_def.h.

◆ GET_IDX_CPY

#define GET_IDX_CPY (   T,
  NAME 
)
Value:
t_gen NAME(t_gen x, int idx1)\
{ \
T *arr = ((T*)(x));\
t_gen tmp = get_mem(1, sizeof(T));\
*(T*)tmp = arr[idx1] ;\
return tmp;\
}

Template function for getting element at a given index of an array for default data types.

Definition at line 107 of file generic_def.h.

◆ PRINT_GEN

#define PRINT_GEN (   T,
  NAME 
)
Value:
void NAME(t_gen x) \
{ \
T y;\
printf(FMT_SPF(y), *((T*)x)); \
}
#define FMT_SPF(T)
Definition: generic_def.h:43

Template print function for default data types.

Definition at line 63 of file generic_def.h.

◆ SWAP

#define SWAP (   T,
  NAME 
)
Value:
void NAME(t_gen x, t_gen y) \
{\
T tmp = *((T*)x);\
*((T*)x) = *((T*)y);\
*((T*)y) = tmp;\
}

Template Swap function for default data types.

Definition at line 33 of file generic_def.h.

◆ SWP_IDX

#define SWP_IDX (   T,
  NAME 
)
Value:
void NAME(t_gen x, int idx1, int idx2)\
{ \
T *arr = ((T*)(x));\
T tmp = arr[idx1] ;\
arr[idx1] = arr[idx2];\
arr[idx2] = tmp;\
}

Template function for swaping elemts at given indicies of an array for default data types.

Definition at line 83 of file generic_def.h.

Function Documentation

◆ assign_char()

t_gen assign_char ( char  )

◆ assign_float()

t_gen assign_float ( float  )

◆ assign_gen()

t_gen assign_gen ( t_gen  )

◆ assign_int()

t_gen assign_int ( int  )

◆ assign_string()

t_gen assign_string ( char *  x)

Definition at line 43 of file generic_def.c.

◆ compare_char()

e_cmpr compare_char ( t_gen  ,
t_gen   
)

Below routines defined as reference for basic datatypes.

◆ compare_float()

e_cmpr compare_float ( t_gen  ,
t_gen   
)

◆ compare_gen()

e_cmpr compare_gen ( t_gen  x,
t_gen  y 
)

Definition at line 13 of file generic_def.c.

◆ compare_idx_char()

e_cmpr compare_idx_char ( t_gen  ,
int  ,
int   
)

◆ compare_idx_float()

e_cmpr compare_idx_float ( t_gen  ,
int  ,
int   
)

◆ compare_idx_int()

e_cmpr compare_idx_int ( t_gen  ,
int  ,
int   
)

◆ compare_int()

e_cmpr compare_int ( t_gen  ,
t_gen   
)

◆ compare_string()

e_cmpr compare_string ( t_gen  x,
t_gen  y 
)

Definition at line 26 of file generic_def.c.

◆ copy_idx_char()

void copy_idx_char ( t_gen  ,
int  ,
t_gen   
)

◆ copy_idx_float()

void copy_idx_float ( t_gen  ,
int  ,
t_gen   
)

◆ copy_idx_int()

void copy_idx_int ( t_gen  ,
int  ,
t_gen   
)

◆ gen_cmpr_idx()

e_cmpr gen_cmpr_idx ( t_gen  x,
int  idx1,
int  idx2 
)

Definition at line 88 of file generic_def.c.

◆ gen_cpy_idx()

void gen_cpy_idx ( t_gen  x,
int  idx1,
t_gen  data 
)

Definition at line 74 of file generic_def.c.

◆ gen_get_idx()

t_gen gen_get_idx ( t_gen  x,
int  idx1 
)

Definition at line 68 of file generic_def.c.

◆ gen_swp_idx()

void gen_swp_idx ( t_gen  x,
int  idx1,
int  idx2 
)

Definition at line 80 of file generic_def.c.

◆ get_idx_char()

t_gen get_idx_char ( t_gen  ,
int   
)

◆ get_idx_char_cpy()

t_gen get_idx_char_cpy ( t_gen  ,
int   
)

◆ get_idx_float()

t_gen get_idx_float ( t_gen  ,
int   
)

◆ get_idx_float_cpy()

t_gen get_idx_float_cpy ( t_gen  ,
int   
)

◆ get_idx_int()

t_gen get_idx_int ( t_gen  ,
int   
)

◆ get_idx_int_cpy()

t_gen get_idx_int_cpy ( t_gen  ,
int   
)

◆ print_char()

void print_char ( t_gen  )

◆ print_float()

void print_float ( t_gen  )

◆ print_gen()

void print_gen ( t_gen  )

◆ print_int()

void print_int ( t_gen  )

◆ print_str()

void print_str ( t_gen  str)

Definition at line 63 of file generic_def.c.

◆ swap_char()

void swap_char ( t_gen  ,
t_gen   
)

◆ swap_float()

void swap_float ( t_gen  ,
t_gen   
)

◆ swap_gen()

void swap_gen ( t_gen  ,
t_gen   
)

◆ swap_idx_char()

void swap_idx_char ( t_gen  ,
int  ,
int   
)

◆ swap_idx_float()

void swap_idx_float ( t_gen  ,
int  ,
int   
)

◆ swap_idx_int()

void swap_idx_int ( t_gen  ,
int  ,
int   
)

◆ swap_int()

void swap_int ( t_gen  ,
t_gen   
)

◆ swap_string()

void swap_string ( t_gen  ,
t_gen   
)