First import, libjson and empty main files

This commit is contained in:
King_DuckZ 2013-08-11 04:02:13 +02:00
commit d7b7d22a0f
226 changed files with 47797 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
build/
*.swp
libjson/Objects_static/
libjson/libjson.a

45
CMakeLists.txt Normal file
View file

@ -0,0 +1,45 @@
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Final" CACHE STRING "possible configurations" FORCE)
set_property (GLOBAL PROPERTY DEBUG_CONFIGURATIONS "Debug;Release")
project (WordReference CXX)
include(ExternalProject)
set (LIBJSON_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/libjson)
set (LIBJSON_LIB_DIR ${PROJECT_SOURCE_DIR}/libjson)
set (LIBJSON_CODE_DIR ${PROJECT_SOURCE_DIR}/libjson)
set (${PROJECT_NAME}_Version_Major 0)
set (${PROJECT_NAME}_Version_Minor 1)
set (${PROJECT_NAME}_App_Name "\"${PROJECT_NAME}\"")
string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
set (${PROJECT_NAME}_SourceCodeVar "\"\$${PROJECT_NAME_UPPER}_SOURCE_PATH\"")
find_package(CURL REQUIRED)
#System inclusion paths
include_directories(SYSTEM
${CURL_INCLUDE_DIRS}
)
include_directories(
.
)
link_directories("${LIBJSON_LIB_DIR}")
add_custom_target(build_json ALL
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY ${LIBJSON_CODE_DIR}
COMMENT "Original libjson makefile target"
)
add_library(json STATIC IMPORTED)
set_property(TARGET json APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG)
set_target_properties(json PROPERTIES IMPORTED_LOCATION_NOCONFIG "${LIBJSON_LIB_DIR}/libjson.a")
add_dependencies(json build_json)
add_executable(${PROJECT_NAME}
main.cpp
)
target_link_libraries(${PROJECT_NAME}
"${CURL_LIBRARIES}"
json
)

BIN
libjson/Documentation.pdf Normal file

Binary file not shown.

View file

@ -0,0 +1,43 @@
<HTML>
<HEAD>
<title>libjson Array Example</title>
<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Array Example</h1>
<p>This quick example will show you how to add an array to your JSON tree.</p>
<p><span id="more-120"></span></p>
<pre class="brush:cpp;wrap-lines:true">JSONNode n(JSON_NODE);
n.push_back(JSONNode(&quot;RootA&quot;, &quot;Hello World&quot;));
JSONNode c(JSON_ARRAY);
c.set_name(&quot;ArrayOfNumbers&quot;);
c.push_back(JSONNode(&quot;&quot;, 16));
c.push_back(JSONNode(&quot;&quot;, 42));
c.push_back(JSONNode(&quot;&quot;, 128));
n.push_back(c);
std::string jc = n.write_formatted();
std::cout &lt;&lt; jc &lt;&lt; std::endl;</pre>
<p>The result will look like this:</p>
<pre class="brush:cpp;wrap-lines:true">{
&quot;RootA&quot; : &quot;Hello World&quot;,
&quot;ArrayOfNumbers&quot; : [
16,
42,
128
]
}</pre>
<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create. Because this is created on the stack, there is no need to clean it up, it will do that when it goes out of scope.</p>
<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>.</p>
<p>Line 3 creates a new child node and this time we&#39;re declaring a type of JSON_ARRAY that states the node will contain a number of nameless children nodes. While it&#39;s possible to have different data types in the same array, you should keep them all the same and treat it as if it were a typed array. Note that you can have an array of JSON_NODE objects, so you&#39;re not limited to simple data types, just be aware that the array will ignore any node names if you have them set.</p>
<p>Lines 5 through 7 add values to the array, in this case they&#39;re all integer values. Because a JSON array cannot contain named values, the name parameter is set to &quot;&quot;.</p>
<p>Line 8 appends the array to our root node.</p>
<p>9 and 10 retrieve the formatted JSON string and dump it to stdout.</p>
<BODY>
</HTML>

View file

@ -0,0 +1,57 @@
<HTML>
<HEAD>
<title>libjson Basic Parser Example</title>
<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Basic Parser</h1>
<p>Previously we looked at how to create a new JSON node tree programmatically that could be sent over the wire to consumer. Now we&#39;ll look at the consumer side and see how to parse the JSON string into our application.</p>
<p><span id="more-135"></span></p>
<p>First we&#39;ll look at the main function in our program that will take a JSON string as input, parse it using the library and pass the tree to a function that will extract useful data.</p>
<pre class="brush:cpp;wrap-lines:true">std::string json = &quot;{\&quot;RootA\&quot;:\&quot;Value in parent node\&quot;,\&quot;ChildNode\&quot;:{\&quot;ChildA\&quot;:\&quot;String Value\&quot;,\&quot;ChildB\&quot;:42}}&quot;;
JSONNode n = libjson::parse(json);
ParseJSON(n);</pre>
<p>The first line is just a simple JSON string containing a child object. You&#39;ll likely get a string from a web service, message buss or even a file.</p>
<p>Line 2 is where the magic happens in the library. We just pass the string to <em>libjson::parse</em> and if all is well, we&#39;ll receive a node tree in return. NOTE that the parser is going to allocate memory on the stack, so do not try and delete it, let it go out of scope.</p>
<p>Line 3 is a function call that we define for iterating through the JSON tree. While mine isn&#39;t pretty, it gets the job done for simple JSON objects.</p>
<pre class="brush:cpp;wrap-lines:true">void ParseJSON(const JSONNode &amp; n){
JSONNode::const_iterator i = n.begin();
while (i != n.end()){
// recursively call ourselves to dig deeper into the tree
if (i -> type() == JSON_ARRAY || i -> type() == JSON_NODE){
ParseJSON(*i);
}
// get the node name and value as a string
std::string node_name = i -> name();
// find out where to store the values
if (node_name == &quot;RootA&quot;){
rootA = i -> as_string();
}
else if (node_name == &quot;ChildA&quot;){
childA = i -> as_string();
}
else if (node_name == &quot;ChildB&quot;)
childB = i -> as_int();
//increment the iterator
++i;
}
}</pre>
<p>Next on line 7 we get a pointer to the first iterator of the node we&#39;re currently dealing with. The iterator lets us navigate through the child nodes, one by one.</p>
<p>Line 8 begins a while loop that will continue until we&#39;ve reached the final iterator returned by <em>json_end</em>.</p>
<p>If the iterator is currenly pointing to a node of type JSON_ARRAY or JSON_NODE, that means we are at a branch that requires a new iterator for processing. Thus line 16 makes a recursive call to the function so that we can start processing on the child node. Without this call, we would get the name of the node but trying to get a value would return nothing.</p>
<p>On line 20 we call the <em>name</em> method that will return a string with the name of the node. If the node is not named or it&#39;s an array&#39;s value, the string will be empty, so check for that.</p>
<p>Lines 23 through 34 are a simple decision tree that attempt to match the name of the node to known values and if a match is made, we use one of the library functions to extract the value of the node. <em>as_string</em> naturally returns the value of the node as a string. This is probably the easiest to use in that it doesn&#39;t care if the value of the node is encased in quotation marks or not, it will always return a string. You can read any node as a string and then typecast to whatever need.</p>
<p>Line 38 increments our iterator to the next node.</p>
<p>So there you have a very simple little parser that will iterate through your tree and grab extract the data. Naturally you&#39;ll want to add error handling and tweak it for your own use.</p>
<BODY>
</HTML>

View file

@ -0,0 +1,46 @@
<HTML>
<HEAD>
<title>libjson Child Node Example</title>
<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Child Node Example</h1>
<p>Now we&#39;ll look at how to create a branch off the main tree.</p>
<p><span id="more-114"></span></p>
<pre class="brush:cpp;wrap-lines:true">JSONNode n(JSON_NODE);
n.push_back(JSONNode(&quot;RootA&quot;, &quot;Value in parent node&quot;));
JSONNode c(JSON_NODE);
c.set_name(&quot;ChildNode&quot;);
c.push_back(JSONNode(&quot;ChildA&quot;, &quot;String Value&quot;));
c.push_back(JSONNode(&quot;ChildB&quot;, 42));
n.push_back(c);
std::string jc = n.write_formatted();
std::cout &lt;&lt; jc &lt;&lt; std::endl;</pre>
<p>The result will look like this:</p>
<pre class="brush:cpp;wrap-lines:true">{
&quot;RootA&quot; : &quot;Value in parent node&quot;,
&quot;ChildNode&quot; : {
&quot;ChildA&quot; : &quot;String Value&quot;,
&quot;ChildB&quot; : 42
}
}</pre>
<p>As in the previous example, we create a root node to hold all of our child nodes on line one using the constructor.</p>
<p>Line 2 adds to the root a string node with the name &quot;RootA&quot; and a value of &quot;Value in parent node&quot;.</p>
<p>On line 3 we&#39;re creating a new, floating node that will be a branch off the root. It&#39;s the same type as our root, JSON_NODE.</p>
<p><em>set_name</em> lets us name the node that we&#39;ve just created. If your branch is an object of some kind, you&#39;ll likely want to name it properly. Note that if you try to name the root node (<em>n</em> in our case), it won&#39;t be written out. The name will only appear if the JSON_NODE is a child of another node.</p>
<p>Lines 5 and 6 add new nodes with values to our branch node <em>c</em>.</p>
<p>Line 7 attaches our branch node <em>c</em> to the root node <em>n</em> after the string node named &quot;RootA&quot;.</p>
<p>Line 8 returns the <em>json_string</em> nicely formatted and 9 prints it to stdout.</p>
<p>With these tools, we can create complicated JSON structures and mimick objects with child properties.</p>
<BODY>
</HTML>

View file

@ -0,0 +1,36 @@
<HTML>
<HEAD>
<title>libjson Simple Write Example</title>
<script type="text/javascript" src="../Library Interface/scripts/shCore.js"></script>
<script type="text/javascript" src="../Library Interface/scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="../Library Interface/styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Simple Write Example</h1>
<p>This example uses the C interface to create a set of JSON nodes that you can then dump to a string and use however you like.</p>
<pre class="brush:cpp;wrap-lines:true">JSONNode n(JSON_NODE);
n.push_back(JSONNode(&quot;String Node&quot;, &quot;String Value&quot;));
n.push_back(JSONNode(&quot;Integer Node&quot;, 42));
n.push_back(JSONNode(&quot;Floating Point Node&quot;, 3.14));
n.push_back(JSONNode(&quot;Boolean Node&quot;, true));
std::string jc = n.write_formatted();
std::cout &lt;&lt; jc &lt;&lt; std::endl;</pre>
<p>The result will look like this:</p>
<pre class="brush:cpp;wrap-lines:true">{
&quot;String Node&quot; : &quot;String Value&quot;,
&quot;Integer Node&quot; : 42,
&quot;Floating Point Node&quot; : 3.14,
&quot;Boolean Node&quot; : true
}</pre>
<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create.</p>
<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>.</p>
<p>Line 3, 4 and 5 create and add new integer, floating point and boolean nodes respctively and add them to the root node. Both the integer and floating point methods will create JSON_NUMBER nodes where the numeric values will be printed to a JSON string without any quotation marks. The boolean method will take a true or a false and print a &quot;true&quot; or &quot;false&quot; in the final JSON string.</p>
<p>Line 6 returns a <em>json_string</em> that contains nicely formatted JSON code from the structure we just created. The string will be nicely tabbed and returned for human readability. Use this for debugging purposes. If you are going into production, use the <em>write </em>method instead which will compact the JSON into a single line that saves space for transmission over the Net or between components.</p>
<BODY>
</HTML>

View file

@ -0,0 +1,48 @@
<HTML>
<HEAD>
<title>libjson Array Example</title>
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Array Example</h1>
<p>This quick example will show you how to add an array to your JSON tree.</p>
<p><span id="more-120"></span></p>
<pre class="brush:cpp;wrap-lines:true">JSONNODE *n = json_new(JSON_NODE);
json_push_back(n, json_new_a(&quot;RootA&quot;, &quot;Hello World&quot;));
JSONNODE *c = json_new(JSON_ARRAY);
json_set_name(c, &quot;ArrayOfNumbers&quot;);
json_push_back(c, json_new_i(NULL, 16));
json_push_back(c, json_new_i(NULL, 42));
json_push_back(c, json_new_i(NULL, 128));
json_push_back(n, c);
json_char *jc = json_write_formatted(n);
printf(&quot;%s\n&quot;, jc);
json_free(jc);
json_delete(n);</pre>
<p>The result will look like this:</p>
<pre class="brush:cpp;wrap-lines:true">{
&quot;RootA&quot; : &quot;Hello World&quot;,
&quot;ArrayOfNumbers&quot; : [
16,
42,
128
]
}</pre>
<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create. Note that, as mentioned in the documentation, any time you call a <em>json_new&#8230;</em> method, you are responsbile for freeing the memory allocated by the method. You can do this manually or by attaching the resulting node pointer to an existing node.</p>
<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>. The <em>json_new_a</em> method will escape your string values when you go to write the final string.</p>
<p>Line 3 creates a new child node and this time we&#39;re declaring a type of JSON_ARRAY that states the node will contain a number of nameless children nodes. While it&#39;s possible to have different data types in the same array, you should keep them all the same and treat it as if it were a typed array. Note that you can have an array of JSON_NODE objects, so you&#39;re not limited to simple data types, just be aware that the array will ignore any node names if you have them set.</p>
<p>Lines 5 through 7 add values to the array, in this case they&#39;re all integer values. Because a JSON array cannot contain named values, the name parameter of <em>json_new_i</em> is set to NULL.</p>
<p>Line 8 appends the array to our root node.</p>
<p>9 and 10 retrieve the formatted JSON string and dump it to stdout.</p>
<p>11 frees memory allocated for our JSON string and 12 frees the entire tree structure.</p>
<p>Chris Larsen 2010-10-08</p>
<BODY>
</HTML>

View file

@ -0,0 +1,77 @@
<HTML>
<HEAD>
<title>libjson Basic Parser Example</title>
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Basic Parser</h1>
<p>Previously we looked at how to create a new JSON node tree programmatically that could be sent over the wire to consumer. Now we&#39;ll look at the consumer side and see how to parse the JSON string into our application.</p>
<p><span id="more-135"></span></p>
<p>First we&#39;ll look at the main function in our program that will take a JSON string as input, parse it using the library and pass the tree to a function that will extract useful data.</p>
<pre class="brush:cpp;wrap-lines:true">char *json = &quot;{\&quot;RootA\&quot;:\&quot;Value in parent node\&quot;,\&quot;ChildNode\&quot;:{\&quot;ChildA\&quot;:\&quot;String Value\&quot;,\&quot;ChildB\&quot;:42}}&quot;;
JSONNODE *n = json_parse(json);
ParseJSON(n);
json_delete(n);</pre>
<p>The first line is just a simple JSON string containing a child object. You&#39;ll likely get a string from a web service, message buss or even a file.</p>
<p>Line 2 is where the magic happens in the library. We just pass the string to <em>json_parse</em> and if all is well, we&#39;ll receive a pointer to a node tree in return. NOTE that the parser is going to allocate memory for the node tree, so you have to free it on your own as we do in line 4.</p>
<p>Line 3 is a function call that we define for iterating through the JSON tree. While mine isn&#39;t pretty, it gets the job done for simple JSON objects.</p>
<pre class="brush:cpp;wrap-lines:true">void ParseJSON(JSONNODE *n){
if (n == NULL){
printf(&quot;Invalid JSON Node\n&quot;);
return;
}
JSONNODE_ITERATOR i = json_begin(n);
while (i != json_end(n)){
if (*i == NULL){
printf(&quot;Invalid JSON Node\n&quot;);
return;
}
// recursively call ourselves to dig deeper into the tree
if (json_type(*i) == JSON_ARRAY || json_type(*i) == JSON_NODE){
ParseJSON(*i);
}
// get the node name and value as a string
json_char *node_name = json_name(*i);
// find out where to store the values
if (strcmp(node_name, &quot;RootA&quot;) == 0){
json_char *node_value = json_as_string(*i);
strcpy(rootA, node_value);
json_free(node_value);
}
else if (strcmp(node_name, &quot;ChildA&quot;) == 0){
json_char *node_value = json_as_string(*i);
strcpy(childA, node_value);
json_free(node_value);
}
else if (strcmp(node_name, &quot;ChildB&quot;) == 0)
childB = json_as_int(*i);
// cleanup and increment the iterator
json_free(node_name);
++i;
}
}</pre>
<p>The first thing you want to do is check for NULL. If at any point in the parsing you run into a NULL value, then its likely that the JSON string wasn&#39;t formatted properly.</p>
<p>Next on line 7 we get a pointer to the first iterator of the node we&#39;re currently dealing with. The iterator lets us navigate through the child nodes, one by one.</p>
<p>Line 8 begins a while loop that will continue until we&#39;ve reached the final iterator returned by <em>json_end</em>.</p>
<p>Again, we should check for an invalid iterator in case something went screwey, and we do so on line 9.</p>
<p>If the iterator is currenly pointing to a node of type JSON_ARRAY or JSON_NODE, that means we are at a branch that requires a new iterator for processing. Thus line 16 makes a recursive call to the function so that we can start processing on the child node. Without this call, we would get the name of the node but trying to get a value would return nothing.</p>
<p>On line 20 we call the <em>json_name</em> method that will return a string with the name of the node. If the node is not named or it&#39;s an array&#39;s value, the string will be empty, so check for that. Also note that you MUST free the memory returned by <em>json_name</em> as we do on line 37.</p>
<p>Lines 23 through 34 are a simple decision tree that attempt to match the name of the node to known values and if a match is made, we use one of the library functions to extract the value of the node. <em>json_as_string</em> naturally returns the value of the node as a string. This is probably the easiest to use in that it doesn&#39;t care if the value of the node is encased in quotation marks or not, it will always return a string. You can read any node as a string and then typecast to whatever need.</p>
<p>Line 37 frees up the node name allocation.</p>
<p>Line 38 increments our iterator to the next node.</p>
<p>So there you have a very simple little parser that will iterate through your tree and grab extract the data. Naturally you&#39;ll want to add error handling and tweak it for your own use.</p>
<p>Chris Larsen 2010-10-08</p>
<BODY>
</HTML>

View file

@ -0,0 +1,50 @@
<HTML>
<HEAD>
<title>libjson Child Node Example</title>
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Child Node Example</h1>
<p>Now we&#39;ll look at how to create a branch off the main tree.</p>
<p><span id="more-114"></span></p>
<pre class="brush:cpp;wrap-lines:true">JSONNODE *n = json_new(JSON_NODE);
json_push_back(n, json_new_a(&quot;RootA&quot;, &quot;Value in parent node&quot;));
JSONNODE *c = json_new(JSON_NODE);
json_set_name(c, &quot;ChildNode&quot;);
json_push_back(c, json_new_a(&quot;ChildA&quot;, &quot;String Value&quot;));
json_push_back(c, json_new_i(&quot;ChildB&quot;, 42));
json_push_back(n, c);
json_char *jc = json_write_formatted(n);
printf(&quot;%s\n&quot;, jc);
json_free(jc);
json_delete(n);</pre>
<p>The result will look like this:</p>
<pre class="brush:cpp;wrap-lines:true">{
&quot;RootA&quot; : &quot;Value in parent node&quot;,
&quot;ChildNode&quot; : {
&quot;ChildA&quot; : &quot;String Value&quot;,
&quot;ChildB&quot; : 42
}
}</pre>
<p>As in the previous example, we create a root node to hold all of our child nodes on line one using <em>json_new</em>.</p>
<p>Line 2 adds to the root a string node with the name &quot;RootA&quot; and a value of &quot;Value in parent node&quot;.</p>
<p>On line 3 we&#39;re creating a new, floating node that will be a branch off the root. It&#39;s the same type as our root, JSON_NODE.</p>
<p><em>json_set_name</em> lets us name the node that we&#39;ve just created. If your branch is an object of some kind, you&#39;ll likely want to name it properly. Note that if you try to name the root node (<em>n</em> in our case), it won&#39;t be written out. The name will only appear if the JSON_NODE is a child of another node.</p>
<p>Lines 5 and 6 add new nodes with values to our branch node <em>c</em>.</p>
<p>Line 7 attaches our branch node <em>c</em> to the root node <em>n</em> after the string node named &quot;RootA&quot;. Note that if you fail to attach the branch to another node, you&#39;ll have to delete it manually or risk a memory leak.</p>
<p>Line 8 returns the <em>json_char</em> string nicely formatted and 9 prints it to stdout.</p>
<p>Line 10 frees our JSON string and line 11 loops through our root tree and frees up the memory we&#39;ve used.</p>
<p>With these tools, we can create complicated JSON structures and mimick objects with child properties.</p>
<p>Chris Larsen 2010-10-08</p>
<BODY>
</HTML>

View file

@ -0,0 +1,17 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(2(){1 h=5;h.I=2(){2 n(c,a){4(1 d=0;d<c.9;d++)i[c[d]]=a}2 o(c){1 a=r.H("J"),d=3;a.K=c;a.M="L/t";a.G="t";a.u=a.v=2(){6(!d&&(!8.7||8.7=="F"||8.7=="z")){d=q;e[c]=q;a:{4(1 p y e)6(e[p]==3)B a;j&&5.C(k)}a.u=a.v=x;a.D.O(a)}};r.N.R(a)}1 f=Q,l=h.P(),i={},e={},j=3,k=x,b;5.T=2(c){k=c;j=q};4(b=0;b<f.9;b++){1 m=f[b].w?f[b]:f[b].S(/\\s+/),g=m.w();n(m,g)}4(b=0;b<l.9;b++)6(g=i[l[b].E.A]){e[g]=3;o(g)}}})();',56,56,'|var|function|false|for|SyntaxHighlighter|if|readyState|this|length|||||||||||||||||true|document||javascript|onload|onreadystatechange|pop|null|in|complete|brush|break|highlight|parentNode|params|loaded|language|createElement|autoloader|script|src|text|type|body|removeChild|findElements|arguments|appendChild|split|all'.split('|'),0,{}))

View file

