1 #ifndef MIDAS_GENERAL_H
2 #define MIDAS_GENERAL_H
20 #define MAX_MSG_LENGTH 2047
23 #define DIRSEPARATOR '\\'
25 #define DIRSEPARATOR '/'
29 #define NUM_DIGITS_IN_PRINTED_EXPONENT 3
31 #define NUM_DIGITS_IN_PRINTED_EXPONENT 2
36 #define _STRCASECMP _stricmp
38 #define _STRCASECMP strcasecmp
48 #define TC_B_BLACK FOREGROUND_GREEN
49 #define TC_D_BLACK FOREGROUND_GREEN
50 #define TC_B_RED FOREGROUND_RED
51 #define TC_D_RED FOREGROUND_RED
52 #define TC_B_GREEN FOREGROUND_GREEN
53 #define TC_D_GREEN FOREGROUND_GREEN
54 #define TC_B_YELLOW FOREGROUND_RED | FOREGROUND_GREEN
55 #define TC_D_YELLOW FOREGROUND_RED | FOREGROUND_GREEN
56 #define TC_B_BLUE FOREGROUND_BLUE
57 #define TC_D_BLUE FOREGROUND_BLUE
58 #define TC_B_VIOLET FOREGROUND_BLUE | FOREGROUND_RED
59 #define TC_D_VIOLET FOREGROUND_BLUE | FOREGROUND_RED
60 #define TC_B_CYAN FOREGROUND_GREEN | FOREGROUND_BLUE
61 #define TC_D_CYAN FOREGROUND_GREEN | FOREGROUND_BLUE
62 #define TC_B_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
63 #define TC_D_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
65 #define TC_DEFAULT TC_D_WHITE
68 #define TC_B_BLACK "\033[0;30m"
69 #define TC_D_BLACK "\033[1;30m"
70 #define TC_B_RED "\033[0;31m"
71 #define TC_D_RED "\033[1;31m"
72 #define TC_B_GREEN "\033[0;32m"
73 #define TC_D_GREEN "\033[1;32m"
74 #define TC_B_YELLOW "\033[0;33m"
75 #define TC_D_YELLOW "\033[1;33m"
76 #define TC_B_BLUE "\033[0;34m"
77 #define TC_D_BLUE "\033[1;34m"
78 #define TC_B_VIOLET "\033[0;35m"
79 #define TC_D_VIOLET "\033[1;35m"
80 #define TC_B_CYAN "\033[0;36m"
81 #define TC_D_CYAN "\033[1;36m"
82 #define TC_B_WHITE "\033[0;37m"
83 #define TC_D_WHITE "\033[1;37m"
85 #define TC_DEFAULT "\033[0m"
90 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
124 #define CHANGE_CONSOLE_COLOUR(_1,_2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), _2)
126 #define CHANGE_CONSOLE_COLOUR(_1,_2) fprintf (_1, "%s", _2)
138 void errorr (
const char* file,
int line,
const char *format, ...);
139 void warningg (
const char* file,
int line,
const char *format, ...);
142 #define errol errorr (__FILE__, __LINE__, "za ktery muze autor teto sqele utility, bezte ho vytahat za usi")
143 #define _errorr0 errorr (__FILE__, __LINE__, "za ktery muze autor teto sqele utility, bezte ho vytahat za usi")
144 #define _errorr1(_1) errorr (__FILE__, __LINE__, _1)
145 #define _errorr2(_1,_2) errorr (__FILE__, __LINE__, _1,_2)
146 #define _errorr3(_1,_2,_3) errorr (__FILE__, __LINE__, _1,_2,_3)
147 #define _errorr4(_1,_2,_3,_4) errorr (__FILE__, __LINE__, _1,_2,_3,_4)
148 #define _errorr5(_1,_2,_3,_4,_5) errorr (__FILE__, __LINE__, _1,_2,_3,_4,_5)
149 #define _errorr6(_1,_2,_3,_4,_5,_6) errorr (__FILE__, __LINE__, _1,_2,_3,_4,_5,_6)
151 #define _errorr(_1) _errorr1(_1)
154 #define _warningg(_1) _warningg1(_1)
156 #define _warningg1(_1) warningg (__FILE__, __LINE__, _1)
157 #define _warningg2(_1,_2) warningg (__FILE__, __LINE__, _1,_2)
158 #define _warningg3(_1,_2,_3) warningg (__FILE__, __LINE__, _1,_2,_3)
159 #define _warningg4(_1,_2,_3,_4) warningg (__FILE__, __LINE__, _1,_2,_3,_4)
160 #define _warningg5(_1,_2,_3,_4,_5) warningg (__FILE__, __LINE__, _1,_2,_3,_4,_5)
166 void openFileTest (
const FILE *stream,
const char *name);
168 FILE*
openFileN (
const char* File,
int Line,
const char *mode,
const char *key,
const char *name);
169 FILE*
openFilePN (
const char* File,
int Line,
const char *mode,
const char *key,
const char *path,
const char *name);
170 FILE*
openFilePNS (
const char* File,
int Line,
const char *mode,
const char *key,
const char *path,
const char *name,
const char *suff);
171 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);
173 #define _openFileN(_1,_2,_3) openFileN (__FILE__, __LINE__, _1,_2,_3)
174 #define _openFilePN(_1,_2,_3,_4) openFilePN (__FILE__, __LINE__, _1,_2,_3,_4)
175 #define _openFilePNS(_1,_2,_3,_4,_5) openFilePNS (__FILE__, __LINE__, _1,_2,_3,_4,_5)
176 #define _openFilePNSS(_1,_2,_3,_4,_5,_6) openFilePNSS(__FILE__, __LINE__, _1,_2,_3,_4,_5,_6)
183 template <
class ArgType>
void allocate (ArgType*& p,
long a) {
if (a) p =
new ArgType [a];
else p = NULL; }
184 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; }
185 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; }
194 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
199 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
206 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
211 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
216 template <
class ArgType>
void deallocateCheck (ArgType*** p,
long a,
long b,
bool check=
true)
218 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
223 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
226 template <
class ArgType>
void deallocateCheck (ArgType*** p,
long a,
long *b,
bool check=
true)
228 if (p == NULL) {
if (check)
_warningg (
"Field for deallocation is NULL"); }
238 template <
class ArgType>
void fill_all_by (ArgType* p,
long a, ArgType value) {
while (a--) p[a] = value; }
239 template <
class ArgType>
void fill_all_by (ArgType** p,
long a,
long b, ArgType value) {
while (a--)
fill_all_by (p[a], b, value); }
240 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); }
244 template <
class ArgType>
void fill_col_by (ArgType** p,
long n,
long j, ArgType value) {
while (n--) p[n][j] = value; }
253 if (!n && old_field)
_errorr (
"allocate_another_val: n == 0 and old_field != NULL - forbidden");
254 ArgType *new_field =
new ArgType [n+1];
255 while (n--) new_field[n] = old_field[n];
257 old_field = new_field;
264 ArgType **new_field =
new ArgType* [n+add];
265 while (n--) new_field[n] = old_field[n];
267 old_field = new_field;
288 if (array[j] == NULL)
break;
290 for (i=j+1; i<n; i++)
292 array[j++] = array[i];
303 while (n--)
if (a1[n] != a2[n])
break;
306 if (a1 == a2 && !n)
return 0;
313 while (n--)
if (val == array[n])
break;
323 for (i=0; i<n-1; i++)
324 for (j=i+1; j<n; j++)
325 if (array[i] == array[j])
return false;
335 if (same_dim && nx!=ny)
return false;
339 for (i=0; i<nx; i++) {
341 if (x[i] == y[j])
break;
343 if (j==ny)
return false;
353 template <
class ArgType>
bool same_array_elements_sym (
long nx,
const ArgType *x,
long ny,
const ArgType *y,
bool same_dim=
false)
364 template <
class ArgType>
void add_array (
long &n1, ArgType *&array1,
long n2,
const ArgType *array2)
368 ArgType *new_array =
new ArgType [n1+n2];
371 for (i=0; i<n1; i++) new_array[ i] = array1[i];
372 for (i=0; i<n2; i++) new_array[n1+i] = array2[i];
380 template <
class ArgType>
void add_array_unique (
long &n1, ArgType *&array1,
long n2,
const ArgType *array2)
387 ArgType *new_array =
new ArgType [n1+n3];
390 for (i=0; i<n1; i++) new_array[n3++] = array1[i];
391 for (i=0; i<n2; i++)
if (!
is_member_of_array (array2[i], n1, array1)) new_array[n3++] = array2[i];
411 #endif // MIDAS_GENERAL_H
void change_console_colour(FILE *stream, ETCLR clr)
void errorr(const char *file, int line, const char *format,...)
*** *** *** *** ERROR FCE *** *** *** ***
#define CHANGE_CONSOLE_COLOUR(_1, _2)
void interchange2(ArgType &a, ArgType &b)
void fill_row_by(ArgType **p, long i, long m, ArgType value)
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)
void deallocateCheckUno(ArgType *p, bool check=true)
long is_member_of_array(ArgType val, long n, const ArgType *array)
check out "val" is member of "array"
void allocate_another_val(long n, ArgType *&old_field)
*** *** *** *** REALLOCATE TEMPLATES *** *** *** ***
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)
FILE * openFileN(const char *File, int Line, const char *mode, const char *key, const char *name)
bool members_are_unique(long n, const ArgType *array)
check out all members of array "a" are uniq
void openFileTest(const FILE *stream, const char *name)
*** *** *** *** FILE FCE *** *** *** ***
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...
#define TC_B_BLACK
*** *** *** *** COLOURS *** *** *** *** Termit Colours
const char * trmt_clr_int2clr(ETCLR clr)
void shake_down_ptr_array(long &n, ArgType *array)
*** *** *** *** VARIOUS TEMPLATES *** *** *** ***
FILE * openFilePNS(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name, const char *suff)
FILE * openFilePN(const char *File, int Line, const char *mode, const char *key, const char *path, const char *name)
void fill_col_by(ArgType **p, long n, long j, ArgType value)
void add_array(long &n1, ArgType *&array1, long n2, const ArgType *array2)
void allocate(ArgType *&p, long a)
*** *** *** *** ALLOCATE TEMPLATES *** *** *** ***
void setadd_another_uno_ptr(long &n, ArgType **&field, ArgType *p)
void deallocateCheck(ArgType *p, bool check=true)
*** *** *** *** DEALLOCATE TEMPLATES *** *** *** ***
void add_array_unique(long &n1, ArgType *&array1, long n2, const ArgType *array2)
void allocate_another_uno_ptr(long n, ArgType **&old_field, long add=1)
void warningg(const char *file, int line, const char *format,...)
void fill_all_by(ArgType *p, long a, ArgType value)
*** *** *** *** FILL TEMPLATES *** *** *** ***