-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring code based on what I was learnt in version 1.
- Loading branch information
0 parents
commit 9daf75a
Showing
11 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.o | ||
unittest | ||
coverage/ | ||
debug/ | ||
release/ | ||
profile/ | ||
makefile_tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "build"] | ||
path = build | ||
url = git@github.com:Loki-Astari/ThorMaker.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
git: | ||
submodules: false | ||
language: cpp | ||
os: | ||
- linux | ||
- osx | ||
compiler: | ||
- gcc | ||
- clang | ||
before_install: | ||
- mv .gitmodules gitmodules.old | ||
- sed -e 's#git@\([^:]*\):#https://\1/#' gitmodules.old > .gitmodules | ||
- rm gitmodules.old | ||
install: | ||
- pushd third | ||
- ./setup | ||
- popd | ||
script: | ||
- make | ||
branches: | ||
only: | ||
- master | ||
- /^feature-*$/ | ||
- /^version-*$/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER 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. | ||
|
||
|
||
This software is "Public Domain" | ||
(i.e. I freely give up my rights for the public good). | ||
|
||
Notes: | ||
|
||
You are free to use this in any code (private/commercial/open source) you like | ||
without fees. | ||
|
||
If you want to credit me as the original author I am happy for any links | ||
back to this git hub project (but it is not required). | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
THORSANVIL_ROOT = $(realpath ./) | ||
|
||
TARGET = Serialize.app | ||
|
||
include $(THORSANVIL_ROOT)/build/tools/Makefile | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
CXXSTDVER = 14 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
[![endorse](http://api.coderwall.com/lokiastari/endorsecount.png)](http://coderwall.com/lokiastari) | ||
[![Build Status](https://travis-ci.org/Loki-Astari/ThorsSerializer.svg?branch=master)](https://travis-ci.org/Loki-Astari/ThorsSerializer) | ||
|
||
|
||
Yet another JSON serialization library for C++ | ||
|
||
###Objective: | ||
|
||
The objective is to make serialization/de-serialization of C++ object to/from | ||
JSON trivial. | ||
|
||
This means: | ||
1) does not build a JSON object. Reads data directly into C++ object. | ||
2) In normal usage there should be NO need to write any code. | ||
3) User should not need to understand JSON or validate its input. | ||
4) Should work seamlessly with streams. | ||
5) Standard containers should automatically work | ||
|
||
I am not concerned about speed. | ||
Though my trivial test work just fine in terms of speed. | ||
|
||
The design was done with the primary goal of communicating with WEB-Servers | ||
that speak JSON. The main envisioned usage was for mobile devices were many | ||
small JSON objects are transfered in both directions. | ||
|
||
###Example Usage with ThorsStream | ||
|
||
https://gist.github.com/Loki-Astari/8201956 | ||
|
||
###Build instructions (SIMPLE) | ||
|
||
make -f MakeSimple | ||
# Note this build a Serialize.a library | ||
# No tests are run and no coverage test are done. | ||
# The serialize library are mostly header files so you will still need these | ||
# to include these from your own files. | ||
|
||
###Building Notes: | ||
This project can also use ThorMaker (which is just a set of makefiles) to build | ||
This not only builds the code but runs unit tests and checks the code coverage of the unit tests. | ||
|
||
Build instructions: | ||
################### | ||
|
||
# Set up required 3rd party libraries boost/gtest | ||
cd third | ||
./setup | ||
|
||
|
||
# The following builds the Json parser and installs the | ||
# release and debug libraries into build/lib and external headers into build/include | ||
cd ../Json | ||
make install | ||
|
||
# The following builds the Serialization libs and installs the | ||
# release and debug libraries into build/lib and external headers into build/include | ||
cd ../Serialize | ||
make install | ||
|
||
|
||
###Example: C++11 (see code in test.cpp for full code) | ||
|
||
/* A class that you want to serialize. */ | ||
class MyClass | ||
{ | ||
int data1; | ||
float data2; | ||
std::string data3; | ||
|
||
// This is only required if the members are private. | ||
friend struct ThorsAnvil::Serialize::Json::JsonSerializeTraits<MyClass>; | ||
}; | ||
|
||
|
||
/* | ||
* Though there is no code involved, you do need to set up | ||
* this structure to tell the library what fields need to be serialized. | ||
* To do this use the macro: JsonSerializeTraits_MAKE() | ||
* Specifying parents to serialize(or void), your class, a list of members to serialize. | ||
*/ | ||
JsonSerializeTraits_MAKE(void, MyClass, data1, data2, data3) | ||
|
||
This allows us to import and export object of the above class really easily. | ||
|
||
MyCLass data; | ||
data.data1 = 56; | ||
data.data2 = 23.456; | ||
data.data3 = "Hi there"; | ||
|
||
std::cout << ThorsAnvil::Serializer::jsonExport(data) << "\n"; | ||
|
||
This generates: | ||
|
||
{"data1": 56 ,"data2": 23.456 ,"data3": "Hi there" } | ||
|
||
It will also handle all standard containers automaticaly: | ||
|
||
std::vector<MyClass> vec(4, data); | ||
std::cout << ThorsAnvil::Serializer::jsonExport(vec) << "\n"; | ||
|
||
// Results in: | ||
[{"data1": 56 ,"data2": 23.456 ,"data3": "Hi there" }, {"data1": 56 ,"data2": 23.456 ,"data3": "Hi there" }, {"data1": 56 ,"data2": 23.456 ,"data3": "Hi there" }, {"data1": 56 ,"data2": 23.456 ,"data3": "Hi there" } ] | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
int main() | ||
{ | ||
// Fake program so Travis build still work | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
boost* | ||
gtest* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Change this as required to point at the root of ThorsAnvil code | ||
ROOT=$(pwd) | ||
THORSANVIL_ROOT=$(dirname ${ROOT}) | ||
|
||
pushd ${THORSANVIL_ROOT} | ||
git submodule init | ||
git submodule update | ||
cd build/third | ||
./setup | ||
popd | ||
|
||
|
||
install="sudo apt-get --yes" | ||
check="list" | ||
|
||
host=`uname` | ||
if [[ "${host}" == "Darwin" ]]; then | ||
# This is a mac use brew | ||
install="brew" | ||
check="brew" | ||
fi | ||
|
||
if [[ "${host}" == "Linux" ]]; then | ||
${install} install libboost-dev | ||
${install} install libboost-doc | ||
fi | ||
if [[ "${host}" == "Darwin" ]]; then | ||
${check} list boost >/dev/null 2>&1 || { echo >&2 "boost required but not install. Will attempt to install"; exit 1; } | ||
if [[ $? == 1 ]]; then | ||
${install} install boost | ||
fi | ||
fi | ||
|
||
|