diff --git a/Utils/ArraySort.h b/Utils/ArraySort.h index 0323348..bee8cf7 100644 --- a/Utils/ArraySort.h +++ b/Utils/ArraySort.h @@ -14,50 +14,47 @@ #include namespace Utils { - class ArraySort { - private: - - public: - static inline - void reverse_int(int *arr, int size) - { - for (int low = 0, high = size - 1; low < high; ++low, --high) { - int tmp = arr[low]; - arr[low] = arr[high]; - arr[high] = tmp; - } + namespace ArraySort { + inline + void reverse_int(int *arr, int size) + { + for (int low = 0, high = size - 1; low < high; ++low, --high) { + int tmp = arr[low]; + arr[low] = arr[high]; + arr[high] = tmp; } + } - static inline - void reverse_float(float *arr, int size) - { - for (int low = 0, high = size - 1; low < high; ++low, --high) { - float tmp = arr[low]; - arr[low] = arr[high]; - arr[high] = tmp; - } + inline + void reverse_float(float *arr, int size) + { + for (int low = 0, high = size - 1; low < high; ++low, --high) { + float tmp = arr[low]; + arr[low] = arr[high]; + arr[high] = tmp; } + } - static inline - void reverse_double(double *arr, int size) - { - for (int low = 0, high = size - 1; low < high; ++low, --high) { - double tmp = arr[low]; - arr[low] = arr[high]; - arr[high] = tmp; - } + inline + void reverse_double(double *arr, int size) + { + for (int low = 0, high = size - 1; low < high; ++low, --high) { + double tmp = arr[low]; + arr[low] = arr[high]; + arr[high] = tmp; } + } - static inline - void reverse_char(char *arr, int size) - { - for (int low = 0, high = size - 1; low < high; ++low, --high) { - char tmp = arr[low]; - arr[low] = arr[high]; - arr[high] = tmp; - } + inline + void reverse_char(char *arr, int size) + { + for (int low = 0, high = size - 1; low < high; ++low, --high) { + char tmp = arr[low]; + arr[low] = arr[high]; + arr[high] = tmp; } - }; + } + } } #endif \ No newline at end of file diff --git a/Utils/ArrayUtils.h b/Utils/ArrayUtils.h index 2104366..ecd8f5f 100644 --- a/Utils/ArrayUtils.h +++ b/Utils/ArrayUtils.h @@ -45,6 +45,7 @@ namespace Utils { return false; } + } } #endif \ No newline at end of file diff --git a/Utils/FileUtils.h b/Utils/FileUtils.h index 38a4011..d3494e4 100644 --- a/Utils/FileUtils.h +++ b/Utils/FileUtils.h @@ -113,6 +113,7 @@ namespace Utils { return file; } + } } #endif \ No newline at end of file diff --git a/Utils/StringUtils.h b/Utils/StringUtils.h index 2fed42d..1e43f74 100644 --- a/Utils/StringUtils.h +++ b/Utils/StringUtils.h @@ -136,6 +136,7 @@ namespace Utils { return text_diff { diffValues, diffMasks, diffIndex }; } + } } #endif \ No newline at end of file diff --git a/Utils/TestUtils.h b/Utils/TestUtils.h index 29d7fd6..5a24626 100644 --- a/Utils/TestUtils.h +++ b/Utils/TestUtils.h @@ -13,30 +13,52 @@ #include #include "MathUtils.h" -#define ASSERT_EQUALS(a, b, t1, t2) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - if (_a == _b) { \ - printf("."); \ - } else { \ - printf("[F]"); \ - printf("\n\n%s - %i: ", __FILE__, __LINE__); \ - printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); \ - return 0; } \ - }) +#ifdef _MSC_VER + #define ASSERT_EQUALS(a, b, t1, t2) (\ + if (a == b) { \ + printf("."); \ + } else { \ + printf("[F]"); \ + printf("\n\n%s - %i: ", __FILE__, __LINE__); \ + printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); \ + return 0; } \ + ) -#define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - __typeof__ (delta) _delta = (delta); \ - __typeof__ (delta) _d = (_a - _b); \ - if (oms_abs(_d) <= _delta) { \ - printf("."); \ - } else { \ - printf("[F]"); \ - printf("\n\n%s - %i: ", __FILE__, __LINE__); \ - printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); \ - return 0; } \ - }) + #define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) (\ + if (oms_abs(a - b) <= _delta) { \ + printf("."); \ + } else { \ + printf("[F]"); \ + printf("\n\n%s - %i: ", __FILE__, __LINE__); \ + printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); \ + return 0; } \ + ) +#else + #define ASSERT_EQUALS(a, b, t1, t2) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + if (_a == _b) { \ + printf("."); \ + } else { \ + printf("[F]"); \ + printf("\n\n%s - %i: ", __FILE__, __LINE__); \ + printf(t1, _a); printf(" != "); printf(t2, _b); printf("\n"); \ + return 0; } \ + }) + + #define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + __typeof__ (delta) _delta = (delta); \ + __typeof__ (delta) _d = (_a - _b); \ + if (oms_abs(_d) <= _delta) { \ + printf("."); \ + } else { \ + printf("[F]"); \ + printf("\n\n%s - %i: ", __FILE__, __LINE__); \ + printf(t1, _a); printf(" != "); printf(t2, _b); printf("\n"); \ + return 0; } \ + }) +#endif #endif diff --git a/Utils/WebUtils.h b/Utils/WebUtils.h index e531626..706ec2d 100644 --- a/Utils/WebUtils.h +++ b/Utils/WebUtils.h @@ -18,46 +18,44 @@ #include "FileUtils.h" namespace Utils { - class WebUtils { - private: - static - int write_download_data (void *ptr, size_t size, size_t nmeb, void *stream) - { - Utils::FileUtils::file_body *out = (Utils::FileUtils::file_body *) stream; - int outSize = size * nmeb; + namespace WebUtils { + static + int write_download_data (void *ptr, size_t size, size_t nmeb, void *stream) + { + Utils::FileUtils::file_body *out = (Utils::FileUtils::file_body *) stream; + int outSize = size * nmeb; - out->content = (char *) malloc(outSize + 1); - if (!out->content) { - fprintf(stderr, "CRITICAL: malloc failed"); - } - - if (out->content) { - memcpy(out->content, ptr, outSize); - - out->size = outSize; - out->content[out->size] = 0; - } - - return out->size; + out->content = (char *) malloc(outSize + 1); + if (!out->content) { + fprintf(stderr, "CRITICAL: malloc failed"); } - public: - static - Utils::FileUtils::file_body download (char *url) - { - file_body page = {0}; + if (out->content) { + memcpy(out->content, ptr, outSize); - CURL *h = curl_easy_init(); - curl_easy_setopt(h, CURLOPT_URL, url); - - curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, write_download_data); - curl_easy_setopt(h, CURLOPT_WRITEDATA, &page); - curl_easy_perform(h); - curl_easy_cleanup(h); - - return page; + out->size = outSize; + out->content[out->size] = 0; } - }; + + return out->size; + } + + static + Utils::FileUtils::file_body download (char *url) + { + file_body page = {0}; + + CURL *h = curl_easy_init(); + curl_easy_setopt(h, CURLOPT_URL, url); + + curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, write_download_data); + curl_easy_setopt(h, CURLOPT_WRITEDATA, &page); + curl_easy_perform(h); + curl_easy_cleanup(h); + + return page; + } + } } #endif \ No newline at end of file