![]() |
pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
|
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 #if PLANK_INLINING_FUNCTIONS 00040 00041 #include "../../../../ext/jansson/jansson.h" 00042 00043 typedef struct PlankJSON 00044 { 00045 json_t json; 00046 } PlankJSON; 00047 00048 00049 static inline PlankJSONRef pl_JSON_Object() 00050 { 00051 return (PlankJSONRef)json_object(); 00052 } 00053 00054 static inline PlankJSONRef pl_JSON_Array() 00055 { 00056 return (PlankJSONRef)json_array(); 00057 } 00058 00059 static inline PlankJSONRef pl_JSON_String (const char* string) 00060 { 00061 return (PlankJSONRef)json_string (string); 00062 } 00063 00064 static inline PlankJSONRef pl_JSON_Int (const PlankLL value) 00065 { 00066 return (PlankJSONRef)json_integer ((PlankL)value); 00067 } 00068 00069 static inline PlankJSONRef pl_JSON_Float (const float value) 00070 { 00071 return (PlankJSONRef)json_real ((double)value); 00072 } 00073 00074 static inline PlankJSONRef pl_JSON_Double (const double value) 00075 { 00076 return (PlankJSONRef)json_real (value); 00077 } 00078 00079 static inline PlankJSONRef pl_JSON_Bool (const PlankB state) 00080 { 00081 return (PlankJSONRef)json_boolean (state); 00082 } 00083 00084 static inline PlankJSONRef pl_JSON_Null() 00085 { 00086 return (PlankJSONRef)json_null(); 00087 } 00088 00089 static inline PlankB pl_JSON_IsObject (PlankJSONRef p) 00090 { 00091 return json_is_object ((json_t*)p); 00092 } 00093 00094 static inline PlankB pl_JSON_IsArray (PlankJSONRef p) 00095 { 00096 return json_is_array ((json_t*)p); 00097 } 00098 00099 static inline PlankB pl_JSON_IsString (PlankJSONRef p) 00100 { 00101 return json_is_string ((json_t*)p); 00102 } 00103 00104 static inline PlankB pl_JSON_IsInt (PlankJSONRef p) 00105 { 00106 return json_is_integer ((json_t*)p) ? PLANK_TRUE : pl_JSON_IsIntEncoded (p); 00107 } 00108 00109 static inline PlankB pl_JSON_IsFloat (PlankJSONRef p) 00110 { 00111 return json_is_real ((json_t*)p) ? PLANK_TRUE : pl_JSON_IsFloatEncoded (p); 00112 } 00113 00114 static inline PlankB pl_JSON_IsDouble (PlankJSONRef p) 00115 { 00116 return json_is_real ((json_t*)p) ? PLANK_TRUE : pl_JSON_IsDoubleEncoded (p); 00117 } 00118 00119 static inline PlankB pl_JSON_IsBool (PlankJSONRef p) 00120 { 00121 return json_is_boolean ((json_t*)p); 00122 } 00123 00124 static inline PlankB pl_JSON_IsNull (PlankJSONRef p) 00125 { 00126 return json_is_null ((json_t*)p); 00127 } 00128 00129 static inline PlankJSONRef pl_JSON_IncrementRefCount (PlankJSONRef p) 00130 { 00131 return (PlankJSONRef)json_incref ((json_t*)p); 00132 } 00133 00134 static inline void pl_JSON_DecrementRefCount (PlankJSONRef p) 00135 { 00136 json_decref ((json_t*)p); 00137 } 00138 00139 static inline PlankL pl_JSON_ObjectGetSize (PlankJSONRef p) 00140 { 00141 return (PlankL)json_object_size ((json_t*)p); 00142 } 00143 00144 static inline PlankJSONRef pl_JSON_ObjectAtKey (PlankJSONRef p, const char* key) 00145 { 00146 return (PlankJSONRef)json_object_get ((json_t*)p, key); 00147 } 00148 00149 static inline void pl_JSON_ObjectPutKey (PlankJSONRef p, const char* key, const PlankJSONRef value) 00150 { 00151 json_object_set_new ((json_t*)p, key, (json_t*)value); 00152 } 00153 00154 static inline PlankL pl_JSON_ArrayGetSize (PlankJSONRef p) 00155 { 00156 return (PlankL)json_array_size ((json_t*)p); 00157 } 00158 00159 static inline PlankJSONRef pl_JSON_ArrayAt (PlankJSONRef p, const PlankL index) 00160 { 00161 return (PlankJSONRef)json_array_get ((json_t*)p, (size_t)index); 00162 } 00163 00164 static inline void pl_JSON_ArrayPut (PlankJSONRef p, const PlankL index, const PlankJSONRef value) 00165 { 00166 json_array_set_new ((json_t*)p, (size_t)index, (json_t*)value); 00167 } 00168 00169 static inline void pl_JSON_ArrayAppend (PlankJSONRef p, const PlankJSONRef value) 00170 { 00171 json_array_append_new ((json_t*)p, (json_t*)value); 00172 } 00173 00174 static inline double pl_JSON_DoubleGet (PlankJSONRef p) 00175 { 00176 double value = 0.0; 00177 00178 if (json_is_real ((json_t*)p)) 00179 { 00180 value = json_real_value ((json_t*)p); 00181 } 00182 else if (pl_JSON_ObjectGetSize (p) == 1) 00183 { 00184 value = pl_JSON_DoubleEncodedGet (p); 00185 } 00186 00187 return value; 00188 } 00189 00190 static inline float pl_JSON_FloatGet (PlankJSONRef p) 00191 { 00192 float value = 0.f; 00193 00194 if (json_is_real ((json_t*)p)) 00195 { 00196 value = (float)json_real_value ((json_t*)p); 00197 } 00198 else if (pl_JSON_ObjectGetSize (p) == 1) 00199 { 00200 value = pl_JSON_FloatEncodedGet (p); 00201 } 00202 00203 return value; 00204 } 00205 00206 static inline PlankLL pl_JSON_IntGet (PlankJSONRef p) 00207 { 00208 PlankLL value = 0; 00209 00210 if (json_is_integer ((json_t*)p)) 00211 { 00212 value = (PlankLL)json_integer_value ((json_t*)p); 00213 } 00214 else if (pl_JSON_ObjectGetSize (p) == 1) 00215 { 00216 value = pl_JSON_IntEncodedGet (p); 00217 } 00218 00219 return value; 00220 } 00221 00222 static inline const char* pl_JSON_StringGet (PlankJSONRef p) 00223 { 00224 return json_string_value ((json_t*)p); 00225 } 00226 00227 00228 00229 00230 #endif // PLANK_INLINING_FUNCTIONS 00231 00232