1 #ifndef GELIB_GENERAL_H 2 #define GELIB_GENERAL_H 11 #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) 30 #define MAX_MSG_LENGTH 2047 33 #define DIRSEPARATOR '\\' 35 #define DIRSEPARATOR '/' 39 #define NUM_DIGITS_IN_PRINTED_EXPONENT 3 41 #define NUM_DIGITS_IN_PRINTED_EXPONENT 2 45 #define _STRCASECMP _stricmp 47 #define _STRCASECMP strcasecmp 57 #define TC_B_BLACK FOREGROUND_GREEN 58 #define TC_D_BLACK FOREGROUND_GREEN 59 #define TC_B_RED FOREGROUND_RED 60 #define TC_D_RED FOREGROUND_RED 61 #define TC_B_GREEN FOREGROUND_GREEN 62 #define TC_D_GREEN FOREGROUND_GREEN 63 #define TC_B_YELLOW FOREGROUND_RED | FOREGROUND_GREEN 64 #define TC_D_YELLOW FOREGROUND_RED | FOREGROUND_GREEN 65 #define TC_B_BLUE FOREGROUND_BLUE 66 #define TC_D_BLUE FOREGROUND_BLUE 67 #define TC_B_VIOLET FOREGROUND_BLUE | FOREGROUND_RED 68 #define TC_D_VIOLET FOREGROUND_BLUE | FOREGROUND_RED 69 #define TC_B_CYAN FOREGROUND_GREEN | FOREGROUND_BLUE 70 #define TC_D_CYAN FOREGROUND_GREEN | FOREGROUND_BLUE 71 #define TC_B_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE 72 #define TC_D_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE 74 #define TC_DEFAULT TC_D_WHITE 77 #define TC_B_BLACK "\033[0;30m" 78 #define TC_D_BLACK "\033[1;30m" 79 #define TC_B_RED "\033[0;31m" 80 #define TC_D_RED "\033[1;31m" 81 #define TC_B_GREEN "\033[0;32m" 82 #define TC_D_GREEN "\033[1;32m" 83 #define TC_B_YELLOW "\033[0;33m" 84 #define TC_D_YELLOW "\033[1;33m" 85 #define TC_B_BLUE "\033[0;34m" 86 #define TC_D_BLUE "\033[1;34m" 87 #define TC_B_VIOLET "\033[0;35m" 88 #define TC_D_VIOLET "\033[1;35m" 89 #define TC_B_CYAN "\033[0;36m" 90 #define TC_D_CYAN "\033[1;36m" 91 #define TC_B_WHITE "\033[0;37m" 92 #define TC_D_WHITE "\033[1;37m" 94 #define TC_DEFAULT "\033[0m" 99 ETC_VOID,
ETC_B_BLACK,
ETC_D_BLACK,
ETC_B_RED,
ETC_D_RED,
ETC_B_GREEN,
ETC_D_GREEN,
ETC_B_YELLOW,
ETC_D_YELLOW,
ETC_B_BLUE,
ETC_D_BLUE,
ETC_B_VIOLET,
ETC_D_VIOLET,
ETC_B_CYAN,
ETC_D_CYAN,
ETC_B_WHITE,
ETC_D_WHITE,
ETC_DEFAULT 133 #define CHANGE_CONSOLE_COLOUR(_1,_2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), _2) 135 #define CHANGE_CONSOLE_COLOUR(_1,_2) fprintf (_1, "%s", _2) 147 void errorr (
const char* file,
int line,
const char *format, ...);
148 void warningg (
const char* file,
int line,
const char *format, ...);
151 #define errol errorr (__FILE__, __LINE__, "za ktery muze autor teto sqele utility, bezte ho vytahat za usi") 152 #define _errorr0 errorr (__FILE__, __LINE__, "za ktery muze autor teto sqele utility, bezte ho vytahat za usi") 153 #define _errorr1(_1) errorr (__FILE__, __LINE__, _1) 154 #define _errorr2(_1,_2) errorr (__FILE__, __LINE__, _1,_2) 155 #define _errorr3(_1,_2,_3) errorr (__FILE__, __LINE__, _1,_2,_3) 156 #define _errorr4(_1,_2,_3,_4) errorr (__FILE__, __LINE__, _1,_2,_3,_4) 157 #define _errorr5(_1,_2,_3,_4,_5) errorr (__FILE__, __LINE__, _1,_2,_3,_4,_5) 158 #define _errorr6(_1,_2,_3,_4,_5,_6) errorr (__FILE__, __LINE__, _1,_2,_3,_4,_5,_6) 160 #define _errorr(_1) _errorr1(_1) 163 #define _warningg(_1) _warningg1(_1) 165 #define _warningg1(_1) warningg (__FILE__, __LINE__, _1) 166 #define _warningg2(_1,_2) warningg (__FILE__, __LINE__, _1,_2) 167 #define _warningg3(_1,_2,_3) warningg (__FILE__, __LINE__, _1,_2,_3) 168 #define _warningg4(_1,_2,_3,_4) warningg (__FILE__, __LINE__, _1,_2,_3,_4) 169 #define _warningg5(_1,_2,_3,_4,_5) warningg (__FILE__, __LINE__, _1,_2,_3,_4,_5) 175 void openFileTest (
const FILE *stream,
const char *name);
177 FILE*
openFileN (
const char* File,
int Line,
const char *mode,
const char *key,
const char *name);
178 FILE*
openFilePN (
const char* File,
int Line,
const char *mode,
const char *key,
const char *path,
const char *name);
179 FILE*
openFilePNS (
const char* File,
int Line,
const char *mode,
const char *key,
const char *path,
const char *name,
const char *suff);
180 FILE*
openFilePNSS (
const char* File,
int Line,
const char *mode,
const char *key,
const char *path,
const char *name,
const char *suff,
const char *suff2);
182 #define _openFileN(_1,_2,_3) openFileN (__FILE__, __LINE__, _1,_2,_3) 183 #define _openFilePN(_1,_2,_3,_4) openFilePN (__FILE__, __LINE__, _1,_2,_3,_4) 184 #define _openFilePNS(_1,_2,_3,_4,_5) openFilePNS (__FILE__, __LINE__, _1,_2,_3,_4,_5) 185 #define _openFilePNSS(_1,_2,_3,_4,_5,_6) openFilePNSS(__FILE__, __LINE__, _1,_2,_3,_4,_5,_6) 192 template <
class ArgType>
void allocate (ArgType*& p,
long a) {
if (a) p =
new ArgType [a];
else p = NULL; }
193 template <
class ArgType>
void allocate (ArgType**& p,
long a,
long b) {
if (a) { p =
new ArgType* [a];
while (a--)
allocate (p[a], b); }
else p = NULL; }
194 template <
class ArgType>
void allocate (ArgType***& p,
long a,
long b,
long c) {
if (a) { p =
new ArgType** [a];
while (a--)
allocate (p[a], b, c); }
else p = NULL; }
203 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
208 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
215 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
220 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
225 template <
class ArgType>
void deallocateCheck (ArgType*** p,
long a,
long b,
bool check=
true)
227 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
232 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
235 template <
class ArgType>
void deallocateCheck (ArgType*** p,
long a,
long *b,
bool check=
true)
237 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
247 template <
class ArgType>
void fill_all_by (ArgType* p,
long a, ArgType value) {
while (a--) p[a] = value; }
248 template <
class ArgType>
void fill_all_by (ArgType** p,
long a,
long b, ArgType value) {
while (a--)
fill_all_by (p[a], b, value); }
249 template <
class ArgType>
void fill_all_by (ArgType*** p,
long a,
long b,
long c, ArgType value) {
while (a--)
fill_all_by (p[a], b, c, value); }
253 template <
class ArgType>
void fill_col_by (ArgType** p,
long n,
long j, ArgType value) {
while (n--) p[n][j] = value; }
262 if (!n && old_field)
_errorr (
"allocate_another_val: n == 0 and old_field != NULL - forbidden");
263 ArgType *new_field =
new ArgType [n+1];
264 while (n--) new_field[n] = old_field[n];
266 old_field = new_field;
273 ArgType **new_field =
new ArgType* [n+add];
274 while (n--) new_field[n] = old_field[n];
276 old_field = new_field;
297 if (array[j] == NULL)
break;
299 for (i=j+1; i<n; i++)
301 array[j++] = array[i];
312 while (n--)
if (a1[n] != a2[n])
break;
315 if (a1 == a2 && !n)
return 0;
322 while (n--)
if (val == array[n])
break;
332 for (i=0; i<n-1; i++)
333 for (j=i+1; j<n; j++)
334 if (array[i] == array[j])
return false;
344 if (same_dim && nx!=ny)
return false;
348 for (i=0; i<nx; i++) {
350 if (x[i] == y[j])
break;
352 if (j==ny)
return false;
362 template <
class ArgType>
bool same_array_elements_sym (
long nx,
const ArgType *x,
long ny,
const ArgType *y,
bool same_dim=
false)
373 template <
class ArgType>
void add_array (
long &n1, ArgType *&array1,
long n2,
const ArgType *array2)
377 ArgType *new_array =
new ArgType [n1+n2];
380 for (i=0; i<n1; i++) new_array[ i] = array1[i];
381 for (i=0; i<n2; i++) new_array[n1+i] = array2[i];
389 template <
class ArgType>
void add_array_unique (
long &n1, ArgType *&array1,
long n2,
const ArgType *array2)
396 ArgType *new_array =
new ArgType [n1+n3];
399 for (i=0; i<n1; i++) new_array[n3++] = array1[i];
400 for (i=0; i<n2; i++)
if (!
is_member_of_array (array2[i], n1, array1)) new_array[n3++] = array2[i];
421 return (stat (name, &buffer) == 0);
430 if (
remove(name) != 0)
440 _errorr2(
"Error deleting file %s", name);
445 #endif // GELIB_GENERAL_H void allocate(ArgType *&p, long a)
*** *** *** *** ALLOCATE TEMPLATES *** *** *** ***
void add_array(long &n1, ArgType *&array1, long n2, const ArgType *array2)
FILE * openFileN(const char *File, int Line, const char *mode, const char *key, const char *name)
#define CHANGE_CONSOLE_COLOUR(_1, _2)
void fill_col_by(ArgType **p, long n, long j, ArgType value)
void change_console_colour(FILE *stream, ETCLR clr)
void openFileTest(const FILE *stream, const char *name)
*** *** *** *** FILE FCE *** *** *** ***
bool members_are_unique(long n, const ArgType *array)
check out all members of array "a" are uniq
void shake_down_ptr_array(long &n, ArgType *array)
*** *** *** *** VARIOUS TEMPLATES *** *** *** ***
#define array(MAT, ROWS, COLS, ROW, COL)
const char * trmt_clr_int2clr(ETCLR clr)
void interchange2(ArgType &a, ArgType &b)
void warningg(const char *file, int line, const char *format,...)
void fill_row_by(ArgType **p, long i, long m, ArgType value)
void setadd_another_uno_ptr(long &n, ArgType **&field, ArgType *p)
void add_array_unique(long &n1, ArgType *&array1, long n2, const ArgType *array2)
long is_member_of_array(ArgType val, long n, const ArgType *array)
check out "val" is member of "array"
#define TC_B_BLACK
*** *** *** *** COLOURS *** *** *** *** Termit Colours
FILE * openFilePN(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name)
FILE * openFilePNS(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff)
void allocate_another_uno_ptr(long n, ArgType **&old_field, long add=1)
bool file_delete_if_exist(const char *name)
bool file_exist(const char *name)
void allocate_another_val(long n, ArgType *&old_field)
*** *** *** *** REALLOCATE TEMPLATES *** *** *** ***
bool same_array_elements_sym(long nx, const ArgType *x, long ny, const ArgType *y, bool same_dim=false)
Function finds out whether every element of the array 'x' is in the array 'y', and symmetrically ever...
void fill_all_by(ArgType *p, long a, ArgType value)
*** *** *** *** FILL TEMPLATES *** *** *** ***
void file_delete_if_exist_exit(const char *name)
void errorr(const char *file, int line, const char *format,...)
*** *** *** *** ERROR FCE *** *** *** ***
bool same_array_elements_asym(long nx, const ArgType *x, long ny, const ArgType *y, bool same_dim=false)
Function finds out whether every element of the array 'x' is in the array 'y'.
long arrays_arenot_identical(long n, ArgType *a1, ArgType *a2)
FILE * openFilePNSS(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff, const char *suff2)
void deallocateCheck(ArgType *p, bool check=true)
*** *** *** *** DEALLOCATE TEMPLATES *** *** *** ***
void deallocateCheckUno(ArgType *p, bool check=true)