@ -0,0 +1,97 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
;(function()
{
// CommonJS
typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
function Brush()
{
// Copyright 2006 Shin, YoungJin
var datatypes = 'ATOM BOOL BOOLEAN BYTE CHAR COLORREF DWORD DWORDLONG DWORD_PTR ' +
'DWORD32 DWORD64 FLOAT HACCEL HALF_PTR HANDLE HBITMAP HBRUSH ' +
'HCOLORSPACE HCONV HCONVLIST HCURSOR HDC HDDEDATA HDESK HDROP HDWP ' +
'HENHMETAFILE HFILE HFONT HGDIOBJ HGLOBAL HHOOK HICON HINSTANCE HKEY ' +
'HKL HLOCAL HMENU HMETAFILE HMODULE HMONITOR HPALETTE HPEN HRESULT ' +
'HRGN HRSRC HSZ HWINSTA HWND INT INT_PTR INT32 INT64 LANGID LCID LCTYPE ' +
'LGRPID LONG LONGLONG LONG_PTR LONG32 LONG64 LPARAM LPBOOL LPBYTE LPCOLORREF ' +
'LPCSTR LPCTSTR LPCVOID LPCWSTR LPDWORD LPHANDLE LPINT LPLONG LPSTR LPTSTR ' +
'LPVOID LPWORD LPWSTR LRESULT PBOOL PBOOLEAN PBYTE PCHAR PCSTR PCTSTR PCWSTR ' +
'PDWORDLONG PDWORD_PTR PDWORD32 PDWORD64 PFLOAT PHALF_PTR PHANDLE PHKEY PINT ' +
'PINT_PTR PINT32 PINT64 PLCID PLONG PLONGLONG PLONG_PTR PLONG32 PLONG64 POINTER_32 ' +
'POINTER_64 PSHORT PSIZE_T PSSIZE_T PSTR PTBYTE PTCHAR PTSTR PUCHAR PUHALF_PTR ' +
'PUINT PUINT_PTR PUINT32 PUINT64 PULONG PULONGLONG PULONG_PTR PULONG32 PULONG64 ' +
'PUSHORT PVOID PWCHAR PWORD PWSTR SC_HANDLE SC_LOCK SERVICE_STATUS_HANDLE SHORT ' +
'SIZE_T SSIZE_T TBYTE TCHAR UCHAR UHALF_PTR UINT UINT_PTR UINT32 UINT64 ULONG ' +
'ULONGLONG ULONG_PTR ULONG32 ULONG64 USHORT USN VOID WCHAR WORD WPARAM WPARAM WPARAM ' +
'char bool short int __int32 __int64 __int8 __int16 long float double __wchar_t ' +
'clock_t _complex _dev_t _diskfree_t div_t ldiv_t _exception _EXCEPTION_POINTERS ' +
'FILE _finddata_t _finddatai64_t _wfinddata_t _wfinddatai64_t __finddata64_t ' +
'__wfinddata64_t _FPIEEE_RECORD fpos_t _HEAPINFO _HFILE lconv intptr_t ' +
'jmp_buf mbstate_t _off_t _onexit_t _PNH ptrdiff_t _purecall_handler ' +
'sig_atomic_t size_t _stat __stat64 _stati64 terminate_function ' +
'time_t __time64_t _timeb __timeb64 tm uintptr_t _utimbuf ' +
'va_list wchar_t wctrans_t wctype_t wint_t signed';
var keywords = 'break case catch class const __finally __exception __try ' +
'const_cast continue private public protected __declspec ' +
'default delete deprecated dllexport dllimport do dynamic_cast ' +
'else enum explicit extern if for friend goto inline ' +
'mutable naked namespace new noinline noreturn nothrow ' +
'register reinterpret_cast return selectany ' +
'sizeof static static_cast struct switch template this ' +
'thread throw true false try typedef typeid typename union ' +
'using uuid virtual void volatile whcar_t while';
var functions = 'assert isalnum isalpha iscntrl isdigit isgraph islower isprint' +
'ispunct isspace isupper isxdigit tolower toupper errno localeconv ' +
'setlocale acos asin atan atan2 ceil cos cosh exp fabs floor fmod ' +
'frexp ldexp log log10 modf pow sin sinh sqrt tan tanh jmp_buf ' +
'longjmp setjmp raise signal sig_atomic_t va_arg va_end va_start ' +
'clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen ' +
'fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell ' +
'fwrite getc getchar gets perror printf putc putchar puts remove ' +
'rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam ' +
'ungetc vfprintf vprintf vsprintf abort abs atexit atof atoi atol ' +
'bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs ' +
'mbtowc qsort rand realloc srand strtod strtol strtoul system ' +
'wcstombs wctomb memchr memcmp memcpy memmove memset strcat strchr ' +
'strcmp strcoll strcpy strcspn strerror strlen strncat strncmp ' +
'strncpy strpbrk strrchr strspn strstr strtok strxfrm asctime ' +
'clock ctime difftime gmtime localtime mktime strftime time';
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings
{ regex: /^ *#.*/gm, css: 'preprocessor' },
{ regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'color1 bold' },
{ regex: new RegExp(this.getKeywords(functions), 'gm'), css: 'functions bold' },
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword bold' }
];
};
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['cpp', 'c'];
SyntaxHighlighter.brushes.Cpp = Brush;
// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,17 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('3 u={8:{}};u.8={A:4(c,k,l,m,n,o){4 d(a,b){2 a!=1?a:b}4 f(a){2 a!=1?a.E():1}c=c.I(":");3 g=c[0],e={};t={"r":K};M=1;5=8.5;9(3 j R c)e[c[j]]="r";k=f(d(k,5.C));l=f(d(l,5.D));m=f(d(m,5.s));o=f(d(o,5.Q));n=f(d(n,5["x-y"]));2{P:g,C:d(t[e.O],k),D:d(t[e.N],l),s:d({"r":r}[e.s],m),"x-y":d(4(a,b){9(3 h=T S("^"+b+"\\\\[(?<q>\\\\w+)\\\\]$","U"),i=1,p=0;p<a.7;p++)6((i=h.J(a[p]))!=1)2 i.q;2 1}(c,"G"),n)}},F:4(c,k,l,m,n,o){4 d(){9(3 a=H,b=0;b<a.7;b++)6(a[b]!==1){6(z a[b]=="L"&&a[b]!="")2 a[b]+"";6(z a[b]=="X"&&a[b].q!="")2 a[b].q+""}2 1}4 f(a,b,h){h=12.13(h);9(3 i=0;i<h.7;i++)h[i].V("15")==b&&a.Y(h[i])}3 g=[];f(g,c,"Z");f(g,c,"W");6(g.7!==0)9(c=0;c<g.7;c++){3 e=g[c],j=d(e.B["14"],e.10,e.B.v,e.v);6(j!==1){j=u.8.A(j,k,l,m,n,o);8.11(j,e)}}}};',62,68,'|null|return|var|function|defaults|if|length|SyntaxHighlighter|for|||||||||||||||||value|true|collapse|reverse|dp|language||first|line|typeof|parseParams|attributes|gutter|toolbar|toString|HighlightAll|firstline|arguments|split|exec|false|string|result|nocontrols|nogutter|brush|ruler|in|XRegExp|new|gi|getAttribute|textarea|object|push|pre|className|highlight|document|getElementsByTagName|class|name'.split('|'),0,{}))

View file

@ -0,0 +1,43 @@
<HTML>
<HEAD>
<title>libjson Simple Write Example</title>
<script type="text/javascript" src="scripts/shCore.js"></script>
<script type="text/javascript" src="scripts/shBrushCpp.js"></script>
<link type="text/css" rel="stylesheet" href="styles/shCoreDefault.css"/>
<script type="text/javascript">SyntaxHighlighter.all();</script>
</HEAD>
<BODY>
<h1>libjson Simple Write Example</h1>
<p>This example uses the C interface to create a set of JSON nodes that you can then dump to a string and use however you like.</p>
<pre class="brush:cpp;wrap-lines:true">JSONNODE *n = json_new(JSON_NODE);
json_push_back(n, json_new_a(&quot;String Node&quot;, &quot;String Value&quot;));
json_push_back(n, json_new_i(&quot;Integer Node&quot;, 42));
json_push_back(n, json_new_f(&quot;Floating Point Node&quot;, 3.14));
json_push_back(n, json_new_b(&quot;Boolean Node&quot;, 1));
json_char *jc = json_write_formatted(n);
printf(&quot;%s\n&quot;, jc);
json_free(jc);
json_delete(n);</pre>
<p>The result will look like this:</p>
<pre class="brush:cpp;wrap-lines:true">{
&quot;String Node&quot; : &quot;String Value&quot;,
&quot;Integer Node&quot; : 42,
&quot;Floating Point Node&quot; : 3.14,
&quot;Boolean Node&quot; : true
}</pre>
<p>The first line generates a new root node for us to work with. This node will contain the entire JSON structure we want to create. Note that, as mentioned in the documentation, any time you call a <em>json_new&#8230;</em> method, you are responsbile for freeing the memory allocated by the method. You can do this manually or by attaching the resulting node pointer to an existing node.</p>
<p>Line 2 creates a new JSON_STRING node, i.e. a node that will have a string value, and attaches the new node to the end of our original root node <em>n</em>. The <em>json_new_a</em> method will escape your string values when you go to write the final string.</p>
<p>Line 3, 4 and 5 create and add new integer, floating point and boolean nodes respctively and add them to the root node. Both the integer and floating point methods will create JSON_NUMBER nodes where the numeric values will be printed to a JSON string without any quotation marks. The boolean method will take a 0 or a 1 and print a &quot;true&quot; or &quot;false&quot; in the final JSON string.</p>
<p>Line 6 returns a <em>json_char</em> string that contains nicely formatted JSON code from the structure we just created. The string will be nicely tabbed and returned for human readability. Use this for debugging purposes. If you are going into production, use the <em>json_write </em>method instead which will compact the JSON into a single line that saves space for transmission over the Net or between components.<br />
NOTE: similar to other libraries, the <em>json_write</em> and <em>json_write_formatted</em> methods allocate memory for the string, so you are responsible for freeing the memory after you&#39;re finished with it.</p>
<p>Line 8 frees the string that <em>json_write_formatted</em> allocated. Any time you use a library function that returns <em>json_char</em>, make sure to free it!</p>
<p>Line 9 is very important as it will free up all of the memory you&#39;ve allocated for the JSONNODEs. Always call this function on a node when you&#39;re finished with it or you will have some nasty memory leaks to contend with.</p>
<p>That&#39;s the simplest way to create a JSON tree.</p>
<p>Chris Larsen 2010-10-08</p>
<BODY>
</HTML>

View file

@ -0,0 +1,226 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}

View file

@ -0,0 +1,328 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: white !important;
}
.syntaxhighlighter .line.alt1 {
background-color: white !important;
}
.syntaxhighlighter .line.alt2 {
background-color: white !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #e0e0e0 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: black !important;
}
.syntaxhighlighter table caption {
color: black !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #6ce26c !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #6ce26c !important;
color: white !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: blue !important;
background: white !important;
border: 1px solid #6ce26c !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: blue !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: red !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #6ce26c !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: black !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: black !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #008200 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: blue !important;
}
.syntaxhighlighter .keyword {
color: #006699 !important;
}
.syntaxhighlighter .preprocessor {
color: gray !important;
}
.syntaxhighlighter .variable {
color: #aa7700 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ff1493 !important;
}
.syntaxhighlighter .constants {
color: #0066cc !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #006699 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: gray !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: red !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}

View file

@ -0,0 +1,331 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: #0a2b1d !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #0a2b1d !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #0a2b1d !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #233729 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: #f8f8f8 !important;
}
.syntaxhighlighter .gutter {
color: #497958 !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #41a83e !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #41a83e !important;
color: #0a2b1d !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #96dd3b !important;
background: black !important;
border: 1px solid #41a83e !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #96dd3b !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: white !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #41a83e !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #ffe862 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #f8f8f8 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #336442 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #9df39f !important;
}
.syntaxhighlighter .keyword {
color: #96dd3b !important;
}
.syntaxhighlighter .preprocessor {
color: #91bb9e !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #96dd3b !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #eb939a !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #91bb9e !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #edef7d !important;
}
.syntaxhighlighter .comments {
font-style: italic !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}

View file

@ -0,0 +1,339 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: white !important;
}
.syntaxhighlighter .line.alt1 {
background-color: white !important;
}
.syntaxhighlighter .line.alt2 {
background-color: white !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #c3defe !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: black !important;
}
.syntaxhighlighter .gutter {
color: #787878 !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #d4d0c8 !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #d4d0c8 !important;
color: white !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #3f5fbf !important;
background: white !important;
border: 1px solid #d4d0c8 !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #3f5fbf !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #aa7700 !important;
}
.syntaxhighlighter .toolbar {
color: #a0a0a0 !important;
background: #d4d0c8 !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: #a0a0a0 !important;
}
.syntaxhighlighter .toolbar a:hover {
color: red !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: black !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #3f5fbf !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #2a00ff !important;
}
.syntaxhighlighter .keyword {
color: #7f0055 !important;
}
.syntaxhighlighter .preprocessor {
color: #646464 !important;
}
.syntaxhighlighter .variable {
color: #aa7700 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ff1493 !important;
}
.syntaxhighlighter .constants {
color: #0066cc !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #7f0055 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: gray !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: red !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}
.syntaxhighlighter .xml .keyword {
color: #3f7f7f !important;
font-weight: normal !important;
}
.syntaxhighlighter .xml .color1, .syntaxhighlighter .xml .color1 a {
color: #7f007f !important;
}
.syntaxhighlighter .xml .string {
font-style: italic !important;
color: #2a00ff !important;
}

View file

@ -0,0 +1,324 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: black !important;
}
.syntaxhighlighter .line.alt1 {
background-color: black !important;
}
.syntaxhighlighter .line.alt2 {
background-color: black !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #2a3133 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: #d3d3d3 !important;
}
.syntaxhighlighter .gutter {
color: #d3d3d3 !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #990000 !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #990000 !important;
color: black !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #ebdb8d !important;
background: black !important;
border: 1px solid #990000 !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #ebdb8d !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #ff7d27 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #990000 !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #9ccff4 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #d3d3d3 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #ff7d27 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #ff9e7b !important;
}
.syntaxhighlighter .keyword {
color: aqua !important;
}
.syntaxhighlighter .preprocessor {
color: #aec4de !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #81cef9 !important;
}
.syntaxhighlighter .constants {
color: #ff9e7b !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: aqua !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #ebdb8d !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff7d27 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #aec4de !important;
}

View file

@ -0,0 +1,328 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: #121212 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #121212 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #121212 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #2c2c29 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: white !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #3185b9 !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #3185b9 !important;
color: #121212 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #3185b9 !important;
background: black !important;
border: 1px solid #3185b9 !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #3185b9 !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #d01d33 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #3185b9 !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #96daff !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: white !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #696854 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #e3e658 !important;
}
.syntaxhighlighter .keyword {
color: #d01d33 !important;
}
.syntaxhighlighter .preprocessor {
color: #435a5f !important;
}
.syntaxhighlighter .variable {
color: #898989 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #aaaaaa !important;
}
.syntaxhighlighter .constants {
color: #96daff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #d01d33 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #ffc074 !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #4a8cdb !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #96daff !important;
}
.syntaxhighlighter .functions {
font-weight: bold !important;
}

View file

@ -0,0 +1,324 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: #222222 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #222222 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #222222 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #253e5a !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: lime !important;
}
.syntaxhighlighter .gutter {
color: #38566f !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #222222 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #428bdd !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #428bdd !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: lime !important;
}
.syntaxhighlighter .toolbar {
color: #aaaaff !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: #aaaaff !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #9ccff4 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: lime !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #428bdd !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: lime !important;
}
.syntaxhighlighter .keyword {
color: #aaaaff !important;
}
.syntaxhighlighter .preprocessor {
color: #8aa6c1 !important;
}
.syntaxhighlighter .variable {
color: aqua !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ff8000 !important;
}
.syntaxhighlighter .constants {
color: yellow !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #aaaaff !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: red !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: yellow !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}

View file

@ -0,0 +1,324 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: #0f192a !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #0f192a !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #0f192a !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #253e5a !important;
}
.syntaxhighlighter .line.highlighted.number {
color: #38566f !important;
}
.syntaxhighlighter table caption {
color: #d1edff !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #0f192a !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #428bdd !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #428bdd !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #1dc116 !important;
}
.syntaxhighlighter .toolbar {
color: #d1edff !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: #d1edff !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #8aa6c1 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #d1edff !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #428bdd !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #1dc116 !important;
}
.syntaxhighlighter .keyword {
color: #b43d3d !important;
}
.syntaxhighlighter .preprocessor {
color: #8aa6c1 !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #b43d3d !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #f8bb00 !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: white !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}

View file

@ -0,0 +1,324 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter a,
.syntaxhighlighter div,
.syntaxhighlighter code,
.syntaxhighlighter table,
.syntaxhighlighter table td,
.syntaxhighlighter table tr,
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;
left: auto !important;
line-height: 1.1em !important;
margin: 0 !important;
outline: 0 !important;
overflow: visible !important;
padding: 0 !important;
position: static !important;
right: auto !important;
text-align: left !important;
top: auto !important;
vertical-align: baseline !important;
width: auto !important;
box-sizing: content-box !important;
font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important;
font-weight: normal !important;
font-style: normal !important;
font-size: 1em !important;
min-height: inherit !important;
min-height: auto !important;
}
.syntaxhighlighter {
width: 100% !important;
margin: 1em 0 1em 0 !important;
position: relative !important;
overflow: auto !important;
font-size: 1em !important;
}
.syntaxhighlighter.source {
overflow: hidden !important;
}
.syntaxhighlighter .bold {
font-weight: bold !important;
}
.syntaxhighlighter .italic {
font-style: italic !important;
}
.syntaxhighlighter .line {
white-space: pre !important;
}
.syntaxhighlighter table {
width: 100% !important;
}
.syntaxhighlighter table caption {
text-align: left !important;
padding: .5em 0 0.5em 1em !important;
}
.syntaxhighlighter table td.code {
width: 100% !important;
}
.syntaxhighlighter table td.code .container {
position: relative !important;
}
.syntaxhighlighter table td.code .container textarea {
box-sizing: border-box !important;
position: absolute !important;
left: 0 !important;
top: 0 !important;
width: 100% !important;
height: 100% !important;
border: none !important;
background: white !important;
padding-left: 1em !important;
overflow: hidden !important;
white-space: pre !important;
}
.syntaxhighlighter table td.gutter .line {
text-align: right !important;
padding: 0 0.5em 0 1em !important;
}
.syntaxhighlighter table td.code .line {
padding: 0 1em !important;
}
.syntaxhighlighter.nogutter td.code .container textarea, .syntaxhighlighter.nogutter td.code .line {
padding-left: 0em !important;
}
.syntaxhighlighter.show {
display: block !important;
}
.syntaxhighlighter.collapsed table {
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar {
padding: 0.1em 0.8em 0em 0.8em !important;
font-size: 1em !important;
position: static !important;
width: auto !important;
height: auto !important;
}
.syntaxhighlighter.collapsed .toolbar span {
display: inline !important;
margin-right: 1em !important;
}
.syntaxhighlighter.collapsed .toolbar span a {
padding: 0 !important;
display: none !important;
}
.syntaxhighlighter.collapsed .toolbar span a.expandSource {
display: inline !important;
}
.syntaxhighlighter .toolbar {
position: absolute !important;
right: 1px !important;
top: 1px !important;
width: 11px !important;
height: 11px !important;
font-size: 10px !important;
z-index: 10 !important;
}
.syntaxhighlighter .toolbar span.title {
display: inline !important;
}
.syntaxhighlighter .toolbar a {
display: block !important;
text-align: center !important;
text-decoration: none !important;
padding-top: 1px !important;
}
.syntaxhighlighter .toolbar a.expandSource {
display: none !important;
}
.syntaxhighlighter.ie {
font-size: .9em !important;
padding: 1px 0 1px 0 !important;
}
.syntaxhighlighter.ie .toolbar {
line-height: 8px !important;
}
.syntaxhighlighter.ie .toolbar a {
padding-top: 0px !important;
}
.syntaxhighlighter.printing .line.alt1 .content,
.syntaxhighlighter.printing .line.alt2 .content,
.syntaxhighlighter.printing .line.highlighted .number,
.syntaxhighlighter.printing .line.highlighted.alt1 .content,
.syntaxhighlighter.printing .line.highlighted.alt2 .content {
background: none !important;
}
.syntaxhighlighter.printing .line .number {
color: #bbbbbb !important;
}
.syntaxhighlighter.printing .line .content {
color: black !important;
}
.syntaxhighlighter.printing .toolbar {
display: none !important;
}
.syntaxhighlighter.printing a {
text-decoration: none !important;
}
.syntaxhighlighter.printing .plain, .syntaxhighlighter.printing .plain a {
color: black !important;
}
.syntaxhighlighter.printing .comments, .syntaxhighlighter.printing .comments a {
color: #008200 !important;
}
.syntaxhighlighter.printing .string, .syntaxhighlighter.printing .string a {
color: blue !important;
}
.syntaxhighlighter.printing .keyword {
color: #006699 !important;
font-weight: bold !important;
}
.syntaxhighlighter.printing .preprocessor {
color: gray !important;
}
.syntaxhighlighter.printing .variable {
color: #aa7700 !important;
}
.syntaxhighlighter.printing .value {
color: #009900 !important;
}
.syntaxhighlighter.printing .functions {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .constants {
color: #0066cc !important;
}
.syntaxhighlighter.printing .script {
font-weight: bold !important;
}
.syntaxhighlighter.printing .color1, .syntaxhighlighter.printing .color1 a {
color: gray !important;
}
.syntaxhighlighter.printing .color2, .syntaxhighlighter.printing .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter.printing .color3, .syntaxhighlighter.printing .color3 a {
color: red !important;
}
.syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a {
color: black !important;
}
.syntaxhighlighter {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #323e41 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: #b9bdb6 !important;
}
.syntaxhighlighter table caption {
color: #b9bdb6 !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #1b2426 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #5ba1cf !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #5ba1cf !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #5ce638 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #e0e8ff !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #b9bdb6 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #878a85 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #5ce638 !important;
}
.syntaxhighlighter .keyword {
color: #5ba1cf !important;
}
.syntaxhighlighter .preprocessor {
color: #435a5f !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #5ba1cf !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #e0e8ff !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: white !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}

View file

@ -0,0 +1,117 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: white !important;
}
.syntaxhighlighter .line.alt1 {
background-color: white !important;
}
.syntaxhighlighter .line.alt2 {
background-color: white !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #e0e0e0 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: black !important;
}
.syntaxhighlighter table caption {
color: black !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #6ce26c !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #6ce26c !important;
color: white !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: blue !important;
background: white !important;
border: 1px solid #6ce26c !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: blue !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: red !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #6ce26c !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: black !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: black !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #008200 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: blue !important;
}
.syntaxhighlighter .keyword {
color: #006699 !important;
}
.syntaxhighlighter .preprocessor {
color: gray !important;
}
.syntaxhighlighter .variable {
color: #aa7700 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ff1493 !important;
}
.syntaxhighlighter .constants {
color: #0066cc !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #006699 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: gray !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: red !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}

View file

@ -0,0 +1,120 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #0a2b1d !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #0a2b1d !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #0a2b1d !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #233729 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: #f8f8f8 !important;
}
.syntaxhighlighter .gutter {
color: #497958 !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #41a83e !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #41a83e !important;
color: #0a2b1d !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #96dd3b !important;
background: black !important;
border: 1px solid #41a83e !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #96dd3b !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: white !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #41a83e !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #ffe862 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #f8f8f8 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #336442 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #9df39f !important;
}
.syntaxhighlighter .keyword {
color: #96dd3b !important;
}
.syntaxhighlighter .preprocessor {
color: #91bb9e !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #96dd3b !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #eb939a !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #91bb9e !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #edef7d !important;
}
.syntaxhighlighter .comments {
font-style: italic !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}

View file

@ -0,0 +1,128 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: white !important;
}
.syntaxhighlighter .line.alt1 {
background-color: white !important;
}
.syntaxhighlighter .line.alt2 {
background-color: white !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #c3defe !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: black !important;
}
.syntaxhighlighter .gutter {
color: #787878 !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #d4d0c8 !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #d4d0c8 !important;
color: white !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #3f5fbf !important;
background: white !important;
border: 1px solid #d4d0c8 !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #3f5fbf !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #aa7700 !important;
}
.syntaxhighlighter .toolbar {
color: #a0a0a0 !important;
background: #d4d0c8 !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: #a0a0a0 !important;
}
.syntaxhighlighter .toolbar a:hover {
color: red !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: black !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #3f5fbf !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #2a00ff !important;
}
.syntaxhighlighter .keyword {
color: #7f0055 !important;
}
.syntaxhighlighter .preprocessor {
color: #646464 !important;
}
.syntaxhighlighter .variable {
color: #aa7700 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ff1493 !important;
}
.syntaxhighlighter .constants {
color: #0066cc !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #7f0055 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: gray !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff1493 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: red !important;
}
.syntaxhighlighter .keyword {
font-weight: bold !important;
}
.syntaxhighlighter .xml .keyword {
color: #3f7f7f !important;
font-weight: normal !important;
}
.syntaxhighlighter .xml .color1, .syntaxhighlighter .xml .color1 a {
color: #7f007f !important;
}
.syntaxhighlighter .xml .string {
font-style: italic !important;
color: #2a00ff !important;
}

View file

@ -0,0 +1,113 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: black !important;
}
.syntaxhighlighter .line.alt1 {
background-color: black !important;
}
.syntaxhighlighter .line.alt2 {
background-color: black !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #2a3133 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: #d3d3d3 !important;
}
.syntaxhighlighter .gutter {
color: #d3d3d3 !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #990000 !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #990000 !important;
color: black !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #ebdb8d !important;
background: black !important;
border: 1px solid #990000 !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #ebdb8d !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #ff7d27 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #990000 !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #9ccff4 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #d3d3d3 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #ff7d27 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #ff9e7b !important;
}
.syntaxhighlighter .keyword {
color: aqua !important;
}
.syntaxhighlighter .preprocessor {
color: #aec4de !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #81cef9 !important;
}
.syntaxhighlighter .constants {
color: #ff9e7b !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: aqua !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #ebdb8d !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #ff7d27 !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #aec4de !important;
}

View file

@ -0,0 +1,117 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #121212 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #121212 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #121212 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #2c2c29 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: white !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #3185b9 !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #3185b9 !important;
color: #121212 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #3185b9 !important;
background: black !important;
border: 1px solid #3185b9 !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #3185b9 !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #d01d33 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #3185b9 !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #96daff !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: white !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #696854 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #e3e658 !important;
}
.syntaxhighlighter .keyword {
color: #d01d33 !important;
}
.syntaxhighlighter .preprocessor {
color: #435a5f !important;
}
.syntaxhighlighter .variable {
color: #898989 !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #aaaaaa !important;
}
.syntaxhighlighter .constants {
color: #96daff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #d01d33 !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #ffc074 !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: #4a8cdb !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #96daff !important;
}
.syntaxhighlighter .functions {
font-weight: bold !important;
}

View file

