-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdataframe.h
264 lines (231 loc) · 8.22 KB
/
cdataframe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/* CDataX
* Pierre CAMELERI
* Raphaël GUIGNOLLE
* cdataframe.c -
* Function to manage a CDataframe
* - Creation
* - Destruction
* - Printing
* - Modification (addition)
* - Getters
* - Setters
* - Sorting
* - Interaction with IO
* Also include some internal function (not declared in header).
*/
#ifndef CDATAX_CDATAFRAME_H
#define CDATAX_CDATAFRAME_H
#include "llc.h"
#include "column.h"
// Should be inferior as an int
#define USER_INPUT_SIZE 255
#define MAX_COL 1024
typedef struct cadataframe {
indexation size;
indexation colsize;
list *data;
} CDataframe;
/**
* @brief Create an empty Cdataframe (no data provided only the an empty list is created)
* @return Pointer to the newly created Cdataframe or the NULL pointer if it cannot allocate memory
* */
CDataframe *create_empty_cdataframe();
/**
* @brief Create an empty Cdataframe (no data provided by all columns defined)
* @param cdftype list of types that will be used
* @param colNames list og names that will be used
* @param size size of the above list
* @return Pointer to the newly created Cdataframe or the NULL pointer if it cannot allocate memory
* */
CDataframe *create_cdataframe(Enum_type *cdfTypes, char **colNames, indexation size);
/**
* @brief Column deletion
* @param cdf Pointer to the CDataframe to delete
* */
void delete_cdataframe(CDataframe **cdf);
/**
* @brief Write all data to a new Cdataframe (from user input)
* @param cdf Cdataframe pointer (should be empty)
* @warning Since, write interacts with IO, it doesn't check memory allocation.
* */
void write(CDataframe **cdf);
/**
* @brief Print all data of an existing Cdataframe
* @param cdf Cdataframe pointer
* @param ref_col Reference column used for sort, NULL if object is preferred
* @return 3, if a ref_col is mentioned but the col isn't sorted
* 2 if ref_col is unknown
* 1 with internal memory allocation,
* 0 else
* */
int print_all(CDataframe *cdf, char *ref_col);
/**
* @brief Print all column names
* @param cdf Cdataframe pointer
* @param from Starting line
* @param to Ending line (excluded)
* @return 2 if there's an error with the section selected, 0 else
* */
int print_columns_names_partial(CDataframe *cdf, indexation from, indexation to);
/**
* @brief Print all column names
* @param cdf Cdataframe pointer
* */
void print_columns_names(CDataframe *cdf);
/**
* @brief Print all lines from a start to an end from an existing Cdataframe
* @param cdf Cdataframe pointer
* @param ref_col Reference column used for sort, NULL if object is preferred
* @param from Starting line
* @param to Ending line (excluded)
* @return 3, if a ref_col is mentioned but the col isn't sorted
* 2 if there's an error with the section selected or name of ref_col,
* 1 with internal memory allocation,
* 0 else
* */
int print_lines(CDataframe *cdf, char *ref_col, indexation from, indexation to);
/**
* @brief Print all columns from a start to an end from an existing Cdataframe
* @param cdf Cdataframe pointer
* @param ref_col Reference column used for sort, NULL if object is preferred
* @param from Starting column
* @param to Ending column (excluded)
* @return 3, if a ref_col is mentioned but the col isn't sorted
* 2 if there's an error with the section selected or name of ref_col,
* 1 with internal memory allocation,
* 0 else
* */
int print_columns(CDataframe *cdf, char *ref_col, indexation from, indexation to);
/**
* @brief Add a new line to an existing Cdataframe
* @param cdf Cdataframe pointer
* @param values Tab of Col_type to insert to the new line
* @param size Size of the previous tab, should be the exact same size as the Cdataframe size
* @return 3 if the cdf is empty (no info on columns types),
* 2 if it's the size,
* 1 if it's the memory allocation,
* 0 else
* */
int add_newline(CDataframe *cdf, Col_type *values, indexation size);
/**
* @brief Add a new line to an existing Cdataframe
* @param cdf Cdataframe pointer
* @param type Type of value to insert
* @param values Tab of Col_type to insert to the new line
* @param size Size of the previous tab, should be the exact same size as the Cdataframe colsize
* @return 2 if it's the size,
* 1 if there's an error with memory allocation,
* 0 else
* */
int add_newcolumn(CDataframe *cdf, Enum_type type, Col_type *values, indexation size, char *title);
/**
* @brief Query column by his name
* @param cdf Cdataframe pointer
* @param title Name of the column
* @return A pointer to that column (may be NULL if nothing is found)
* */
Column *query_column_by_name(CDataframe *cdf, char *title);
/**
* @brief Delete one line of the Cdataframe
* @param cdf Cdataframe pointer
* @param line Line to remove
* @warning Line represent object, no sorting
* @return 0 on success, 2 if there's an error the line parameter
* */
int del_line(CDataframe *cdf, indexation line);
/**
* @brief Delete one column of the Cdataframe, query by names
* @param cdf Cdataframe pointer
* @param col_title Column name to remove
* @return 0 on success, 2 if there's an error the col_name parameter
* */
int del_column(CDataframe *cdf, char *col_title);
/**
* @brief Rename one column name
* @param cdf Cdataframe pointer
* @param col_title Column name to rename
* @param newTitle New title of the column
* @return 0 on success,
* 1 if there's an error with the memory allocation
* 2 if there's an error the col_title parameter
* */
int rename_column(CDataframe *cdf, char *col_title, char *newTitle);
/**
* @brief Give a pointer to the first cell with the matching value
* @param cdf Cdataframe pointer
* @param var Value to find
* @return A pointer to the value (first found by column) if it's found, the NULL pointer else
* */
Col_type *find_in(CDataframe *cdf, void *var);
/**
* @brief Give a pointer to the value at the line and column wanted
* @param cdf Cdataframe pointer
* @param line The line index
* @param col_title column name to find in
* @warning Line is ordered according to objects (no sorting)
* @return A pointer to the value if it's found, the NULL pointer else
* */
Col_type *get_var(CDataframe *cdf, char *col_title, indexation line);
/**
* @brief Get the amount of lines
* @param cdf Cdataframe pointer
* @return Number of lines
* */
indexation get_lines_amount(CDataframe *cdf);
/**
* @brief Get the amount of lines
* @param cdf Cdataframe pointer
* @return Number of columns
* */
indexation get_columns_amount(CDataframe *cdf);
/**
* @brief Get the occurrences of a var in a Cdataframe
* @param cdf Cdataframe pointer
* @param var Variable to compare
* @return Number of occurrences
* */
int get_occurrences(CDataframe *cdf, void *var);
/**
* @brief Get the occurrences of a var superior to a var in a Cdataframe
* @param cdf Cdataframe pointer
* @param var Variable to compare
* @return Number of occurrences
* */
int get_superior_occurrences(CDataframe *cdf, void *var);
/**
* @brief Get the occurrences of a var inferior to a var in a Cdataframe
* @param cdf Cdataframe pointer
* @param var variable to compare
* @return number of occurrences
* */
int get_inferior_occurrences(CDataframe *cdf, void *var);
/**
* @brief Sort 1 column
* @param cdf Cdataframe pointer
* @param col_title Name of the column to align sort on
* @param sort_dir Direction to sort either ASC or DESC is accepted
* @warning Fail if col_title is not found or sort_dir is incorrect !
* */
void sorting_column(CDataframe *cdf, char *col_title, int sort_dir);
/**
* @brief Sort all columns
* @param cdf Cdataframe pointer
* @param sort_dir Direction to sort either ASC or DESC is accepted
* @warning Fail if sort_dir is incorrect !
* */
void sort_all_columns(CDataframe *cdf, int sort_dir);
/**
* @brief Export into a csvfile
* @param cdf Pointer to the CDataframe
* @param file_name Csv filename where export file
* @warning If the file exists it will be overwritten
* */
void save_into_csv(CDataframe *cdf, char *file_name);
/**
* @brief Create a CDataframe from csvfile
* @param file_name CSV filename
* @param dftype Array of types
* @param size Size of the types array
* */
CDataframe *load_from_csv(char *file_name, Enum_type *dftype, int size);
#endif //CDATAX_CDATAFRAME_H