Skip to content
Permalink
Browse files

Add CLI commands for demo (in a quick and dirty way)

  • Loading branch information...
pinnecke committed Mar 1, 2019
1 parent 6c1f0d2 commit 7af5198e4528c38eb1b18b6fed2b29b6b88d29fb
@@ -179,6 +179,14 @@ typedef struct
uint32_t nested_value_object_id,
void *capture);

void (*visit_object_property)(carbon_archive_t *archive, path_stack_t path,
carbon_object_id_t parent_id,
carbon_string_id_t key, carbon_basic_type_e type, bool is_array_type, void *capture);


void (*visit_object_array_prop)(carbon_archive_t *archive, path_stack_t path, carbon_object_id_t parent_id, carbon_string_id_t key, carbon_basic_type_e type, void *capture);

bool (*get_column_entry_count)(carbon_archive_t *archive, path_stack_t path, carbon_string_id_t key, carbon_basic_type_e type, uint32_t count, void *capture);

} carbon_archive_visitor_t;

@@ -189,7 +197,10 @@ carbon_archive_visit_archive(carbon_archive_t *archive, const carbon_archive_vis
CARBON_EXPORT(bool)
carbon_archive_visitor_print_path(FILE *file, carbon_archive_t *archive, const carbon_vec_t ofType(carbon_path_entry_t) *path_stack);

CARBON_EXPORT(void)
carbon_archive_visitor_path_to_string(char path_buffer[2048], carbon_archive_t *archive, const carbon_vec_t ofType(carbon_path_entry_t) *path_stack);

CARBON_EXPORT(bool)
carbon_archive_visitor_path_compare(const carbon_vec_t ofType(carbon_path_entry_t) *lhs, const char *rhs, carbon_archive_t *archive);
carbon_archive_visitor_path_compare(const carbon_vec_t ofType(carbon_path_entry_t) *path, carbon_string_id_t *group_name, const char *path_str, carbon_archive_t *archive);

#endif
@@ -79,6 +79,71 @@ typedef enum carbon_basic_type
CARBON_BASIC_TYPE_OBJECT,
} carbon_basic_type_e;

#define CARBON_FUNC_UNUSED __attribute__((unused))

CARBON_FUNC_UNUSED static const char *
carbon_basic_type_to_json_type_str(carbon_basic_type_e t)
{
switch (t) {
case CARBON_BASIC_TYPE_INT8:
case CARBON_BASIC_TYPE_INT16:
case CARBON_BASIC_TYPE_INT32:
case CARBON_BASIC_TYPE_INT64:
case CARBON_BASIC_TYPE_UINT8:
case CARBON_BASIC_TYPE_UINT16:
case CARBON_BASIC_TYPE_UINT32:
case CARBON_BASIC_TYPE_UINT64:
return "integer";
case CARBON_BASIC_TYPE_NUMBER:
return "number";
case CARBON_BASIC_TYPE_STRING:
return "string";
case CARBON_BASIC_TYPE_BOOLEAN:
return "boolean";
case CARBON_BASIC_TYPE_NULL:
return "null";
case CARBON_BASIC_TYPE_OBJECT:
return "object";
default:
return "(unknown)";
}
}

CARBON_FUNC_UNUSED static const char *
carbon_basic_type_to_system_type_str(carbon_basic_type_e t)
{
switch (t) {
case CARBON_BASIC_TYPE_INT8:
return "int8";
case CARBON_BASIC_TYPE_INT16:
return "int16";
case CARBON_BASIC_TYPE_INT32:
return "int32";
case CARBON_BASIC_TYPE_INT64:
return "int64";
case CARBON_BASIC_TYPE_UINT8:
return "uint8";
case CARBON_BASIC_TYPE_UINT16:
return "uint16";
case CARBON_BASIC_TYPE_UINT32:
return "uint32";
case CARBON_BASIC_TYPE_UINT64:
return "uint64";
case CARBON_BASIC_TYPE_NUMBER:
return "float32";
case CARBON_BASIC_TYPE_STRING:
return "string64";
case CARBON_BASIC_TYPE_BOOLEAN:
return "bool8";
case CARBON_BASIC_TYPE_NULL:
return "void";
case CARBON_BASIC_TYPE_OBJECT:
return "variable";
default:
return "(unknown)";
}
}

