Update code style

This commit is contained in:
Dennis Eichhorn 2023-12-12 03:14:55 +00:00
parent b34004c1cb
commit 33b480fbae
31 changed files with 2370 additions and 2369 deletions

View File

@ -17,10 +17,8 @@
#include "../DatabaseType.h"
#include "../DatabaseStatus.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef struct {
size_t rows = 0;
size_t columns = 0;
@ -56,7 +54,6 @@ namespace DataStorage
return QueryResult();
}
};
}
}
#endif

View File

@ -21,10 +21,8 @@
#include "PostgresqlConnection.h"
#include "SQLiteConnection.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
ConnectionAbstract *create_connection(DbConnectionConfig dbdata)
{
switch (dbdata.db) {
@ -56,7 +54,6 @@ namespace DataStorage
return;
}
}
}
}
#endif

View File

@ -15,10 +15,8 @@
#include "../DatabaseType.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef struct {
DatabaseType db = DatabaseType::UNDEFINED;
@ -55,7 +53,6 @@ namespace DataStorage
dbdata->password = NULL;
}
}
}
}
#endif

View File

@ -20,10 +20,8 @@
#include "../DatabaseType.h"
#include "../DatabaseStatus.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
struct MysqlConnection : ConnectionAbstract {
MysqlConnection(DbConnectionConfig dbdata)
{
@ -144,7 +142,6 @@ namespace DataStorage
return result;
}
};
}
}
#endif

View File

@ -20,10 +20,8 @@
#include "../DatabaseType.h"
#include "../DatabaseStatus.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
struct PostgresqlConnection : ConnectionAbstract {
PostgresqlConnection(DbConnectionConfig dbdata)
{
@ -138,7 +136,6 @@ namespace DataStorage
return result;
}
};
}
}
#endif

View File

@ -20,10 +20,8 @@
#include "../DatabaseType.h"
#include "../DatabaseStatus.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
struct SQLiteConnection : ConnectionAbstract {
SQLiteConnection(DbConnectionConfig dbdata)
{
@ -155,7 +153,6 @@ namespace DataStorage
return result;
}
};
}
}
#endif

View File

@ -10,10 +10,8 @@
#ifndef DATASTORAGE_DATABASE_STATUS_H
#define DATASTORAGE_DATABASE_STATUS_H
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef enum {
OK = 0,
MISSING_DATABASE = 1,
@ -22,7 +20,6 @@ namespace DataStorage
READONLY = 4,
CLOSED = 5
} DatabaseStatus;
}
}
#endif

View File

@ -12,10 +12,8 @@
#include <string.h>
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef enum {
MYSQL = 1,
SQLITE = 2,
@ -38,7 +36,6 @@ namespace DataStorage
return DatabaseType::UNDEFINED;
}
}
}
#endif

View File

@ -18,10 +18,8 @@
#include "ReadMapper.h"
#include "MapperAbstract.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
static DataStorage::Database::ConnectionAbstract *db;
static const char *dateTimeFormat = "Y-m-d H:i:s";
@ -53,7 +51,6 @@ namespace DataStorage
return readMapper->getAll();
}
};
}
}
#endif

View File

@ -13,10 +13,8 @@
#include <stdio.h>
#include <stdlib.h>
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef enum {
MAPPER_DEFAULT = 0,
MAPPER_GET = 1,
@ -216,7 +214,6 @@ namespace DataStorage
free(data->BELONGS_TO);
}
}
}
}
#endif

View File

@ -12,14 +12,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "../Connection/ConnectionAbstract.h"
#include "DataMapperTypes.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
struct MapperAbstract {
const DataStorage::Database::MapperData *mapper = NULL;
@ -101,7 +100,6 @@ namespace DataStorage
virtual void *execute(void *options = NULL);
};
}
}
#endif

View File

@ -17,10 +17,8 @@
#include "DataMapperFactory.h"
#include "MapperAbstract.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
struct ReadMapper : MapperAbstract {
ReadMapper *get()
{
@ -64,7 +62,6 @@ namespace DataStorage
return NULL;
}
};
}
}
#endif

View File

@ -13,10 +13,8 @@
#include <stdio.h>
#include <stdlib.h>
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef struct {
char *name;
char *type;
@ -56,7 +54,6 @@ namespace DataStorage
field->foreignKey = NULL;
}
}
}
}
#endif

View File

@ -15,10 +15,8 @@
#include "DbField.h"
namespace DataStorage
namespace DataStorage::Database
{
namespace Database
{
typedef struct {
char *name;
DbField *fields;
@ -41,7 +39,6 @@ namespace DataStorage
schema->fields = NULL;
}
}
}
}
#endif

View File