@ -0,0 +1,113 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #222222 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #222222 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #222222 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #253e5a !important;
}
.syntaxhighlighter .line.highlighted.number {
color: white !important;
}
.syntaxhighlighter table caption {
color: lime !important;
}
.syntaxhighlighter .gutter {
color: #38566f !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #222222 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #428bdd !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #428bdd !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: lime !important;
}
.syntaxhighlighter .toolbar {
color: #aaaaff !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: #aaaaff !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #9ccff4 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: lime !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #428bdd !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: lime !important;
}
.syntaxhighlighter .keyword {
color: #aaaaff !important;
}
.syntaxhighlighter .preprocessor {
color: #8aa6c1 !important;
}
.syntaxhighlighter .variable {
color: aqua !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ff8000 !important;
}
.syntaxhighlighter .constants {
color: yellow !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #aaaaff !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: red !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: yellow !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}

View file

@ -0,0 +1,113 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #0f192a !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #0f192a !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #0f192a !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #253e5a !important;
}
.syntaxhighlighter .line.highlighted.number {
color: #38566f !important;
}
.syntaxhighlighter table caption {
color: #d1edff !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #0f192a !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #428bdd !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #428bdd !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #1dc116 !important;
}
.syntaxhighlighter .toolbar {
color: #d1edff !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: #d1edff !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #8aa6c1 !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #d1edff !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #428bdd !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #1dc116 !important;
}
.syntaxhighlighter .keyword {
color: #b43d3d !important;
}
.syntaxhighlighter .preprocessor {
color: #8aa6c1 !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #f7e741 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #b43d3d !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #f8bb00 !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: white !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}

View file

@ -0,0 +1,113 @@
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
* @copyright
* Copyright (C) 2004-2010 Alex Gorbatchev.
*
* @license
* Dual licensed under the MIT and GPL licenses.
*/
.syntaxhighlighter {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.alt1 {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.alt2 {
background-color: #1b2426 !important;
}
.syntaxhighlighter .line.highlighted.alt1, .syntaxhighlighter .line.highlighted.alt2 {
background-color: #323e41 !important;
}
.syntaxhighlighter .line.highlighted.number {
color: #b9bdb6 !important;
}
.syntaxhighlighter table caption {
color: #b9bdb6 !important;
}
.syntaxhighlighter .gutter {
color: #afafaf !important;
}
.syntaxhighlighter .gutter .line {
border-right: 3px solid #435a5f !important;
}
.syntaxhighlighter .gutter .line.highlighted {
background-color: #435a5f !important;
color: #1b2426 !important;
}
.syntaxhighlighter.printing .line .content {
border: none !important;
}
.syntaxhighlighter.collapsed {
overflow: visible !important;
}
.syntaxhighlighter.collapsed .toolbar {
color: #5ba1cf !important;
background: black !important;
border: 1px solid #435a5f !important;
}
.syntaxhighlighter.collapsed .toolbar a {
color: #5ba1cf !important;
}
.syntaxhighlighter.collapsed .toolbar a:hover {
color: #5ce638 !important;
}
.syntaxhighlighter .toolbar {
color: white !important;
background: #435a5f !important;
border: none !important;
}
.syntaxhighlighter .toolbar a {
color: white !important;
}
.syntaxhighlighter .toolbar a:hover {
color: #e0e8ff !important;
}
.syntaxhighlighter .plain, .syntaxhighlighter .plain a {
color: #b9bdb6 !important;
}
.syntaxhighlighter .comments, .syntaxhighlighter .comments a {
color: #878a85 !important;
}
.syntaxhighlighter .string, .syntaxhighlighter .string a {
color: #5ce638 !important;
}
.syntaxhighlighter .keyword {
color: #5ba1cf !important;
}
.syntaxhighlighter .preprocessor {
color: #435a5f !important;
}
.syntaxhighlighter .variable {
color: #ffaa3e !important;
}
.syntaxhighlighter .value {
color: #009900 !important;
}
.syntaxhighlighter .functions {
color: #ffaa3e !important;
}
.syntaxhighlighter .constants {
color: #e0e8ff !important;
}
.syntaxhighlighter .script {
font-weight: bold !important;
color: #5ba1cf !important;
background-color: none !important;
}
.syntaxhighlighter .color1, .syntaxhighlighter .color1 a {
color: #e0e8ff !important;
}
.syntaxhighlighter .color2, .syntaxhighlighter .color2 a {
color: white !important;
}
.syntaxhighlighter .color3, .syntaxhighlighter .color3 a {
color: #ffaa3e !important;
}

360
libjson/JSONOptions.h Normal file
View file

@ -0,0 +1,360 @@
#ifndef JSON_OPTIONS_H
#define JSON_OPTIONS_H
/**
* This file holds all of the compiling options for easy access and so
* that you don't have to remember them, or look them up all the time
*/
/*
* JSON_LIBRARY must be declared if libjson is compiled as a static or dynamic
* library. This exposes a C-style interface, but none of the inner workings of libjson
*/
#define JSON_LIBRARY
/*
* JSON_STRICT removes all of libjson's extensions. Meaning no comments, no special numbers
*/
//#define JSON_STRICT
/*
* JSON_DEBUG is used to perform extra error checking. Because libjson usually
* does on the fly parsing, validation is impossible, so this option will allow
* you to register an error callback so that you can record what is going wrong
* before the library crashes. This option does not protect from these errors,
* it simply tells you about them, which is nice for debugging, but not preferable
* for release candidates
*/
//#define JSON_DEBUG
/*
* JSON_ISO_STRICT turns off all code that uses non-standard C++. This removes all
* references to long long and long double as well as a few others
*/
//#define JSON_ISO_STRICT
/*
* JSON_SAFE performs similarly to JSON_DEBUG, except this option does protect
* from the errors that it encounters. This option is recommended for those who
* feel it's possible for their program to encounter invalid json.
*/
#define JSON_SAFE
/*
* JSON_STDERROR routes error messages to cerr instead of a callback, this
* option hides the callback registering function. This will usually display
* messages in the console
*/
//#define JSON_STDERROR
/*
* JSON_PREPARSE causes all parsing to be done immediately. By default, libjson
* parses nodes on the fly as they are needed, this makes parsing much faster if
* your program gets a lot of information that it doesn't need. An example of
* this would be a client application communicating with a server if the server
* returns things like last modified date and other things that you don't use.
*/
//#define JSON_PREPARSE
/*
* JSON_LESS_MEMORY will force libjson to let go of memory as quickly as it can
* this is recommended for software that has to run on less than optimal machines.
* It will cut libjson's memory usage by about 20%, but also run slightly slower.
* It's recommended that you also compile using the -Os option, as this will also
* reduce the size of the library
*/
//#define JSON_LESS_MEMORY
/*
* JSON_UNICODE tells libjson to use wstrings instead of regular strings, this
* means that libjson supports the full array of unicode characters, but also takes
* much more memory and processing power.
*/
//#define JSON_UNICODE
/*
* JSON_REF_COUNT causes libjson to reference count JSONNodes, which makes copying
* and passing them around much faster. It is recommended that this stay on for
* most uses
*/
#define JSON_REF_COUNT
/*
* JSON_BINARY is used to support binary, which is base64 encoded and decoded by libjson,
* if this option is not turned off, no base64 support is included
*/
#define JSON_BINARY
/*
* JSON_EXPOSE_BASE64 is used to turn on the functionality of libjson's base64 encoding
* and decoding. This may be useful if you want to obfuscate your json, or send binary data over
* a network
*/
#define JSON_EXPOSE_BASE64
/*
* JSON_ITERATORS turns on all of libjson's iterating functionality. This would usually
* only be turned off while compiling for use with C
*/
#define JSON_ITERATORS
/*
* JSON_STREAM turns on libjson's streaming functionality. This allows you to give parts of
* your json into a stream, which will automatically hit a callback when full nodes are
* completed
*/
#define JSON_STREAM
/*
* JSON_MEMORY_CALLBACKS exposes functions to register callbacks for allocating, resizing,
* and freeing memory. Because libjson is designed for customizability, it is feasible
* that some users would like to further add speed by having the library utilize a memory
* pool. With this option turned on, the default behavior is still done internally unless
* a callback is registered. So you can have this option on and not use it.
*/
//#define JSON_MEMORY_CALLBACKS
/*
* JSON_MEMORY_MANAGE is used to create functionality to automatically track and clean
* up memory that has been allocated by the user. This includes strings, binary data, and
* nodes. It also exposes bulk delete functions.
*/
//#define JSON_MEMORY_MANAGE
/*
* JSON_MEMORY_POOL Turns on libjson's iteraction with mempool++. It is more efficient that simply
* connecting mempool++ to the callbacks because it integrates things internally and uses a number
* of memory pools. This value tells libjson how large of a memory pool to start out with. 500KB
* should suffice for most cases. libjson will distribute that within the pool for the best
* performance depending on other settings.
*/
//#define JSON_MEMORY_POOL 524288
/*
* JSON_MUTEX_CALLBACKS exposes functions to register callbacks to lock and unlock
* mutexs and functions to lock and unlock JSONNodes and all of it's children. This
* does not prevent other threads from accessing the node, but will prevent them from
* locking it. It is much easier for the end programmer to allow libjson to manage
* your mutexs because of reference counting and manipulating trees, libjson automatically
* tracks mutex controls for you, so you only ever lock what you need to
*/
//#define JSON_MUTEX_CALLBACKS
/*
* JSON_MUTEX_MANAGE lets you set mutexes and forget them, libjson will not only keep
* track of the mutex, but also keep a count of how many nodes are using it, and delete
* it when there are no more references
*/
//#define JSON_MUTEX_MANAGE
/*
* JSON_NO_C_CONSTS removes consts from the C interface. It still acts the same way, but
* this may be useful for using the header with languages or variants that don't have const
*/
//#define JSON_NO_C_CONSTS
/*
* JSON_OCTAL allows libjson to use octal values in numbers.
*/
//#define JSON_OCTAL
/*
* JSON_WRITE_PRIORITY turns on libjson's writing capabilties. Without this libjson can only
* read and parse json, this allows it to write back out. Changing the value of the writer
* changes how libjson compiles, and how fast it will go when writing
*/
#define JSON_WRITE_PRIORITY MED
/*
* JSON_READ_PRIORITY turns on libjson's reading capabilties. Changing the value of the reader
* changes how libjson compiles, and how fast it will go when writing
*/
#define JSON_READ_PRIORITY HIGH
/*
* JSON_NEWLINE affects how libjson writes. If this option is turned on, libjson
* will use whatever it's defined as for the newline signifier, otherwise, it will use
* standard unix \n.
*/
//#define JSON_NEWLINE "\r\n" //\r\n is standard for most windows and dos programs
/*
* JSON_INDENT affects how libjson writes. If this option is turned on, libjson
* will use \t to indent formatted json, otherwise it will use the number of characters
* that you specify. If this is not turned on, then it will use the tab (\t) character
*/
//#define JSON_INDENT " "
/*
* JSON_ESCAPE_WRITES tells the libjson engine to escape special characters when it writes
* out. If this option is turned off, the json it outputs may not adhere to JSON standards
*/
#define JSON_ESCAPE_WRITES
/*
* JSON_COMMENTS tells libjson to store and write comments. libjson always supports
* parsing json that has comments in it as it simply ignores them, but with this option
* it keeps the comments and allows you to insert further comments
*/
#define JSON_COMMENTS
/*
* JSON_WRITE_BASH_COMMENTS will cause libjson to write all comments in bash (#) style
* if this option is not turned on, then it will use C-style comments. Bash comments are
* all single line
*/
//#define JSON_WRITE_BASH_COMMENTS
/*
* JSON_WRITE_SINGLE_LINE_COMMENTS will cause libjson to write all comments in using //
* notation, or (#) if that option is on. Some parsers do not support multiline C comments
* although, this option is not needed for bash comments, as they are all single line anyway
*/
//#define JSON_WRITE_SINGLE_LINE_COMMENTS
/*
* JSON_ARRAY_SIZE_ON_ON_LINE allows you to put small arrays of primitives all on one line
* in a write_formatted. This is common for tuples, like coordinates. If must be defined
* as an integer
*/
//#define JSON_ARRAY_SIZE_ON_ONE_LINE 2
/*
* JSON_VALIDATE turns on validation features of libjson.
*/
#define JSON_VALIDATE
/*
* JSON_CASE_INSENSITIVE_FUNCTIONS turns on funtions for finding child nodes in a case-
* insenititve way
*/
#define JSON_CASE_INSENSITIVE_FUNCTIONS
/*
* JSON_INDEX_TYPE allows you th change the size type for the children functions. If this
* option is not used then unsigned int is used. This option is useful for cutting down
* on memory, or using huge numbers of child nodes (over 4 billion)
*/
//#define JSON_INDEX_TYPE unsigned int
/*
* JSON_BOOL_TYPE lets you change the bool type for the C interface. Because before C99 there
* was no bool, and even then it's just a typedef, you may want to use something else. If this
* is not defined, it will revert to int
*/
//#define JSON_BOOL_TYPE char
/*
* JSON_INT_TYPE lets you change the int type for as_int. If you ommit this option, the default
* long will be used
*/
//#define JSON_INT_TYPE long
/*
* JSON_NUMBER_TYPE lets you change the number type for as_float as well as the internal storage for the
* number. If you omit this option, the default double will be used for most cases and float for JSON_LESS_MEMORY
*/
//#define JSON_NUMBER_TYPE double
/*
* JSON_STRING_HEADER allows you to change the type of string that libjson uses both for the
* interface and internally. It must implement most of the STL string interface, but not all
* of it. Things like wxString or QString should wourk without much trouble
*/
//#define JSON_STRING_HEADER "../TestSuite/StringTest.h"
/*
* JSON_UNIT_TEST is used to maintain and debug the libjson. It makes all private
* members and functions public so that tests can do checks of the inner workings
* of libjson. This should not be turned on by end users.
*/
//#define JSON_UNIT_TEST
/*
* JSON_NO_EXCEPTIONS turns off any exception throwing by the library. It may still use exceptions
* internally, but the interface will never throw anything.
*/
//#define JSON_NO_EXCEPTIONS
/*
* JSON_DEPRECATED_FUNCTIONS turns on functions that have been deprecated, this is for backwards
* compatibility between major releases. It is highly recommended that you move your functions
* over to the new equivalents
*/
#define JSON_DEPRECATED_FUNCTIONS
/*
* JSON_CASTABLE allows you to call as_bool on a number and have it do the 0 or not 0 check,
* it also allows you to ask for a string from a number, or boolean, and have it return the right thing.
* Without this option, those types of requests are undefined. It also exposes the as_array, as_node, and cast
* functions
*/
#define JSON_CASTABLE
/*
* JSON_SECURITY_MAX_NEST_LEVEL is a security measure added to make prevent against DoS attacks
* This only affects validation, as if you are worried about security attacks, then you are
* most certainly validating json before sending it to be parsed. This option allows you to limitl how many
* levels deep a JSON Node can go. 128 is a good depth to start with
*/
#define JSON_SECURITY_MAX_NEST_LEVEL 128
/*
* JSON_SECURITY_MAX_STRING_LENGTH is another security measure, preventing DoS attacks with very long
* strings of JSON. 32MB is the default value for this, this allows large images to be embedded
*/
#define JSON_SECURITY_MAX_STRING_LENGTH 33554432
/*
* JSON_SECURITY_MAX_STREAM_OBJECTS is a security measure for streams. It prevents DoS attacks with
* large number of objects hitting the stream all at once. 128 is a lot of objects, but not out of
* the question for high speed systems.
*/
#define JSON_SECURITY_MAX_STREAM_OBJECTS 128
#endif

13
libjson/License.txt Normal file
View file

@ -0,0 +1,13 @@
This license is also available in Documentation.pdf
Copyright 2010 Jonathan Wallace. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY JONATHAN WALLACE ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JONATHAN WALLACE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Jonathan Wallace.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,270 @@
#ifndef LIBBASE64_CPP_H
#define LIBBASE64_CPP_H
#include <string>
//#define LIBBASE64_THROW_STD_INVALID_ARGUMENT
//version info
#define __LIBBASE64_MAJOR__ 1
#define __LIBBASE64_MINOR__ 1
#define __LIBBASE64_PATCH__ 0
#define __LIBBASE64_VERSION__ (__LIBBASE64_MAJOR__ * 10000 + __LIBBASE64_MINOR__ * 100 + __LIBBASE64_PATCH__)
//code coverage and asserts
#ifdef NDEBUG
#define LIBBASE64_ASSERT(cond, msg) (void)0
#define CREATEBOUNDCHECKER(type, name, ubound, lbound) (void)0
#define GETITEM_BOUNDCHECK(loc, name) (*(loc))
#else
#include <iostream>
#define LIBBASE64_ASSERT(cond, msg) if (!(cond)){ std::cerr << msg << std::endl; throw false; }
template<typename T>
class libbase64_boundChecker {
public:
libbase64_boundChecker(const T * lbound, const T * ubound) : upperbound(ubound), lowerbound(lbound){};
T getLocation(const T * loc){
LIBBASE64_ASSERT(loc < upperbound, "Array index above bounds");
LIBBASE64_ASSERT(loc >= lowerbound, "Array index below bounds");
return *loc;
}
private:
const T * lowerbound;
const T * upperbound;
};
#define CREATEBOUNDCHECKER(type, name, ubound, lbound) libbase64_boundChecker<type> name(ubound, lbound)
#define GETITEM_BOUNDCHECK(loc, name) name.getLocation(loc)
#ifdef LIBBASE64CODECOVERAGE
#define LIBBASE64CODECOVERAGEBRANCH { static bool f_codeCoverage_ = false; if (f_codeCoverage_ == false){ libbase64::getCoverageHits<STRINGTYPE, CHARTYPE, UCHARTYPE, SAFETY>(true); f_codeCoverage_ = true; } }
#endif
#endif
#ifndef LIBBASE64CODECOVERAGE
#define LIBBASE64CODECOVERAGEBRANCH (void)0
#endif
//predictive branching optimizations
#ifdef __GNUC__
#define LIBBASE64_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
#if (LIBBASE64_GCC_VERSION >= 29600)
#define libbase64_likely(x) __builtin_expect((long)((bool)(x)),1)
#define libbase64_unlikely(x) __builtin_expect((long)((bool)(x)),0)
#endif
#endif
#ifndef libbase64_likely
#define libbase64_likely(x) x
#define libbase64_unlikely(x) x
#endif
namespace libbase64 {
#ifdef LIBBASE64CODECOVERAGE //Gets the number of branches that has been made
template<class STRINGTYPE, typename CHARTYPE, typename UCHARTYPE, bool SAFETY>
static size_t getCoverageHits(bool inc){
static size_t hits = 0;
if (inc) ++hits;
return hits;
}
#endif
//characters used in convertions
namespace libbase64_characters {
template<typename T>
inline static const T * getChar64(void){
static const T char64s[64] = {
(T)'A', (T)'B', (T)'C', (T)'D', (T)'E', (T)'F', (T)'G', (T)'H', (T)'I', (T)'J', (T)'K', (T)'L', (T)'M',
(T)'N', (T)'O', (T)'P', (T)'Q', (T)'R', (T)'S', (T)'T', (T)'U', (T)'V', (T)'W', (T)'X', (T)'Y', (T)'Z',
(T)'a', (T)'b', (T)'c', (T)'d', (T)'e', (T)'f', (T)'g', (T)'h', (T)'i', (T)'j', (T)'k', (T)'l', (T)'m',
(T)'n', (T)'o', (T)'p', (T)'q', (T)'r', (T)'s', (T)'t', (T)'u', (T)'v', (T)'w', (T)'x', (T)'y', (T)'z',
(T)'0', (T)'1', (T)'2', (T)'3', (T)'4', (T)'5', (T)'6', (T)'7', (T)'8', (T)'9', (T)'+', (T)'/'
};
return char64s;
}
template<typename T>
inline static T getChar(unsigned char bin){
CREATEBOUNDCHECKER(T, char64bounds, getChar64<T>(), getChar64<T>() + 64);
return GETITEM_BOUNDCHECK(getChar64<T>() + bin, char64bounds);
}
template<typename T>
inline static T toBinary(T c) {
static T binaryConvert[80] = {62,48,49,50,63,52,53,54,55,56,57,58,59,60,61,249,250,251,252,253,254,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
CREATEBOUNDCHECKER(T, binaryConvertsbounds, binaryConvert, binaryConvert + 80);
return GETITEM_BOUNDCHECK(binaryConvert + c - 43, binaryConvertsbounds);
}
template<typename T>
static inline T & emptyString(void){
static T t;
return t;
}
}
namespace libbase64_Calculator {
inline static size_t getEncodingSize(size_t bytes){
return (bytes + 2 - ((bytes + 2) % 3)) / 3 * 4;
}
inline static size_t getDecodingSize(size_t res){
return res * 3 / 4;
}
}
/**
* Encodes data into a base64 string of STRINGTYPE
*/
template<class STRINGTYPE, typename CHARTYPE, typename UCHARTYPE, bool SAFETY>
static STRINGTYPE encode(const unsigned char * binary, size_t bytes){
CREATEBOUNDCHECKER(unsigned char, binarybounds, binary, binary + bytes);
//make sure that there is actually something to encode
if (SAFETY){
if (libbase64_unlikely(bytes == 0)){
LIBBASE64CODECOVERAGEBRANCH;
return libbase64_characters::emptyString<STRINGTYPE>();
}
}
//calculate length and how misaligned it is
size_t misaligned = bytes % 3;
STRINGTYPE result;
result.reserve(libbase64_Calculator::getEncodingSize(bytes));
//do all of the ones that are 3 byte aligned
for (size_t i = 0, aligned((bytes - misaligned) / 3); i < aligned; ++i){
LIBBASE64CODECOVERAGEBRANCH;
result += libbase64_characters::getChar<CHARTYPE>((GETITEM_BOUNDCHECK(binary, binarybounds) & 0xFC) >> 2);
result += libbase64_characters::getChar<CHARTYPE>(((GETITEM_BOUNDCHECK(binary, binarybounds) & 0x03) << 4) + ((GETITEM_BOUNDCHECK(binary + 1, binarybounds) & 0xF0) >> 4));
result += libbase64_characters::getChar<CHARTYPE>(((GETITEM_BOUNDCHECK(binary + 1, binarybounds) & 0x0F) << 2) + ((GETITEM_BOUNDCHECK(binary + 2, binarybounds) & 0xC0) >> 6));
result += libbase64_characters::getChar<CHARTYPE>(GETITEM_BOUNDCHECK(binary + 2, binarybounds) & 0x3F);
binary += 3;
}
//handle any additional characters at the end of it
if (libbase64_likely(misaligned != 0)){
LIBBASE64CODECOVERAGEBRANCH;
//copy the rest into a temporary buffer, need it for the null terminators
unsigned char temp[3] = { '\0', '\0', '\0' };
for (unsigned char i = 0; i < (unsigned char)misaligned; ++i){
LIBBASE64CODECOVERAGEBRANCH;
temp[i] = GETITEM_BOUNDCHECK(binary++, binarybounds);
}
//now do the final three bytes
result += libbase64_characters::getChar<CHARTYPE>((temp[0] & 0xFC) >> 2);
result += libbase64_characters::getChar<CHARTYPE>(((temp[0] & 0x03) << 4) + ((temp[1] & 0xF0) >> 4));
if (misaligned == 2){
LIBBASE64CODECOVERAGEBRANCH;
result += libbase64_characters::getChar<CHARTYPE>(((temp[1] & 0x0F) << 2) + ((temp[2] & 0xC0) >> 6));
} else {
LIBBASE64CODECOVERAGEBRANCH;
result += (CHARTYPE)'=';
}
result += (CHARTYPE)'=';
} else {
LIBBASE64CODECOVERAGEBRANCH;
}
LIBBASE64_ASSERT(libbase64_Calculator::getEncodingSize(bytes) == result.length(), "Reserve wasn't the correct guess");
return result;
}
template<class STRINGTYPE, typename CHARTYPE, typename UCHARTYPE, bool SAFETY>
static std::string decode(const STRINGTYPE & encoded){
//check length to be sure its acceptable for base64
const size_t length = encoded.length();
if (SAFETY){
if (libbase64_unlikely((length % 4) != 0)){
LIBBASE64CODECOVERAGEBRANCH;
return libbase64_characters::emptyString<std::string>();
}
if (libbase64_unlikely(length == 0)){
LIBBASE64CODECOVERAGEBRANCH;
return libbase64_characters::emptyString<std::string>();
}
//check to be sure there aren't odd characters or characters in the wrong places
size_t pos = encoded.find_first_not_of(libbase64_characters::getChar64<CHARTYPE>());
if (libbase64_unlikely(pos != STRINGTYPE::npos)){
LIBBASE64CODECOVERAGEBRANCH;
if (libbase64_unlikely(encoded[pos] != (CHARTYPE)'=')){
LIBBASE64CODECOVERAGEBRANCH; //INVALID_CHAR
#ifdef LIBBASE64_THROW_STD_INVALID_ARGUMENT
throw std::invalid_argument("invalid character in base64");
#else
return libbase64_characters::emptyString<std::string>();
#endif
}
if (pos != length - 1){
LIBBASE64CODECOVERAGEBRANCH;
if (libbase64_unlikely(pos != length - 2)){
LIBBASE64CODECOVERAGEBRANCH; //EQUAL_WRONG_PLACE
#ifdef LIBBASE64_THROW_STD_INVALID_ARGUMENT
throw std::invalid_argument("equal sign in wrong place in base64");
#else
return libbase64_characters::emptyString<std::string>();
#endif
}
if (libbase64_unlikely(encoded[pos + 1] != (CHARTYPE)'=')){
LIBBASE64CODECOVERAGEBRANCH; //EQUAL_NOT_LAST
#ifdef LIBBASE64_THROW_STD_INVALID_ARGUMENT
throw std::invalid_argument("invalid character in base64");
#else
return libbase64_characters::emptyString<std::string>();
#endif
}
LIBBASE64CODECOVERAGEBRANCH;
} else {
LIBBASE64CODECOVERAGEBRANCH;
}
} else {
LIBBASE64CODECOVERAGEBRANCH;
}
}
const CHARTYPE * runner = encoded.data();
const CHARTYPE * end = runner + encoded.length();
CREATEBOUNDCHECKER(CHARTYPE, encodedbounds, runner, end);
size_t aligned = length / 4; //don't do the last ones as they might be = padding
std::string result;
--aligned;
result.reserve(libbase64_Calculator::getDecodingSize(length));
//first do the ones that can not have any padding
for (unsigned int i = 0; i < aligned; ++i){
const CHARTYPE second = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 1, encodedbounds));
const CHARTYPE third = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 2, encodedbounds));
result += (libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner, encodedbounds)) << 2) + ((second & 0x30) >> 4);
result += ((second & 0xf) << 4) + ((third & 0x3c) >> 2);
result += ((third & 0x3) << 6) + libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 3, encodedbounds));
runner += 4;
}
//now do the ones that might have padding, the first two characters can not be padding, so do them quickly
const CHARTYPE second = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 1, encodedbounds));
result += (libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner + 0, encodedbounds)) << 2) + ((second & 0x30) >> 4);
runner += 2;
if ((runner != end) && (*runner != (CHARTYPE)'=')){ //not two = pads
LIBBASE64CODECOVERAGEBRANCH;
const CHARTYPE third = libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner, encodedbounds));
result += ((second & 0xf) << 4) + ((third & 0x3c) >> 2);
++runner;
if ((runner != end) && (*runner != (CHARTYPE)'=')){ //no padding
LIBBASE64CODECOVERAGEBRANCH;
result += ((third & 0x3) << 6) + libbase64_characters::toBinary<UCHARTYPE>(GETITEM_BOUNDCHECK(runner, encodedbounds));
} else {
LIBBASE64CODECOVERAGEBRANCH;
}
} else {
LIBBASE64CODECOVERAGEBRANCH;
}
LIBBASE64_ASSERT(libbase64_Calculator::getDecodingSize(length) >= result.length(), "Reserve wasn't the correct guess, too small");
LIBBASE64_ASSERT((result.length() <= 3) || (libbase64_Calculator::getDecodingSize(length) > result.length() - 3), "Reserve wasn't the correct guess, too big");
return result;
}
}
#endif

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,13 @@
#include "JSONAllocator.h"
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
#include "JSONMemory.h"
void * JSONAllocatorRelayer::alloc(size_t bytes) json_nothrow {
return JSONMemory::json_malloc(bytes);
}
void JSONAllocatorRelayer::dealloc(void * ptr) json_nothrow {
JSONMemory::json_free(ptr);
}
#endif

View file

@ -0,0 +1,82 @@
#ifndef JSON_ALLOCATOR_H
#define JSON_ALLOCATOR_H
#include "JSONStats.h"
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
#include <cstddef>
//need these for the json_nothrow
#include "JSONDefs/Visual_C.h"
#include "JSONDefs/GNU_C.h"
#include "JSONDefs/Unknown_C.h"
class JSONAllocatorRelayer {
public:
static void * alloc(size_t bytes) json_nothrow json_hot;
static void dealloc(void * ptr) json_nothrow json_hot;
};
template <class T> class json_allocator;
// specialize for void:
template <> class json_allocator<void> {
public:
typedef void* pointer;
typedef const void* const_pointer;
// reference to void members are impossible.
typedef void value_type;
template <class U> struct rebind { typedef json_allocator<U> other; };
};
template <class T> class json_allocator {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
template <class U> struct rebind { typedef json_allocator<U> other; };
//LIBJSON_OBJECT(json_allocator);
inline json_allocator() json_nothrow {
//LIBJSON_CTOR;
}
inline json_allocator(const json_allocator&) json_nothrow {
//LIBJSON_COPY_CTOR;
}
template <class U> inline json_allocator(const json_allocator<U>&) json_nothrow {
//LIBJSON_COPY_CTOR;
}
inline ~json_allocator() json_nothrow {
//LIBJSON_DTOR;
}
inline pointer address(reference x) const { return &x; }
inline const_pointer address(const_reference x) const { return &x; }
inline pointer allocate(size_type n, json_allocator<void>::const_pointer = 0) json_hot {
return (pointer)JSONAllocatorRelayer::alloc(n * sizeof(T));
}
inline void deallocate(pointer p, size_type) json_hot {
JSONAllocatorRelayer::dealloc(p);
}
inline size_type max_size() const json_nothrow { return 0xEFFFFFFF; }
inline void construct(pointer p, const T& val){
new(p)T(val);
};
inline void destroy(pointer p){
((T*)p) -> ~T();
}
};
template <class T1, class T2> inline bool operator==(const json_allocator<T1>&, const json_allocator<T2>&) json_nothrow { return true; }
template <class T1, class T2> inline bool operator!=(const json_allocator<T1>&, const json_allocator<T2>&) json_nothrow { return false; }
#endif
#endif

View file