#define CARBON_NOT_IMPLEMENTED \
{ \
carbon_err_t err; \
@@ -198,8 +263,6 @@ typedef enum carbon_basic_type

#define CARBON_UNUSED(x) (void)(x)

#define CARBON_FUNC_UNUSED __attribute__((unused))

#define CARBON_BUILT_IN(x) CARBON_FUNC_UNUSED x

#define ofType(x) /** a convenience way to write types for generic containers; no effect than just a visual one */
@@ -46,17 +46,42 @@ typedef union {
uint32_t null;
} carbon_encoded_doc_value_t;

typedef enum
{
CARBON_ENCODED_DOC_PROP_STRING_TYPE_ENCODED_STRING,
CARBON_ENCODED_DOC_PROP_STRING_TYPE_DECODED_STRING,
} carbon_encoded_doc_prop_string_type_e;

typedef enum
{
CARBON_ENCODED_DOC_PROP_VALUE_TYPE_BUILTIN,
CARBON_ENCODED_DOC_PROP_VALUE_TYPE_DECODED_STRING,
} carbon_encoded_doc_prop_value_type_e;

typedef struct
{
carbon_encoded_doc_t *context;
carbon_string_id_t key;
carbon_basic_type_e type;
carbon_encoded_doc_t *context;

carbon_encoded_doc_prop_string_type_e key_type;
union {
carbon_string_id_t key_id;
char *key_str;
} key;

carbon_encoded_doc_prop_value_type_e value_type;
carbon_basic_type_e type;

} carbon_encoded_doc_prop_header_t;

typedef struct
{
carbon_encoded_doc_prop_header_t header;
carbon_encoded_doc_value_t value;

union {
carbon_encoded_doc_value_t builtin;
char *string;
} value;

} carbon_encoded_doc_prop_t;

typedef struct
@@ -113,6 +138,10 @@ carbon_encoded_doc_get_object_id(carbon_object_id_t *oid, carbon_encoded_doc_t *
CARBON_EXPORT(bool) \
carbon_encoded_doc_add_prop_##name(carbon_encoded_doc_t *doc, carbon_string_id_t key, built_in_type value);

#define DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(name, built_in_type) \
CARBON_EXPORT(bool) \
carbon_encoded_doc_add_prop_##name##_decoded(carbon_encoded_doc_t *doc, const char *key, built_in_type value);

DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC(int8, carbon_int8_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC(int16, carbon_int16_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC(int32, carbon_int32_t)
@@ -125,16 +154,41 @@ DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC(number, carbon_number_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC(boolean, carbon_boolean_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC(string, carbon_string_id_t)

DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(int8, carbon_int8_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(int16, carbon_int16_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(int32, carbon_int32_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(int64, carbon_int64_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(uint8, carbon_uint8_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(uint16, carbon_uint16_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(uint32, carbon_uint32_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(uint64, carbon_uint64_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(number, carbon_number_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(boolean, carbon_boolean_t)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_BASIC_DECODED(string, carbon_string_id_t)

CARBON_EXPORT(bool)
carbon_encoded_doc_add_prop_string_decoded_string_value_decoded(carbon_encoded_doc_t *doc, const char *key, const char *value);

CARBON_EXPORT(bool)
carbon_encoded_doc_add_prop_null(carbon_encoded_doc_t *doc, carbon_string_id_t key);

CARBON_EXPORT(bool)
carbon_encoded_doc_add_prop_null_decoded(carbon_encoded_doc_t *doc, const char *key);

CARBON_EXPORT(bool)
carbon_encoded_doc_add_prop_object(carbon_encoded_doc_t *doc, carbon_string_id_t key, carbon_encoded_doc_t *value);

CARBON_EXPORT(bool)
carbon_encoded_doc_add_prop_object_decoded(carbon_encoded_doc_t *doc, const char *key, carbon_encoded_doc_t *value);

#define DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(name) \
CARBON_EXPORT(bool) \
carbon_encoded_doc_add_prop_array_##name(carbon_encoded_doc_t *doc, carbon_string_id_t key);

#define DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(name) \
CARBON_EXPORT(bool) \
carbon_encoded_doc_add_prop_array_##name##_decoded(carbon_encoded_doc_t *doc, const char *key);

DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(int8)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(int16)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(int32)
@@ -149,11 +203,30 @@ DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(string)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(null)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE(object)

DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(int8)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(int16)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(int32)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(int64)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(uint8)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(uint16)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(uint32)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(uint64)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(number)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(boolean)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(string)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(null)
DEFINE_CARBON_ENCODED_DOC_ADD_PROP_ARRAY_TYPE_DECODED(object)

#define DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(name, built_in_type) \
CARBON_EXPORT(bool) \
carbon_encoded_doc_array_push_##name(carbon_encoded_doc_t *doc, carbon_string_id_t key, \
const built_in_type *array, uint32_t array_length);

#define DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(name, built_in_type) \
CARBON_EXPORT(bool) \
carbon_encoded_doc_array_push_##name##_decoded(carbon_encoded_doc_t *doc, const char *key, \
const built_in_type *array, uint32_t array_length);

DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(int8, carbon_int8_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(int16, carbon_int16_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(int32, carbon_int32_t)
@@ -167,12 +240,28 @@ DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(boolean, carbon_boolean_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(string, carbon_string_id_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE(null, carbon_uint32_t)

DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(int8, carbon_int8_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(int16, carbon_int16_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(int32, carbon_int32_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(int64, carbon_int64_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(uint8, carbon_uint8_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(uint16, carbon_uint16_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(uint32, carbon_uint32_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(uint64, carbon_uint64_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(number, carbon_number_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(boolean, carbon_boolean_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(string, carbon_string_id_t)
DEFINE_CARBON_ENCODED_DOC_ARRAY_PUSH_TYPE_DECODED(null, carbon_uint32_t)

//CARBON_EXPORT(bool)
//carbon_encoded_doc_array_push_null(carbon_encoded_doc_t *doc, carbon_string_id_t key, uint32_t how_many);

CARBON_EXPORT(bool)
carbon_encoded_doc_array_push_object(carbon_encoded_doc_t *doc, carbon_string_id_t key, carbon_object_id_t id);

CARBON_EXPORT(bool)
carbon_encoded_doc_array_push_object_decoded(carbon_encoded_doc_t *doc, const char *key, carbon_object_id_t id);

CARBON_EXPORT(bool)
carbon_encoded_doc_get_nested_object(carbon_encoded_doc_t *nested, carbon_object_id_t oid, carbon_encoded_doc_t *doc);

@@ -45,7 +45,7 @@ typedef struct
typedef struct
{
carbon_vec_t key_data;
carbon_vec_t ofType(carbon_bucket_t) table;
carbon_vec_t ofType(carbon_hashset_bucket_t) table;
carbon_spinlock_t lock;
uint32_t size;
carbon_err_t err;
@@ -62,6 +62,9 @@ carbon_hashset_cpy(carbon_hashset_t *src);
CARBON_EXPORT(bool)
carbon_hashset_drop(carbon_hashset_t *map);

CARBON_EXPORT(carbon_vec_t *)
carbon_hashset_keys(carbon_hashset_t *map);

CARBON_EXPORT(bool)
carbon_hashset_clear(carbon_hashset_t *map);

Oops, something went wrong.

0 comments on commit 7af5198

Please sign in to comment.
You can’t perform that action at this time.