-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLCCore.h
120 lines (97 loc) · 4.6 KB
/
LCCore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef LivelyC_LCCore_h
#define LivelyC_LCCore_h
#include "ExternalLibs.h"
#define HASH_LENGTH 41
#define LC_HASH_BYTE_LENGTH 20
extern char *LCUnnamedObject;
//Errors
#define ErrorObjectImmutable "can't add mutable objects to immutable object"
typedef int LCInteger;
typedef unsigned char LCByte;
typedef enum {
LCEqual,
LCGreater,
LCSmaller
} LCCompare;
typedef enum {
LCBinary,
LCText
} LCFormat;
typedef struct LCObject* LCObjectRef;
typedef struct LCType* LCTypeRef;
typedef struct LCStore* LCStoreRef;
typedef struct LCContext* LCContextRef;
typedef LCObjectRef LCStringRef;
typedef LCTypeRef(*stringToType)(char *typeString);
typedef void(*writeStreamFun)(void *cookie, LCByte data[], size_t length);
typedef void(*closeStreamFun)(void *cookie);
typedef LCObjectRef(*LCCreateEachCb)(LCInteger i, void* info, LCObjectRef each);
typedef FILE*(*writeData)(void *cookie, LCTypeRef type, char *key);
typedef void(*deleteData)(void *cookie, LCTypeRef type, char *key);
typedef FILE*(*readData)(void *cookie, LCTypeRef type, char *key);
typedef void (*callback)(void *cookie);
typedef void(*childCallback) (void *cookie, char *key, LCObjectRef objects[], size_t length, bool composite);
typedef void (*walkChildren)(LCObjectRef object, void *cookie, childCallback cb);
typedef void (*storeChildren)(LCObjectRef object, char *key, LCObjectRef objects[], size_t length);
/*
- a type either implements serialize/deserializeData or walk/storeChildren but never both.
- serializationFormat decides whether an object can be rendered as a composite or not
- initData should return any data the object needs to start deserialization
- dealloc should always release all child objects and free the objects data if possible
*/
struct LCType {
char* name;
bool immutable;
LCFormat serializationFormat;
void (*dealloc)(LCObjectRef object);
LCCompare (*compare)(LCObjectRef object1, LCObjectRef object2);
void (*serializeData)(LCObjectRef object, FILE *fd);
void* (*deserializeData)(LCObjectRef object, FILE *fd);
void* (*initData)(void);
walkChildren walkChildren;
storeChildren storeChildren;
void *meta;
};
LCObjectRef objectCreate(LCTypeRef type, void* data);
LCObjectRef objectCreateFromContext(LCContextRef context, LCTypeRef type, char hash[HASH_LENGTH]);
LCObjectRef objectCreateFromFile(LCContextRef context, LCTypeRef type, FILE *fd);
void* objectData(LCObjectRef object);
LCTypeRef objectType(LCObjectRef object);
bool objectImmutable(LCObjectRef object);
bool objectsImmutable(LCObjectRef objects[], size_t length);
LCObjectRef objectRetain(LCObjectRef object);
LCObjectRef objectRelease(LCObjectRef object);
void objectReleaseAlt(void *object);
LCInteger objectRetainCount(LCObjectRef object);
LCCompare objectCompare(LCObjectRef object1, LCObjectRef object2);
LCContextRef objectContext(LCObjectRef object);
void objectSerializeToLevels(LCObjectRef object, LCInteger levels, FILE *fpw);
void objectSerializeAsComposite(LCObjectRef object, FILE *fpw);
void objectSerialize(LCObjectRef object, FILE* fd);
void objectSerializeBinaryData(LCObjectRef object, FILE *fd);
void objectDeserializeBinaryData(LCObjectRef object, FILE *fd);
void objectDeserialize(LCObjectRef object, FILE* fd);
void objectStoreChildren(LCObjectRef object, char *key, LCObjectRef objects[], size_t length);
void objectHash(LCObjectRef object, char hashBuffer[HASH_LENGTH]);
LCStringRef objectCreateHashString(LCObjectRef object);
void objectStore(LCObjectRef object, LCContextRef context);
void objectStoreAsComposite(LCObjectRef object, LCContextRef context);
void objectsStore(LCObjectRef objects[], size_t length, LCContextRef context);
void objectCache(LCObjectRef object);
void objectDeleteCache(LCObjectRef object, LCContextRef context);
void objectsSort(LCObjectRef objects[], size_t length);
bool objectHashEqual(LCObjectRef object1, LCObjectRef object2);
char* typeName(LCTypeRef type);
bool typeImmutable(LCTypeRef type);
LCFormat typeSerializationFormat(LCTypeRef type);
bool typeBinarySerialized(LCTypeRef type);
LCStoreRef storeCreate(void *cookie, writeData writefn, deleteData deletefn, readData readfn);
bool storeFileExists(LCStoreRef store, LCTypeRef type, char hash[HASH_LENGTH]);
FILE* storeWriteData(LCStoreRef store, LCTypeRef type, char hash[HASH_LENGTH]);
void storeDeleteData(LCStoreRef store, LCTypeRef type, char hash[HASH_LENGTH]);
FILE* storeReadData(LCStoreRef store, LCTypeRef type, char hash[HASH_LENGTH]);
LCContextRef contextCreate(LCStoreRef store, stringToType translateFuns[], size_t length);
LCTypeRef contextStringToType(LCContextRef context, char* typeString);
LCTypeRef coreStringToType(char* typeString);
void lcFree(void* object);
#endif