@ -0,0 +1,94 @@
#include "JSONChildren.h"
#include "JSONNode.h"
/*
* reserves a certain number of bytes, in memory saving mode it creates a special
* type of child container that will not autoshrink
*/
void jsonChildren::reserve2(jsonChildren *& mine, json_index_t amount) json_nothrow {
if (mine -> array != 0){
if (mine -> mycapacity < amount){
mine -> inc(amount - mine -> mycapacity);
#ifdef JSON_LESS_MEMORY
mine = jsonChildren_Reserved::newChildren_Reserved(mine, amount);
#endif
}
} else {
mine -> reserve(amount);
}
}
void jsonChildren::inc(void) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null inc"));
if (json_unlikely(mysize == mycapacity)){ //it's full
if (json_unlikely(mycapacity == 0)){ //the array hasn't been created yet
JSON_ASSERT(!array, JSON_TEXT("Expanding a 0 capacity array, but not null"));
#ifdef JSON_LESS_MEMORY
array = json_malloc<JSONNode*>(1);
mycapacity = 1;
#else
array = json_malloc<JSONNode*>(8); //8 seems average for JSON, and it's only 64 bytes
mycapacity = 8;
#endif
} else {
#ifdef JSON_LESS_MEMORY
mycapacity += 1; //increment the size of the array
#else
mycapacity <<= 1; //double the size of the array
#endif
array = json_realloc<JSONNode*>(array, mycapacity);
}
}
}
void jsonChildren::inc(json_index_t amount) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null inc(amount)"));
if (json_unlikely(amount == 0)) return;
if (json_likely(mysize + amount >= mycapacity)){ //it's full
if (json_unlikely(mycapacity == 0)){ //the array hasn't been created yet
JSON_ASSERT(!array, JSON_TEXT("Expanding a 0 capacity array, but not null"));
#ifdef JSON_LESS_MEMORY
array = json_malloc<JSONNode*>(amount);
mycapacity = amount;
#else
array = json_malloc<JSONNode*>(amount > 8 ? amount : 8); //8 seems average for JSON, and it's only 64 bytes
mycapacity = amount > 8 ? amount : 8;
#endif
} else {
#ifdef JSON_LESS_MEMORY
mycapacity = mysize + amount; //increment the size of the array
#else
while(mysize + amount > mycapacity){
mycapacity <<= 1; //double the size of the array
}
#endif
array = json_realloc<JSONNode*>(array, mycapacity);
}
}
}
//actually deletes everything within the vector, this is safe to do on an empty or even a null array
void jsonChildren::deleteAll(void) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null deleteAll"));
json_foreach(this, runner){
JSON_ASSERT(*runner != JSON_TEXT('\0'), JSON_TEXT("a null pointer within the children"));
JSONNode::deleteJSONNode(*runner); //this is why I can't do forward declaration
}
}
void jsonChildren::doerase(JSONNode ** position, json_index_t number) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null doerase"));
JSON_ASSERT(array != 0, JSON_TEXT("erasing something from a null array 2"));
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array 2"));
JSON_ASSERT(position + number <= array + mysize, JSON_TEXT("erasing out of bounds 2"));
if (position + number >= array + mysize){
mysize = (json_index_t)(position - array);
#ifndef JSON_ISO_STRICT
JSON_ASSERT((long long)position - (long long)array >= 0, JSON_TEXT("doing negative allocation"));
#endif
} else {
std::memmove(position, position + number, (mysize - (position - array) - number) * sizeof(JSONNode *));
mysize -= number;
}
}

View file

@ -0,0 +1,329 @@
#ifndef JSONCHILDREN_H
#define JSONCHILDREN_H
#include "JSONMemory.h"
#include "JSONDebug.h" //for JSON_ASSERT macro
#ifdef JSON_LESS_MEMORY
#ifdef __GNUC__
#pragma pack(push, 1)
#elif _MSC_VER
#pragma pack(push, jsonChildren, 1)
#endif
#endif
#define json_foreach(chldrn, itrtr)\
JSONNode ** itrtr = chldrn -> begin();\
for(JSONNode ** itrtr##_end = chldrn -> end(); itrtr != itrtr##_end; ++itrtr)
/*
This class is essentially a vector that has been heavily optimized for the specific purpose
of holding JSONNode children. It acts the same way as a vector, it has a automatically
expanding array. On destruction, this container automatically destroys everything contained
in it as well, so that you libjson doesn't have to do that.
T is JSONNode*, I can't define it that way directly because JSONNode uses this container, and because
the container deletes the children automatically, forward declaration can't be used
*/
class JSONNode; //forward declaration
#ifdef JSON_LESS_MEMORY
#define childrenVirtual virtual
#else
#define childrenVirtual
#endif
class jsonChildren {
public:
LIBJSON_OBJECT(jsonChildren);
//starts completely empty and the array is not allocated
jsonChildren(void) json_nothrow : array(0), mysize(0), mycapacity(0) {
LIBJSON_CTOR;
}
#ifdef JSON_LESS_MEMORY
jsonChildren(JSONNode** ar, json_index_t si, json_index_t ca) json_nothrow : array(ar), mysize(si), mycapacity(ca) {
LIBJSON_CTOR;
}
#endif
//deletes the array and everything that is contained within it (using delete)
childrenVirtual ~jsonChildren(void) json_nothrow {
if (json_unlikely(array != 0)){ //the following function calls are safe, but take more time than a check here
deleteAll();
libjson_free<JSONNode*>(array);
}
LIBJSON_DTOR;
}
//increase the size of the array
void inc(json_index_t amount) json_nothrow;
void inc(void) json_nothrow;
//Adds something to the vector, doubling the array if necessary
void push_back(JSONNode * item) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null push_back"));
inc();
array[mysize++] = item;
}
//Adds something to the front of the vector, doubling the array if necessary
void push_front(JSONNode * item) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null push_front"));
inc();
std::memmove(array + 1, array, mysize++ * sizeof(JSONNode *));
array[0] = item;
}
//gets an item out of the vector by it's position
inline JSONNode * operator[] (json_index_t position) const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null []"));
JSON_ASSERT(position < mysize, JSON_TEXT("Using [] out of bounds"));
JSON_ASSERT(position < mycapacity, JSON_TEXT("Using [] out of bounds"));
JSON_ASSERT(array != 0, JSON_TEXT("Array is null"));
return array[position];
}
//returns the allocated capacity, but keep in mind that some might not be valid
inline json_index_t capacity() const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null capacity"));
return mycapacity;
}
//returns the number of valid objects within the vector
inline json_index_t size() const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null size"));
return mysize;
}
//tests whether or not the vector is empty
inline bool empty() const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null empty"));
return mysize == 0;
}
//clears (and deletes) everything from the vector and sets it's size to 0
inline void clear() json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null clear"));
if (json_likely(array != 0)){ //don't bother clearing anything if there is nothing in it
JSON_ASSERT(mycapacity != 0, JSON_TEXT("mycapacity is not zero, but array is null"));
deleteAll();
mysize = 0;
}
JSON_ASSERT(mysize == 0, JSON_TEXT("mysize is not zero after clear"));
}
//returns the beginning of the array
inline JSONNode ** begin(void) const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null begin"));
return array;
}
//returns the end of the array
inline JSONNode ** end(void) const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null end"));
return array + mysize;
}
//makes sure that even after shirnking and expanding, the iterator is in same relative position
template <bool reverse>
struct iteratorKeeper {
public:
LIBJSON_OBJECT(jsonChildren::iteratorKeeper);
iteratorKeeper(jsonChildren * pthis, JSONNode ** & position) json_nothrow :
myRelativeOffset(reverse ? (json_index_t)(pthis -> array + (size_t)pthis -> mysize - position) : (json_index_t)(position - pthis -> array)),
myChildren(pthis),
myPos(position){
LIBJSON_CTOR;
}
~iteratorKeeper(void) json_nothrow {
LIBJSON_DTOR;
if (reverse){
myPos = myChildren -> array + myChildren -> mysize - myRelativeOffset;
} else {
myPos = myChildren -> array + myRelativeOffset;
}
}
private:
iteratorKeeper(const iteratorKeeper &);
iteratorKeeper & operator = (const iteratorKeeper &);
json_index_t myRelativeOffset;
jsonChildren * myChildren;
JSONNode ** & myPos;
};
//This function DOES NOT delete the item it points to
inline void erase(JSONNode ** & position) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase"));
JSON_ASSERT(array != 0, JSON_TEXT("erasing something from a null array 1"));
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array 1"));
JSON_ASSERT(position <= array + mysize, JSON_TEXT("erasing out of bounds 1"));
std::memmove(position, position + 1, (mysize-- - (position - array) - 1) * sizeof(JSONNode *));
iteratorKeeper<false> ik(this, position);
shrink();
}
//This function DOES NOT delete the item it points to
inline void erase(JSONNode ** & position, json_index_t number) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase 2"));
doerase(position, number);
iteratorKeeper<false> ik(this, position);
shrink();
}
//This function DOES NOT delete the item it points to
inline void erase(JSONNode ** position, json_index_t number, JSONNode ** & starter) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase 3"));
doerase(position, number);
iteratorKeeper<false> ik(this, starter);
shrink();
}
#ifdef JSON_LIBRARY
void insert(JSONNode ** & position, JSONNode * item) json_nothrow{
#else
void insert(JSONNode ** & position, JSONNode * item, bool reverse = false) json_nothrow {
#endif
JSON_ASSERT(this != 0, JSON_TEXT("Children is null insert"));
//position isnt relative to array because of realloc
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array insert 1"));
JSON_ASSERT(position <= array + mysize, JSON_TEXT("position is above the end of the array insert 1"));
#ifndef JSON_LIBRARY
if (reverse){
iteratorKeeper<true> ik(this, position);
inc();
} else
#endif
{
iteratorKeeper<false> ik(this, position);
inc();
}
std::memmove(position + 1, position, (mysize++ - (position - array)) * sizeof(JSONNode *));
*position = item;
}
void insert(JSONNode ** & position, JSONNode ** items, json_index_t num) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null insert 2"));
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array insert 2"));
JSON_ASSERT(position <= array + mysize, JSON_TEXT("position is above the end of the array insert 2"));
{
iteratorKeeper<false> ik(this, position);
inc(num);
}
const size_t ptrs = ((JSONNode **)(array + mysize)) - position;
std::memmove(position + num, position, ptrs * sizeof(JSONNode *));
std::memcpy(position, items, num * sizeof(JSONNode *));
mysize += num;
}
inline void reserve(json_index_t amount) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null reserve"));
JSON_ASSERT(array == 0, JSON_TEXT("reserve is not meant to expand a preexisting array"));
JSON_ASSERT(mycapacity == 0, JSON_TEXT("reservec is not meant to expand a preexisting array"));
JSON_ASSERT(mysize == 0, JSON_TEXT("reserves is not meant to expand a preexisting array"));
array = json_malloc<JSONNode*>(mycapacity = amount);
}
//it is static because mine might change pointers entirely
static void reserve2(jsonChildren *& mine, json_index_t amount) json_nothrow;
//shrinks the array to only as large as it needs to be to hold everything within it
inline childrenVirtual void shrink() json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null shrink"));
if (json_unlikely(mysize == 0)){ //size is zero, we should completely free the array
libjson_free<JSONNode*>(array); //free does checks for a null pointer, so don't bother checking
array = 0;
#ifdef JSON_LESS_MEMORY
} else { //need to shrink it, using realloc
JSON_ASSERT(array != 0, JSON_TEXT("shrinking a null array that is not size 0"));
array = json_realloc<JSONNode*>(array, mysize);
#endif
}
mycapacity = mysize;
}
inline static void deleteChildren(jsonChildren * ptr) json_nothrow {
#ifdef JSON_MEMORY_CALLBACKS
ptr -> ~jsonChildren();
libjson_free<jsonChildren>(ptr);
#else
delete ptr;
#endif
}
inline static jsonChildren * newChildren(void) {
#ifdef JSON_MEMORY_CALLBACKS
return new(json_malloc<jsonChildren>(1)) jsonChildren();
#else
return new jsonChildren();
#endif
}
JSONNode ** array; //the expandable array
json_index_t mysize; //the number of valid items
json_index_t mycapacity; //the number of possible items
JSON_PROTECTED
//to make sure it's not copyable
jsonChildren(const jsonChildren &);
jsonChildren & operator = (const jsonChildren &);
void deleteAll(void) json_nothrow json_hot; //implemented in JSONNode.cpp
void doerase(JSONNode ** position, json_index_t number) json_nothrow;
};
#ifdef JSON_LESS_MEMORY
class jsonChildren_Reserved : public jsonChildren {
public:
LIBJSON_OBJECT(jsonChildren_Reserved);
jsonChildren_Reserved(jsonChildren * orig, json_index_t siz) json_nothrow : jsonChildren(orig -> array, orig -> mysize, orig -> mycapacity), myreserved(siz) {
orig -> array = 0;
deleteChildren(orig);
LIBJSON_CTOR;
}
jsonChildren_Reserved(const jsonChildren_Reserved & orig) json_nothrow : jsonChildren(orig.array, orig.mysize, orig.mycapacity), myreserved(orig.myreserved){
LIBJSON_COPY_CTOR;
}
inline virtual ~jsonChildren_Reserved() json_nothrow {
LIBJSON_DTOR;
};
inline virtual void shrink() json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null shrink reserved"));
if (json_unlikely(mysize == 0)){ //size is zero, we should completely free the array
libjson_free<JSONNode*>(array); //free does checks for a null pointer, so don't bother checking
array = 0;
} else if (mysize > myreserved){
JSON_ASSERT(array != 0, JSON_TEXT("shrinking a null array that is not size 0"));
array = json_realloc<JSONNode*>(array, mysize);
}
}
#ifdef JSON_LESS_MEMORY
inline static jsonChildren * newChildren_Reserved(jsonChildren * orig, json_index_t siz) json_nothrow {
#ifdef JSON_MEMORY_CALLBACKS
return new(json_malloc<jsonChildren_Reserved>(1)) jsonChildren_Reserved(orig, siz);
#else
return new jsonChildren_Reserved(orig, siz);
#endif
}
#endif
JSON_PRIVATE
jsonChildren_Reserved & operator = (const jsonChildren_Reserved &);
json_index_t myreserved;
};
#endif
#ifdef JSON_LESS_MEMORY
#ifdef __GNUC__
#pragma pack(pop)
#elif _MSC_VER
#pragma pack(pop, jsonChildren)
#endif
#endif
#endif

View file

@ -0,0 +1,42 @@
#include "JSONDebug.h"
#ifdef JSON_DEBUG
#ifdef JSON_STDERROR
#include <iostream> //need std::cerr
#else
#include "JSONSingleton.h"
//otherwise, use a callback to tell the end user what happened
json_error_callback_t JSONDebug::register_callback(json_error_callback_t callback) json_nothrow {
json_error_callback_t res = JSONSingleton<json_error_callback_t>::get();
JSONSingleton<json_error_callback_t>::set(callback);
return res;
}
#endif
//Something went wrong or an assert failed
void JSONDebug::_JSON_FAIL(const json_string & msg) json_nothrow {
#ifdef JSON_STDERROR //no callback, just use stderror
#ifndef JSON_UNICODE
std::cerr << msg << std::endl;
#else
std::cerr << std::string(msg.begin(), msg.end()) << std::endl;
#endif
#else
if (json_error_callback_t ErrorCallback = JSONSingleton<json_error_callback_t>::get()){ //only do anything if the callback is registered
#ifdef JSON_LIBRARY
ErrorCallback(msg.c_str());
#else
ErrorCallback(msg);
#endif
}
#endif
}
//asserts that condition is true, more useful than cassert because it lets you keep going
void JSONDebug::_JSON_ASSERT(bool condition, const json_string & msg) json_nothrow {
if (json_unlikely(!condition)){
_JSON_FAIL(msg);
}
}
#endif

View file

@ -0,0 +1,59 @@
#ifndef LIBJSON_GUARD_DEBUG_H
#define LIBJSON_GUARD_DEBUG_H
#include "JSONDefs.h"
#include "JSONStats.h"
#ifdef JSON_DEBUG
#ifdef JSON_SAFE
#define JSON_ASSERT_SAFE(condition, msg, code)\
{\
if (json_unlikely(!(condition))){\
JSON_FAIL(msg);\
code\
}\
}
#define JSON_FAIL_SAFE(msg, code)\
{\
JSON_FAIL(msg);\
code\
}
#else
#define JSON_ASSERT_SAFE(condition, msg, code) JSON_ASSERT(condition, msg)
#define JSON_FAIL_SAFE(msg, code) JSON_FAIL(msg)
#endif
#define JSON_FAIL(msg) JSONDebug::_JSON_FAIL(msg)
#define JSON_ASSERT(bo, msg) JSONDebug::_JSON_ASSERT(bo, msg)
class JSONDebug {
public:
#ifndef JSON_STDERROR
static json_error_callback_t register_callback(json_error_callback_t callback) json_nothrow json_cold;
#endif
static void _JSON_FAIL(const json_string & msg) json_nothrow json_cold;
static void _JSON_ASSERT(bool condition, const json_string & msg) json_nothrow json_cold;
};
#else
#ifdef JSON_SAFE
#define JSON_ASSERT_SAFE(condition, msg, code)\
{\
if (json_unlikely(!(condition))){\
code\
}\
}
#define JSON_FAIL_SAFE(msg, code)\
{\
code\
}
#else
#define JSON_ASSERT_SAFE(condition, msg, code)
#define JSON_FAIL_SAFE(msg, code)
#endif
#define JSON_ASSERT(condition, msg)
#define JSON_FAIL(msg)
#endif
#endif

View file

@ -0,0 +1,184 @@
#ifndef JSONDEFS_H
#define JSONDEFS_H
/*
Defines all of the types of functions and various other definitions
that are used in C applications, this is very useful if dynamically loading
the library instead of linking.
*/
#include "../../JSONOptions.h"
#include "JSONDefs/Unknown_C.h"
#include "JSONDefs/GNU_C.h"
#include "JSONDefs/Visual_C.h"
#include "JSONDefs/Strings_Defs.h"
#define __LIBJSON_MAJOR__ 7
#define __LIBJSON_MINOR__ 6
#define __LIBJSON_PATCH__ 1
#define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__)
#define JSON_NULL '\0'
#define JSON_STRING '\1'
#define JSON_NUMBER '\2'
#define JSON_BOOL '\3'
#define JSON_ARRAY '\4'
#define JSON_NODE '\5'
#ifdef __cplusplus
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
#include "JSONAllocator.h"
#else
#define json_allocator std::allocator
#endif
#ifdef JSON_STRING_HEADER
#include JSON_STRING_HEADER
#else
typedef std::basic_string<json_char, std::char_traits<json_char>, json_allocator<json_char> > json_string;
#endif
#endif
#define JSON_MAP(x, y) std::map<x, y, std::less<x>, json_allocator<std::pair<const x, y> > >
#ifdef JSON_NO_EXCEPTIONS
#define json_throw(x)
#define json_try
#define json_catch(exception, code)
#else
#define json_throw(x) throw(x)
#define json_try try
#define json_catch(exception, code) catch(exception){ code }
#endif
#ifdef JSON_STRICT
#ifndef JSON_UNICODE
#error, JSON_UNICODE is required for JSON_STRICT
#endif
#ifdef JSON_COMMENTS
#error, JSON_COMMENTS is required to be off for JSON_STRICT
#endif
#endif
#ifdef JSON_ISO_STRICT
#ifdef JSON_UNICODE
#error, You can not use unicode under ANSI Strict C++
#endif
#else
#ifdef __GNUC__
#ifdef __STRICT_ANSI__
#warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you
#define JSON_ISO_STRICT
#endif
#endif
#endif
#ifdef JSON_NUMBER_TYPE
typedef JSON_NUMBER_TYPE json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001
#else
#ifdef JSON_LESS_MEMORY
typedef float json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001f
#else
typedef double json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001
#endif
#endif
#ifdef JSON_LESS_MEMORY
/* PACKED and BITS stored in compiler specific headers */
#define START_MEM_SCOPE {
#define END_MEM_SCOPE }
#else
#define PACKED(x)
#define BITS(x)
#define START_MEM_SCOPE
#define END_MEM_SCOPE
#endif
#if defined JSON_DEBUG || defined JSON_SAFE
#ifdef JSON_LIBRARY
typedef void (*json_error_callback_t)(const json_char *);
#else
typedef void (*json_error_callback_t)(const json_string &);
#endif
#endif
#ifdef JSON_INDEX_TYPE
typedef JSON_INDEX_TYPE json_index_t;
#else
typedef unsigned int json_index_t;
#endif
#ifdef JSON_BOOL_TYPE
typedef JSON_BOOL_TYPE json_bool_t;
#else
typedef int json_bool_t;
#endif
#ifdef JSON_INT_TYPE
typedef JSON_INT_TYPE json_int_t;
#else
typedef long json_int_t;
#endif
#define JSONSTREAM_SELF (void*)-1
typedef void (*json_stream_e_callback_t)(void * identifier);
typedef void (*json_mutex_callback_t)(void *);
typedef void (*json_free_t)(void *);
#ifndef JSON_LIBRARY
typedef void * (*json_malloc_t)(size_t);
typedef void * (*json_realloc_t)(void *, size_t);
#else
#define JSONNODE void /* so that JSONNODE* is void* */
typedef JSONNODE** JSONNODE_ITERATOR;
#ifdef JSON_STREAM
#define JSONSTREAM void
typedef void (*json_stream_callback_t)(JSONNODE *, void * identifier);
#endif
typedef void * (*json_malloc_t)(unsigned long);
typedef void * (*json_realloc_t)(void *, unsigned long);
#endif
#ifdef JSON_DEBUG
#ifdef NDEBUG
#ifdef __GNUC__
#warning, Have JSON_DEBUG on in a release build
#else
#error, Have JSON_DEBUG on in a release build
#endif
#endif
#else
#ifndef NDEBUG
#ifdef __GNUC__
#warning, Release build of libjson, but NDEBUG is not on
#else
#error, Release build of libjson, but NDEBUG is not on
#endif
#endif
#endif
#ifdef JSON_UNIT_TEST
#define JSON_PRIVATE public:
#define JSON_PROTECTED public:
#else
#define JSON_PRIVATE private:
#define JSON_PROTECTED protected:
#endif
#ifdef JSON_STREAM
#ifndef JSON_READ_PRIORITY
#error, JSON_STREAM also requires JSON_READ_PRIORITY
#endif
#endif
#ifdef JSON_VALIDATE
#ifndef JSON_READ_PRIORITY
#error, JSON_VALIDATE also requires JSON_READ_PRIORITY
#endif
#endif
#define JSON_TEMP_COMMENT_IDENTIFIER JSON_TEXT('#')
#endif

View file

@ -0,0 +1,184 @@
#ifndef JSONDEFS_H
#define JSONDEFS_H
/*
Defines all of the types of functions and various other definitions
that are used in C applications, this is very useful if dynamically loading
the library instead of linking.
*/
#include "../../JSONOptions.h"
#include "JSONDefs/Unknown_C.h"
#include "JSONDefs/GNU_C.h"
#include "JSONDefs/Visual_C.h"
#include "JSONDefs/Strings_Defs.h"
#define __LIBJSON_MAJOR__ 7
#define __LIBJSON_MINOR__ 6
#define __LIBJSON_PATCH__ 0
#define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__)
#define JSON_NULL '\0'
#define JSON_STRING '\1'
#define JSON_NUMBER '\2'
#define JSON_BOOL '\3'
#define JSON_ARRAY '\4'
#define JSON_NODE '\5'
#ifdef __cplusplus
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
#include "JSONAllocator.h"
#else
#define json_allocator std::allocator
#endif
#ifdef JSON_STRING_HEADER
#include JSON_STRING_HEADER
#else
typedef std::basic_string<json_char, std::char_traits<json_char>, json_allocator<json_char> > json_string;
#endif
#endif
#define JSON_MAP(x, y) std::map<x, y, std::less<x>, json_allocator<std::pair<const x, y> > >
#ifdef JSON_NO_EXCEPTIONS
#define json_throw(x)
#define json_try
#define json_catch(exception, code)
#else
#define json_throw(x) throw(x)
#define json_try try
#define json_catch(exception, code) catch(exception){ code }
#endif
#ifdef JSON_STRICT
#ifndef JSON_UNICODE
#error, JSON_UNICODE is required for JSON_STRICT
#endif
#ifdef JSON_COMMENTS
#error, JSON_COMMENTS is required to be off for JSON_STRICT
#endif
#endif
#ifdef JSON_ISO_STRICT
#ifdef JSON_UNICODE
#error, You can not use unicode under ANSI Strict C++
#endif
#else
#ifdef __GNUC__
#ifdef __STRICT_ANSI__
#warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you
#define JSON_ISO_STRICT
#endif
#endif
#endif
#ifdef JSON_NUMBER_TYPE
typedef JSON_NUMBER_TYPE json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001
#else
#ifdef JSON_LESS_MEMORY
typedef float json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001f
#else
typedef double json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001
#endif
#endif
#ifdef JSON_LESS_MEMORY
/* PACKED and BITS stored in compiler specific headers */
#define START_MEM_SCOPE {
#define END_MEM_SCOPE }
#else
#define PACKED(x)
#define BITS(x)
#define START_MEM_SCOPE
#define END_MEM_SCOPE
#endif
#if defined JSON_DEBUG || defined JSON_SAFE
#ifdef JSON_LIBRARY
typedef void (*json_error_callback_t)(const json_char *);
#else
typedef void (*json_error_callback_t)(const json_string &);
#endif
#endif
#ifdef JSON_INDEX_TYPE
typedef JSON_INDEX_TYPE json_index_t;
#else
typedef unsigned int json_index_t;
#endif
#ifdef JSON_BOOL_TYPE
typedef JSON_BOOL_TYPE json_bool_t;
#else
typedef int json_bool_t;
#endif
#ifdef JSON_INT_TYPE
typedef JSON_INT_TYPE json_int_t;
#else
typedef long json_int_t;
#endif
#define JSONSTREAM_SELF (void*)-1
typedef void (*json_stream_e_callback_t)(void * identifier);
typedef void (*json_mutex_callback_t)(void *);
typedef void (*json_free_t)(void *);
#ifndef JSON_LIBRARY
typedef void * (*json_malloc_t)(size_t);
typedef void * (*json_realloc_t)(void *, size_t);
#else
#define JSONNODE void /* so that JSONNODE* is void* */
typedef JSONNODE** JSONNODE_ITERATOR;
#ifdef JSON_STREAM
#define JSONSTREAM void
typedef void (*json_stream_callback_t)(JSONNODE *, void * identifier);
#endif
typedef void * (*json_malloc_t)(unsigned long);
typedef void * (*json_realloc_t)(void *, unsigned long);
#endif
#ifdef JSON_DEBUG
#ifdef NDEBUG
#ifdef __GNUC__
#warning, Have JSON_DEBUG on in a release build
#else
#error, Have JSON_DEBUG on in a release build
#endif
#endif
#else
#ifndef NDEBUG
#ifdef __GNUC__
#warning, Release build of libjson, but NDEBUG is not on
#else
#error, Release build of libjson, but NDEBUG is not on
#endif
#endif
#endif
#ifdef JSON_UNIT_TEST
#define JSON_PRIVATE public:
#define JSON_PROTECTED public:
#else
#define JSON_PRIVATE private:
#define JSON_PROTECTED protected:
#endif
#ifdef JSON_STREAM
#ifndef JSON_READ_PRIORITY
#error, JSON_STREAM also requires JSON_READ_PRIORITY
#endif
#endif
#ifdef JSON_VALIDATE
#ifndef JSON_READ_PRIORITY
#error, JSON_VALIDATE also requires JSON_READ_PRIORITY
#endif
#endif
#define JSON_TEMP_COMMENT_IDENTIFIER JSON_TEXT('#')
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,67 @@
#ifndef JSON_GNU_C_HEADER
#define JSON_GUN_C_HEADER
#ifdef __GNUC__
#define json_deprecated(method, warning) method __attribute__((deprecated))
#if (__GNUC__ >= 3)
#define JSON_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#else
#define JSON_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
#endif
#if (JSON_GCC_VERSION >= 40300)
#define json_hot __attribute__ ((hot))
#define json_cold __attribute__ ((cold))
#define json_pure json_nothrow __attribute__ ((pure, hot))
#define json_malloc_attr json_nothrow __attribute__ ((malloc, hot))
/* Can do priorities */
#if (JSON_WRITE_PRIORITY == HIGH)
#define json_write_priority __attribute__ ((hot))
#elif (JSON_WRITE_PRIORITY == LOW)
#define json_write_priority __attribute__ ((cold))
#else
#define json_write_priority
#endif
#if (JSON_READ_PRIORITY == HIGH)
#define json_read_priority __attribute__ ((hot))
#elif (JSON_READ_PRIORITY == LOW)
#define json_read_priority __attribute__ ((cold))
#else
#define json_read_priority
#endif
#define json_likely(x) __builtin_expect((long)((bool)(x)),1)
#define json_unlikely(x) __builtin_expect((long)((bool)(x)),0)
#else
#if (JSON_GCC_VERSION >= 29600)
#define json_pure json_nothrow __attribute__ ((pure))
#define json_likely(x) __builtin_expect((long)((bool)(x)),1)
#define json_unlikely(x) __builtin_expect((long)((bool)(x)),0)
#else
#define json_pure json_nothrow
#define json_likely(x) x
#define json_unlikely(x) x
#endif
#define json_malloc_attr json_nothrow __attribute__ ((malloc))
#define json_write_priority
#define json_read_priority
#define json_hot
#define json_cold
#endif
#define json_nothrow throw()
#define json_throws(x) throw(x)
#ifdef JSON_LESS_MEMORY
#define PACKED(x) :x __attribute__ ((packed))
#define BITS(x) :x
#endif
#endif
#endif

