YAJL 2.0.0
yajl_gen.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007-2011, Lloyd Hilaiel <lloyd@hilaiel.com>
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00022 #include <yajl/yajl_common.h>
00023 
00024 #ifndef __YAJL_GEN_H__
00025 #define __YAJL_GEN_H__
00026 
00027 #include <stddef.h>
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif    
00032 
00033     typedef enum {
00035         yajl_gen_status_ok = 0,
00038         yajl_gen_keys_must_be_strings,
00041         yajl_max_depth_exceeded,
00044         yajl_gen_in_error_state,
00046         yajl_gen_generation_complete,                
00049         yajl_gen_invalid_number,
00052         yajl_gen_no_buf,
00056         yajl_gen_invalid_string
00057     } yajl_gen_status;
00058 
00060     typedef struct yajl_gen_t * yajl_gen;
00061 
00063     typedef void (*yajl_print_t)(void * ctx,
00064                                  const char * str,
00065                                  size_t len);
00066 
00070     typedef enum {
00072         yajl_gen_beautify = 0x01,
00078         yajl_gen_indent_string = 0x02,
00088         yajl_gen_print_callback = 0x04,
00094         yajl_gen_validate_utf8 = 0x08
00095     } yajl_gen_option;
00096 
00101     YAJL_API int yajl_gen_config(yajl_gen g, yajl_gen_option opt, ...);
00102 
00111     YAJL_API yajl_gen yajl_gen_alloc(const yajl_alloc_funcs * allocFuncs);
00112 
00114     YAJL_API void yajl_gen_free(yajl_gen handle);
00115 
00116     YAJL_API yajl_gen_status yajl_gen_integer(yajl_gen hand, long long int number);
00120     YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number);
00121     YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand,
00122                                              const char * num,
00123                                              size_t len);
00124     YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand,
00125                                              const unsigned char * str,
00126                                              size_t len);
00127     YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand);
00128     YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean);    
00129     YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand);
00130     YAJL_API yajl_gen_status yajl_gen_map_close(yajl_gen hand);
00131     YAJL_API yajl_gen_status yajl_gen_array_open(yajl_gen hand);
00132     YAJL_API yajl_gen_status yajl_gen_array_close(yajl_gen hand);
00133 
00137     YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand,
00138                                               const unsigned char ** buf,
00139                                               size_t * len);
00140 
00144     YAJL_API void yajl_gen_clear(yajl_gen hand);
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif    
00149 
00150 #endif