4#define _BLOCK_PROPERTIES_INIT_CAPACITY 16
10#include "coordinate.h"
56Block* createBlock(
char* name) {
72char* Block_getProperty(
Block* b,
char* name) {
74 if (name == 0)
return 0;
91void Block_setProperty(
Block* b,
char* name,
char* value) {
93 if (name == 0)
return;
94 if (value == 0)
return;
104 p->
name = strcpy((
char*) malloc(strlen(name) + 1), name);
105 p->
value = strcpy((
char*) malloc(strlen(value) + 1), value);
123void Block_removeProperty(
Block* b,
char* name) {
125 if (name == 0)
return;
150char* Block_toString(
Block* b) {
151 if (b == 0)
return 0;
153 char* name = (
char*) malloc(strlen(b->
name) + 1);
154 sprintf(name,
"%s", b->
name);
159 int bytes = strlen(name) + 1;
164 char* str = (
char*) malloc(bytes);
165 sprintf(str,
"%s<", name);
169 if (i < b->propertyCount - 1)
170 sprintf(str,
"%s, ", str);
174 if (str[l - 1] !=
'>')
175 sprintf(str,
"%s>", str);
185Block* Block_fromString(
const char* str) {
186 if (str == 0)
return 0;
189 if (l == 0)
return 0;
191 char* str0 = (
char*) malloc(l + 1);
194 char* name = strtok(str0,
"<");
200 char* name0 = (
char*) malloc(strlen(name) + 1);
203 Block* b = createBlock(name0);
205 char* properties = strtok(0,
"<");
206 if (properties == 0) {
211 char*
property = strtok(properties,
"=,");
214 while (property != 0) {
218 int l = strlen(property);
221 if (value[l - 1] ==
'>') {
225 Block_setProperty(b, key, value);
231 property = strtok(0,
"=,");
273 char* block = Block_toString(object->
block);
274 char* coordinate = Coordinate2D_toString(object->
coordinate);
276 char* str = (
char*) malloc(strlen(block) + strlen(coordinate) + 3);
277 sprintf(str,
"%s: %s", block, coordinate);
288 char* blockStr = strtok(str,
":");
289 char* coordinateStr = strtok(0,
":");
291 Block* block = Block_fromString(blockStr);
292 Coordinate2D* coordinate = Coordinate2D_fromString(coordinateStr);
294 return createLevelObject2D(block, coordinate);
331 char* block = Block_toString(object->
block);
332 char* coordinate = Coordinate3D_toString(object->
coordinate);
334 char* str = (
char*) malloc(strlen(block) + strlen(coordinate) + 3);
335 sprintf(str,
"%s: %s", block, coordinate);
346 char* blockStr = strtok(str,
":");
347 char* coordinateStr = strtok(0,
":");
349 Block* block = Block_fromString(blockStr);
350 Coordinate3D* coordinate = Coordinate3D_fromString(coordinateStr);
352 return createLevelObject3D(block, coordinate);
char * value
Definition block.h:24
char * name
Definition block.h:19
int propertyCapacity
Definition block.h:49
int propertyCount
Definition block.h:44
BlockProperty ** properties
Definition block.h:39
char * name
Definition block.h:34
Definition coordinate.h:11
Definition coordinate.h:108
Block * block
Definition block.h:246
Coordinate2D * coordinate
Definition block.h:251
Block * block
Definition block.h:305
Coordinate3D * coordinate
Definition block.h:310