-
Notifications
You must be signed in to change notification settings - Fork 1
/
LCStage.c
71 lines (57 loc) · 1.94 KB
/
LCStage.c
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
#include "LCStage.h"
typedef struct stageData* stageDataRef;
struct stageData {
LCMutableDictionaryRef updates;
};
void stageDealloc(LCObjectRef object);
struct LCType typeStage = {
.name = "LCStage",
.immutable = false,
.dealloc = stageDealloc
};
LCTypeRef LCTypeStage = &typeStage;
LCStageRef LCStageCreate() {
stageDataRef newStage = malloc(sizeof(struct stageData));
if (newStage) {
newStage->updates = LCMutableDictionaryCreate(NULL, 0);
return objectCreate(LCTypeStage, newStage);
} else {
return NULL;
}
};
static LCMutableDictionaryRef stageUpdates(LCStageRef stage) {
stageDataRef stageData = objectData(stage);
return stageData->updates;
}
void LCStageAddEntry(LCStageRef stage, char* path, LCObjectRef data) {
LCStringRef lcPath = LCStringCreate(path);
LCArrayRef pathArray = createPathArray(lcPath);
LCMutableDictionarySetValueForKey(stageUpdates(stage), pathArray, data);
objectRelease(lcPath);
objectRelease(pathArray);
}
void LCStageDeletePath(LCStageRef stage, char* path) {
LCStringRef lcPath = LCStringCreate(path);
LCArrayRef pathArray = createPathArray(lcPath);
LCMutableDictionarySetValueForKey(stageUpdates(stage), pathArray, NULL);
objectRelease(lcPath);
objectRelease(pathArray);
}
void LCStageAddKeyValues(LCStageRef stage, LCKeyValueRef keyValues[], size_t length) {
for (LCInteger i=0; i<length; i++) {
LCArrayRef pathArray = createPathArray(LCKeyValueKey(keyValues[i]));
LCKeyValueRef pathValue = LCKeyValueCreate(pathArray, LCKeyValueValue(keyValues[i]));
LCMutableDictionaryAddEntry(stageUpdates(stage), pathValue);
objectRelease(pathArray);
objectRelease(pathValue);
}
}
LCKeyValueRef* LCStageUpdates(LCStageRef stage) {
return LCMutableDictionaryEntries(stageUpdates(stage));
}
size_t LCStageUpdatesLength(LCStageRef stage) {
return LCMutableDictionaryLength(stageUpdates(stage));
}
void stageDealloc(LCObjectRef stage) {
objectRelease(stageUpdates(stage));
}