@ -2,6 +2,8 @@
#define HASH_MD5_H
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
// https://www.rfc-editor.org/rfc/rfc1321
@ -37,7 +39,7 @@ namespace Hash {
uint32_t a, b, c, d;
uint32_t aa, bb, cc, dd;
ptr = data;
ptr = (const unsigned char *) data;
a = ctx->a;
b = ctx->b;

View File

@ -116,6 +116,7 @@
#define HASH_MEOW_H
// #include <immintrin.h>
#include <stdio.h>
#if !defined(meow_u8)
#define MEOW_HASH_VERSION 5
@ -199,10 +200,8 @@
pxor(r2, r3)
#endif
namespace Hash
namespace Hash::Meow
{
namespace Meow
{
#if MEOW_DUMP
struct meow_dump
{
@ -739,7 +738,6 @@ namespace Hash
return (const char *) str;
}
}
}
#undef INSTRUCTION_REORDER_BARRIER

View File

@ -200,7 +200,7 @@ void sha_256_write(struct Sha_256 *sha_256, const void *data, size_t len)
{
sha_256->total_len += len;
const uint8_t *p = data;
const uint8_t *p = (uint8_t *) data;
while (len > 0) {
/*

View File

@ -14,10 +14,8 @@
#include <opencv2/opencv.hpp>
#include <vector>
namespace Image
namespace Image::BillDetection
{
namespace BillDetection
{
cv::Mat highlightBill(cv::Mat in)
{
cv::Mat gray;
@ -75,7 +73,6 @@ namespace Image
return out;
}
}
}
#endif

View File

@ -13,10 +13,8 @@
#include <stdio.h>
#include <math.h>
namespace Image
namespace Image::ImageUtils
{
namespace ImageUtils
{
inline
float lightnessFromRgb(int r, int g, int b)
{
@ -33,17 +31,6 @@ namespace Image
return lStar / 100.0;
}
inline
int rgbToInt(int r, int g, int b)
{
int rgb = r;
rgb = (rgb << 8) + g;
rgb = (rgb << 8) + b;
return rgb;
}
}
}
#endif

View File

@ -16,7 +16,7 @@
#include "ImageUtils.h"
#include "../Utils/MathUtils.h"
namespace Image
namespace Image::Kernel
{
const float KERNEL_RIDGE_1[3][3] = {
{0.0, -1.0, 0.0},
@ -62,8 +62,6 @@ namespace Image
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
};
namespace Kernel
{
inline
cv::Mat convolve(cv::Mat in, const float kernel[][3])
{
@ -75,7 +73,6 @@ namespace Image
return out;
}
}
}
#endif

View File

@ -16,10 +16,8 @@
#include "../Utils/MathUtils.h"
namespace Image
namespace Image::Skew
{
namespace Skew
{
cv::Mat deskewHoughLines(cv::Mat in, int maxDegree = 45)
{
cv::Size dim = in.size();
@ -87,7 +85,6 @@ namespace Image
return out;
}
}
}
#endif

View File

@ -16,10 +16,8 @@
#include "ImageUtils.h"
#include "../Utils/MathUtils.h"
namespace Image
namespace Image::Thresholding
{
namespace Thresholding
{
cv::Mat integralThresholding(cv::Mat in)
{
cv::Size dim = in.size();
@ -75,7 +73,6 @@ namespace Image
return out;
}
}
}
#endif

View File

@ -16,10 +16,8 @@
#include "../Hash/MeowHash.h"
namespace Stdlib
namespace Stdlib::HashTable
{
namespace HashTable
{
typedef struct {
const char *key;
void *value;
@ -215,7 +213,6 @@ namespace Stdlib
free(table->entries);
}
}
}
#endif

View File

@ -48,9 +48,7 @@ namespace Utils
if (pos != NULL) {
memcpy(dir, arg, (pos - arg) * sizeof(char));
chdir(dir);
free(dir);
}
}

View File

@ -13,10 +13,8 @@
#include <stdio.h>
#include <stdlib.h>
namespace Utils
namespace Utils::ArraySort
{
namespace ArraySort
{
inline
void reverse_int(int64_t *arr, size_t size)
{
@ -56,7 +54,6 @@ namespace Utils
arr[high] = tmp;
}
}
}
}
#endif

View File

@ -16,10 +16,8 @@
#include "StringUtils.h"
namespace Utils
namespace Utils::ArrayUtils
{
namespace ArrayUtils
{
inline
char* get_arg(const char *id, char **argv, size_t size)
{
@ -194,18 +192,17 @@ namespace Utils
}
for (size_t i = 0; i < size1; ++i) {
merged[i] = (char*) malloc((strlen(arr1[i]) + 1) * sizeof(char));
strcpy(merged[i], arr1[i]);
merged[i] = (char*) malloc((strlen(array1[i]) + 1) * sizeof(char));
strcpy(merged[i], array1[i]);
}
for (size_t i = 0; i < size2; ++i) {
merged[i] = (char*) malloc((strlen(arr2[i]) + 1) * sizeof(char));
strcpy(merged[i], arr2[i]);
merged[i] = (char*) malloc((strlen(array2[i]) + 1) * sizeof(char));
strcpy(merged[i], array2[i]);
}
return merged;
}
}
}
#endif

57
Utils/ColorUtils.h Normal file
View File

@ -0,0 +1,57 @@
/**
* Karaka
*
* @package Utils
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef UTILS_STRING_UTILS_H
#define UTILS_STRING_UTILS_H
#include <stdio.h>
#include <stdlib.h>
namespace Utils::ColorUtils
{
typedef struct {
char r = 0;
char g = 0;
char b = 0;
} RGB;
inline
RGB* int_to_rgb(int rgb)
{
RGB* result = (RGB*) malloc(1 * sizeof(RGB));
result->r = rgb & 255;
result->g = (rgb >> 8) & 255;
result->b = (rgb >> 16) & 255;
return result;
}
inline
int rgb_to_int(RGB* rgb)
{
int i = (255 & rgb->r) << 16;
i += (255 & rgb->g) << 8;
i += (255 & rgb->b);
return i;
}
inline
int rgb_to_int(char r, char g, char b)
{
int i = (255 & r) << 16;
i += (255 & g) << 8;
i += (255 & b);
return i;
}
}
#endif

View File

@ -23,10 +23,8 @@
#include "OSWrapper.h"
namespace Utils
namespace Utils::FileUtils
{
namespace FileUtils
{
inline
bool file_exists (const char *filename)
{
@ -128,7 +126,6 @@ namespace Utils
return file;
}
}
}
#endif

View File

@ -14,12 +14,8 @@
#include <stdlib.h>
#include <time.h>
namespace Utils
namespace Utils::Rng::StringUtils
{
namespace Rng
{
namespace StringUtils
{
inline
char* generate_string(
size_t min = 10, size_t max = 10,
@ -38,6 +34,6 @@ namespace Utils
return randomString;
}
}
}
}
#endif

View File

@ -17,10 +17,8 @@
#include "MathUtils.h"
#include "ArraySort.h"
namespace Utils
namespace Utils::StringUtils
{
namespace StringUtils
{
inline
char *search_replace(const char *haystack, const char *needle, const char *replace)
{
@ -97,6 +95,7 @@ namespace Utils
return count;
}
inline
char *strsep(char **sp, char *sep)
{
char *p, *s;
@ -117,6 +116,8 @@ namespace Utils
return(s);
}
// @todo Implement delim as const char* (also allow \0 length)
inline
int str_split(char **list, char *str, const char delim)
{
size_t splits = str_count(str, (char *) &delim) + 1;
@ -135,16 +136,47 @@ namespace Utils
return i;
}
// @todo Implement delim as const char* (also allow \0 length)
inline
char* str_combine(char **str, size_t size, const char delim)
{
if (size < 1) {
return NULL;
}
size_t total_size = 0;
for (size_t i = 0; i < size; ++i) {
total_size += strlen(str[i]);
}
// If delim ever becomes a string replace * 1 with * strlen(delimiter)
total_size += (size - 1) * 1 + 1;
char *result = (char *) malloc(total_size * sizeof(char));
if (!result) {
return NULL;
}
strcpy(result, str[0]);
for (size_t i = 0; i < size; ++i) {
strcat(result, &delim);
strcat(result, str[i]);
}
return result;
}
typedef struct {
char **values;
int *masks;
int size;
int64_t *masks;
size_t size;
} text_diff;
text_diff computeLCSDiff(char **from, int fromSize, char **to, int toSize)
{
char **diffValues = (char **) malloc(fromSize * toSize * sizeof(char *));
int *diffMasks = (int *) calloc(fromSize * toSize, sizeof(int));
int64_t *diffMasks = (int64_t *) calloc(fromSize * toSize, sizeof(int64_t));
int *dm = (int *) calloc((fromSize + 1) * (toSize + 1), sizeof(int));
@ -173,7 +205,7 @@ namespace Utils
}
}
int diffIndex = 0;
size_t diffIndex = 0;
i = fromSize;
j = toSize;
@ -254,7 +286,7 @@ namespace Utils
}
diffValues = diffValuesT;
int *diffMasksT = (int *) realloc(diffMasks, diffIndex * sizeof(int));
int64_t *diffMasksT = (int64_t *) realloc(diffMasks, diffIndex * sizeof(int64_t));
if (!diffMasksT) {
free(diffMasks);
}
@ -271,7 +303,6 @@ namespace Utils
return text_diff{diffValues, diffMasks, diffIndex};
}
}
}
#endif

View File

@ -23,10 +23,8 @@
#include "FileUtils.h"
namespace Utils
namespace Utils::WebUtils
{
namespace WebUtils
{
static bool CURL_SETUP = false;
inline
@ -293,7 +291,6 @@ namespace Utils
return null;
}
}
}
#endif