mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-01-20 15:08:40 +00:00
change to namespaces
This commit is contained in:
parent
04ab177b23
commit
9c0859daff
|
|
@ -14,50 +14,47 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
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
|
||||
|
|
@ -45,6 +45,7 @@ namespace Utils {
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -113,6 +113,7 @@ namespace Utils {
|
|||
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -136,6 +136,7 @@ namespace Utils {
|
|||
|
||||
return text_diff { diffValues, diffMasks, diffIndex };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -13,30 +13,52 @@
|
|||
#include <stdio.h>
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue
Block a user