View file

@ -0,0 +1,36 @@
#ifndef STRINGS_DEFS_HEADER
#define STRINGS_DEFS_HEADER
#include "../../../JSONOptions.h"
#ifdef JSON_UNICODE
#define json_char wchar_t
#define json_uchar wchar_t
#ifdef __cplusplus
#include <cwchar> /* need wide characters */
#ifndef JSON_STRING_HEADER
#include <string>
#endif
#else
#include <wchar.h> /* need wide characters */
#endif
#define JSON_TEXT(s) L ## s
#define json_strlen wcslen
#define json_strcmp wcscmp
#else
#define json_char char
#define json_uchar unsigned char
#ifdef __cplusplus
#ifndef JSON_STRING_HEADER
#include <string>
#endif
#else
#include <string.h> /* still need it for strlen and such */
#endif
#define JSON_TEXT(s) s
#define json_strlen strlen
#define json_strcmp strcmp
#endif
#endif

View file

@ -0,0 +1,26 @@
#ifndef JSON_UNKNOWN_C_HEADER
#define JSON_UNKNOWN_C_HEADER
#if !defined(__GNUC__) && !defined(_MSC_VER)
#define json_deprecated(method, warning) method
#define json_nothrow
#define json_throws(x)
#define json_pure json_nothrow
#define json_read_priority
#define json_write_priority
#define json_malloc_attr json_nothrow
#define json_hot
#define json_cold
#define json_likely(x) x
#define json_unlikely(x) x
#ifdef JSON_LESS_MEMORY
#define PACKED(x) :x
#define BITS(x) :x
#endif
#endif
#endif

View file

@ -0,0 +1,26 @@
#ifndef JSON_VISUAL_C_HEADER
#define JSON_VISUAL_C_HEADER
#ifdef _MSC_VER
#define json_deprecated(method, warning) __declspec(deprecated(warning)) method
#define json_nothrow
#define json_throws(x)
#define json_pure json_nothrow
#define json_read_priority
#define json_write_priority
#define json_malloc_attr json_nothrow
#define json_hot
#define json_cold
#define json_likely(x) x
#define json_unlikely(x) x
#ifdef JSON_LESS_MEMORY
#define PACKED(x) :x
#define BITS(x) :x
#endif
#endif
#endif

View file

@ -0,0 +1,95 @@
#ifndef JSON_GLOBALS_H
#define JSON_GLOBALS_H
#include "JSONDefs.h"
/*
* The use of singletons for globals makes globals not
* actually be initialized until it is first needed, this
* makes the library faster to load, and have a smaller
* memory footprint
*/
#define json_global_decl(TYPE, NAME, VALUE) \
class jsonSingleton ## NAME { \
public: \
inline static TYPE & getValue() json_nothrow { \
static jsonSingleton ## NAME single; \
return single.val; \
} \
protected: \
inline jsonSingleton ## NAME() json_nothrow : val(VALUE) {} \
TYPE val; \
}
#define json_global_decl_strconfig(TYPE, NAME, VALUE) \
class jsonSingleton ## NAME { \
public: \
inline static TYPE & getValue() json_nothrow { \
static jsonSingleton ## NAME single; \
return single.val; \
} \
protected: \
inline jsonSingleton ## NAME() json_nothrow { \
const std::string tmp = std::string(VALUE); \
val = json_string(tmp.begin(), tmp.end()); \
} \
TYPE val; \
}
#define json_global(NAME) jsonSingleton ## NAME::getValue()
#include <string>
json_global_decl(json_string, EMPTY_JSON_STRING, );
json_global_decl(std::string, EMPTY_STD_STRING, );
json_global_decl(json_string, CONST_TRUE, JSON_TEXT("true"));
json_global_decl(json_string, CONST_FALSE, JSON_TEXT("false"));
json_global_decl(json_string, CONST_NULL, JSON_TEXT("null"));
#ifndef JSON_NEWLINE
json_global_decl(json_string, NEW_LINE, JSON_TEXT("\n"));
#else
json_global_decl_strconfig(json_string, NEW_LINE, JSON_NEWLINE);
#endif
#ifdef JSON_WRITE_BASH_COMMENTS
json_global_decl(json_string, SINGLELINE_COMMENT, JSON_TEXT("#"));
#else
json_global_decl(json_string, SINGLELINE_COMMENT, JSON_TEXT("//"));
#endif
#ifdef JSON_INDENT
json_global_decl_strconfig(json_string, INDENT, JSON_INDENT);
#endif
#ifdef JSON_MUTEX_CALLBACKS
#include <map>
json_global_decl(JSON_MAP(void *, unsigned int), MUTEX_MANAGER, );
json_global_decl(JSON_MAP(int, JSON_MAP(void *, unsigned int) ), THREAD_LOCKS, );
#endif
#ifdef JSON_LIBRARY
#ifdef JSON_MEMORY_MANAGE
#include "JSONMemory.h"
json_global_decl(auto_expand, STRING_HANDLER, );
json_global_decl(auto_expand_node, NODE_HANDLER, );
#ifdef JSON_STREAM
json_global_decl(auto_expand_stream, STREAM_HANDLER, );
#endif
#endif
#endif
//These are common error responses
json_global_decl(json_string, ERROR_TOO_LONG, JSON_TEXT("Exceeding JSON_SECURITY_MAX_STRING_LENGTH"));
json_global_decl(json_string, ERROR_UNKNOWN_LITERAL, JSON_TEXT("Unknown JSON literal: "));
json_global_decl(json_string, ERROR_NON_CONTAINER, JSON_TEXT("Calling container method on non-container: "));
json_global_decl(json_string, ERROR_NON_ITERATABLE, JSON_TEXT("Calling iterator method on non-iteratable: "));
json_global_decl(json_string, ERROR_NULL_IN_CHILDREN, JSON_TEXT("a null pointer within the children"));
json_global_decl(json_string, ERROR_UNDEFINED, JSON_TEXT("Undefined results: "));
json_global_decl(json_string, ERROR_LOWER_RANGE, JSON_TEXT(" is outside the lower range of "));
json_global_decl(json_string, ERROR_UPPER_RANGE, JSON_TEXT(" is outside the upper range of "));
json_global_decl(json_string, ERROR_NOT_BASE64, JSON_TEXT("Not base64"));
json_global_decl(json_string, ERROR_OUT_OF_MEMORY, JSON_TEXT("Out of memory"));
#endif

View file

@ -0,0 +1,214 @@
#include "JSONNode.h"
#ifdef JSON_ITERATORS
#ifdef JSON_REF_COUNT
#define JSON_ASSERT_UNIQUE(x) JSON_ASSERT(internal -> refcount == 1, json_string(JSON_TEXT(x)) + JSON_TEXT(" in non single reference"))
#else
#define JSON_ASSERT_UNIQUE(x) (void)0
#endif
#ifdef JSON_MUTEX_CALLBACKS
#define JSON_MUTEX_COPY2 ,internal -> mylock
#else
#define JSON_MUTEX_COPY2
#endif
JSONNode::json_iterator JSONNode::find(const json_string & name_t) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("find"));
makeUniqueInternal();
if (JSONNode ** res = internal -> at(name_t)){
return ptr_to_json_iterator(res);
}
return end();
}
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
JSONNode::json_iterator JSONNode::find_nocase(const json_string & name_t) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("find_nocase"));
makeUniqueInternal();
if (JSONNode ** res = internal -> at_nocase(name_t)){
return ptr_to_json_iterator(res);
}
return end();
}
#endif
JSONNode::json_iterator JSONNode::erase(json_iterator pos) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("erase"));
JSON_ASSERT_UNIQUE("erase 1");
JSON_ASSERT_SAFE(pos < end(), JSON_TEXT("erase out of range"), return end(););
JSON_ASSERT_SAFE(pos >= begin(), JSON_TEXT("erase out of range"), return begin(););
deleteJSONNode(*(json_iterator_ptr(pos)));
internal -> CHILDREN -> erase(json_iterator_ptr(pos));
return (empty()) ? end() : pos;
}
JSONNode::json_iterator JSONNode::erase(json_iterator _start, const json_iterator & _end) json_nothrow {
if (_start == _end) return _start;
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("erase"));
JSON_ASSERT_UNIQUE("erase 3");
JSON_ASSERT_SAFE(_start <= end(), JSON_TEXT("erase out of lo range"), return end(););
JSON_ASSERT_SAFE(_end <= end(), JSON_TEXT("erase out of hi range"), return end(););
JSON_ASSERT_SAFE(_start >= begin(), JSON_TEXT("erase out of lo range"), return begin(););
JSON_ASSERT_SAFE(_end >= begin(), JSON_TEXT("erase out of hi range"), return begin(););
for (JSONNode ** pos = json_iterator_ptr(_start); pos < json_iterator_ptr(_end); ++pos){
deleteJSONNode(*pos);
}
internal -> CHILDREN -> erase(json_iterator_ptr(_start), (json_index_t)(json_iterator_ptr(_end) - json_iterator_ptr(_start)));
return (empty()) ? end() : _start;
}
#ifdef JSON_LIBRARY
JSONNode::json_iterator JSONNode::insert(json_iterator pos, JSONNode * x) json_nothrow {
#else
JSONNode::json_iterator JSONNode::insert(json_iterator pos, const JSONNode & x) json_nothrow {
#endif
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("insert"));
JSON_ASSERT_UNIQUE("insert 1");
if (json_iterator_ptr(pos) >= internal -> CHILDREN -> end()){
internal -> push_back(x);
return end() - 1;
}
JSON_ASSERT_SAFE(pos >= begin(), JSON_TEXT("insert out of lo range"), return begin(););
#ifdef JSON_LIBRARY
internal -> CHILDREN -> insert(json_iterator_ptr(pos), x);
#else
internal -> CHILDREN -> insert(json_iterator_ptr(pos), newJSONNode(x));
#endif
return pos;
}
JSONNode::json_iterator JSONNode::insertFFF(json_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("insertFFF"));
JSON_ASSERT_UNIQUE("insertFFF");
JSON_ASSERT_SAFE(pos <= end(), JSON_TEXT("insert out of high range"), return end(););
JSON_ASSERT_SAFE(pos >= begin(), JSON_TEXT("insert out of low range"), return begin(););
const json_index_t num = (json_index_t)(_end - _start);
json_auto<JSONNode *> mem(num);
JSONNode ** runner = mem.ptr;
for (JSONNode ** po = _start; po < _end; ++po){
*runner++ = newJSONNode(*(*po) JSON_MUTEX_COPY2);
}
internal -> CHILDREN -> insert(json_iterator_ptr(pos), mem.ptr, num);
return pos;
}
#ifndef JSON_LIBRARY
JSONNode::const_iterator JSONNode::find(const json_string & name_t) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("find"));
if (JSONNode ** res = internal -> at(name_t)){
return JSONNode::const_iterator(res);
}
return JSONNode::const_iterator(internal -> end());
}
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
JSONNode::const_iterator JSONNode::find_nocase(const json_string & name_t) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("find_nocase"));
if (JSONNode ** res = internal -> at_nocase(name_t)){
return JSONNode::const_iterator(res);
}
return JSONNode::const_iterator(internal -> end());
}
#endif
JSONNode::reverse_iterator JSONNode::erase(reverse_iterator pos) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("erase"));
JSON_ASSERT_UNIQUE("erase 2");
JSON_ASSERT_SAFE(pos < rend(), JSON_TEXT("erase out of range"), return rend(););
JSON_ASSERT_SAFE(pos >= rbegin(), JSON_TEXT("erase out of range"), return rbegin(););
deleteJSONNode(*(pos.it));
internal -> CHILDREN -> erase(pos.it);
return (empty()) ? rend() : pos + 1;
}
JSONNode::reverse_iterator JSONNode::erase(reverse_iterator _start, const reverse_iterator & _end) json_nothrow {
if (_start == _end) return _start;
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("erase"));
JSON_ASSERT_UNIQUE("erase 4");
JSON_ASSERT_SAFE(_start <= rend(), JSON_TEXT("erase out of lo range"), return rend(););
JSON_ASSERT_SAFE(_end <= rend(), JSON_TEXT("erase out of hi range"), return rend(););
JSON_ASSERT_SAFE(_start >= rbegin(), JSON_TEXT("erase out of lo range"), return rbegin(););
JSON_ASSERT_SAFE(_end >= rbegin(), JSON_TEXT("erase out of hi range"), return rbegin(););
for (JSONNode ** pos = _start.it; pos > _end.it; --pos){
deleteJSONNode(*pos);
}
const json_index_t num = (json_index_t)(_start.it - _end.it);
internal -> CHILDREN -> erase(_end.it + 1, num, _start.it);
return (empty()) ? rend() : _start + num;
}
JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const JSONNode & x) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("insert"));
JSON_ASSERT_UNIQUE("insert 1");
if (pos.it < internal -> CHILDREN -> begin()){
internal -> push_front(x);
return rend() - 1;
}
JSON_ASSERT_SAFE(pos >= rbegin(), JSON_TEXT("insert out of range"), return rbegin(););
internal -> CHILDREN -> insert(++pos.it, newJSONNode(x), true);
return pos;
}
JSONNode::reverse_iterator JSONNode::insertRFF(reverse_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("insertRFF"));
JSON_ASSERT_UNIQUE("insert RFF");
JSON_ASSERT_SAFE(pos <= rend(), JSON_TEXT("insert out of range"), return rend(););
JSON_ASSERT_SAFE(pos >= rbegin(), JSON_TEXT("insert out of range"), return rbegin(););
const json_index_t num = (json_index_t)(_end - _start);
json_auto<JSONNode *> mem(num);
JSONNode ** runner = mem.ptr + num;
for (JSONNode ** po = _start; po < _end; ++po){ //fill it backwards
*(--runner) = newJSONNode(*(*po) JSON_MUTEX_COPY2);
}
internal -> CHILDREN -> insert(++pos.it, mem.ptr, num);
return pos - num + 1;
}
JSONNode::iterator JSONNode::insertFRR(json_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("insertFRR"));
JSON_ASSERT_UNIQUE("insert FRR");
JSON_ASSERT_SAFE(pos <= end(), JSON_TEXT("insert out of range"), return end(););
JSON_ASSERT_SAFE(pos >= begin(), JSON_TEXT("insert out of range"), return begin(););
const json_index_t num = (json_index_t)(_start - _end);
json_auto<JSONNode *> mem(num);
JSONNode ** runner = mem.ptr;
for (JSONNode ** po = _start; po > _end; --po){
*runner++ = newJSONNode(*(*po) JSON_MUTEX_COPY2);
}
internal -> CHILDREN -> insert(pos.it, mem.ptr, num);
return pos;
}
JSONNode::reverse_iterator JSONNode::insertRRR(reverse_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("insertRRR"));
JSON_ASSERT_UNIQUE("insert RRR");
JSON_ASSERT_SAFE(pos <= rend(), JSON_TEXT("insert out of range"), return rend(););
JSON_ASSERT_SAFE(pos >= rbegin(), JSON_TEXT("insert out of range"), return rbegin(););
const json_index_t num = (json_index_t)(_start - _end);
json_auto<JSONNode *> mem(num);
JSONNode ** runner = mem.ptr;
for (JSONNode ** po = _start; po > _end; --po){
*runner++ = newJSONNode(*(*po) JSON_MUTEX_COPY2);
}
internal -> CHILDREN -> insert(++pos.it, mem.ptr, num);
return pos - num + 1;
}
#endif
#endif

View file

