data_structures
types.h
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* types.h :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/16 22:13:11 by unite #+# #+# */
10 /* Updated: 2020/09/07 23:39:12 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #ifndef TYPES_H
15 
16 # define TYPES_H
17 
18 # include <stdlib.h>
19 # include "utils.h"
20 
47 typedef struct s_type
48 {
49  char *name;
50  void *(*copy)(const void *);
51  void (*del)(void *);
52  int (*cmp)(const void *, const void *);
53  size_t (*hash)(const void *, size_t);
54 } t_type;
55 
60 extern const t_type *g_type_char;
61 
66 extern const t_type *g_type_float;
67 
72 extern const t_type *g_type_int;
73 
78 extern const t_type *g_type_str;
79 
84 extern const t_type *g_type_array;
85 
90 int *int2ptr(int a);
91 
96 char *char2ptr(char a);
97 
102 float *float2ptr(float a);
103 
108 int ptr2int(const void *ptr);
109 
114 char ptr2char(const void *ptr);
115 
120 float ptr2float(const void *ptr);
121 
122 #endif
s_type::name
char * name
The name of a datatype as a string.
Definition: types.h:49
g_type_float
const t_type * g_type_float
A representation of the float data type.
Definition: type_float.c:56
s_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition: types.h:52
float2ptr
float * float2ptr(float a)
Converts float to float*
Definition: data2ptr.c:32
g_type_str
const t_type * g_type_str
A representation of the char* data type.
Definition: type_str.c:51
char2ptr
char * char2ptr(char a)
Converts char to char*
Definition: data2ptr.c:24
g_type_char
const t_type * g_type_char
A representation of the char data type.
Definition: type_char.c:54
utils.h
s_type::hash
size_t(* hash)(const void *, size_t)
(optional) A function pointer used to get a hash value of this data type
Definition: types.h:53
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
g_type_int
const t_type * g_type_int
A representation of the int data type.
Definition: type_int.c:56
ptr2int
int ptr2int(const void *ptr)
Converts int* to int
Definition: ptr2data.c:16
s_type::del
void(* del)(void *)
A function pointer used to free the memory taken by the data type.
Definition: types.h:51
ptr2float
float ptr2float(const void *ptr)
Converts float* to float
Definition: ptr2data.c:21
ptr2char
char ptr2char(const void *ptr)
Converts char* to char
Definition: ptr2data.c:26
int2ptr
int * int2ptr(int a)
Converts int to int*
Definition: data2ptr.c:16
g_type_array
const t_type * g_type_array
A representation of the t_array data type.
Definition: type_array.c:33