visual studio project
This commit is contained in:
18
base/base.h
18
base/base.h
@@ -1,12 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "std.h"
|
||||
#include "types.h"
|
||||
#include "errors.h"
|
||||
#include "mystr.h"
|
||||
|
||||
// executes codeblock and prints execution time
|
||||
#define optime(opname,repeats,codeblock) ({\
|
||||
/*#define optime(opname,repeats,codeblock) ({\
|
||||
struct timespec start, stop;\
|
||||
clock_gettime(CLOCK_REALTIME, &start);\
|
||||
for(uint64 ___OPREP=0;___OPREP<repeats;___OPREP++)\
|
||||
@@ -14,4 +18,16 @@
|
||||
clock_gettime(CLOCK_REALTIME, &stop);\
|
||||
double t=(double)(stop.tv_sec-start.tv_sec+(double)(stop.tv_nsec-start.tv_nsec)/1000000000)/repeats;\
|
||||
printf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
|
||||
})*/
|
||||
#define optime(opname,repeats,codeblock) ({\
|
||||
clock_t start=clock();\
|
||||
for(uint64 ___OPREP=0;___OPREP<repeats;___OPREP++)\
|
||||
(codeblock);\
|
||||
clock_t stop=clock();\
|
||||
double t=(double)(stop-start)/CLOCKS_PER_SEC/repeats;\
|
||||
printf("\e[93moperation \e[94m%s\e[93m lasted \e[94m%lf \e[93mseconds\n",opname,t);\
|
||||
})
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum err_t {
|
||||
SUCCESS, //not an error
|
||||
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX, ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR
|
||||
@@ -14,3 +18,7 @@ void _throwstr(const char* errmesg, const char* srcfile, int line, const char* f
|
||||
CHOOSE(IFTYPE(E,int), _throwint(E,__FILE__,__LINE__,__func__), \
|
||||
CHOOSE(IFTYPE(E,char[]), _throwstr(E,__FILE__,__LINE__,__func__), \
|
||||
printf("\e[31m[%s:%d/%s] UNKNOWN ERROR\n",__FILE__,__LINE__,__func__)))
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -36,7 +36,7 @@ char* char_multiply(char c, uint32 n){
|
||||
}
|
||||
|
||||
//copies str content to new char pointer value (adding '\0' at the end)
|
||||
char* string_cpToCharPtr(string str){
|
||||
char* string_cpToCptr(string str){
|
||||
char* cptr=malloc(str.length*sizeof(char)+1);
|
||||
if(str.length==0) return NULL;
|
||||
cptr[str.length]=0;
|
||||
|
||||
10
base/mystr.h
10
base/mystr.h
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
|
||||
//returns length of string (including \0)
|
||||
@@ -24,7 +28,7 @@ typedef struct string{
|
||||
static const string stringNull={NULL,0};
|
||||
|
||||
//copies str content to new char pointer value (adding '\0' at the end)
|
||||
char* string_cpToCharPtr(string str);
|
||||
char* string_cpToCptr(string str);
|
||||
|
||||
//copies cptr content (excluding '\0' at the end) to new string
|
||||
string string_cpFromCharPtr(char* cptr);
|
||||
@@ -34,3 +38,7 @@ bool string_compare(string str0, string str1);
|
||||
|
||||
//creates new string which is reversed variant of <s>
|
||||
string string_reverse(string s);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
36
base/std.h
36
base/std.h
@@ -1,4 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
@@ -11,3 +16,34 @@
|
||||
#define IFTYPE(X, T) __builtin_types_compatible_p(typeof(X), T)
|
||||
|
||||
#define dbg(N) printf("\e[95m%d\n",N)
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "mincore_downlevel.lib") // Support OS older than SDK
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#define CALL __cdecl
|
||||
#elif defined(__GNUC__)
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
#if __SIZEOF_POINTER__ == 4
|
||||
#define CALL __attribute__((__cdecl__))
|
||||
#else
|
||||
#define CALL
|
||||
#endif
|
||||
#else
|
||||
#pragma GCC error "unknown compiler"
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define IFWIN(YES, NO) YES
|
||||
#elif defined(__GNUC__)
|
||||
#define IFWIN(YES, NO) NO
|
||||
#else
|
||||
#pragma GCC error "unknown compiler"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
14
base/types.c
14
base/types.c
@@ -4,7 +4,7 @@
|
||||
#include "../Hashtable/Hashtable.h"
|
||||
#include "../SearchTree/SearchTree.h"
|
||||
|
||||
const char* typename(my_type t){
|
||||
const char* my_type_name(my_type t){
|
||||
switch (t) {
|
||||
case Null: return "Null";
|
||||
case Double: return "Double";
|
||||
@@ -119,12 +119,12 @@ void Unitype_free(Unitype u){
|
||||
void printuni(Unitype v){
|
||||
switch (v.type) {
|
||||
case Null: printf("{Null}");break;
|
||||
case Double: printf("{%s : %lf}",typename(v.type),v.Double);break;
|
||||
case Char: printf("{%s : '%c'}",typename(v.type),v.Char);break;
|
||||
case Double: printf("{%s : %lf}",my_type_name(v.type),v.Double);break;
|
||||
case Char: printf("{%s : '%c'}",my_type_name(v.type),v.Char);break;
|
||||
case Bool:
|
||||
case UInt64: printf("{%s : %lu}",typename(v.type),v.UInt64);break;
|
||||
case Int64: printf("{%s : %ld}",typename(v.type),v.Int64);break;
|
||||
case CharPtr: printf("{%s : \"%s\"}",typename(v.type),(char*)v.VoidPtr);break;
|
||||
default: printf("{%s : %p}",typename(v.type),v.VoidPtr);break;
|
||||
case UInt64: printf("{%s : %lu}",my_type_name(v.type),v.UInt64);break;
|
||||
case Int64: printf("{%s : %ld}",my_type_name(v.type),v.Int64);break;
|
||||
case CharPtr: printf("{%s : \"%s\"}",my_type_name(v.type),(char*)v.VoidPtr);break;
|
||||
default: printf("{%s : %p}",my_type_name(v.type),v.VoidPtr);break;
|
||||
}
|
||||
}
|
||||
|
||||
19
base/types.h
19
base/types.h
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "std.h"
|
||||
|
||||
typedef int8_t int8;
|
||||
@@ -10,7 +14,7 @@ typedef int32_t int32;
|
||||
typedef uint32_t uint32;
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
typedef enum my_type{
|
||||
typedef enum __attribute__((__packed__)) my_type {
|
||||
Null, Float, Double, Char, Bool,
|
||||
UInt8, Int8, UInt16, Int16, UInt32, Int32, UInt64, Int64,
|
||||
UInt8Ptr, Int8Ptr, UInt16Ptr, Int16Ptr, UInt32Ptr, Int32Ptr, UInt64Ptr, Int64Ptr,
|
||||
@@ -19,15 +23,10 @@ typedef enum my_type{
|
||||
AutoarrInt8Ptr, AutoarrUInt8Ptr, AutoarrInt16Ptr, AutoarrUInt16Ptr,
|
||||
AutoarrInt32Ptr, AutoarrUInt32Ptr, AutoarrInt64Ptr, AutoarrUInt64Ptr,
|
||||
AutoarrUnitypePtr, AutoarrKVPairPtr
|
||||
} __attribute__ ((__packed__)) my_type;
|
||||
} my_type;
|
||||
|
||||
//returns type name
|
||||
const char* typename(my_type t);
|
||||
const char* my_type_name(my_type t);
|
||||
|
||||
// returns size of type in bytes
|
||||
int8 typesize(my_type type);
|
||||
|
||||
// can store any base type
|
||||
typedef struct Unitype{
|
||||
union {
|
||||
int64 Int64;
|
||||
@@ -50,3 +49,7 @@ static const Unitype UniFalse={.Bool=false,.type=Bool};
|
||||
//frees VoidPtr value or does nothing if type isn't pointer
|
||||
void Unitype_free(Unitype u);
|
||||
void printuni(Unitype v);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user