@ -0,0 +1,149 @@
#include "JSONMemory.h"
#ifdef JSON_MEMORY_MANAGE
#include "JSONNode.h"
void auto_expand::purge(void) json_nothrow {
for(JSON_MAP(void *, void *)::iterator i = mymap.begin(), en = mymap.end(); i != en; ++i){
#if defined(JSON_DEBUG) || defined(JSON_SAFE)
void * temp = (void*)i -> first; //because its pass by reference
libjson_free<void>(temp);
#else
libjson_free<void>((void*)i -> first);
#endif
}
}
void auto_expand_node::purge(void) json_nothrow {
for(JSON_MAP(void *, JSONNode *)::iterator i = mymap.begin(), en = mymap.end(); i != en; ++i){
JSONNode::deleteJSONNode((JSONNode *)i -> second);
}
}
#ifdef JSON_STREAM
#include "JSONStream.h"
void auto_expand_stream::purge(void) json_nothrow {
for(JSON_MAP(void *, JSONStream *)::iterator i = mymap.begin(), en = mymap.end(); i != en; ++i){
JSONStream::deleteJSONStream((JSONStream *)i -> second);
}
}
#endif
#endif
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
#ifdef JSON_MEMORY_POOL
#include "JSONMemoryPool.h"
static bucket_pool_8<MEMPOOL_1, MEMPOOL_2, MEMPOOL_3, MEMPOOL_4, MEMPOOL_5, MEMPOOL_6, MEMPOOL_7, MEMPOOL_8> json_generic_mempool;
//This class is only meant to initiate the mempool to start out using std::malloc/realloc/free
class mempool_callback_setter {
public:
LIBJSON_OBJECT(mempool_callback_setter);
inline mempool_callback_setter(void) json_nothrow {
` LIBJSON_CTOR;
mempool_callbacks::set(std::malloc, std::realloc, std::free);
}
private:
inline mempool_callback_setter(const mempool_callback_setter & o);
inline mempool_callback_setter & operator = (const mempool_callback_setter & o);
};
static mempool_callback_setter __mempoolcallbacksetter;
#endif
#include "JSONSingleton.h"
void * JSONMemory::json_malloc(size_t siz) json_nothrow {
#ifdef JSON_MEMORY_POOL
return json_generic_mempool.allocate(siz);
#else
if (json_malloc_t callback = JSONSingleton<json_malloc_t>::get()){
#if(defined(JSON_DEBUG) && (!defined(JSON_MEMORY_CALLBACKS))) //in debug mode without mem callback, see if the malloc was successful
void * result = callback(siz);
JSON_ASSERT(result, JSON_TEXT("Out of memory"));
return result;
#else
return callback(siz);
#endif
}
#if(defined(JSON_DEBUG) && (!defined(JSON_MEMORY_CALLBACKS))) //in debug mode without mem callback, see if the malloc was successful
void * result = std::malloc(siz);
JSON_ASSERT(result, JSON_TEXT("Out of memory"));
return result;
#else
return std::malloc(siz);
#endif
#endif
}
void JSONMemory::json_free(void * ptr) json_nothrow {
#ifdef JSON_MEMORY_POOL
json_generic_mempool.deallocate(ptr);
#else
if (json_free_t callback = JSONSingleton<json_free_t>::get()){
callback(ptr);
} else {
std::free(ptr);
}
#endif
}
void * JSONMemory::json_realloc(void * ptr, size_t siz) json_nothrow {
#ifdef JSON_MEMORY_POOL
return json_generic_mempool.reallocate(ptr, siz);
#else
if (json_realloc_t callback = JSONSingleton<json_realloc_t>::get()){
#if(defined(JSON_DEBUG) && (!defined(JSON_MEMORY_CALLBACKS))) //in debug mode without mem callback, see if the malloc was successful
void * result = callback(ptr, siz);
JSON_ASSERT(result, JSON_TEXT("Out of memory"));
return result;
#else
return callback(ptr, siz);
#endif
}
#if(defined(JSON_DEBUG) && (!defined(JSON_MEMORY_CALLBACKS))) //in debug mode without mem callback, see if the malloc was successful
void * result = std::realloc(ptr, siz);
JSON_ASSERT(result, JSON_TEXT("Out of memory"));
return result;
#else
return std::realloc(ptr, siz);
#endif
#endif
}
#ifdef JSON_MEMORY_POOL
//it is okay to pass null to these callbacks, no make sure they function exists
static void * malloc_proxy(size_t siz) json_nothrow {
if (json_malloc_t callback = JSONSingleton<json_malloc_t>::get()){
return callback(siz);
}
return std::malloc(siz);
}
static void * realloc_proxy(void * ptr, size_t siz) json_nothrow {
if (json_realloc_t callback = JSONSingleton<json_realloc_t>::get()){
return callback(ptr, siz);
}
return std::realloc(ptr, siz);
}
static void free_proxy(void * ptr){
if (json_free_t callback = JSONSingleton<json_free_t>::get()){
callback(ptr);
} else {
std::free(ptr);
}
}
#endif
void JSONMemory::registerMemoryCallbacks(json_malloc_t mal, json_realloc_t real, json_free_t fre) json_nothrow {
JSONSingleton<json_malloc_t>::set(mal);
JSONSingleton<json_realloc_t>::set(real);
JSONSingleton<json_free_t>::set(fre);
#ifdef JSON_MEMORY_POOL
mempool_callbacks::set(malloc_proxy, realloc_proxy, free_proxy);
#endif
}
#endif

View file

@ -0,0 +1,175 @@
#ifndef JSON_MEMORY_H
#define JSON_MEMORY_H
#include <cstdlib> //for malloc, realloc, and free
#include <cstring> //for memmove
#include "JSONDebug.h"
#if defined(JSON_DEBUG) || defined(JSON_SAFE)
#define JSON_FREE_PASSTYPE &
#else
#define JSON_FREE_PASSTYPE
#endif
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
class JSONMemory {
public:
static void * json_malloc(size_t siz) json_malloc_attr;
static void * json_realloc(void * ptr, size_t siz) json_malloc_attr;
static void json_free(void * ptr) json_nothrow;
static void registerMemoryCallbacks(json_malloc_t mal, json_realloc_t real, json_free_t fre) json_nothrow json_cold;
private:
JSONMemory(void);
};
template <typename T> static inline T * json_malloc(size_t count) json_malloc_attr;
template <typename T> static inline T * json_malloc(size_t count) json_nothrow {
return (T *)JSONMemory::json_malloc(sizeof(T) * count);
}
template <typename T> static inline T * json_realloc(T * ptr, size_t count) json_malloc_attr;
template <typename T> static inline T * json_realloc(T * ptr, size_t count) json_nothrow {
return (T *)JSONMemory::json_realloc(ptr, sizeof(T) * count);
}
template <typename T> static inline void libjson_free(T * JSON_FREE_PASSTYPE ptr) json_nothrow {
JSONMemory::json_free(ptr);
#if defined(JSON_DEBUG) || defined(JSON_SAFE) //in debug or safe mode, set the pointer to 0 so that it can't be used again
ptr = 0;
#endif
}
#else
template <typename T> static inline T * json_malloc(size_t count) json_malloc_attr;
template <typename T> static inline T * json_malloc(size_t count) json_nothrow {
#ifdef JSON_DEBUG //in debug mode, see if the malloc was successful
void * result = std::malloc(count * sizeof(T));
JSON_ASSERT(result != 0, JSON_TEXT("Out of memory"));
#ifdef JSON_NULL_MEMORY
std::memset(result, '\0', count * sizeof(T));
#endif
return (T *)result;
#else
return (T *)std::malloc(count * sizeof(T));
#endif
}
template <typename T> static inline void libjson_free(T * JSON_FREE_PASSTYPE ptr) json_nothrow {
std::free(ptr);
#if defined(JSON_DEBUG) || defined(JSON_SAFE) //in debug or safe mode, set the pointer to 0 so that it can't be used again
ptr = 0;
#endif
}
template <typename T> static inline T * json_realloc(T * ptr, size_t count) json_malloc_attr;
template <typename T> static inline T * json_realloc(T * ptr, size_t count) json_nothrow {
#ifdef JSON_DEBUG //in debug mode, check the results of realloc to be sure it was successful
void * result = std::realloc(ptr, count * sizeof(T));
JSON_ASSERT(result != 0, JSON_TEXT("Out of memory"));
return (T *)result;
#else
return (T *)std::realloc(ptr, count * sizeof(T));
#endif
}
#endif
#ifdef JSON_MEMORY_MANAGE
#include <map>
class JSONNode;
struct auto_expand {
public:
LIBJSON_OBJECT(auto_expand);
auto_expand(void) json_nothrow : mymap(){ LIBJSON_CTOR;}
~auto_expand(void) json_nothrow { purge(); LIBJSON_DTOR; }
void purge(void) json_nothrow;
inline void clear(void) json_nothrow { purge(); mymap.clear(); }
inline void * insert(void * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; }
inline void remove(void * ptr) json_nothrow {
JSON_MAP(void *, void *)::iterator i = mymap.find(ptr);
JSON_ASSERT(i != mymap.end(), JSON_TEXT("Removing a non-managed item"));
mymap.erase(i);
}
JSON_MAP(void *, void *) mymap;
private:
auto_expand(const auto_expand &);
auto_expand & operator = (const auto_expand &);
};
struct auto_expand_node {
public:
LIBJSON_OBJECT(auto_expand_node);
auto_expand_node(void) json_nothrow : mymap(){ LIBJSON_CTOR; }
~auto_expand_node(void) json_nothrow { purge(); LIBJSON_DTOR; }
void purge(void) json_nothrow ;
inline void clear(void) json_nothrow { purge(); mymap.clear(); }
inline JSONNode * insert(JSONNode * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; }
inline void remove(void * ptr) json_nothrow {
JSON_MAP(void *, JSONNode *)::iterator i = mymap.find(ptr);
if(json_likely(i != mymap.end())) mymap.erase(i);
}
JSON_MAP(void *, JSONNode *) mymap;
private:
auto_expand_node(const auto_expand_node &);
auto_expand_node & operator = (const auto_expand_node &);
};
#ifdef JSON_STREAM
class JSONStream;
struct auto_expand_stream {
public:
LIBJSON_OBJECT(auto_expand_stream);
auto_expand_stream(void) json_nothrow : mymap(){ LIBJSON_CTOR; }
~auto_expand_stream(void) json_nothrow { purge(); LIBJSON_DTOR; }
void purge(void) json_nothrow ;
inline void clear(void) json_nothrow { purge(); mymap.clear(); }
inline JSONStream * insert(JSONStream * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; }
inline void remove(void * ptr) json_nothrow {
JSON_MAP(void *, JSONStream *)::iterator i = mymap.find(ptr);
if(json_likely(i != mymap.end())) mymap.erase(i);
}
JSON_MAP(void *, JSONStream *) mymap;
private:
auto_expand_stream(const auto_expand_stream &);
auto_expand_stream & operator = (const auto_expand_stream &);
};
#endif
#endif
//The C++ way, use an self-deleting pointer and let the optimizer decide when it gets destroyed
template <typename T>
class json_auto {
public:
LIBJSON_OBJECT(json_auto);
json_auto(void) json_nothrow : ptr(0){ LIBJSON_CTOR; }
json_auto(size_t count) json_nothrow : ptr(json_malloc<T>(count)){ LIBJSON_CTOR; }
json_auto(T * arg) json_nothrow : ptr(arg){ LIBJSON_CTOR; }
~json_auto(void) json_nothrow {
libjson_free<T>(ptr);
LIBJSON_DTOR;
}
inline void set(T * p) json_nothrow{
ptr = p;
}
T * ptr;
private:
json_auto(const json_auto &);
json_auto & operator =(const json_auto &);
};
//Clears a string, if required, frees the memory
static inline void clearString(json_string & str) json_nothrow {
#ifdef JSON_LESS_MEMORY
json_string().swap(str);
#else
str.clear();
#endif
}
//Shrinks a string
static inline void shrinkString(json_string & str) json_nothrow {
#ifdef JSON_LESS_MEMORY
if (str.capacity() != str.length()) str = json_string(str.begin(), str.end());
#endif
}
#endif

View file

@ -0,0 +1,38 @@
#ifndef LIBJSON_GUARD_MEMORY_POOL_H
#define LIBJSON_GUARD_MEMORY_POOL_H
#ifdef JSON_MEMORY_POOL
#include "../Dependencies/mempool++/mempool.h"
//this macro expands to the number of bytes a pool gets based on block size and number of 32s of the total pool it gets
#define jsonPoolPart(bytes_per_block, thirty_seconds_of_mem) bytes_per_block, ((thirty_seconds_of_mem * JSON_MEMORY_POOL / 32) / bytes_per_block)
#ifdef JSON_PREPARSE
#define NODEPOOL jsonPoolPart(sizeof(JSONNode), 1)
#define INTERNALNODEPOOL jsonPoolPart(sizeof(internalJSONNode), 3)
#define MEMPOOL_1 jsonPoolPart(8, 2)
#define MEMPOOL_2 jsonPoolPart(16, 2)
#define MEMPOOL_3 jsonPoolPart(32, 2)
#define MEMPOOL_4 jsonPoolPart(64, 2)
#define MEMPOOL_5 jsonPoolPart(128, 3)
#define MEMPOOL_6 jsonPoolPart(256, 4)
#define MEMPOOL_7 jsonPoolPart(512, 5)
#define MEMPOOL_8 jsonPoolPart(4096, 8)
#else
#define NODEPOOL jsonPoolPart(sizeof(JSONNode), 2)
#define INTERNALNODEPOOL jsonPoolPart(sizeof(internalJSONNode), 7)
#define MEMPOOL_1 jsonPoolPart(8, 1)
#define MEMPOOL_2 jsonPoolPart(16, 1)
#define MEMPOOL_3 jsonPoolPart(32, 1)
#define MEMPOOL_4 jsonPoolPart(64, 1)
#define MEMPOOL_5 jsonPoolPart(128, 3)
#define MEMPOOL_6 jsonPoolPart(256, 3)
#define MEMPOOL_7 jsonPoolPart(512, 5)
#define MEMPOOL_8 jsonPoolPart(4096, 8)
#endif
#endif
#endif

View file

@ -0,0 +1,356 @@
#include "JSONNode.h"
#define IMPLEMENT_CTOR(type)\
JSONNode::JSONNode(const json_string & name_t, type value_t) json_nothrow : internal(internalJSONNode::newInternal()){\
internal -> Set(value_t);\
internal -> setname(name_t);\
LIBJSON_CTOR;\
}
IMPLEMENT_FOR_ALL_TYPES(IMPLEMENT_CTOR)
#ifndef JSON_LIBRARY
JSONNode::JSONNode(const json_string & name_t, const json_char * value_t) json_nothrow : internal(internalJSONNode::newInternal()){
internal -> Set(json_string(value_t));
internal -> setname(name_t);
LIBJSON_CTOR;
}
#endif
#if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY))
#include "JSONWorker.h"
JSONNode JSONNode::stringType(const json_string & str){
JSONNode res;
res.set_name(json_global(EMPTY_JSON_STRING));
#ifdef JSON_LESS_MEMORY
res = JSONWorker::FixString(str, res.internal, false);
#else
res = JSONWorker::FixString(str, res.internal -> _string_encoded);
#endif
return res;
}
void JSONNode::set_name_(const json_string & newname) json_nothrow {
#ifdef JSON_LESS_MEMORY
json_string _newname = JSONWorker::FixString(newname, internal, true);
#else
json_string _newname = JSONWorker::FixString(newname, internal -> _name_encoded);
#endif
set_name(_newname);
}
#endif
#ifdef JSON_CASTABLE
JSONNode JSONNode::as_node(void) const json_nothrow {
JSON_CHECK_INTERNAL();
if (type() == JSON_NODE){
return *this;
} else if (type() == JSON_ARRAY){
JSONNode res(duplicate());
res.internal -> _type = JSON_NODE;
return res;
}
#ifdef JSON_MUTEX_CALLBACKS
if (internal -> mylock != 0){
JSONNode res(JSON_NODE);
res.set_mutex(internal -> mylock);
return res;
}
#endif
return JSONNode(JSON_NODE);
}
JSONNode JSONNode::as_array(void) const json_nothrow {
JSON_CHECK_INTERNAL();
if (type() == JSON_ARRAY){
return *this;
} else if (type() == JSON_NODE){
JSONNode res(duplicate());
res.internal -> _type = JSON_ARRAY;
json_foreach(res.internal -> CHILDREN, runner){
(*runner) -> clear_name();
}
return res;
}
#ifdef JSON_MUTEX_CALLBACKS
if (internal -> mylock != 0){
JSONNode res(JSON_ARRAY);
res.set_mutex(internal -> mylock);
return res;
}
#endif
return JSONNode(JSON_ARRAY);
}
void JSONNode::cast(char newtype) json_nothrow {
JSON_CHECK_INTERNAL();
if (newtype == type()) return;
switch(newtype){
case JSON_NULL:
nullify();
return;
case JSON_STRING:
*this = as_string();
return;
case JSON_NUMBER:
*this = as_float();
return;
case JSON_BOOL:
*this = as_bool();
return;
case JSON_ARRAY:
*this = as_array();
return;
case JSON_NODE:
*this = as_node();
return;
}
JSON_FAIL(JSON_TEXT("cast to unknown type"));
}
#endif
//different just to supress the warning
#ifdef JSON_REF_COUNT
void JSONNode::merge(JSONNode & other) json_nothrow {
#else
void JSONNode::merge(JSONNode &) json_nothrow {
#endif
JSON_CHECK_INTERNAL();
#ifdef JSON_REF_COUNT
if (internal == other.internal) return;
JSON_ASSERT(*this == other, JSON_TEXT("merging two nodes that aren't equal"));
if (internal -> refcount < other.internal -> refcount){
*this = other;
} else {
other = *this;
}
#endif
}
#ifdef JSON_REF_COUNT
void JSONNode::merge(JSONNode * other) json_nothrow {
JSON_CHECK_INTERNAL();
if (internal == other -> internal) return;
*other = *this;
}
//different just to supress the warning
void JSONNode::merge(unsigned int num, ...) json_nothrow {
#else
void JSONNode::merge(unsigned int, ...) json_nothrow {
#endif
JSON_CHECK_INTERNAL();
#ifdef JSON_REF_COUNT
va_list args;
va_start(args, num);
for(unsigned int i = 0; i < num; ++i){
merge(va_arg(args, JSONNode*));
}
va_end(args);
#endif
}
JSONNode JSONNode::duplicate(void) const json_nothrow {
JSON_CHECK_INTERNAL();
JSONNode mycopy(*this);
#ifdef JSON_REF_COUNT
JSON_ASSERT(internal == mycopy.internal, JSON_TEXT("copy ctor failed to ref count correctly"));
mycopy.makeUniqueInternal();
#endif
JSON_ASSERT(internal != mycopy.internal, JSON_TEXT("makeUniqueInternal failed"));
return mycopy;
}
JSONNode & JSONNode::at(json_index_t pos) json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
if (json_unlikely(pos >= internal -> size())){
JSON_FAIL(JSON_TEXT("at() out of bounds"));
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
return (*this)[pos];
}
const JSONNode & JSONNode::at(json_index_t pos) const json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
if (json_unlikely(pos >= internal -> size())){
JSON_FAIL(JSON_TEXT("at() const out of bounds"));
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
return (*this)[pos];
}
JSONNode & JSONNode::operator[](json_index_t pos) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(pos < internal -> size(), JSON_TEXT("[] out of bounds"));
makeUniqueInternal();
return *(internal -> at(pos));
}
const JSONNode & JSONNode::operator[](json_index_t pos) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(pos < internal -> size(), JSON_TEXT("[] const out of bounds"));
return *(internal -> at(pos));
}
JSONNode & JSONNode::at(const json_string & name_t) json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("at"));
makeUniqueInternal();
if (JSONNode ** res = internal -> at(name_t)){
return *(*res);
}
JSON_FAIL(json_string(JSON_TEXT("at could not find child by name: ")) + name_t);
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
const JSONNode & JSONNode::at(const json_string & name_t) const json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("at"));
if (JSONNode ** res = internal -> at(name_t)){
return *(*res);
}
JSON_FAIL(json_string(JSON_TEXT("at const could not find child by name: ")) + name_t);
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
JSONNode & JSONNode::at_nocase(const json_string & name_t) json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("at_nocase"));
makeUniqueInternal();
if (JSONNode ** res = internal -> at_nocase(name_t)){
return *(*res);
}
JSON_FAIL(json_string(JSON_TEXT("at_nocase could not find child by name: ")) + name_t);
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
const JSONNode & JSONNode::at_nocase(const json_string & name_t) const json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("at_nocase"));
if (JSONNode ** res = internal -> at_nocase(name_t)){
return *(*res);
}
JSON_FAIL(json_string(JSON_TEXT("at_nocase const could not find child by name: ")) + name_t);
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
#endif
#ifndef JSON_LIBRARY
struct auto_delete {
public:
auto_delete(JSONNode * node) json_nothrow : mynode(node){};
~auto_delete(void) json_nothrow { JSONNode::deleteJSONNode(mynode); };
JSONNode * mynode;
private:
auto_delete(const auto_delete &);
auto_delete & operator = (const auto_delete &);
};
#endif
JSONNode JSON_PTR_LIB JSONNode::pop_back(json_index_t pos) json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
if (json_unlikely(pos >= internal -> size())){
JSON_FAIL(JSON_TEXT("pop_back out of bounds"));
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
}
makeUniqueInternal();
#ifdef JSON_LIBRARY
return internal -> pop_back(pos);
#else
auto_delete temp(internal -> pop_back(pos));
return *temp.mynode;
#endif
}
JSONNode JSON_PTR_LIB JSONNode::pop_back(const json_string & name_t) json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("pop_back"));
#ifdef JSON_LIBRARY
return internal -> pop_back(name_t);
#else
if (JSONNode * res = internal -> pop_back(name_t)){
auto_delete temp(res);
return *(temp.mynode);
}
JSON_FAIL(json_string(JSON_TEXT("pop_back const could not find child by name: ")) + name_t);
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
#endif
}
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
JSONNode JSON_PTR_LIB JSONNode::pop_back_nocase(const json_string & name_t) json_throws(std::out_of_range) {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("pop_back_no_case"));
#ifdef JSON_LIBRARY
return internal -> pop_back_nocase(name_t);
#else
if (JSONNode * res = internal -> pop_back_nocase(name_t)){
auto_delete temp(res);
return *(temp.mynode);
}
JSON_FAIL(json_string(JSON_TEXT("pop_back_nocase could not find child by name: ")) + name_t);
json_throw(std::out_of_range(json_global(EMPTY_STD_STRING)));
#endif
}
#endif
#ifdef JSON_MEMORY_POOL
#include "JSONMemoryPool.h"
memory_pool<NODEPOOL> json_node_mempool;
#endif
void JSONNode::deleteJSONNode(JSONNode * ptr) json_nothrow {
#ifdef JSON_MEMORY_POOL
ptr -> ~JSONNode();
json_node_mempool.deallocate((void*)ptr);
#elif defined(JSON_MEMORY_CALLBACKS)
ptr -> ~JSONNode();
libjson_free<JSONNode>(ptr);
#else
delete ptr;
#endif
}
inline JSONNode * _newJSONNode(const JSONNode & orig) {
#ifdef JSON_MEMORY_POOL
return new((JSONNode*)json_node_mempool.allocate()) JSONNode(orig);
#elif defined(JSON_MEMORY_CALLBACKS)
return new(json_malloc<JSONNode>(1)) JSONNode(orig);
#else
return new JSONNode(orig);
#endif
}
JSONNode * JSONNode::newJSONNode(const JSONNode & orig JSON_MUTEX_COPY_DECL) {
#ifdef JSON_MUTEX_CALLBACKS
if (parentMutex != 0){
JSONNode * temp = _newJSONNode(orig);
temp -> set_mutex(parentMutex);
return temp;
}
#endif
return _newJSONNode(orig);
}
JSONNode * JSONNode::newJSONNode(internalJSONNode * internal_t) {
#ifdef JSON_MEMORY_POOL
return new((JSONNode*)json_node_mempool.allocate()) JSONNode(internal_t);
#elif defined(JSON_MEMORY_CALLBACKS)
return new(json_malloc<JSONNode>(1)) JSONNode(internal_t);
#else
return new JSONNode(internal_t);
#endif
}
JSONNode * JSONNode::newJSONNode_Shallow(const JSONNode & orig) {
#ifdef JSON_MEMORY_POOL
return new((JSONNode*)json_node_mempool.allocate()) JSONNode(true, const_cast<JSONNode &>(orig));
#elif defined(JSON_MEMORY_CALLBACKS)
return new(json_malloc<JSONNode>(1)) JSONNode(true, const_cast<JSONNode &>(orig));
#else
return new JSONNode(true, const_cast<JSONNode &>(orig));
#endif
}

View file

@ -0,0 +1,985 @@
#ifndef JSONNODE_H
#define JSONNODE_H
#include "JSONDebug.h" //for string type
#include "internalJSONNode.h" //internal structure for json value
#include <stdexcept>
#include <cstdarg> //for the ... parameter
#ifdef JSON_BINARY
#include "JSON_Base64.h"
#endif
#ifdef JSON_LESS_MEMORY
#ifdef __GNUC__
#pragma pack(push, 1)
#elif _MSC_VER
#pragma pack(push, JSONNode_pack, 1)
#endif
#endif
#ifndef JSON_REF_COUNT
#define makeUniqueInternal() (void)0
#endif
#define JSON_CHECK_INTERNAL() JSON_ASSERT(internal != 0, JSON_TEXT("no internal"))
#ifdef JSON_MUTEX_CALLBACKS
#define JSON_MUTEX_COPY_DECL ,void * parentMutex
#define JSON_MUTEX_COPY_DECL2 ,void * parentMutex = 0
#else
#define JSON_MUTEX_COPY_DECL
#define JSON_MUTEX_COPY_DECL2
#endif
#ifdef JSON_LIBRARY
#define JSON_PTR_LIB *
#define JSON_NEW(x) JSONNode::newJSONNode_Shallow(x)
#define DECLARE_FOR_ALL_TYPES(foo)\
foo(json_int_t)json_nothrow;\
foo(json_number) json_nothrow;\
foo(bool) json_nothrow;\
foo(const json_string &) json_nothrow;
#define DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
foo(json_int_t) const json_nothrow;\
foo(json_number) const json_nothrow;\
foo(bool) const json_nothrow;\
foo(const json_string &) const json_nothrow;\
#define DECLARE_FOR_ALL_TYPES_CONST(foo)\
DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
foo(const JSONNode &) const json_nothrow;
#define IMPLEMENT_FOR_ALL_NUMBERS(foo)\
foo(json_int_t)\
foo(json_number)
#else
#define JSON_PTR_LIB
#define JSON_NEW(x) x
#ifdef JSON_ISO_STRICT
#define DECLARE_FOR_LONG_LONG(foo)
#define DECLARE_FOR_LONG_LONG_CONST(foo)
#define IMPLEMENT_FOR_LONG_LONG(foo)
#define DECLARE_FOR_LONG_DOUBLE(foo)
#define DECLARE_FOR_LONG_DOUBLE_CONST(foo)
#define IMPLEMENT_FOR_LONG_DOUBLE(foo)
#else
#define DECLARE_FOR_LONG_LONG(foo) foo(long long) json_nothrow; foo(unsigned long long) json_nothrow;
#define DECLARE_FOR_LONG_LONG_CONST(foo) foo(long long) const json_nothrow; foo(unsigned long long) const json_nothrow;
#define IMPLEMENT_FOR_LONG_LONG(foo) foo(long long) foo(unsigned long long)
#define DECLARE_FOR_LONG_DOUBLE(foo) foo(long double) json_nothrow;
#define DECLARE_FOR_LONG_DOUBLE_CONST(foo) foo(long double) const json_nothrow;
#define IMPLEMENT_FOR_LONG_DOUBLE(foo) foo(long double)
#endif
#define DECLARE_FOR_ALL_TYPES(foo)\
foo(char) json_nothrow; foo(unsigned char) json_nothrow;\
foo(short) json_nothrow; foo(unsigned short) json_nothrow;\
foo(int) json_nothrow; foo(unsigned int) json_nothrow;\
foo(long) json_nothrow; foo(unsigned long) json_nothrow;\
foo(float) json_nothrow; foo(double) json_nothrow;\
foo(bool) json_nothrow;\
foo(const json_string &) json_nothrow;\
foo(const json_char *) json_nothrow;\
DECLARE_FOR_LONG_LONG(foo)\
DECLARE_FOR_LONG_DOUBLE(foo)
#define DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
foo(char) const json_nothrow; foo(unsigned char) const json_nothrow;\
foo(short) const json_nothrow; foo(unsigned short) const json_nothrow;\
foo(int) const json_nothrow; foo(unsigned int) const json_nothrow;\
foo(long) const json_nothrow; foo(unsigned long) const json_nothrow;\
foo(float) const json_nothrow; foo(double) const json_nothrow;\
foo(bool) const json_nothrow;\
foo(const json_string &) const json_nothrow;\
DECLARE_FOR_LONG_LONG_CONST(foo)\
DECLARE_FOR_LONG_DOUBLE_CONST(foo)
#define DECLARE_FOR_ALL_TYPES_CONST(foo)\
DECLARE_FOR_ALL_CAST_TYPES_CONST(foo)\
foo(const JSONNode &) const json_nothrow;\
foo(const json_char *) const json_nothrow;
#define IMPLEMENT_FOR_ALL_NUMBERS(foo)\
foo(char) foo(unsigned char)\
foo(short) foo(unsigned short)\
foo(int) foo(unsigned int)\
foo(long) foo(unsigned long)\
foo(float) foo(double)\
IMPLEMENT_FOR_LONG_LONG(foo)\
IMPLEMENT_FOR_LONG_DOUBLE(foo)
#endif
#define IMPLEMENT_FOR_ALL_TYPES(foo)\
IMPLEMENT_FOR_ALL_NUMBERS(foo)\
foo(const json_string &)\
foo(bool)
/*
This class is mostly just a wrapper class around internalJSONNode, this class keeps
the reference count and handles copy on write and such. This class is also responsible
for argument checking and throwing exceptions if needed.
*/
class JSONNode {
public:
LIBJSON_OBJECT(JSONNode);
explicit JSONNode(char mytype = JSON_NODE) json_nothrow json_hot;
#define DECLARE_CTOR(type) explicit JSONNode(const json_string & name_t, type value_t)
DECLARE_FOR_ALL_TYPES(DECLARE_CTOR)
JSONNode(const JSONNode & orig) json_nothrow json_hot;
~JSONNode(void) json_nothrow json_hot;
#if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY))
static JSONNode stringType(const json_string & str);
void set_name_(const json_string & newname) json_nothrow json_write_priority;
#endif
json_index_t size(void) const json_nothrow json_read_priority;
bool empty(void) const json_nothrow json_read_priority;
void clear(void) json_nothrow json_cold;
unsigned char type(void) const json_nothrow json_read_priority;
json_string name(void) const json_nothrow json_read_priority;
void set_name(const json_string & newname) json_nothrow json_write_priority;
#ifdef JSON_COMMENTS
void set_comment(const json_string & comment) json_nothrow;
json_string get_comment(void) const json_nothrow;
#endif
#if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
void preparse(void) json_nothrow json_read_priority;
#endif
json_string as_string(void) const json_nothrow json_read_priority;
json_int_t as_int(void) const json_nothrow json_read_priority;
json_number as_float(void) const json_nothrow json_read_priority;
bool as_bool(void) const json_nothrow json_read_priority;
#ifdef JSON_CASTABLE
JSONNode as_node(void) const json_nothrow json_read_priority;
JSONNode as_array(void) const json_nothrow json_read_priority;
void cast(char newtype) json_nothrow;
#endif
#ifdef JSON_BINARY
std::string as_binary(void) const json_nothrow json_cold;
void set_binary(const unsigned char * bin, size_t bytes) json_nothrow json_cold;
#endif
JSONNode & at(json_index_t pos) json_throws(std::out_of_range);
const JSONNode & at(json_index_t pos) const json_throws(std::out_of_range);
JSONNode & operator[](json_index_t pos) json_nothrow;
const JSONNode & operator[](json_index_t pos) const json_nothrow;
JSONNode & at(const json_string & name_t) json_throws(std::out_of_range);
const JSONNode & at(const json_string & name_t) const json_throws(std::out_of_range);
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
JSONNode & at_nocase(const json_string & name_t) json_throws(std::out_of_range);
const JSONNode & at_nocase(const json_string & name_t) const json_throws(std::out_of_range);
#endif
JSONNode & operator[](const json_string & name_t) json_nothrow;
const JSONNode & operator[](const json_string & name_t) const json_nothrow;
#ifdef JSON_LIBRARY
void push_back(JSONNode * node) json_nothrow;
#else
void push_back(const JSONNode & node) json_nothrow;
#endif
void reserve(json_index_t siz) json_nothrow;
JSONNode JSON_PTR_LIB pop_back(json_index_t pos) json_throws(std::out_of_range);
JSONNode JSON_PTR_LIB pop_back(const json_string & name_t) json_throws(std::out_of_range);
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
JSONNode JSON_PTR_LIB pop_back_nocase(const json_string & name_t) json_throws(std::out_of_range);
#endif
DECLARE_FOR_ALL_TYPES(JSONNode & operator =)
JSONNode & operator = (const JSONNode &) json_nothrow;
DECLARE_FOR_ALL_TYPES_CONST(bool operator ==)
DECLARE_FOR_ALL_TYPES_CONST(bool operator !=)
void nullify(void) json_nothrow;
void swap(JSONNode & other) json_nothrow;
void merge(JSONNode & other) json_nothrow json_cold;
void merge(unsigned int num, ...) json_nothrow json_cold;
JSONNode duplicate(void) const json_nothrow;
//iterator
#ifdef JSON_ITERATORS
#ifndef JSON_LIBRARY
#define json_iterator_ptr(iter) iter.it
#define ptr_to_json_iterator(iter) json_iterator(iter)
struct iterator;
struct const_iterator {
inline const_iterator& operator ++(void) json_nothrow { ++it; return *this; }
inline const_iterator& operator --(void) json_nothrow { --it; return *this; }
inline const_iterator& operator +=(long i) json_nothrow { it += i; return *this; }
inline const_iterator& operator -=(long i) json_nothrow { it -= i; return *this; }
inline const_iterator operator ++(int) json_nothrow {
const_iterator result(*this);
++it;
return result;
}
inline const_iterator operator --(int) json_nothrow {
const_iterator result(*this);
--it;
return result;
}
inline const_iterator operator +(long i) const json_nothrow {
const_iterator result(*this);
result.it += i;
return result;
}
inline const_iterator operator -(long i) const json_nothrow {
const_iterator result(*this);
result.it -= i;
return result;
}
inline const JSONNode& operator [](size_t pos) const json_nothrow { return const_cast<const JSONNode&>(*it[pos]); };
inline const JSONNode& operator *(void) const json_nothrow { return const_cast<const JSONNode&>(*(*it)); }
inline const JSONNode* operator ->(void) const json_nothrow { return const_cast<const JSONNode*>(*it); }
inline bool operator == (const const_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const const_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const const_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const const_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const const_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const const_iterator & other) const json_nothrow { return it <= other.it; }
inline bool operator == (const iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const iterator & other) const json_nothrow { return it <= other.it; }
inline const_iterator & operator =(const const_iterator & orig) json_nothrow { it = orig.it; return *this; }
const_iterator (const const_iterator & orig) json_nothrow : it(orig.it) {}
private:
JSONNode ** it;
const_iterator(JSONNode ** starter) : it(starter) {}
friend class JSONNode;
friend struct iterator;
};
const_iterator begin(void) const json_nothrow;
const_iterator end(void) const json_nothrow;
struct iterator {
inline iterator& operator ++(void) json_nothrow { ++it; return *this; }
inline iterator& operator --(void) json_nothrow { --it; return *this; }
inline iterator& operator +=(long i) json_nothrow { it += i; return *this; }
inline iterator& operator -=(long i) json_nothrow { it -= i; return *this; }
inline iterator operator ++(int) json_nothrow {
iterator result(*this);
++it;
return result;
}
inline iterator operator --(int) json_nothrow {
iterator result(*this);
--it;
return result;
}
inline iterator operator +(long i) const json_nothrow {
iterator result(*this);
result.it += i;
return result;
}
inline iterator operator -(long i) const json_nothrow {
iterator result(*this);
result.it -= i;
return result;
}
inline JSONNode& operator [](size_t pos) const json_nothrow { return *it[pos]; };
inline JSONNode& operator *(void) const json_nothrow { return *(*it); }
inline JSONNode* operator ->(void) const json_nothrow { return *it; }
inline bool operator == (const iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const iterator & other) const json_nothrow { return it <= other.it; }
inline iterator & operator = (const iterator & orig) json_nothrow { it = orig.it; return *this; }
inline bool operator == (const const_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const const_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const const_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const const_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const const_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const const_iterator & other) const json_nothrow { return it <= other.it; }
inline iterator & operator = (const const_iterator & orig) json_nothrow { it = orig.it; return *this; }
iterator (const iterator & orig) json_nothrow : it(orig.it) {}
inline operator const_iterator() const json_nothrow { return const_iterator(it); }
private:
JSONNode ** it;
iterator(JSONNode ** starter) json_nothrow : it(starter) {}
friend class JSONNode;
friend struct const_iterator;
};
typedef iterator json_iterator;
struct reverse_iterator;
struct reverse_const_iterator {
inline reverse_const_iterator& operator ++(void) json_nothrow{ --it; return *this; }
inline reverse_const_iterator& operator --(void) json_nothrow{ ++it; return *this; }
inline reverse_const_iterator& operator +=(long i) json_nothrow{ it -= i; return *this; }
inline reverse_const_iterator& operator -=(long i) json_nothrow{ it += i; return *this; }
inline reverse_const_iterator operator ++(int) json_nothrow{
reverse_const_iterator result(*this);
--it;
return result;
}
inline reverse_const_iterator operator --(int) json_nothrow{
reverse_const_iterator result(*this);
++it;
return result;
}
inline reverse_const_iterator operator +(long i) const json_nothrow {
reverse_const_iterator result(*this);
result.it -= i;
return result;
}
inline reverse_const_iterator operator -(long i) const json_nothrow {
reverse_const_iterator result(*this);
result.it += i;
return result;
}
inline const JSONNode& operator [](size_t pos) const json_nothrow { return const_cast<const JSONNode&>(*it[pos]); };
inline const JSONNode& operator *(void) const json_nothrow { return const_cast<const JSONNode&>(*(*it)); }
inline const JSONNode* operator ->(void) const json_nothrow { return const_cast<const JSONNode*>(*it); }
inline bool operator == (const reverse_const_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const reverse_const_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator < (const reverse_const_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator <= (const reverse_const_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator > (const reverse_const_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator >= (const reverse_const_iterator & other) const json_nothrow { return it <= other.it; }
inline bool operator == (const reverse_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const reverse_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator < (const reverse_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator <= (const reverse_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator > (const reverse_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator >= (const reverse_iterator & other) const json_nothrow { return it <= other.it; }
inline reverse_const_iterator & operator = (const reverse_const_iterator & orig) json_nothrow { it = orig.it; return *this; }
reverse_const_iterator (const reverse_const_iterator & orig) json_nothrow : it(orig.it) {}
private:
JSONNode ** it;
reverse_const_iterator(JSONNode ** starter) json_nothrow : it(starter) {}
friend class JSONNode;
friend struct reverse_iterator;
};
reverse_const_iterator rbegin(void) const json_nothrow;
reverse_const_iterator rend(void) const json_nothrow;
struct reverse_iterator {
inline reverse_iterator& operator ++(void) json_nothrow { --it; return *this; }
inline reverse_iterator& operator --(void) json_nothrow { ++it; return *this; }
inline reverse_iterator& operator +=(long i) json_nothrow { it -= i; return *this; }
inline reverse_iterator& operator -=(long i) json_nothrow { it += i; return *this; }
inline reverse_iterator operator ++(int) json_nothrow {
reverse_iterator result(*this);
--it;
return result;
}
inline reverse_iterator operator --(int) json_nothrow {
reverse_iterator result(*this);
++it;
return result;
}
inline reverse_iterator operator +(long i) const json_nothrow {
reverse_iterator result(*this);
result.it -= i;
return result;
}
inline reverse_iterator operator -(long i) const json_nothrow {
reverse_iterator result(*this);
result.it += i;
return result;
}
inline JSONNode& operator [](size_t pos) const json_nothrow { return *it[pos]; };
inline JSONNode& operator *(void) const json_nothrow { return *(*it); }
inline JSONNode* operator ->(void) const json_nothrow { return *it; }
inline bool operator == (const reverse_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const reverse_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator < (const reverse_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator <= (const reverse_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator > (const reverse_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator >= (const reverse_iterator & other) const json_nothrow { return it <= other.it; }
inline bool operator == (const reverse_const_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const reverse_const_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator < (const reverse_const_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator <= (const reverse_const_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator > (const reverse_const_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator >= (const reverse_const_iterator & other) const json_nothrow { return it <= other.it; }
inline reverse_iterator & operator = (const reverse_iterator & orig) json_nothrow { it = orig.it; return *this; }
reverse_iterator (const reverse_iterator & orig) json_nothrow : it(orig.it) {}
inline operator reverse_const_iterator() const json_nothrow { return reverse_const_iterator(it); }
private:
JSONNode ** it;
reverse_iterator(JSONNode ** starter) json_nothrow : it(starter) {}
friend class JSONNode;
friend struct reverse_const_iterator;
};
reverse_iterator rbegin(void) json_nothrow;
reverse_iterator rend(void) json_nothrow;
const_iterator find(const json_string & name_t) const json_nothrow;
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
const_iterator find_nocase(const json_string & name_t) const json_nothrow;
#endif
reverse_iterator erase(reverse_iterator pos) json_nothrow;
reverse_iterator erase(reverse_iterator start, const reverse_iterator & end) json_nothrow;
iterator insert(iterator pos, const JSONNode & x) json_nothrow;
reverse_iterator insert(reverse_iterator pos, const JSONNode & x) json_nothrow;
iterator insert(iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow;
reverse_iterator insert(reverse_iterator pos, const iterator & _start, const iterator & _end) json_nothrow;
reverse_iterator insert(reverse_iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow;
json_iterator insert(json_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow;
reverse_iterator insert(reverse_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow;
json_iterator insert(json_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow;
reverse_iterator insert(reverse_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow;
#else
typedef JSONNode** json_iterator;
#define json_iterator_ptr(iter) iter
#define ptr_to_json_iterator(iter) iter
json_iterator insert(json_iterator pos, JSONNode * x) json_nothrow;
#endif
json_iterator begin(void) json_nothrow;
json_iterator end(void) json_nothrow;
json_iterator find(const json_string & name_t) json_nothrow;
#ifdef JSON_CASE_INSENSITIVE_FUNCTIONS
json_iterator find_nocase(const json_string & name_t) json_nothrow;
#endif
json_iterator erase(json_iterator pos) json_nothrow;
json_iterator erase(json_iterator start, const json_iterator & end) json_nothrow;
json_iterator insert(json_iterator pos, const json_iterator & _start, const json_iterator & _end) json_nothrow;
#endif
#ifdef JSON_MUTEX_CALLBACKS
static void register_mutex_callbacks(json_mutex_callback_t lock, json_mutex_callback_t unlock, void * manager_lock) json_nothrow json_cold;
#ifdef JSON_MUTEX_MANAGE
static void register_mutex_destructor(json_mutex_callback_t destroy) json_nothrow json_cold;
#endif
static void set_global_mutex(void * mutex) json_nothrow json_cold;
void set_mutex(void * mutex) json_nothrow json_cold;
void lock(int thread) json_nothrow json_cold;
void unlock(int thread) json_nothrow json_cold;
struct auto_lock {
public:
auto_lock(JSONNode & node, int thread) json_nothrow: mynode(&node), mythread(thread){
mynode -> lock(mythread);
}
auto_lock(JSONNode * node, int thread) json_nothrow: mynode(node), mythread(thread){
mynode -> lock(mythread);
}
~auto_lock(void) json_nothrow{
mynode -> unlock(mythread);
}
private:
auto_lock & operator = (const auto_lock &);
auto_lock(const auto_lock &);
JSONNode * mynode;
int mythread;
};
static void * getThisLock(JSONNode * pthis) json_nothrow json_cold;
#endif
#ifdef JSON_WRITE_PRIORITY
#ifdef JSON_LESS_MEMORY
#define DEFAULT_APPROX_SIZE 8
#define DEFAULT_APPROX_SIZE_FORMATTED 16
#else
#define DEFAULT_APPROX_SIZE 1024
#define DEFAULT_APPROX_SIZE_FORMATTED 2048
#endif
json_string write(size_t approxsize = DEFAULT_APPROX_SIZE) const json_nothrow json_write_priority;
json_string write_formatted(size_t approxsize = DEFAULT_APPROX_SIZE_FORMATTED) const json_nothrow json_write_priority;
#endif
#ifdef JSON_DEBUG
#ifndef JSON_LIBRARY
JSONNode dump(void) const json_nothrow;
#endif
#endif
static void deleteJSONNode(JSONNode * ptr) json_nothrow json_hot;
static JSONNode * newJSONNode_Shallow(const JSONNode & orig) json_hot;
#define DECLARE_CAST_OP(type) operator type()
//DECLARE_FOR_ALL_CAST_TYPES_CONST(DECLARE_CAST_OP)
JSON_PRIVATE
static JSONNode * newJSONNode(const JSONNode & orig JSON_MUTEX_COPY_DECL2) json_hot;
static JSONNode * newJSONNode(internalJSONNode * internal_t) json_hot;
#ifdef JSON_READ_PRIORITY
//used by JSONWorker
JSONNode(const json_string & unparsed) json_nothrow : internal(internalJSONNode::newInternal(unparsed)){ //root, specialized because it can only be array or node
LIBJSON_CTOR;
}
#endif
JSONNode(internalJSONNode * internal_t) json_nothrow : internal(internal_t){ //do not increment anything, this is only used in one case and it's already taken care of
LIBJSON_CTOR;
}
JSONNode(bool, JSONNode & orig) json_nothrow json_hot;
void decRef(void) json_nothrow json_hot; //decrements internal's counter, deletes it if needed
#ifdef JSON_REF_COUNT
void makeUniqueInternal(void) json_nothrow; //makes internal it's own
void merge(JSONNode * other) json_nothrow json_cold;
#endif
#ifdef JSON_DEBUG
#ifndef JSON_LIBRARY
JSONNode dump(size_t & totalmemory) json_nothrow;
#endif
#endif
#ifdef JSON_ITERATORS
#ifndef JSON_LIBRARY
json_iterator insertFRR(json_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
reverse_iterator insertRRR(reverse_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
reverse_iterator insertRFF(reverse_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
#endif
json_iterator insertFFF(json_iterator pos, JSONNode ** const _start, JSONNode ** const _end) json_nothrow;
#endif
inline void clear_name(void) json_nothrow {
JSON_CHECK_INTERNAL();
makeUniqueInternal();
internal -> clearname();
}
mutable internalJSONNode * internal;
friend class JSONWorker;
friend class internalJSONNode;
};
/*
Implementations are here to keep the class declaration cleaner. They can't be placed in a different
file because they are inlined.
*/
#define CAST_OP(type)\
inline JSONNode::operator type() const json_nothrow {\
return static_cast<type>(*internal);\
}
//IMPLEMENT_FOR_ALL_TYPES(CAST_OP)
inline JSONNode::JSONNode(char mytype) json_nothrow : internal(internalJSONNode::newInternal(mytype)){
JSON_ASSERT((mytype == JSON_NULL) ||
(mytype == JSON_STRING) ||
(mytype == JSON_NUMBER) ||
(mytype == JSON_BOOL) ||
(mytype == JSON_ARRAY) ||
(mytype == JSON_NODE), JSON_TEXT("Not a proper JSON type"));
LIBJSON_CTOR;
}
inline JSONNode::JSONNode(const JSONNode & orig) json_nothrow : internal(orig.internal -> incRef()){
LIBJSON_COPY_CTOR;
}
//this allows a temp node to simply transfer its contents, even with ref counting off
inline JSONNode::JSONNode(bool, JSONNode & orig) json_nothrow : internal(orig.internal){
orig.internal = 0;
LIBJSON_CTOR;
}
inline JSONNode::~JSONNode(void) json_nothrow{
if (internal != 0) decRef();
LIBJSON_DTOR;
}
inline json_index_t JSONNode::size(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> size();
}
inline bool JSONNode::empty(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> empty();
}
inline void JSONNode::clear(void) json_nothrow {
JSON_CHECK_INTERNAL();
if (!empty()){
makeUniqueInternal();
internal -> CHILDREN -> clear();
}
}
inline unsigned char JSONNode::type(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> type();
}
inline json_string JSONNode::name(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> name();
}
inline void JSONNode::set_name(const json_string & newname) json_nothrow{
JSON_CHECK_INTERNAL();
makeUniqueInternal();
internal -> setname(newname);
}
#ifdef JSON_COMMENTS
inline void JSONNode::set_comment(const json_string & newname) json_nothrow{
JSON_CHECK_INTERNAL();
makeUniqueInternal();
internal -> setcomment(newname);
}
inline json_string JSONNode::get_comment(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> getcomment();
}
#endif
//#ifdef JSON_DEPRECATED_FUNCTIONS
inline json_string JSONNode::as_string(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return static_cast<json_string>(*internal);
}
inline json_int_t JSONNode::as_int(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return static_cast<json_int_t>(*internal);
}
inline json_number JSONNode::as_float(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return static_cast<json_number>(*internal);
}
inline bool JSONNode::as_bool(void) const json_nothrow {
JSON_CHECK_INTERNAL();
return static_cast<bool>(*internal);
}
//#endif
#ifdef JSON_BINARY
inline void JSONNode::set_binary(const unsigned char * bin, size_t bytes) json_nothrow{
JSON_CHECK_INTERNAL();
*this = JSONBase64::json_encode64(bin, bytes);
}
inline std::string JSONNode::as_binary(void) const json_nothrow {
JSON_ASSERT_SAFE(type() == JSON_STRING, JSON_TEXT("using as_binary for a non-string type"), return json_global(EMPTY_STD_STRING););
JSON_CHECK_INTERNAL();
return JSONBase64::json_decode64(as_string());
}
#endif
inline JSONNode & JSONNode::operator[](const json_string & name_t) json_nothrow {
JSON_CHECK_INTERNAL();
makeUniqueInternal();
return *(*(internal -> at(name_t)));
}
inline const JSONNode & JSONNode::operator[](const json_string & name_t) const json_nothrow {
JSON_CHECK_INTERNAL();
return *(*(internal -> at(name_t)));
}
#ifdef JSON_LIBRARY
inline void JSONNode::push_back(JSONNode * child) json_nothrow{
#else
inline void JSONNode::push_back(const JSONNode & child) json_nothrow{
#endif
JSON_CHECK_INTERNAL();
makeUniqueInternal();
internal -> push_back(child);
}
inline void JSONNode::reserve(json_index_t siz) json_nothrow{
makeUniqueInternal();
internal -> reserve(siz);
}
inline JSONNode & JSONNode::operator = (const JSONNode & orig) json_nothrow {
JSON_CHECK_INTERNAL();
#ifdef JSON_REF_COUNT
if (internal == orig.internal) return *this; //don't want it accidentally deleting itself
#endif
decRef(); //dereference my current one
internal = orig.internal -> incRef(); //increase reference of original
return *this;
}
#ifndef JSON_LIBRARY
inline JSONNode & JSONNode::operator = (const json_char * val) json_nothrow {
JSON_CHECK_INTERNAL();
*this = json_string(val);
return *this;
}
#endif
#define NODE_SET_TYPED(type)\
inline JSONNode & JSONNode::operator = (type val) json_nothrow {\
LIBJSON_ASSIGNMENT;\
JSON_CHECK_INTERNAL();\
makeUniqueInternal();\
internal -> Set(val);\
return *this;\
}
IMPLEMENT_FOR_ALL_TYPES(NODE_SET_TYPED)
/*
This section is the equality operators
*/
#define NODE_CHECK_EQUALITY(type)\
inline bool JSONNode::operator == (type val) const json_nothrow {\
JSON_CHECK_INTERNAL();\
return internal -> IsEqualToNum<type>(val);\
}
IMPLEMENT_FOR_ALL_NUMBERS(NODE_CHECK_EQUALITY)
inline bool JSONNode::operator == (const json_string & val) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> IsEqualTo(val);
}
#ifndef JSON_LIBRARY
inline bool JSONNode::operator == (const json_char * val) const json_nothrow {
JSON_CHECK_INTERNAL();
return *this == json_string(val);
}
#endif
inline bool JSONNode::operator == (bool val) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> IsEqualTo(val);
}
inline bool JSONNode::operator == (const JSONNode & val) const json_nothrow {
JSON_CHECK_INTERNAL();
return internal -> IsEqualTo(val.internal);
}
/*
This section is the inequality operators
*/
#define NODE_CHECK_INEQUALITY(type)\
inline bool JSONNode::operator != (type val) const json_nothrow {\
JSON_CHECK_INTERNAL();\
return !(*this == val);\
}
IMPLEMENT_FOR_ALL_TYPES(NODE_CHECK_INEQUALITY)
NODE_CHECK_INEQUALITY(const JSONNode &)
#ifndef JSON_LIBRARY
NODE_CHECK_INEQUALITY(const json_char * )
#endif
inline void JSONNode::nullify(void) json_nothrow {
JSON_CHECK_INTERNAL();
makeUniqueInternal();
internal -> Nullify();
}
inline void JSONNode::swap(JSONNode & other) json_nothrow {
JSON_CHECK_INTERNAL();
internalJSONNode * temp = other.internal;
other.internal = internal;
internal = temp;
JSON_CHECK_INTERNAL();
}
inline void JSONNode::decRef(void) json_nothrow { //decrements internal's counter, deletes it if needed
JSON_CHECK_INTERNAL();
#ifdef JSON_REF_COUNT
internal -> decRef();
if (internal -> hasNoReferences()){
internalJSONNode::deleteInternal(internal);
}
#else
internalJSONNode::deleteInternal(internal);
#endif
}
#ifdef JSON_REF_COUNT
inline void JSONNode::makeUniqueInternal() json_nothrow { //makes internal it's own
JSON_CHECK_INTERNAL();
internal = internal -> makeUnique(); //might return itself or a new one that's exactly the same
}
#endif
#ifdef JSON_ITERATORS
inline JSONNode::json_iterator JSONNode::begin(void) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("begin"));
makeUniqueInternal();
return json_iterator(internal -> begin());
}
inline JSONNode::json_iterator JSONNode::end(void) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("end"));
makeUniqueInternal();
return json_iterator(internal -> end());
}
#ifndef JSON_LIBRARY
inline JSONNode::const_iterator JSONNode::begin(void) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("begin"));
return JSONNode::const_iterator(internal -> begin());
}
inline JSONNode::const_iterator JSONNode::end(void) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("end"));
return JSONNode::const_iterator(internal -> end());
}
inline JSONNode::reverse_iterator JSONNode::rbegin(void) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rbegin"));
makeUniqueInternal();
return JSONNode::reverse_iterator(internal -> end() - 1);
}
inline JSONNode::reverse_iterator JSONNode::rend(void) json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rend"));
makeUniqueInternal();
return JSONNode::reverse_iterator(internal -> begin() - 1);
}
inline JSONNode::reverse_const_iterator JSONNode::rbegin(void) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rbegin"));
return JSONNode::reverse_const_iterator(internal -> end() - 1);
}
inline JSONNode::reverse_const_iterator JSONNode::rend(void) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT(type() == JSON_NODE || type() == JSON_ARRAY, json_global(ERROR_NON_ITERATABLE) + JSON_TEXT("rend"));
return JSONNode::reverse_const_iterator(internal -> begin() - 1);
}
inline JSONNode::iterator JSONNode::insert(json_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow {
return insertFFF(pos, _start.it, _end.it);
}
inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const const_iterator & _start, const const_iterator & _end) json_nothrow {
return insertRFF(pos, _start.it, _end.it);
}
inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const iterator & _start, const iterator & _end) json_nothrow {
return insertRFF(pos, _start.it, _end.it);
}
inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow {
return insertRRR(pos, _start.it, _end.it);
}
inline JSONNode::reverse_iterator JSONNode::insert(reverse_iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow {
return insertRRR(pos, _start.it, _end.it);
}
inline JSONNode::iterator JSONNode::insert(json_iterator pos, const reverse_const_iterator & _start, const reverse_const_iterator & _end) json_nothrow {
return insertFRR(pos, _start.it, _end.it);
}
inline JSONNode::iterator JSONNode::insert(iterator pos, const reverse_iterator & _start, const reverse_iterator & _end) json_nothrow {
return insertFRR(pos, _start.it, _end.it);
}
#endif
inline JSONNode::json_iterator JSONNode::insert(json_iterator pos, const json_iterator & _start, const json_iterator & _end) json_nothrow {
return insertFFF(pos, json_iterator_ptr(_start), json_iterator_ptr(_end));
}
#endif
#ifdef JSON_WRITE_PRIORITY
inline json_string JSONNode::write(size_t approxsize) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT("Writing a non-writable node"), return json_global(EMPTY_JSON_STRING););
json_string result;
result.reserve(approxsize);
internal -> Write(0xFFFFFFFF, true, result);
return result;
}
inline json_string JSONNode::write_formatted(size_t approxsize) const json_nothrow {
JSON_CHECK_INTERNAL();
JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSON_TEXT("Writing a non-writable node"), return json_global(EMPTY_JSON_STRING););
json_string result;
result.reserve(approxsize);
internal -> Write(0, true, result);
return result;
}
#endif
#if !defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY)
inline void JSONNode::preparse(void) json_nothrow {
JSON_CHECK_INTERNAL();
internal -> preparse();
}
#endif
#ifdef JSON_DEBUG
#ifndef JSON_LIBRARY
inline JSONNode JSONNode::dump(void) const json_nothrow {
JSON_CHECK_INTERNAL();
JSONNode dumpage(JSON_NODE);
dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("this"), (long)this)));
size_t total = 0;
JSONNode node(internal -> Dump(total));
dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("total bytes used"), total)));
dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("bytes used"), sizeof(JSONNode))));
dumpage.push_back(JSON_NEW(node));
return dumpage;
}
inline JSONNode JSONNode::dump(size_t & totalmemory) json_nothrow {
JSON_CHECK_INTERNAL();
JSONNode dumpage(JSON_NODE);
dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("this"), (long)this)));
dumpage.push_back(JSON_NEW(JSONNode(JSON_TEXT("bytes used"), sizeof(JSONNode))));
dumpage.push_back(JSON_NEW(internal -> Dump(totalmemory)));
return dumpage;
}
#endif
#endif
#ifdef JSON_LESS_MEMORY
#ifdef __GNUC__
#pragma pack(pop)
#elif _MSC_VER
#pragma pack(pop, JSONNode_pack)
#endif
#endif
#endif

View file

@ -0,0 +1,203 @@
#include "JSONNode.h"
#include "JSONGlobals.h"
#ifdef JSON_MUTEX_CALLBACKS
json_mutex_callback_t json_lock_callback = 0;
json_mutex_callback_t json_unlock_callback = 0;
void * global_mutex = 0;
void * manager_mutex = 0;
struct AutoLock {
public:
LIBJSON_OBJECT(AutoLock);
AutoLock(void) json_nothrow {
LIBJSON_CTOR;
json_lock_callback(manager_mutex);
}
~AutoLock(void) json_nothrow {
LIBJSON_DTOR;
json_unlock_callback(manager_mutex);
}
private:
AutoLock(const AutoLock &);
AutoLock & operator = (const AutoLock &);
};
#ifdef JSON_MUTEX_MANAGE
json_mutex_callback_t json_destroy = 0;
//make sure that the global mutex is taken care of too
struct auto_global {
public:
LIBJSON_OBJECT(auto_global;)
auto_global(void) json_nothrow { LIBJSON_CTOR; }
~auto_global(void) json_nothrow {
LIBJSON_DTOR;
if (global_mutex){
JSON_ASSERT_SAFE(json_destroy != 0, JSON_TEXT("No json_destroy in mutex managed mode"), return;);
json_destroy(global_mutex);
}
}
private:
auto_global(const auto_global &);
auto_global & operator = (const auto_global &);
};
auto_global cleanupGlobal;
#endif
void JSONNode::register_mutex_callbacks(json_mutex_callback_t lock, json_mutex_callback_t unlock, void * manager_lock) json_nothrow {
json_lock_callback = lock;
json_unlock_callback = unlock;
manager_mutex = manager_lock;
}
void JSONNode::set_global_mutex(void * mutex) json_nothrow {
global_mutex = mutex;
}
void JSONNode::set_mutex(void * mutex) json_nothrow {
makeUniqueInternal();
internal -> _set_mutex(mutex);
}
void * JSONNode::getThisLock(JSONNode * pthis) json_nothrow {
if (pthis -> internal -> mylock != 0){
return pthis -> internal -> mylock;
}
JSON_ASSERT(global_mutex != 0, JSON_TEXT("No global_mutex")); //this is safe, because it's just goingi to return 0 anyway
return global_mutex;
}
void JSONNode::lock(int thread) json_nothrow {
JSON_ASSERT_SAFE(json_lock_callback != 0, JSON_TEXT("No locking callback"), return;);
AutoLock lockControl;
//first, figure out what needs to be locked
void * thislock = getThisLock(this);
#ifdef JSON_SAFE
if (json_unlikely(thislock == 0)) return;
#endif
//make sure that the same thread isn't locking it more than once (possible due to complex ref counting)
JSON_MAP(int, JSON_MAP(void *, unsigned int) )::iterator it = json_global(THREAD_LOCKS).find(thread);
if (it == json_global(THREAD_LOCKS).end()){
JSON_MAP(void *, unsigned int) newthread;
newthread[thislock] = 1;
json_global(THREAD_LOCKS).insert(std::pair<int, JSON_MAP(void *, unsigned int) >(thread, newthread));
} else { //this thread already has some things locked, check if the current mutex is
JSON_MAP(void *, unsigned int) & newthread = it -> second;
JSON_MAP(void *, unsigned int)::iterator locker(newthread.find(thislock));
if (locker == newthread.end()){ //current mutex is not locked, set it to locked
newthread.insert(std::pair<void *, unsigned int>(thislock, 1));
} else { //it's already locked, don't relock it
++(locker -> second);
return; //don't try to relock, it will deadlock the program
}
}
//if I need to, lock it
json_lock_callback(thislock);
}
void JSONNode::unlock(int thread) json_nothrow{
JSON_ASSERT_SAFE(json_unlock_callback != 0, JSON_TEXT("No unlocking callback"), return;);
AutoLock lockControl;
//first, figure out what needs to be locked
void * thislock = getThisLock(this);
#ifdef JSON_SAFE
if (thislock == 0) return;
#endif
//get it out of the map
JSON_MAP(int, JSON_MAP(void *, unsigned int) )::iterator it = json_global(THREAD_LOCKS).find(thread);
JSON_ASSERT_SAFE(it != json_global(THREAD_LOCKS).end(), JSON_TEXT("thread unlocking something it didn't lock"), return;);
//get the mutex out of the thread
JSON_MAP(void *, unsigned int) & newthread = it -> second;
JSON_MAP(void *, unsigned int)::iterator locker = newthread.find(thislock);
JSON_ASSERT_SAFE(locker != newthread.end(), JSON_TEXT("thread unlocking mutex it didn't lock"), return;);
//unlock it
if (--(locker -> second)) return; //other nodes is this same thread still have a lock on it
//if I need to, unlock it
newthread.erase(locker);
json_unlock_callback(thislock);
}
#ifdef JSON_MUTEX_MANAGE
void JSONNode::register_mutex_destructor(json_mutex_callback_t destroy) json_nothrow {
json_destroy = destroy;
}
#endif
void internalJSONNode::_set_mutex(void * mutex, bool unset) json_nothrow {
if (unset) _unset_mutex(); //for reference counting
mylock = mutex;
if (mutex != 0){
#ifdef JSON_MUTEX_MANAGE
JSON_MAP(void *, unsigned int)::iterator it = json_global(MUTEX_MANAGER).find(mutex);
if (it == json_global(MUTEX_MANAGER).end()){
json_global(MUTEX_MANAGER).insert(std::pair<void *, unsigned int>(mutex, 1));
} else {
++it -> second;
}
#endif
if (isContainer()){
json_foreach(CHILDREN, myrunner){
(*myrunner) -> set_mutex(mutex);
}
}
}
}
void internalJSONNode::_unset_mutex(void) json_nothrow {
#ifdef JSON_MUTEX_MANAGE
if (mylock != 0){
JSON_MAP(void *, unsigned int)::iterator it = json_global(MUTEX_MANAGER).find(mylock);
JSON_ASSERT_SAFE(it != json_global(MUTEX_MANAGER).end(), JSON_TEXT("Mutex not managed"), return;);
--it -> second;
if (it -> second == 0){
JSON_ASSERT_SAFE(json_destroy, JSON_TEXT("You didn't register a destructor for mutexes"), return;);
json_global(MUTEX_MANAGER).erase(it);
}
}
#endif
}
#ifdef JSON_DEBUG
#ifndef JSON_LIBRARY
JSONNode internalJSONNode::DumpMutex(void) const json_nothrow {
JSONNode mut(JSON_NODE);
mut.set_name(JSON_TEXT("mylock"));
#ifdef JSON_MUTEX_MANAGE
if (mylock != 0){
mut.push_back(JSON_NEW(JSONNode(JSON_TEXT("this"), (long)mylock)));
JSON_MAP(void *, unsigned int)::iterator it = json_global(MUTEX_MANAGER).find(mylock);
if (it == json_global(MUTEX_MANAGER).end()){
mut.push_back(JSON_NEW(JSONNode(JSON_TEXT("references"), JSON_TEXT("error"))));
} else {
mut.push_back(JSON_NEW(JSONNode(JSON_TEXT("references"), it -> second)));
}
} else {
mut = (long)mylock;
}
#else
mut = (long)mylock;
#endif
return mut;
}
#endif
#endif
#else
#ifdef JSON_MUTEX_MANAGE
#error You can not have JSON_MUTEX_MANAGE on without JSON_MUTEX_CALLBACKS
#endif
#endif

View file

@ -0,0 +1,499 @@
/*
* JSONPreparse.cpp
* TestSuite
*
* Created by Wallace on 4/13/11.
* Copyright 2011 Streamwide. All rights reserved.
*
*/
#include "JSONPreparse.h"
#if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY))
#ifdef JSON_COMMENTS
json_string extractComment(json_string::const_iterator & ptr, json_string::const_iterator & end);
json_string extractComment(json_string::const_iterator & ptr, json_string::const_iterator & end){
json_string::const_iterator start;
json_string result;
looplabel:
if (json_unlikely(((ptr != end) && (*ptr == JSON_TEMP_COMMENT_IDENTIFIER)))){
start = ++ptr;
for(; (ptr != end) && (*(ptr) != JSON_TEMP_COMMENT_IDENTIFIER); ++ptr){}
result += json_string(start, ptr);
if (json_unlikely(ptr == end)) return result;
++ptr;
if (json_unlikely(((ptr != end) && (*ptr == JSON_TEMP_COMMENT_IDENTIFIER)))){
result += JSON_TEXT('\n');
goto looplabel;
}
}
return result;
}
#define GET_COMMENT(x, y, name) json_string name = extractComment(x, y)
#define RETURN_NODE(node, name){\
JSONNode res = node;\
res.set_comment(name);\
return res;\
}
#define RETURN_NODE_NOCOPY(node, name){\
node.set_comment(name);\
return node;\
}
#define SET_COMMENT(node, name) node.set_comment(name)
#define COMMENT_ARG(name) ,name
#else
#define GET_COMMENT(x, y, name) (void)0
#define RETURN_NODE(node, name) return node
#define RETURN_NODE_NOCOPY(node, name) return node
#define SET_COMMENT(node, name) (void)0
#define COMMENT_ARG(name)
#endif
inline bool isHex(json_char c) json_pure;
inline bool isHex(json_char c) json_nothrow {
return (((c >= JSON_TEXT('0')) && (c <= JSON_TEXT('9'))) ||
((c >= JSON_TEXT('A')) && (c <= JSON_TEXT('F'))) ||
((c >= JSON_TEXT('a')) && (c <= JSON_TEXT('f'))));
}
#ifdef JSON_STRICT
#include "NumberToString.h"
#endif
json_number FetchNumber(const json_string & _string) json_nothrow;
json_number FetchNumber(const json_string & _string) json_nothrow {
#ifdef JSON_STRICT
return NumberToString::_atof(_string.c_str());
#else
#ifdef JSON_UNICODE
const size_t len = _string.length();
#if defined(_MSC_VER) && defined(JSON_SAFE)
const size_t bytes = (len * (sizeof(json_char) / sizeof(char))) + 1;
json_auto<char> temp(bytes);
size_t res;
errno_t err = std::wcstombs_s(&res, temp.ptr, bytes, _string.c_str(), len);
if (err != 0){
return (json_number)0.0;
}
#elif defined(JSON_SAFE)
const size_t bytes = (len * (sizeof(json_char) / sizeof(char))) + 1;
json_auto<char> temp(bytes);
size_t res = std::wcstombs(temp.ptr, _string.c_str(), len);
if (res == (size_t)-1){ //-1 is error code for this function
return (json_number)0.0;
}
#else
json_auto<char> temp(len + 1);
size_t res = std::wcstombs(temp.ptr, _string.c_str(), len);
#endif
temp.ptr[res] = JSON_TEXT('\0');
return (json_number)std::atof(temp.ptr);
#else
return (json_number)std::atof(_string.c_str());
#endif
#endif
}
JSONNode JSONPreparse::isValidNumber(json_string::const_iterator & ptr, json_string::const_iterator & end){
//ptr points at the first character in the number
//ptr will end up past the last character
json_string::const_iterator start = ptr;
bool decimal = false;
bool scientific = false;
//first letter is weird
switch(*ptr){
#ifndef JSON_STRICT
case JSON_TEXT('.'):
decimal = true;
break;
case JSON_TEXT('+'):
#endif
case JSON_TEXT('-'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
case JSON_TEXT('8'):
case JSON_TEXT('9'):
break;
case JSON_TEXT('0'):
++ptr;
switch(*ptr){
case JSON_TEXT('.'):
decimal = true;
break;
case JSON_TEXT('e'):
case JSON_TEXT('E'):
scientific = true;
++ptr;
if (ptr == end) throw false;
switch(*ptr){
case JSON_TEXT('-'):
case JSON_TEXT('+'):
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
case JSON_TEXT('8'):
case JSON_TEXT('9'):
break;
default:
throw false;
}
break;
#ifndef JSON_STRICT
case JSON_TEXT('x'):
while(isHex(*++ptr)){};
return JSONNode(json_global(EMPTY_JSON_STRING), FetchNumber(json_string(start, end - 1)));
#ifdef JSON_OCTAL
#ifdef __GNUC__
case JSON_TEXT('0') ... JSON_TEXT('7'): //octal
#else
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
#endif
while((*++ptr >= JSON_TEXT('0')) && (*ptr <= JSON_TEXT('7'))){};
if ((*ptr != JSON_TEXT('8')) && (*ptr != JSON_TEXT('9'))){
return JSONNode(json_global(EMPTY_JSON_STRING), FetchNumber(json_string(start, ptr - 1)));
}
throw false;
case JSON_TEXT('8'):
case JSON_TEXT('9'):
break;
#else
#ifdef __GNUC__
case JSON_TEXT('0') ... JSON_TEXT('9'):
#else
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
case JSON_TEXT('8'):
case JSON_TEXT('9'):
#endif
break;
#endif
#else
#ifdef __GNUC__
case JSON_TEXT('0') ... JSON_TEXT('9'):
#else
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
case JSON_TEXT('8'):
case JSON_TEXT('9'):
#endif
break;
#endif
default: //just a 0
return JSONNode(json_global(EMPTY_JSON_STRING), FetchNumber(json_string(start, ptr - 1)));;
}
break;
default:
throw false;
}
++ptr;
//next digits
while (true){
switch(*ptr){
case JSON_TEXT('.'):
if (json_unlikely(decimal)) throw false; //multiple decimals
if (json_unlikely(scientific)) throw false;
decimal = true;
break;
case JSON_TEXT('e'):
case JSON_TEXT('E'):
if (json_likely(scientific)) throw false;
scientific = true;
++ptr;
switch(*ptr){
case JSON_TEXT('-'):
case JSON_TEXT('+'):
#ifdef __GNUC__
case JSON_TEXT('0') ... JSON_TEXT('9'):
#else
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
case JSON_TEXT('8'):
case JSON_TEXT('9'):
#endif
break;
default:
throw false;
}
break;
#ifdef __GNUC__
case JSON_TEXT('0') ... JSON_TEXT('9'):
#else
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
case JSON_TEXT('8'):
case JSON_TEXT('9'):
#endif
break;
default:
return JSONNode(json_global(EMPTY_JSON_STRING), FetchNumber(json_string(start, ptr)));;
}
++ptr;
}
throw false;
}
#ifndef JSON_STRICT
#define LETTERCASE(x, y)\
case JSON_TEXT(x):\
case JSON_TEXT(y)
#define LETTERCHECK(x, y)\
if (json_unlikely((*++ptr != JSON_TEXT(x)) && (*ptr != JSON_TEXT(y)))) throw false
#else
#define LETTERCASE(x, y)\
case JSON_TEXT(x)
#define LETTERCHECK(x, y)\
if (json_unlikely(*++ptr != JSON_TEXT(x))) throw false
#endif
JSONNode JSONPreparse::isValidMember(json_string::const_iterator & ptr, json_string::const_iterator & end){
//ptr is on the first character of the member
//ptr will end up immediately after the last character in the member
if (ptr == end) throw false;
switch(*ptr){
case JSON_TEXT('\"'):{
return JSONNode::stringType(isValidString(++ptr, end));
}
case JSON_TEXT('{'):
return isValidObject(++ptr, end);
case JSON_TEXT('['):
return isValidArray(++ptr, end);
LETTERCASE('t', 'T'):
LETTERCHECK('r', 'R');
LETTERCHECK('u', 'U');
LETTERCHECK('e', 'E');
++ptr;
return JSONNode(json_global(EMPTY_JSON_STRING), true);
LETTERCASE('f', 'F'):
LETTERCHECK('a', 'A');
LETTERCHECK('l', 'L');
LETTERCHECK('s', 'S');
LETTERCHECK('e', 'E');
++ptr;
return JSONNode(json_global(EMPTY_JSON_STRING), false);
LETTERCASE('n', 'N'):
LETTERCHECK('u', 'U');
LETTERCHECK('l', 'L');
LETTERCHECK('l', 'L');
++ptr;
return JSONNode(JSON_NULL);
#ifndef JSON_STRICT
case JSON_TEXT('}'): //null in libjson
case JSON_TEXT(']'): //null in libjson
case JSON_TEXT(','): //null in libjson
return JSONNode(JSON_NULL);
#endif
}
//a number
return isValidNumber(ptr, end);
}
json_string JSONPreparse::isValidString(json_string::const_iterator & ptr, json_string::const_iterator & end){
//ptr is pointing to the first character after the quote
//ptr will end up behind the closing "
json_string::const_iterator start = ptr;
while(ptr != end){
switch(*ptr){
case JSON_TEXT('\\'):
switch(*(++ptr)){
case JSON_TEXT('\"'):
case JSON_TEXT('\\'):
case JSON_TEXT('/'):
case JSON_TEXT('b'):
case JSON_TEXT('f'):
case JSON_TEXT('n'):
case JSON_TEXT('r'):
case JSON_TEXT('t'):
break;
case JSON_TEXT('u'):
if (json_unlikely(!isHex(*++ptr))) throw false;
if (json_unlikely(!isHex(*++ptr))) throw false;
//fallthrough to \x
#ifndef JSON_STRICT
case JSON_TEXT('x'): //hex
#endif
if (json_unlikely(!isHex(*++ptr))) throw false;
if (json_unlikely(!isHex(*++ptr))) throw false;
break;
#ifndef JSON_OCTAL
#ifdef __GNUC__
case JSON_TEXT('0') ... JSON_TEXT('7'): //octal
#else
case JSON_TEXT('0'):
case JSON_TEXT('1'):
case JSON_TEXT('2'):
case JSON_TEXT('3'):
case JSON_TEXT('4'):
case JSON_TEXT('5'):
case JSON_TEXT('6'):
case JSON_TEXT('7'):
#endif
if (json_unlikely((*++ptr < JSON_TEXT('0')) || (*ptr > JSON_TEXT('7')))) throw false;
if (json_unlikely((*++ptr < JSON_TEXT('0')) || (*ptr > JSON_TEXT('7')))) throw false;
break;
#endif
default:
throw false;
}
break;
case JSON_TEXT('\"'):
return json_string(start, ptr++);
}
++ptr;
}
throw false;
}
void JSONPreparse::isValidNamedObject(json_string::const_iterator & ptr, json_string::const_iterator & end, JSONNode & parent COMMENT_PARAM(comment)) {
//ptr should be right before the string name
{
json_string _name = isValidString(++ptr, end);
if (json_unlikely(*ptr++ != JSON_TEXT(':'))) throw false;
JSONNode res = isValidMember(ptr, end);
res.set_name_(_name);
SET_COMMENT(res, comment);
#ifdef JSON_LIBRARY
parent.push_back(&res);
#else
parent.push_back(res);
#endif
}
if (ptr == end) throw false;
switch(*ptr){
case JSON_TEXT(','):
++ptr;
{
GET_COMMENT(ptr, end, nextcomment);
isValidNamedObject(ptr, end, parent COMMENT_ARG(nextcomment)); //will handle all of them
}
return;
case JSON_TEXT('}'):
++ptr;
return;
default:
throw false;
}
}
JSONNode JSONPreparse::isValidObject(json_string::const_iterator & ptr, json_string::const_iterator & end) {
//ptr should currently be pointing past the {, so this must be the start of a name, or the closing }
//ptr will end up past the last }
JSONNode res(JSON_NODE);
GET_COMMENT(ptr, end, comment);
switch(*ptr){
case JSON_TEXT('\"'):
isValidNamedObject(ptr, end, res COMMENT_ARG(comment));
return res;
case JSON_TEXT('}'):
++ptr;
return res;
default:
throw false;
}
}
void pushArrayMember(JSONNode & res, json_string::const_iterator & ptr, json_string::const_iterator & end);
void pushArrayMember(JSONNode & res, json_string::const_iterator & ptr, json_string::const_iterator & end){
GET_COMMENT(ptr, end, comment);
JSONNode temp = JSONPreparse::isValidMember(ptr, end);
SET_COMMENT(temp, comment);
#ifdef JSON_LIBRARY
res.push_back(&temp);
#else
res.push_back(temp);
#endif
}
JSONNode JSONPreparse::isValidArray(json_string::const_iterator & ptr, json_string::const_iterator & end) {
//ptr should currently be pointing past the [, so this must be the start of a member, or the closing ]
//ptr will end up past the last ]
JSONNode res(JSON_ARRAY);
do{
switch(*ptr){
case JSON_TEXT(']'):
++ptr;
return res;
default:
pushArrayMember(res, ptr, end);
switch(*ptr){
case JSON_TEXT(','):
break;
case JSON_TEXT(']'):
++ptr;
return res;
default:
throw false;
}
break;
}
} while (++ptr != end);
throw false;
}
JSONNode JSONPreparse::isValidRoot(const json_string & json) json_throws(std::invalid_argument) {
json_string::const_iterator it = json.begin();
json_string::const_iterator end = json.end();
try {
GET_COMMENT(it, end, comment);
switch(*it){
case JSON_TEXT('{'):
RETURN_NODE(isValidObject(++it, end), comment);
case JSON_TEXT('['):
RETURN_NODE(isValidArray(++it, end), comment);
}
} catch (...){}
#ifndef JSON_NO_EXCEPTIONS
throw std::invalid_argument(json_global(EMPTY_STD_STRING));
#else
return JSONNode(JSON_NULL);
#endif
}
#endif

View file

@ -0,0 +1,28 @@
#ifndef LIBJSON_GUARD_PREPARSE_H
#define LIBJSON_GUARD_PREPARSE_H
#include "JSONDebug.h"
#include "JSONNode.h"
#if (defined(JSON_PREPARSE) && defined(JSON_READ_PRIORITY))
#ifdef JSON_COMMENTS
#define COMMENT_PARAM(name) ,const json_string & name
#else
#define COMMENT_PARAM(name)
#endif
class JSONPreparse {
public:
static JSONNode isValidNumber(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority;
static JSONNode isValidMember(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority;
static json_string isValidString(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority;
static void isValidNamedObject(json_string::const_iterator & ptr, json_string::const_iterator & end, JSONNode & parent COMMENT_PARAM(comment)) json_read_priority;
static JSONNode isValidObject(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority;
static JSONNode isValidArray(json_string::const_iterator & ptr, json_string::const_iterator & end) json_read_priority;
static JSONNode isValidRoot(const json_string & json) json_throws(std::invalid_argument) json_read_priority;
};
#endif
#endif

View file

@ -0,0 +1,308 @@
#ifndef JSON_SHARED_STRING_H
#define JSON_SHARED_STRING_H
/*
* This class allows json objects to share string
* Since libjson is a parser, it does a lot of substrings, but since
* a string with all of the information already exists, those substrings
* can be infered by an offset and length and a pointer to the master
* string
*
* EXPERIMENTAL, Not used yet
*/
#include "JSONDebug.h"
#include "JSONGlobals.h"
#include "JSONMemory.h"
/*
mallocs: 3351
frees: 3351
reallocs: 3
bytes: 298751 (291 KB)
max bytes at once: 3624 (3 KB)
avg bytes at once: 970 (0 KB)
*/
#ifdef JSON_LESS_MEMORY
#ifdef __GNUC__
#pragma pack(push, 1)
#elif _MSC_VER
#pragma pack(push, json_shared_string_pack, 1)
#endif
#endif
class json_shared_string {
public:
struct iterator;
struct const_iterator {
const_iterator(const json_char * p, const json_shared_string * pa) : parent(pa), it(p){}
inline const_iterator& operator ++(void) json_nothrow { ++it; return *this; }
inline const_iterator& operator --(void) json_nothrow { --it; return *this; }
inline const_iterator& operator +=(long i) json_nothrow { it += i; return *this; }
inline const_iterator& operator -=(long i) json_nothrow { it -= i; return *this; }
inline const_iterator operator ++(int) json_nothrow {
const_iterator result(*this);
++it;
return result;
}
inline const_iterator operator --(int) json_nothrow {
const_iterator result(*this);
--it;
return result;
}
inline const_iterator operator +(long i) const json_nothrow {
const_iterator result(*this);
result.it += i;
return result;
}
inline const_iterator operator -(long i) const json_nothrow {
const_iterator result(*this);
result.it -= i;
return result;
}
inline const json_char & operator [](size_t pos) const json_nothrow { return it[pos]; };
inline const json_char & operator *(void) const json_nothrow { return *it; }
inline const json_char * operator ->(void) const json_nothrow { return it; }
inline bool operator == (const const_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const const_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const const_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const const_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const const_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const const_iterator & other) const json_nothrow { return it <= other.it; }
inline bool operator == (const iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const iterator & other) const json_nothrow { return it <= other.it; }
inline const_iterator & operator =(const const_iterator & orig) json_nothrow { it = orig.it; return *this; }
const_iterator (const const_iterator & orig) json_nothrow : it(orig.it) {}
private:
const json_shared_string * parent;
const json_char * it;
friend class json_shared_string;
friend struct iterator;
};
struct iterator {
iterator(const json_char * p, const json_shared_string * pa) : parent(pa), it(p){}
inline iterator& operator ++(void) json_nothrow { ++it; return *this; }
inline iterator& operator --(void) json_nothrow { --it; return *this; }
inline iterator& operator +=(long i) json_nothrow { it += i; return *this; }
inline iterator& operator -=(long i) json_nothrow { it -= i; return *this; }
inline iterator operator ++(int) json_nothrow {
iterator result(*this);
++it;
return result;
}
inline iterator operator --(int) json_nothrow {
iterator result(*this);
--it;
return result;
}
inline iterator operator +(long i) const json_nothrow {
iterator result(*this);
result.it += i;
return result;
}
inline iterator operator -(long i) const json_nothrow {
iterator result(*this);
result.it -= i;
return result;
}
inline const json_char & operator [](size_t pos) const json_nothrow { return it[pos]; };
inline const json_char & operator *(void) const json_nothrow { return *it; }
inline const json_char * operator ->(void) const json_nothrow { return it; }
inline bool operator == (const const_iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const const_iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const const_iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const const_iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const const_iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const const_iterator & other) const json_nothrow { return it <= other.it; }
inline bool operator == (const iterator & other) const json_nothrow { return it == other.it; }
inline bool operator != (const iterator & other) const json_nothrow { return it != other.it; }
inline bool operator > (const iterator & other) const json_nothrow { return it > other.it; }
inline bool operator >= (const iterator & other) const json_nothrow { return it >= other.it; }
inline bool operator < (const iterator & other) const json_nothrow { return it < other.it; }
inline bool operator <= (const iterator & other) const json_nothrow { return it <= other.it; }
inline iterator & operator =(const iterator & orig) json_nothrow { it = orig.it; return *this; }
iterator (const iterator & orig) json_nothrow : it(orig.it) {}
private:
const json_shared_string * parent;
const json_char * it;
friend class json_shared_string;
friend struct const_iterator;
};
inline json_shared_string::iterator begin(void){
iterator res = iterator(data(), this);
return res;
}
inline json_shared_string::iterator end(void){
iterator res = iterator(data() + len, this);
return res;
}
inline json_shared_string::const_iterator begin(void) const {
const_iterator res = const_iterator(data(), this);
return res;
}
inline json_shared_string::const_iterator end(void) const {
const_iterator res = const_iterator(data() + len, this);
return res;
}
inline json_string::iterator std_begin(void){
return _str -> mystring.begin() + offset;
}
inline json_string::iterator std_end(void){
return std_begin() + len;
}
inline json_string::const_iterator std_begin(void) const{
return _str -> mystring.begin() + offset;
}
inline json_string::const_iterator std_end(void) const{
return std_begin() + len;
}
inline json_shared_string(void) : offset(0), len(0), _str(new(json_malloc<json_shared_string_internal>(1)) json_shared_string_internal(json_global(EMPTY_JSON_STRING))) {}
inline json_shared_string(const json_string & str) : offset(0), len(str.length()), _str(new(json_malloc<json_shared_string_internal>(1)) json_shared_string_internal(str)) {}
inline json_shared_string(const json_shared_string & str, size_t _offset, size_t _len) : _str(str._str), offset(str.offset + _offset), len(_len) {
++_str -> refCount;
}
inline json_shared_string(const json_shared_string & str, size_t _offset) : _str(str._str), offset(str.offset + _offset), len(str.len - _offset) {
++_str -> refCount;
}
inline json_shared_string(const iterator & s, const iterator & e) : _str(s.parent -> _str), offset(s.it - s.parent -> _str -> mystring.data()), len(e.it - s.it){
++_str -> refCount;
}
inline ~json_shared_string(void){
deref();
}
inline bool empty(void) const { return len == 0; }
size_t find(json_char ch, size_t pos = 0) const {
if (_str -> refCount == 1) return _str -> mystring.find(ch, pos);
json_string::const_iterator e = std_end();
for(json_string::const_iterator b = std_begin() + pos; b != e; ++b){
if (*b == ch) return b - std_begin();
}
return json_string::npos;
}
inline json_char & operator[] (size_t loc){
return _str -> mystring[loc + offset];
}
inline json_char operator[] (size_t loc) const {
return _str -> mystring[loc + offset];
}
inline void clear(){ len = 0; }
inline size_t length() const { return len; }
inline const json_char * c_str() const { return toString().c_str(); }
inline const json_char * data() const { return _str -> mystring.data() + offset; }
inline bool operator != (const json_shared_string & other) const {
if ((other._str == _str) && (other.len == len) && (other.offset == offset)) return false;
return other.toString() != toString();
}
inline bool operator == (const json_shared_string & other) const {
if ((other._str == _str) && (other.len == len) && (other.offset == offset)) return true;
return other.toString() == toString();
}
inline bool operator == (const json_string & other) const {
return other == toString();
}
json_string & toString(void) const {
//gonna have to do a real substring now anyway, so do it completely
if (_str -> refCount == 1){
if (offset || len != _str -> mystring.length()){
_str -> mystring = json_string(std_begin(), std_end());
}
} else if (offset || len != _str -> mystring.length()){
--_str -> refCount; //dont use deref because I know its not going to be deleted
_str = new(json_malloc<json_shared_string_internal>(1)) json_shared_string_internal(json_string(std_begin(), std_end()));
}
offset = 0;
return _str -> mystring;
}
inline void assign(const json_shared_string & other, size_t _offset, size_t _len){
if (other._str != _str){
deref();
_str = other._str;
}
++_str -> refCount;
offset = other.offset + _offset;
len = _len;
}
json_shared_string(const json_shared_string & other) : _str(other._str), offset(other.offset), len(other.len){
++_str -> refCount;
}
json_shared_string & operator =(const json_shared_string & other){
if (other._str != _str){
deref();
_str = other._str;
++_str -> refCount;
}
offset = other.offset;
len = other.len;
return *this;
}
json_shared_string & operator += (const json_char c){
toString() += c;
++len;
return *this;
}
//when doing a plus equal of another string, see if it shares the string and starts where this one left off, in which case just increase len
JSON_PRIVATE
struct json_shared_string_internal {
inline json_shared_string_internal(const json_string & _mystring) : mystring(_mystring), refCount(1) {}
json_string mystring;
size_t refCount PACKED(20);
};
inline void deref(void){
if (--_str -> refCount == 0){
_str -> ~json_shared_string_internal();
libjson_free<json_shared_string_internal>(_str);
}
}
mutable json_shared_string_internal * _str;
mutable size_t offset PACKED(20);
mutable size_t len PACKED(20);
};
#ifdef JSON_LESS_MEMORY
#ifdef __GNUC__
#pragma pack(pop)
#elif _MSC_VER
#pragma pack(pop, json_shared_string_pack,)
#endif
#endif
#endif

View file

@ -0,0 +1,23 @@
#ifndef JSONSINGLETON_H
#define JSONSINGLETON_H
template <typename T> class JSONSingleton {
public:
static inline T get(void){
return get_singleton() -> ptr;
}
static inline void set(T p){
get_singleton() -> ptr = p;
}
private:
inline JSONSingleton() : ptr(NULL) { }
JSONSingleton(const JSONSingleton<T> &);
JSONSingleton<T> operator = (const JSONSingleton<T> &);
static inline JSONSingleton<T> * get_singleton(void){
static JSONSingleton<T> instance;
return &instance;
}
T ptr;
};
#endif

Some files were not shown because too many files have changed in this diff Show more