pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
plank_JSON.h
00001 /*
00002  -------------------------------------------------------------------------------
00003  This file is part of the Plink, Plonk, Plank libraries
00004   by Martin Robinson
00005  
00006  http://code.google.com/p/pl-nk/
00007  
00008  Copyright University of the West of England, Bristol 2011-14
00009  All rights reserved.
00010  
00011  Redistribution and use in source and binary forms, with or without
00012  modification, are permitted provided that the following conditions are met:
00013  
00014  * Redistributions of source code must retain the above copyright
00015    notice, this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright
00017    notice, this list of conditions and the following disclaimer in the
00018    documentation and/or other materials provided with the distribution.
00019  * Neither the name of University of the West of England, Bristol nor 
00020    the names of its contributors may be used to endorse or promote products
00021    derived from this software without specific prior written permission.
00022  
00023  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026  DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 
00027  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00028  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00029  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00030  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00031  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00032  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00033  
00034  This software makes use of third party libraries. For more information see:
00035  doc/license.txt included in the distribution.
00036  -------------------------------------------------------------------------------
00037  */
00038 
00039 #ifndef PLANK_JSON_H
00040 #define PLANK_JSON_H
00041 
00042 #include "../../files/plank_File.h"
00043     
00044 #define PLANK_JSON_TYPE                     "type"  ///< Plank's custom JSON object "type" key
00045 #define PLANK_JSON_VERSION                  "vers"  ///< Plank's custom JSON object "versions" key
00046 #define PLANK_JSON_FLOATBINARY              "Bf"    ///< Plank's custom JSON binary float, - Base64 encoded
00047 #define PLANK_JSON_INTBINARY                "Bi"    ///< Plank's custom JSON binary int, - Base64 encoded
00048 #define PLANK_JSON_DOUBLEBINARY             "Bd"    ///< Plank's custom JSON binary double, - Base64 encoded
00049 #define PLANK_JSON_FLOATARRAYBINARY         "Bf[]"  ///< Plank's custom JSON binary float array, - Base64 encoded
00050 #define PLANK_JSON_INTARRAYBINARY           "Bi[]"  ///< Plank's custom JSON binary int array, - Base64 encoded
00051 #define PLANK_JSON_DOUBLEARRAYBINARY        "Bd[]"  ///< Plank's custom JSON binary double array, - Base64 encoded
00052 #define PLANK_JSON_FLOATARRAYCOMPRESSED     "Zf[]"  ///< Plank's custom JSON compressed float array, - deflated, then Base64 encoded
00053 #define PLANK_JSON_INTARRAYCOMPRESSED       "Zi[]"  ///< Plank's custom JSON compressed int array, - deflated, then Base64 encoded
00054 #define PLANK_JSON_DOUBLEARRAYCOMPRESSED    "Zd[]"  ///< Plank's custom JSON compressed double array, - deflated, then Base64 encoded
00055 
00056 #define PLANK_JSON_COMPRESSIONLEVEL         9
00057 
00058 #define PLANK_JSON_INDENT(n)      (n & 0x1F)
00059 #define PLANK_JSON_COMPACT        0x20
00060 #define PLANK_JSON_ENSURE_ASCII   0x40
00061 #define PLANK_JSON_SORT_KEYS      0x80
00062 #define PLANK_JSON_PRESERVE_ORDER 0x100
00063 #define PLANK_JSON_ENCODE_ANY     0x200
00064 #define PLANK_JSON_ESCAPE_SLASH   0x400
00065 #define PLANK_JSON_DEFAULTFLAGS   (PLANK_JSON_PRESERVE_ORDER | PLANK_JSON_INDENT (2))
00066 
00067 
00071 #define PLANK_JSON_ENCODEDSTRINGLENGTH      80
00072 
00073 PLANK_BEGIN_C_LINKAGE
00074 
00075 typedef struct PlankJSON* PlankJSONRef;
00076 
00077 static PlankJSONRef pl_JSON_Object();
00078 static PlankJSONRef pl_JSON_Array();
00079 static PlankJSONRef pl_JSON_String (const char* string);
00080 static PlankJSONRef pl_JSON_Int (const PlankLL value);
00081 static PlankJSONRef pl_JSON_Float (const float value);
00082 static PlankJSONRef pl_JSON_Double (const double value);
00083 static PlankJSONRef pl_JSON_Bool (const PlankB state);
00084 static PlankJSONRef pl_JSON_Null();
00085 
00086 PlankJSONRef pl_JSON_FromFile (PlankFileRef f);
00087 PlankResult pl_JSON_WriteToFile (PlankJSONRef p, PlankFileRef f, const int flags);
00088 
00089 static PlankB pl_JSON_IsObject (PlankJSONRef p);
00090 static PlankB pl_JSON_IsArray (PlankJSONRef p);
00091 static PlankB pl_JSON_IsString (PlankJSONRef p);
00092 static PlankB pl_JSON_IsInt(PlankJSONRef p);
00093 static PlankB pl_JSON_IsFloat (PlankJSONRef p);
00094 static PlankB pl_JSON_IsDouble (PlankJSONRef p);
00095 static PlankB pl_JSON_IsBool (PlankJSONRef p);
00096 static PlankB pl_JSON_IsNull (PlankJSONRef p);
00097 
00098 static PlankJSONRef pl_JSON_IncrementRefCount (PlankJSONRef p);
00099 static void pl_JSON_DecrementRefCount (PlankJSONRef p);
00100 
00101 static PlankL pl_JSON_ObjectGetSize (PlankJSONRef p);
00102 static PlankJSONRef pl_JSON_ObjectAtKey (PlankJSONRef p, const char* key);
00103 static void pl_JSON_ObjectPutKey (PlankJSONRef p, const char* key, const PlankJSONRef value);
00104 
00105 static PlankL pl_JSON_ArrayGetSize (PlankJSONRef p);
00106 static PlankJSONRef pl_JSON_ArrayAt (PlankJSONRef p, const PlankL index);
00107 static void pl_JSON_ArrayPut (PlankJSONRef p, const PlankL index, const PlankJSONRef value);
00108 static void pl_JSON_ArrayAppend (PlankJSONRef p, const PlankJSONRef value);
00109 
00110 static double pl_JSON_DoubleGet (PlankJSONRef p);
00111 static float pl_JSON_FloatGet (PlankJSONRef p);
00112 static PlankLL pl_JSON_IntGet (PlankJSONRef p);
00113 static const char* pl_JSON_StringGet (PlankJSONRef p);
00114 
00115 //
00116 
00117 PlankJSONRef pl_JSON_IntBinary (const PlankLL value);
00118 PlankJSONRef pl_JSON_FloatBinary (const float value);
00119 PlankJSONRef pl_JSON_DoubleBinary (const double value);
00120 PlankJSONRef pl_JSON_IntArrayBinary (const PlankLL* values, const PlankL count);
00121 PlankJSONRef pl_JSON_FloatArrayBinary (const float* values, const PlankL count);
00122 PlankJSONRef pl_JSON_DoubleArrayBinary (const double* values, const PlankL count);
00123 PlankJSONRef pl_JSON_IntArrayCompressed (const PlankLL* values, const PlankL count);
00124 PlankJSONRef pl_JSON_FloatArrayCompressed (const float* values, const PlankL count);
00125 PlankJSONRef pl_JSON_DoubleArrayCompressed (const double* values, const PlankL count);
00126 PlankJSONRef pl_JSON_IntArray (const PlankLL* values, const PlankL count);
00127 PlankJSONRef pl_JSON_FloatArray (const float* values, const PlankL count);
00128 PlankJSONRef pl_JSON_DoubleArray (const double* values, const PlankL count);
00129 
00130 
00131 PlankB pl_JSON_IsIntEncoded (PlankJSONRef p);
00132 PlankB pl_JSON_IsFloatEncoded (PlankJSONRef p);
00133 PlankB pl_JSON_IsDoubleEncoded (PlankJSONRef p);
00134 PlankB pl_JSON_IsIntArrayEncoded (PlankJSONRef p);
00135 PlankB pl_JSON_IsFloatArrayEncoded (PlankJSONRef p);
00136 PlankB pl_JSON_IsDoubleArrayEncoded (PlankJSONRef p);
00137 PlankB pl_JSON_IsError (PlankJSONRef p);
00138 
00139 
00140 PlankLL pl_JSON_IntEncodedGet (PlankJSONRef p);
00141 float pl_JSON_FloatEncodedGet (PlankJSONRef p);
00142 double pl_JSON_DoubleEncodedGet (PlankJSONRef p);
00143 PlankResult pl_JSON_IntArrayGet (PlankJSONRef p, PlankDynamicArrayRef array);
00144 PlankResult pl_JSON_FloatArrayGet (PlankJSONRef p, PlankDynamicArrayRef array);
00145 PlankResult pl_JSON_DoubleArrayGet (PlankJSONRef p, PlankDynamicArrayRef array);
00146 
00151 PlankJSONRef pl_JSON_StringSplit (const char* string, const PlankL count);
00152 
00153 
00154 PlankJSONRef pl_JSON_VersionString (const PlankUC ex, const PlankUC major, const PlankUC minor, const PlankUC micro);
00155 PlankUI pl_JSON_VersionCode (const PlankUC ex, const PlankUC major, const PlankUC minor, const PlankUC micro);
00156 PlankUI pl_JSON_VersionGet (PlankJSONRef p);
00157 
00158 void pl_JSON_ObjectSetType (PlankJSONRef p, const char* type);
00159 void pl_JSON_ObjectSetVersionString (PlankJSONRef p, const PlankUC ex, const PlankUC major, const PlankUC minor, const PlankUC micro);
00160 void pl_JSON_ObjectSetVersionCode (PlankJSONRef p, const PlankUC ex, const PlankUC major, const PlankUC minor, const PlankUC micro);
00161 PlankUI pl_JSON_ObjectGetVersion (PlankJSONRef p);
00162 PlankB pl_JSON_IsObjectType (PlankJSONRef p, const char* type);
00163 
00164 
00165 PLANK_END_C_LINKAGE
00166 
00167 #define PLANK_INLINING_FUNCTIONS 1
00168 #include "plank_JSONInline.h"
00169 #undef PLANK_INLINING_FUNCTIONS
00170 
00171 
00172 #endif // PLANK_JSON_H
 All Classes Functions Typedefs Enumerations Enumerator Properties