aboutsummaryrefslogtreecommitdiff
path: root/include/ucl.h
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2014-07-18 06:49:18 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2014-07-18 06:49:18 +0000
commitf4dd0993e1caedccd8cc6a4fe8a82bd185cafb0b (patch)
treea102c783265745f7ec86e8c9a7ecdda02d5b8ac8 /include/ucl.h
parenteaa81a1805da0fde938c109a768e9c48471c3bb9 (diff)
downloadsrc-f4dd0993e1caedccd8cc6a4fe8a82bd185cafb0b.tar.gz
src-f4dd0993e1caedccd8cc6a4fe8a82bd185cafb0b.zip
Import libucl 2014-07-16vendor/libucl/20140716
Notes
Notes: svn path=/vendor/libucl/dist/; revision=268828 svn path=/vendor/libucl/20140716/; revision=268829; tag=vendor/libucl/20140716
Diffstat (limited to 'include/ucl.h')
-rw-r--r--include/ucl.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/include/ucl.h b/include/ucl.h
index 3eeea9a7df0e..b40f11322508 100644
--- a/include/ucl.h
+++ b/include/ucl.h
@@ -786,6 +786,7 @@ UCL_EXTERN bool ucl_parser_set_filevars (struct ucl_parser *parser, const char *
* @{
*/
+struct ucl_emitter_context;
/**
* Structure using for emitter callbacks
*/
@@ -798,10 +799,49 @@ struct ucl_emitter_functions {
int (*ucl_emitter_append_int) (int64_t elt, void *ud);
/** Append floating point element */
int (*ucl_emitter_append_double) (double elt, void *ud);
+ /** Free userdata */
+ void (*ucl_emitter_free_func)(void *ud);
/** Opaque userdata pointer */
void *ud;
};
+struct ucl_emitter_operations {
+ /** Write a primitive element */
+ void (*ucl_emitter_write_elt) (struct ucl_emitter_context *ctx,
+ const ucl_object_t *obj, bool first, bool print_key);
+ /** Start ucl object */
+ void (*ucl_emitter_start_object) (struct ucl_emitter_context *ctx,
+ const ucl_object_t *obj, bool print_key);
+ /** End ucl object */
+ void (*ucl_emitter_end_object) (struct ucl_emitter_context *ctx,
+ const ucl_object_t *obj);
+ /** Start ucl array */
+ void (*ucl_emitter_start_array) (struct ucl_emitter_context *ctx,
+ const ucl_object_t *obj, bool print_key);
+ void (*ucl_emitter_end_array) (struct ucl_emitter_context *ctx,
+ const ucl_object_t *obj);
+};
+
+/**
+ * Structure that defines emitter functions
+ */
+struct ucl_emitter_context {
+ /** Name of emitter (e.g. json, compact_json) */
+ const char *name;
+ /** Unique id (e.g. UCL_EMIT_JSON for standard emitters */
+ int id;
+ /** A set of output functions */
+ const struct ucl_emitter_functions *func;
+ /** A set of output operations */
+ const struct ucl_emitter_operations *ops;
+ /** Current amount of indent tabs */
+ unsigned int ident;
+ /** Top level object */
+ const ucl_object_t *top;
+ /** The rest of context */
+ unsigned char data[1];
+};
+
/**
* Emit object to a string
* @param obj object
@@ -817,11 +857,81 @@ UCL_EXTERN unsigned char *ucl_object_emit (const ucl_object_t *obj,
* @param obj object
* @param emit_type if type is #UCL_EMIT_JSON then emit json, if type is
* #UCL_EMIT_CONFIG then emit config like object
+ * @param emitter a set of emitter functions
* @return dump of an object (must be freed after using) or NULL in case of error
*/
UCL_EXTERN bool ucl_object_emit_full (const ucl_object_t *obj,
enum ucl_emitter emit_type,
struct ucl_emitter_functions *emitter);
+
+/**
+ * Start streamlined UCL object emitter
+ * @param obj top UCL object
+ * @param emit_type emit type
+ * @param emitter a set of emitter functions
+ * @return new streamlined context that should be freed by
+ * `ucl_object_emit_streamline_finish`
+ */
+UCL_EXTERN struct ucl_emitter_context* ucl_object_emit_streamline_new (
+ const ucl_object_t *obj, enum ucl_emitter emit_type,
+ struct ucl_emitter_functions *emitter);
+
+/**
+ * Start object or array container for the streamlined output
+ * @param ctx streamlined context
+ * @param obj container object
+ */
+UCL_EXTERN void ucl_object_emit_streamline_start_container (
+ struct ucl_emitter_context *ctx, const ucl_object_t *obj);
+/**
+ * Add a complete UCL object to streamlined output
+ * @param ctx streamlined context
+ * @param obj object to output
+ */
+UCL_EXTERN void ucl_object_emit_streamline_add_object (
+ struct ucl_emitter_context *ctx, const ucl_object_t *obj);
+/**
+ * End previously added container
+ * @param ctx streamlined context
+ */
+UCL_EXTERN void ucl_object_emit_streamline_end_container (
+ struct ucl_emitter_context *ctx);
+/**
+ * Terminate streamlined container finishing all containers in it
+ * @param ctx streamlined context
+ */
+UCL_EXTERN void ucl_object_emit_streamline_finish (
+ struct ucl_emitter_context *ctx);
+
+/**
+ * Returns functions to emit object to memory
+ * @param pmem target pointer (should be freed by caller)
+ * @return emitter functions structure
+ */
+UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_memory_funcs (
+ void **pmem);
+
+/**
+ * Returns functions to emit object to FILE *
+ * @param fp FILE * object
+ * @return emitter functions structure
+ */
+UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_file_funcs (
+ FILE *fp);
+/**
+ * Returns functions to emit object to a file descriptor
+ * @param fd file descriptor
+ * @return emitter functions structure
+ */
+UCL_EXTERN struct ucl_emitter_functions* ucl_object_emit_fd_funcs (
+ int fd);
+
+/**
+ * Free emitter functions
+ * @param f pointer to functions
+ */
+UCL_EXTERN void ucl_object_emit_funcs_free (struct ucl_emitter_functions *f);
+
/** @} */
/**