Commit 3b6a44d8 authored by mathieu _alkama_ m's avatar mathieu _alkama_ m Committed by Gargaj
Browse files

Update other dependancies

parent 3e79be29
# JSON++
[![Build Status](https://travis-ci.org/hjiang/jsonxx.svg?branch=master)](https://travis-ci.org/hjiang/jsonxx)
## Introduction
JSON++ is a light-weight JSON parser, writer and reader written in C++.
JSON++ can also convert JSON documents into lossless XML documents.
## Contributors
* http://github.com/hjiang
* http://github.com/elanthis
* http://github.com/r-lyeh
If you've made substantial contribution, please add your link here.
## Why another JSON parser?
Perhaps because web service clients are usually written in dynamic languages these days, none of the existing C++ JSON parsers fitted my needs very well, so I wrote one that I used in another project. My goals for JSON++ were:
* Efficient in both memory and speed.
* No third party dependencies. JSON++ only depends on the standard C++ library.
* Cross platform.
* Robust.
* Small and convenient API. Most of the time, you only need to call one function and two function templates.
* Easy to integrate. JSON++ only has one source file and one header file. Just compile the source file and link with your program.
* Able to construct documents dynamically.
* JSON writer: write documents in JSON format.
Other contributors have sinced added more functionalities:
* XML writer: convert documents to JSONx format. See http://goo.gl/I3cxs for details.
* XML writer: convert documents to JXML format. See https://github.com/r-lyeh/JXML for details.
* XML writer: convert documents to JXMLex format. See https://github.com/r-lyeh/JXMLex for details.
* XML writer: convert documents to tagged XML format. See https://github.com/hjiang/jsonxx/issues/12 for details.
## Compiler version
You need a modern C++ compiler. For older compilers, please try [legacy branch](https://github.com/hjiang/jsonxx/tree/legacy).
## Configuration
### Strict/permissive parsing
JSONxx can parse JSON documents both in strict or permissive mode.
When `jsonxx::Settings::Parser` is set to `Strict`, JSONxx parser will accept:
* Fully conformant JSON documents *only*.
When `jsonxx::Settings::Parser` is set to `Permissive`, JSONxx parser will accept:
* Fully conformant JSON documents
* Ending commas in arrays and objects: `{ "array": [0,1,2,], }`
* Single quoted strings: `['hello', "world"]`
* C++ style comments: `{ "width": 320, "height": 240 } //Picture details`
Default value is `Permissive`.
When `jsonxx::Settings::UnquotedKeys` is set to `Enabled`, JSONxx parser will accept:
* Unquoted keys: `{name: "world"}`
Default value is `Disabled`.
### Assertions
JSONxx uses internally `JSONXX_ASSERT(...)` macro that works both in debug and release mode. Set `jsonxx::Settings::Assertions` value to `Disabled` to disable assertions.
Default value is `Enabled`.
## Usage
The following snippets are from one of the unit tests. They are quite self-descriptive.
~~~C++
using namespace std;
using namespace jsonxx;
string teststr(
"{"
" \"foo\" : 1,"
" \"bar\" : false,"
" \"person\" : {\"name\" : \"GWB\", \"age\" : 60,},"
" \"data\": [\"abcd\", 42],"
"}"
);
// Parse string or stream
Object o;
assert(o.parse(teststr));
// Validation. Checking for JSON types and values as well
assert(1 == o.get<Number>("foo"));
assert(o.has<Boolean>("bar"));
assert(o.has<Object>("person"));
assert(o.get<Object>("person").has<Number>("age"));
assert(!o.get<Object>("person").has<Boolean>("old"));
assert(o.get<Object>("person").get<Boolean>("old", false));
assert(o.has<Array>("data"));
assert(o.get<Array>("data").get<Number>(1) == 42);
assert(o.get<Array>("data").get<String>(0) == "abcd");
assert(o.get<Array>("data").get<String>(2, "hello") == "hello");
assert(!o.has<Number>("data"));
cout << o.json() << endl; // JSON output
cout << o.xml(JSONx) << endl; // JSON to XML conversion (JSONx subtype)
cout << o.xml(JXML) << endl; // JSON to XML conversion (JXML subtype)
cout << o.xml(JXMLex) << endl; // JSON to XML conversion (JXMLex subtype)
~~~
~~~C++
// Generate JSON document dynamically
using namespace std;
using namespace jsonxx;
Array a;
a << 123;
a << "hello world";
a << 3.1415;
a << 99.95f;
a << 'h';
a << Object("key", "value");
Object o;
o << "key1" << "value";
o << "key2" << 123;
o << "key3" << a;
cout << o.json() << endl;
~~~
## To do
* Custom JSON comments (C style /**/) when permissive parsing is enabled.
......@@ -77,7 +77,7 @@ bool match(const char* pattern, std::istream& input) {
bool parse_string(std::istream& input, String& value) {
char ch = '\0', delimiter = '"';
if (!match("\"", input)) {
if (Parser == Strict) {
if (parser_is_strict()) {
return false;
}
delimiter = '\'';
......@@ -121,7 +121,7 @@ bool parse_string(std::istream& input, String& value) {
ss << std::hex << ch;
}
if( input.good() && (ss >> i) )
value.push_back(i);
value.push_back(static_cast<char>(i));
}
break;
default:
......@@ -168,7 +168,7 @@ bool parse_identifier(std::istream& input, String& value) {
(ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9')) {
value.push_back(ch);
value.push_back(ch);
}
else if(ch == '\t' || ch == ' ') {
input >> std::ws;
......@@ -209,7 +209,7 @@ bool parse_null(std::istream& input) {
if (match("null", input)) {
return true;
}
if (Parser == Strict) {
if (parser_is_strict()) {
return false;
}
return (input.peek()==',');
......@@ -224,7 +224,7 @@ bool parse_object(std::istream& input, Object& object) {
}
bool parse_comment(std::istream &input) {
if( Parser == Permissive )
if( parser_is_permissive() )
if( !input.eof() && input.peek() == '/' )
{
char ch0(0);
......@@ -281,9 +281,9 @@ bool Object::parse(std::istream& input, Object& object) {
do {
std::string key;
if(UnquotedKeys == Enabled) {
if (unquoted_keys_are_enabled()) {
if (!parse_identifier(input, key)) {
if (Parser == Permissive) {
if (parser_is_permissive()) {
if (input.peek() == '}')
break;
}
......@@ -292,7 +292,7 @@ bool Object::parse(std::istream& input, Object& object) {
}
else {
if (!parse_string(input, key)) {
if (Parser == Permissive) {
if (parser_is_permissive()) {
if (input.peek() == '}')
break;
}
......@@ -307,7 +307,18 @@ bool Object::parse(std::istream& input, Object& object) {
delete v;
break;
}
object.value_map_[key] = v;
// TODO(hjiang): Add an option to allow duplicated keys?
if (object.value_map_.find(key) == object.value_map_.end()) {
object.value_map_[key] = v;
} else {
if (parser_is_permissive()) {
delete object.value_map_[key];
object.value_map_[key] = v;
} else {
delete v;
return false;
}
}
} while (match(",", input));
......@@ -1067,6 +1078,13 @@ Array::Array(const Array &other) {
Array::Array(const Value &value) {
import(value);
}
void Array::append(const Array &other) {
if (this != &other) {
values_.push_back( new Value(other) );
} else {
append( Array(*this) );
}
}
void Array::import(const Array &other) {
if (this != &other) {
// default
......
......@@ -7,6 +7,7 @@
#pragma once
#include <cstddef>
#include <cassert>
#include <iostream>
#include <map>
......@@ -32,11 +33,25 @@
#define JSONXX_COMPILER_HAS_CXX11 0
#endif
#ifdef _MSC_VER
// disable the C4127 warning if using VC, see http://stackoverflow.com/a/12042515
#define JSONXX_ASSERT(...) \
do { \
__pragma(warning(push)) __pragma(warning(disable:4127)) \
if( jsonxx::Assertions ) \
__pragma(warning(pop)) \
jsonxx::assertion(__FILE__,__LINE__,#__VA_ARGS__,bool(__VA_ARGS__)); \
__pragma(warning(push)) __pragma(warning(disable:4127)) \
} while(0) \
__pragma(warning(pop))
#else
#define JSONXX_ASSERT(...) do { if( jsonxx::Assertions ) \
jsonxx::assertion(__FILE__,__LINE__,#__VA_ARGS__,bool(__VA_ARGS__)); } while(0)
#endif
namespace jsonxx {
// FIXME(hjiang): Those should really be dynamic.
// Settings
enum Settings {
// constants
......@@ -50,6 +65,17 @@ enum Settings {
Assertions = Enabled // enabled or disabled assertions (these asserts work both in DEBUG and RELEASE builds)
};
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4127)
#endif
inline bool parser_is_strict() { return Parser == Strict; }
inline bool parser_is_permissive() { return Parser == Permissive; }
inline bool unquoted_keys_are_enabled() { return UnquotedKeys == Enabled; }
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// Constants for .write() and .xml() methods
enum Format {
JSON = 0, // JSON output
......@@ -166,6 +192,8 @@ class Array {
bool parse(std::istream &input);
bool parse(const std::string &input);
typedef std::vector<Value*> container;
void append(const Array &other);
void append(const Value &value) { import(value); }
void import(const Array &other);
void import(const Value &value);
Array &operator<<(const Array &other);
......@@ -382,7 +410,7 @@ const T& Object::get(const std::string& key, const typename identity<T>::type& d
return default_value;
}
}
template<>
inline bool Value::is<Value>() const {
return true;
......@@ -417,12 +445,12 @@ template<>
inline bool Value::is<Object>() const {
return type_ == OBJECT_;
}
template<>
inline Value& Value::get<Value>() {
return *this;
}
template<>
inline const Value& Value::get<Value>() const {
return *this;
......
<!--- THIS FILE IS AUTOMATICALLY GENERATED, DO NOT CHANGE IT BY HAND --->
stb
===
single-file public domain (or MIT licensed) libraries for C/C++ <a name="stb_libs"></a>
Most libraries by stb, except: stb_dxt by Fabian "ryg" Giesen, stb_image_resize
by Jorge L. "VinoBS" Rodriguez, and stb_sprintf by Jeff Roberts.
library | lastest version | category | LoC | description
--------------------- | ---- | -------- | --- | --------------------------------
**[stb_vorbis.c](stb_vorbis.c)** | 1.16 | audio | 5486 | decode ogg vorbis files from file/memory to float/16-bit signed output
**[stb_image.h](stb_image.h)** | 2.22 | graphics | 7547 | image loading/decoding from file/memory: JPG, PNG, TGA, BMP, PSD, GIF, HDR, PIC
**[stb_truetype.h](stb_truetype.h)** | 1.21 | graphics | 4882 | parse, decode, and rasterize characters from truetype fonts
**[stb_image_write.h](stb_image_write.h)** | 1.13 | graphics | 1622 | image writing to disk: PNG, TGA, BMP
**[stb_image_resize.h](stb_image_resize.h)** | 0.96 | graphics | 2630 | resize images larger/smaller with good quality
**[stb_rect_pack.h](stb_rect_pack.h)** | 1.00 | graphics | 628 | simple 2D rectangle packer with decent quality
**[stb_ds.h](stb_ds.h)** | 0.4 | utility | 1669 | typesafe dynamic array and hash tables for C, will compile in C++
**[stb_sprintf.h](stb_sprintf.h)** | 1.06 | utility | 1860 | fast sprintf, snprintf for C/C++
**[stretchy_buffer.h](stretchy_buffer.h)** | 1.03 | utility | 262 | typesafe dynamic array for C (i.e. approximation to vector<>), doesn't compile as C++
**[stb_textedit.h](stb_textedit.h)** | 1.13 | user&nbsp;interface | 1404 | guts of a text editor for games etc implementing them from scratch
**[stb_voxel_render.h](stb_voxel_render.h)** | 0.88 | 3D&nbsp;graphics | 3806 | Minecraft-esque voxel rendering "engine" with many more features
**[stb_dxt.h](stb_dxt.h)** | 1.08b | 3D&nbsp;graphics | 728 | Fabian "ryg" Giesen's real-time DXT compressor
**[stb_perlin.h](stb_perlin.h)** | 0.4 | 3D&nbsp;graphics | 366 | revised Perlin noise (3D input, 1D output)
**[stb_easy_font.h](stb_easy_font.h)** | 1.0 | 3D&nbsp;graphics | 303 | quick-and-dirty easy-to-deploy bitmap font for printing frame rate, etc
**[stb_tilemap_editor.h](stb_tilemap_editor.h)** | 0.41 | game&nbsp;dev | 4161 | embeddable tilemap editor
**[stb_herringbone_wa...](stb_herringbone_wang_tile.h)** | 0.7 | game&nbsp;dev | 1221 | herringbone Wang tile map generator
**[stb_c_lexer.h](stb_c_lexer.h)** | 0.10 | parsing | 964 | simplify writing parsers for C-like languages
**[stb_divide.h](stb_divide.h)** | 0.92 | math | 421 | more useful 32-bit modulus e.g. "euclidean divide"
**[stb_connected_comp...](stb_connected_components.h)** | 0.96 | misc | 1049 | incrementally compute reachability on grids
**[stb.h](stb.h)** | 2.34 | misc | 14453 | helper functions for C, mostly redundant in C++; basically author's personal stuff
**[stb_leakcheck.h](stb_leakcheck.h)** | 0.5 | misc | 190 | quick-and-dirty malloc/free leak-checking
Total libraries: 21
Total lines of C code: 55652
FAQ
---
#### What's the license?
These libraries are in the public domain. You can do anything you
want with them. You have no legal obligation
to do anything else, although I appreciate attribution.
They are also licensed under the MIT open source license, if you have lawyers
who are unhappy with public domain. Every source file includes an explicit
dual-license for you to choose from.
#### <a name="other_libs"></a> Are there other single-file public-domain/open source libraries with minimal dependencies out there?
[Yes.](https://github.com/nothings/single_file_libs)
#### If I wrap an stb library in a new library, does the new library have to be public domain/MIT?
No, because it's public domain you can freely relicense it to whatever license your new
library wants to be.
#### What's the deal with SSE support in GCC-based compilers?
stb_image will either use SSE2 (if you compile with -msse2) or
will not use any SIMD at all, rather than trying to detect the
processor at runtime and handle it correctly. As I understand it,
the approved path in GCC for runtime-detection require
you to use multiple source files, one for each CPU configuration.
Because stb_image is a header-file library that compiles in only
one source file, there's no approved way to build both an
SSE-enabled and a non-SSE-enabled variation.
While we've tried to work around it, we've had multiple issues over
the years due to specific versions of gcc breaking what we're doing,
so we've given up on it. See https://github.com/nothings/stb/issues/280
and https://github.com/nothings/stb/issues/410 for examples.
#### Some of these libraries seem redundant to existing open source libraries. Are they better somehow?
Generally they're only better in that they're easier to integrate,
easier to use, and easier to release (single file; good API; no
attribution requirement). They may be less featureful, slower,
and/or use more memory. If you're already using an equivalent
library, there's probably no good reason to switch.
#### Can I link directly to the table of stb libraries?
You can use [this URL](https://github.com/nothings/stb#stb_libs) to link directly to that list.
#### Why do you list "lines of code"? It's a terrible metric.
Just to give you some idea of the internal complexity of the library,
to help you manage your expectations, or to let you know what you're
getting into. While not all the libraries are written in the same
style, they're certainly similar styles, and so comparisons between
the libraries are probably still meaningful.
Note though that the lines do include both the implementation, the
part that corresponds to a header file, and the documentation.
#### Why single-file headers?
Windows doesn't have standard directories where libraries
live. That makes deploying libraries in Windows a lot more
painful than open source developers on Unix-derivates generally
realize. (It also makes library dependencies a lot worse in Windows.)
There's also a common problem in Windows where a library was built
against a different version of the runtime library, which causes
link conflicts and confusion. Shipping the libs as headers means
you normally just compile them straight into your project without
making libraries, thus sidestepping that problem.
Making them a single file makes it very easy to just
drop them into a project that needs them. (Of course you can
still put them in a proper shared library tree if you want.)
Why not two files, one a header and one an implementation?
The difference between 10 files and 9 files is not a big deal,
but the difference between 2 files and 1 file is a big deal.
You don't need to zip or tar the files up, you don't have to
remember to attach *two* files, etc.
#### Why "stb"? Is this something to do with Set-Top Boxes?
No, they are just the initials for my name, Sean T. Barrett.
This was not chosen out of egomania, but as a moderately sane
way of namespacing the filenames and source function names.
#### Will you add more image types to stb_image.h?
If people submit them, I generally add them, but the goal of stb_image
is less for applications like image viewer apps (which need to support
every type of image under the sun) and more for things like games which
can choose what images to use, so I may decline to add them if they're
too rare or if the size of implementation vs. apparent benefit is too low.
#### Do you have any advice on how to create my own single-file library?
Yes. https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
#### Why public domain?
I prefer it over GPL, LGPL, BSD, zlib, etc. for many reasons.
Some of them are listed here:
https://github.com/nothings/stb/blob/master/docs/why_public_domain.md
#### Why C?
Primarily, because I use C, not C++. But it does also make it easier
for other people to use them from other languages.
#### Why not C99? stdint.h, declare-anywhere, etc.
I still use MSVC 6 (1998) as my IDE because it has better human factors
for me than later versions of MSVC.
This diff is collapsed.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment