From 2eeee9f3d0d93885dcb8002b9e92db66aca8bf17 Mon Sep 17 00:00:00 2001 From: rdcelis Date: Fri, 24 Apr 2015 11:57:29 +0200 Subject: [PATCH 01/16] Added pure String manipulation methods *StringifyToString *AsCharString --- src/JSON.cpp | 22 ++++++++++++++++++++ src/JSON.h | 1 + src/JSONValue.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/JSONValue.h | 3 +++ 4 files changed, 79 insertions(+) diff --git a/src/JSON.cpp b/src/JSON.cpp index 0b966c0..9279f59 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -121,6 +121,28 @@ std::wstring JSON::Stringify(const JSONValue *value) return L""; } +/** + * Turns the passed in JSONValue into a JSON encode string + * + * @access public + * + * @param JSONValue* value The root value + * + * @return std::string Returns a JSON encoded string representation of the given value + */ +std::string JSON::StringifyToString(const JSONValue *value) +{ + if (value != NULL){ + + char buffer [4096]; //Internal buffer of 4096 chars + wcstombs(buffer, value->Stringify().c_str(), sizeof(buffer)); + return buffer; + } + + else + return ""; +} + /** * Skips over any whitespace characters (space, tab, \r or \n) defined by the JSON spec * diff --git a/src/JSON.h b/src/JSON.h index 184a5de..60ddc8d 100644 --- a/src/JSON.h +++ b/src/JSON.h @@ -100,6 +100,7 @@ class JSON static JSONValue* Parse(const char *data); static JSONValue* Parse(const wchar_t *data); static std::wstring Stringify(const JSONValue *value); + static std::string StringifyToString(const JSONValue *value); protected: static bool SkipWhitespace(const wchar_t **data); static bool ExtractString(const wchar_t **data, std::wstring &str); diff --git a/src/JSONValue.cpp b/src/JSONValue.cpp index b87a927..e01bc23 100644 --- a/src/JSONValue.cpp +++ b/src/JSONValue.cpp @@ -337,6 +337,21 @@ JSONValue::JSONValue(const std::wstring &m_string_value) string_value = m_string_value; } +/** + * Basic constructor for creating a JSON Value of type String + * + * @access public + * + * @param std::string m_string_value The string to use as the value + */ +JSONValue::JSONValue(const std::string &m_string_value) +{ + wchar_t wstr[2048]; //Internal buffer of 2048 chars + mbstowcs(wstr, m_string_value.c_str(), sizeof(wstr)); + type = JSONType_String; + string_value = std::wstring(wstr); +} + /** * Basic constructor for creating a JSON Value of type Bool * @@ -498,6 +513,25 @@ const std::wstring &JSONValue::AsString() const return string_value; } +/** + * Retrieves the String value of this JSONValue + * Use IsString() before using this method. + * + * @access public + * + * @return std::string Returns the string value + */ +const std::string JSONValue::AsCharString() const +{ + char buffer [2048]; //Internal buffer of 2048 chars + wcstombs(buffer, string_value.c_str(), sizeof(buffer)); + std::stringstream ss; + std::string s; + ss << buffer; + ss >> s; + return s; +} + /** * Retrieves the Bool value of this JSONValue * Use IsBool() before using this method. @@ -696,6 +730,25 @@ std::wstring JSONValue::Stringify(bool const prettyprint) const return StringifyImpl(indentDepth); } +/** + * Creates a JSON encoded string for the value with all necessary characters escaped + * + * @access public + * + * @param bool prettyprint Enable prettyprint + * + * @return std::wstring Returns the JSON string + */ +std::string JSONValue::StringifyToString(bool const prettyprint) const +{ + size_t const indentDepth = prettyprint ? 1 : 0; + + char buffer [4096]; //Internal buffer of 4096 chars + wcstombs(buffer, StringifyImpl(indentDepth).c_str(), sizeof(buffer)); + + return buffer; +} + /** * Creates a JSON encoded string for the value with all necessary characters escaped diff --git a/src/JSONValue.h b/src/JSONValue.h index 797d255..6b17f73 100755 --- a/src/JSONValue.h +++ b/src/JSONValue.h @@ -42,6 +42,7 @@ class JSONValue JSONValue(/*NULL*/); JSONValue(const wchar_t *m_char_value); JSONValue(const std::wstring &m_string_value); + JSONValue(const std::string &m_string_value); JSONValue(bool m_bool_value); JSONValue(double m_number_value); JSONValue(const JSONArray &m_array_value); @@ -56,6 +57,7 @@ class JSONValue bool IsObject() const; const std::wstring &AsString() const; + const std::string AsCharString() const; bool AsBool() const; double AsNumber() const; const JSONArray &AsArray() const; @@ -69,6 +71,7 @@ class JSONValue std::vector ObjectKeys() const; std::wstring Stringify(bool const prettyprint = false) const; + std::string StringifyToString(bool const prettyprint = false) const; protected: static JSONValue *Parse(const wchar_t **data); From ad008ae98e0244b15a2989d52e4dbb8c10cf660f Mon Sep 17 00:00:00 2001 From: vgoni Date: Mon, 27 Apr 2015 10:47:42 +0200 Subject: [PATCH 02/16] Added string easy creator --- src/JSONString.cpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++ src/JSONString.h | 36 ++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100755 src/JSONString.cpp create mode 100755 src/JSONString.h diff --git a/src/JSONString.cpp b/src/JSONString.cpp new file mode 100755 index 0000000..7018ad0 --- /dev/null +++ b/src/JSONString.cpp @@ -0,0 +1,75 @@ +#include "JSONString.h" + +void JSONString::startJSON() +{ + _jsonstring += "{"; +} + +void JSONString::finishJSON() +{ + _jsonstring += "}"; +} + +void JSONString::continueJSON() +{ + _jsonstring += ","; +} + +void JSONString::startArray() +{ + _jsonstring += "["; +} + +void JSONString::finishArray() +{ + _jsonstring += "]"; +} + +void JSONString::addInt(std::string id, int data) +{ + std::ostringstream os; + os << data ; + + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += os.str(); +} + +void JSONString::addUnsignedInt(std::string id, unsigned int data) +{ + std::ostringstream os; + os << data ; + + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += os.str(); +} + +void JSONString::addString(std::string id, std::string data) +{ + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += "\""; + _jsonstring += data; + _jsonstring += "\""; +} + +void JSONString::addArray(std::string id, std::string data) +{ + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += data; +} + +void JSONString::printString() +{ + printf("%s", _jsonstring.c_str()); +} diff --git a/src/JSONString.h b/src/JSONString.h new file mode 100755 index 0000000..b120407 --- /dev/null +++ b/src/JSONString.h @@ -0,0 +1,36 @@ +#ifndef _JSONSTRING_H_ +#define _JSONSTRING_H_ + +#include +#include +#include +#include +#include "JSONString.h" + +class JSONString +{ +public: + JSONString():_jsonstring(""){}; + + void startJSON(); // Only limits, no use for internal json subobjects + void finishJSON(); // same + void continueJSON(); // Separator between JSON objects + + void startArray(); + void finishArray(); + + void addInt(std::string id, int data); + void addUnsignedInt(std::string id, unsigned int data); + void addString(std::string id, std::string data); + void addArray(std::string id, std::string data); + + std::string getString() { return _jsonstring; }; + const char* getChar() { return _jsonstring.c_str(); }; + + void printString(); + +private: + std::string _jsonstring; +}; + +#endif // END _JSONSTRING_H_ From 1e237de2094048e55f5eef2f48405aa5df64a9be Mon Sep 17 00:00:00 2001 From: rdcelis Date: Tue, 28 Apr 2015 12:20:24 +0200 Subject: [PATCH 03/16] Fixed AsCharString return Now the method returns the full string and not only the text until the first white space --- src/JSONValue.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/JSONValue.cpp b/src/JSONValue.cpp index e01bc23..4afd122 100644 --- a/src/JSONValue.cpp +++ b/src/JSONValue.cpp @@ -525,11 +525,8 @@ const std::string JSONValue::AsCharString() const { char buffer [2048]; //Internal buffer of 2048 chars wcstombs(buffer, string_value.c_str(), sizeof(buffer)); - std::stringstream ss; - std::string s; - ss << buffer; - ss >> s; - return s; + + return buffer; } /** From fcda89018944f62d6e345f4beeadfc5555641525 Mon Sep 17 00:00:00 2001 From: rdcelis Date: Thu, 14 May 2015 13:07:51 +0200 Subject: [PATCH 04/16] Removed internal buffers in the methods that return string value Signed-off-by: rdcelis --- src/JSON.cpp | 6 +++--- src/JSONValue.cpp | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/JSON.cpp b/src/JSON.cpp index 9279f59..07251d4 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -134,9 +134,9 @@ std::string JSON::StringifyToString(const JSONValue *value) { if (value != NULL){ - char buffer [4096]; //Internal buffer of 4096 chars - wcstombs(buffer, value->Stringify().c_str(), sizeof(buffer)); - return buffer; + std::string result; + result.assign(value->Stringify().begin(), value->Stringify().end()); + return result; } else diff --git a/src/JSONValue.cpp b/src/JSONValue.cpp index 4afd122..89ada94 100644 --- a/src/JSONValue.cpp +++ b/src/JSONValue.cpp @@ -523,10 +523,9 @@ const std::wstring &JSONValue::AsString() const */ const std::string JSONValue::AsCharString() const { - char buffer [2048]; //Internal buffer of 2048 chars - wcstombs(buffer, string_value.c_str(), sizeof(buffer)); - - return buffer; + std::string result; + result.assign(string_value.begin(), string_value.end()); + return result; } /** @@ -740,10 +739,10 @@ std::string JSONValue::StringifyToString(bool const prettyprint) const { size_t const indentDepth = prettyprint ? 1 : 0; - char buffer [4096]; //Internal buffer of 4096 chars - wcstombs(buffer, StringifyImpl(indentDepth).c_str(), sizeof(buffer)); - - return buffer; + std::wstring data = StringifyImpl(indentDepth); + std::string result; + result.assign(data.begin(), data.end()); + return result; } From be17628c733a17a6cf09c41583ac55331ddf6a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Go=C3=B1i=20Sanz?= Date: Wed, 16 Sep 2015 15:25:58 +0200 Subject: [PATCH 05/16] Refactor and add CMake files --- CMakeLists.txt | 23 +++ Makefile | 27 --- README.md | 10 + {src => code}/demo/example.cpp | 0 {src => code}/demo/functions.h | 0 {src => code}/demo/nix-main.cpp | 0 {src => code}/demo/testcases.cpp | 0 {src => code}/demo/win-main.cpp | 0 {src => code/include}/JSON.h | 0 {src => code/include}/JSONString.h | 14 +- {src => code/include}/JSONValue.h | 0 {src => code/src}/JSON.cpp | 0 {src => code/src}/JSONString.cpp | 1 + {src => code/src}/JSONValue.cpp | 0 {test_cases => test}/fail1.json | 0 {test_cases => test}/fail10.json | 0 {test_cases => test}/fail11.json | 0 {test_cases => test}/fail12.json | 0 {test_cases => test}/fail13.json | 0 {test_cases => test}/fail14.json | 0 {test_cases => test}/fail15.json | 0 {test_cases => test}/fail16.json | 0 {test_cases => test}/fail17.json | 0 {test_cases => test}/fail18.json | 0 {test_cases => test}/fail19.json | 0 {test_cases => test}/fail2.json | 0 {test_cases => test}/fail20.json | 0 {test_cases => test}/fail21.json | 0 {test_cases => test}/fail22.json | 0 {test_cases => test}/fail23.json | 0 {test_cases => test}/fail3.json | 0 {test_cases => test}/fail4.json | 0 {test_cases => test}/fail5.json | 0 {test_cases => test}/fail6.json | 0 {test_cases => test}/fail7.json | 0 {test_cases => test}/fail8.json | 0 {test_cases => test}/fail9.json | 0 {test_cases => test}/pass1.json | 0 {test_cases => test}/pass2.json | 0 {test_cases => test}/pass3.json | 0 {test_cases => test}/pass4.json | 0 {test_cases => test}/pass5.json | 0 vs2008/JSONDemo.sln | 17 -- vs2008/JSONDemo.vcproj | 179 ---------------- vs2008/common_controls.manifest | 8 - vs2008/gui.rc | 107 ---------- vs2008/resource.h | 25 --- xcode5/xcode5.xcodeproj/project.pbxproj | 260 ------------------------ 48 files changed, 41 insertions(+), 630 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile rename {src => code}/demo/example.cpp (100%) rename {src => code}/demo/functions.h (100%) rename {src => code}/demo/nix-main.cpp (100%) rename {src => code}/demo/testcases.cpp (100%) rename {src => code}/demo/win-main.cpp (100%) rename {src => code/include}/JSON.h (100%) rename {src => code/include}/JSONString.h (93%) rename {src => code/include}/JSONValue.h (100%) rename {src => code/src}/JSON.cpp (100%) rename {src => code/src}/JSONString.cpp (98%) rename {src => code/src}/JSONValue.cpp (100%) rename {test_cases => test}/fail1.json (100%) rename {test_cases => test}/fail10.json (100%) rename {test_cases => test}/fail11.json (100%) rename {test_cases => test}/fail12.json (100%) rename {test_cases => test}/fail13.json (100%) rename {test_cases => test}/fail14.json (100%) rename {test_cases => test}/fail15.json (100%) rename {test_cases => test}/fail16.json (100%) rename {test_cases => test}/fail17.json (100%) rename {test_cases => test}/fail18.json (100%) rename {test_cases => test}/fail19.json (100%) rename {test_cases => test}/fail2.json (100%) rename {test_cases => test}/fail20.json (100%) rename {test_cases => test}/fail21.json (100%) rename {test_cases => test}/fail22.json (100%) rename {test_cases => test}/fail23.json (100%) rename {test_cases => test}/fail3.json (100%) rename {test_cases => test}/fail4.json (100%) rename {test_cases => test}/fail5.json (100%) rename {test_cases => test}/fail6.json (100%) rename {test_cases => test}/fail7.json (100%) rename {test_cases => test}/fail8.json (100%) rename {test_cases => test}/fail9.json (100%) rename {test_cases => test}/pass1.json (100%) rename {test_cases => test}/pass2.json (100%) rename {test_cases => test}/pass3.json (100%) rename {test_cases => test}/pass4.json (100%) rename {test_cases => test}/pass5.json (100%) delete mode 100644 vs2008/JSONDemo.sln delete mode 100644 vs2008/JSONDemo.vcproj delete mode 100644 vs2008/common_controls.manifest delete mode 100644 vs2008/gui.rc delete mode 100644 vs2008/resource.h delete mode 100644 xcode5/xcode5.xcodeproj/project.pbxproj diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..747e0bf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 2.8.0) + +# Header +#-----------------------------------------------------------------------# +SET(PROJ_NAME SimpleJSON) +PROJECT(${PROJ_NAME}) + +INCLUDE_DIRECTORIES("code/include") + +# Source, macro to find all files. If you add more, regenerate project +#-----------------------------------------------------------------------# +FILE(GLOB ${PROJ_NAME}_SRC + "code/src/*.cpp" +) +FILE(GLOB ${PROJ_NAME}_HEADERS + "code/include/*.h" +) + +# Create Library +#-----------------------------------------------------------------------# +ADD_LIBRARY(${PROJ_NAME} STATIC ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) + +MESSAGE(" * Project ${PROJ_NAME} done!") # Out info diff --git a/Makefile b/Makefile deleted file mode 100644 index b6ed25e..0000000 --- a/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# Change to whatever your C++ compiler is -CC=g++ - -# Compile settings -CFLAGS=-c -Wall -LFLAGS=-lm - -# Source files -SOURCES=src/JSON.cpp src/JSONValue.cpp src/demo/nix-main.cpp src/demo/example.cpp src/demo/testcases.cpp -HEADERS=src/JSON.h src/JSONValue.h -OBJECTS=$(SOURCES:src/%.cpp=obj/%.o) - -# Output -EXECUTABLE=JSONDemo - -all: $(SOURCES) $(EXECUTABLE) - -$(EXECUTABLE): $(OBJECTS) - $(CC) $(LFLAGS) $(OBJECTS) -o $@ - -obj/%.o: src/%.cpp $(HEADERS) - @test -d $(@D) || mkdir -p $(@D) - $(CC) $(CFLAGS) $(@:obj/%.o=src/%.cpp) -o $@ - -clean: - rm -f $(OBJECTS) $(EXECUTABLE) - diff --git a/README.md b/README.md index c292634..a569fcc 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,13 @@ these are simply type definitions as outlined below: * JSONArray: std::vector * JSONObject: std::map + +Compiling crossplatform with CMake +------------------------------------- + +1º Set this path in source +2º Choose a toolchain if is needed and you IDE configuration (MSVS, Eclipse, Makefile...) +3º Choose a path where set your build +4º Configure & generate + +``` diff --git a/src/demo/example.cpp b/code/demo/example.cpp similarity index 100% rename from src/demo/example.cpp rename to code/demo/example.cpp diff --git a/src/demo/functions.h b/code/demo/functions.h similarity index 100% rename from src/demo/functions.h rename to code/demo/functions.h diff --git a/src/demo/nix-main.cpp b/code/demo/nix-main.cpp similarity index 100% rename from src/demo/nix-main.cpp rename to code/demo/nix-main.cpp diff --git a/src/demo/testcases.cpp b/code/demo/testcases.cpp similarity index 100% rename from src/demo/testcases.cpp rename to code/demo/testcases.cpp diff --git a/src/demo/win-main.cpp b/code/demo/win-main.cpp similarity index 100% rename from src/demo/win-main.cpp rename to code/demo/win-main.cpp diff --git a/src/JSON.h b/code/include/JSON.h similarity index 100% rename from src/JSON.h rename to code/include/JSON.h diff --git a/src/JSONString.h b/code/include/JSONString.h similarity index 93% rename from src/JSONString.h rename to code/include/JSONString.h index b120407..871e975 100755 --- a/src/JSONString.h +++ b/code/include/JSONString.h @@ -5,30 +5,30 @@ #include #include #include -#include "JSONString.h" +#include class JSONString { public: JSONString():_jsonstring(""){}; - + void startJSON(); // Only limits, no use for internal json subobjects void finishJSON(); // same void continueJSON(); // Separator between JSON objects - + void startArray(); void finishArray(); - + void addInt(std::string id, int data); void addUnsignedInt(std::string id, unsigned int data); void addString(std::string id, std::string data); void addArray(std::string id, std::string data); - + std::string getString() { return _jsonstring; }; const char* getChar() { return _jsonstring.c_str(); }; - + void printString(); - + private: std::string _jsonstring; }; diff --git a/src/JSONValue.h b/code/include/JSONValue.h similarity index 100% rename from src/JSONValue.h rename to code/include/JSONValue.h diff --git a/src/JSON.cpp b/code/src/JSON.cpp similarity index 100% rename from src/JSON.cpp rename to code/src/JSON.cpp diff --git a/src/JSONString.cpp b/code/src/JSONString.cpp similarity index 98% rename from src/JSONString.cpp rename to code/src/JSONString.cpp index 7018ad0..6ae879b 100755 --- a/src/JSONString.cpp +++ b/code/src/JSONString.cpp @@ -1,4 +1,5 @@ #include "JSONString.h" +#include void JSONString::startJSON() { diff --git a/src/JSONValue.cpp b/code/src/JSONValue.cpp similarity index 100% rename from src/JSONValue.cpp rename to code/src/JSONValue.cpp diff --git a/test_cases/fail1.json b/test/fail1.json similarity index 100% rename from test_cases/fail1.json rename to test/fail1.json diff --git a/test_cases/fail10.json b/test/fail10.json similarity index 100% rename from test_cases/fail10.json rename to test/fail10.json diff --git a/test_cases/fail11.json b/test/fail11.json similarity index 100% rename from test_cases/fail11.json rename to test/fail11.json diff --git a/test_cases/fail12.json b/test/fail12.json similarity index 100% rename from test_cases/fail12.json rename to test/fail12.json diff --git a/test_cases/fail13.json b/test/fail13.json similarity index 100% rename from test_cases/fail13.json rename to test/fail13.json diff --git a/test_cases/fail14.json b/test/fail14.json similarity index 100% rename from test_cases/fail14.json rename to test/fail14.json diff --git a/test_cases/fail15.json b/test/fail15.json similarity index 100% rename from test_cases/fail15.json rename to test/fail15.json diff --git a/test_cases/fail16.json b/test/fail16.json similarity index 100% rename from test_cases/fail16.json rename to test/fail16.json diff --git a/test_cases/fail17.json b/test/fail17.json similarity index 100% rename from test_cases/fail17.json rename to test/fail17.json diff --git a/test_cases/fail18.json b/test/fail18.json similarity index 100% rename from test_cases/fail18.json rename to test/fail18.json diff --git a/test_cases/fail19.json b/test/fail19.json similarity index 100% rename from test_cases/fail19.json rename to test/fail19.json diff --git a/test_cases/fail2.json b/test/fail2.json similarity index 100% rename from test_cases/fail2.json rename to test/fail2.json diff --git a/test_cases/fail20.json b/test/fail20.json similarity index 100% rename from test_cases/fail20.json rename to test/fail20.json diff --git a/test_cases/fail21.json b/test/fail21.json similarity index 100% rename from test_cases/fail21.json rename to test/fail21.json diff --git a/test_cases/fail22.json b/test/fail22.json similarity index 100% rename from test_cases/fail22.json rename to test/fail22.json diff --git a/test_cases/fail23.json b/test/fail23.json similarity index 100% rename from test_cases/fail23.json rename to test/fail23.json diff --git a/test_cases/fail3.json b/test/fail3.json similarity index 100% rename from test_cases/fail3.json rename to test/fail3.json diff --git a/test_cases/fail4.json b/test/fail4.json similarity index 100% rename from test_cases/fail4.json rename to test/fail4.json diff --git a/test_cases/fail5.json b/test/fail5.json similarity index 100% rename from test_cases/fail5.json rename to test/fail5.json diff --git a/test_cases/fail6.json b/test/fail6.json similarity index 100% rename from test_cases/fail6.json rename to test/fail6.json diff --git a/test_cases/fail7.json b/test/fail7.json similarity index 100% rename from test_cases/fail7.json rename to test/fail7.json diff --git a/test_cases/fail8.json b/test/fail8.json similarity index 100% rename from test_cases/fail8.json rename to test/fail8.json diff --git a/test_cases/fail9.json b/test/fail9.json similarity index 100% rename from test_cases/fail9.json rename to test/fail9.json diff --git a/test_cases/pass1.json b/test/pass1.json similarity index 100% rename from test_cases/pass1.json rename to test/pass1.json diff --git a/test_cases/pass2.json b/test/pass2.json similarity index 100% rename from test_cases/pass2.json rename to test/pass2.json diff --git a/test_cases/pass3.json b/test/pass3.json similarity index 100% rename from test_cases/pass3.json rename to test/pass3.json diff --git a/test_cases/pass4.json b/test/pass4.json similarity index 100% rename from test_cases/pass4.json rename to test/pass4.json diff --git a/test_cases/pass5.json b/test/pass5.json similarity index 100% rename from test_cases/pass5.json rename to test/pass5.json diff --git a/vs2008/JSONDemo.sln b/vs2008/JSONDemo.sln deleted file mode 100644 index 1f3f035..0000000 --- a/vs2008/JSONDemo.sln +++ /dev/null @@ -1,17 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JSONDemo", "JSONDemo.vcproj", "{06DE72C5-3E2A-4DFC-A60E-69B8471E8AC1}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {06DE72C5-3E2A-4DFC-A60E-69B8471E8AC1}.Release|Win32.ActiveCfg = Release|Win32 - {06DE72C5-3E2A-4DFC-A60E-69B8471E8AC1}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/vs2008/JSONDemo.vcproj b/vs2008/JSONDemo.vcproj deleted file mode 100644 index 756dff8..0000000 --- a/vs2008/JSONDemo.vcproj +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/vs2008/common_controls.manifest b/vs2008/common_controls.manifest deleted file mode 100644 index 6a6ea3e..0000000 --- a/vs2008/common_controls.manifest +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/vs2008/gui.rc b/vs2008/gui.rc deleted file mode 100644 index d8f48a0..0000000 --- a/vs2008/gui.rc +++ /dev/null @@ -1,107 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.K.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_JSONDEMO DIALOGEX 0, 0, 500, 294 -STYLE DS_SETFONT | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_APPWINDOW -CAPTION "SimpleJSON library demo" -FONT 8, "Courier New", 400, 0, 0x0 -BEGIN - GROUPBOX "Input data: ",IDC_STATIC,7,7,486,129 - GROUPBOX "Output data: ",IDC_STATIC,7,161,486,126 - EDITTEXT IDC_INPUT,17,22,464,100,ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL - EDITTEXT IDC_OUTPUT,17,177,464,100,ES_MULTILINE | ES_READONLY | ES_WANTRETURN | WS_VSCROLL - PUSHBUTTON "Verify",IDC_VERIFY,8,141,55,14 - PUSHBUTTON "Verify + Echo",IDC_ECHO,75,141,55,14 - PUSHBUTTON "Example 1",IDC_EX1,142,141,55,14 - PUSHBUTTON "Example 2",IDC_EX2,209,141,55,14 - PUSHBUTTON "Example 3",IDC_EX3,276,141,55,14 - PUSHBUTTON "Example 4",IDC_EX4,343,141,55,14 - PUSHBUTTON "Test Cases",IDC_TESTCASES,410,141,55,14 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_JSONDEMO, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 493 - TOPMARGIN, 7 - BOTTOMMARGIN, 287 - END -END -#endif // APSTUDIO_INVOKED - -#endif // English (U.K.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/vs2008/resource.h b/vs2008/resource.h deleted file mode 100644 index 96b0225..0000000 --- a/vs2008/resource.h +++ /dev/null @@ -1,25 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by gui.rc -// -#define IDD_JSONDEMO 101 -#define IDC_INPUT 1001 -#define IDC_OUTPUT 1002 -#define IDC_VERIFY 1003 -#define IDC_ECHO 1004 -#define IDC_EX1 1005 -#define IDC_EX2 1006 -#define IDC_EX3 1008 -#define IDC_EX4 1009 -#define IDC_TESTCASES 1007 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1007 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/xcode5/xcode5.xcodeproj/project.pbxproj b/xcode5/xcode5.xcodeproj/project.pbxproj deleted file mode 100644 index 797b499..0000000 --- a/xcode5/xcode5.xcodeproj/project.pbxproj +++ /dev/null @@ -1,260 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 9D82EB98182AA0A600296124 /* example.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9D82EB8F182AA0A600296124 /* example.cpp */; }; - 9D82EB99182AA0A600296124 /* nix-main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9D82EB91182AA0A600296124 /* nix-main.cpp */; }; - 9D82EB9A182AA0A600296124 /* testcases.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9D82EB92182AA0A600296124 /* testcases.cpp */; }; - 9D82EB9C182AA0A600296124 /* JSON.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9D82EB94182AA0A600296124 /* JSON.cpp */; }; - 9D82EB9D182AA0A600296124 /* JSONValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9D82EB96182AA0A600296124 /* JSONValue.cpp */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 9DE5668718259D9F000B32B4 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 12; - dstPath = ""; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 9D82EB8F182AA0A600296124 /* example.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = example.cpp; sourceTree = ""; }; - 9D82EB90182AA0A600296124 /* functions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = functions.h; sourceTree = ""; }; - 9D82EB91182AA0A600296124 /* nix-main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "nix-main.cpp"; sourceTree = ""; }; - 9D82EB92182AA0A600296124 /* testcases.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = testcases.cpp; sourceTree = ""; }; - 9D82EB94182AA0A600296124 /* JSON.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSON.cpp; sourceTree = ""; }; - 9D82EB95182AA0A600296124 /* JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSON.h; sourceTree = ""; }; - 9D82EB96182AA0A600296124 /* JSONValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSONValue.cpp; sourceTree = ""; }; - 9D82EB97182AA0A600296124 /* JSONValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSONValue.h; sourceTree = ""; }; - 9DE5668918259D9F000B32B4 /* SimpleJSONdemo */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SimpleJSONdemo; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 9DE5668618259D9F000B32B4 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 9D82EB8D182AA0A600296124 /* src */ = { - isa = PBXGroup; - children = ( - 9D82EB8E182AA0A600296124 /* demo */, - 9D82EB94182AA0A600296124 /* JSON.cpp */, - 9D82EB95182AA0A600296124 /* JSON.h */, - 9D82EB96182AA0A600296124 /* JSONValue.cpp */, - 9D82EB97182AA0A600296124 /* JSONValue.h */, - ); - name = src; - path = ../src; - sourceTree = ""; - }; - 9D82EB8E182AA0A600296124 /* demo */ = { - isa = PBXGroup; - children = ( - 9D82EB8F182AA0A600296124 /* example.cpp */, - 9D82EB90182AA0A600296124 /* functions.h */, - 9D82EB91182AA0A600296124 /* nix-main.cpp */, - 9D82EB92182AA0A600296124 /* testcases.cpp */, - ); - path = demo; - sourceTree = ""; - }; - 9DE5668018259D9F000B32B4 = { - isa = PBXGroup; - children = ( - 9D82EB8D182AA0A600296124 /* src */, - 9DE5668A18259D9F000B32B4 /* Products */, - ); - sourceTree = ""; - }; - 9DE5668A18259D9F000B32B4 /* Products */ = { - isa = PBXGroup; - children = ( - 9DE5668918259D9F000B32B4 /* SimpleJSONdemo */, - ); - name = Products; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 9DE5668818259D9F000B32B4 /* xcode5 */ = { - isa = PBXNativeTarget; - buildConfigurationList = 9DE5669218259D9F000B32B4 /* Build configuration list for PBXNativeTarget "xcode5" */; - buildPhases = ( - 9DE5668518259D9F000B32B4 /* Sources */, - 9DE5668618259D9F000B32B4 /* Frameworks */, - 9DE5668718259D9F000B32B4 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = xcode5; - productName = xcode5; - productReference = 9DE5668918259D9F000B32B4 /* SimpleJSONdemo */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 9DE5668118259D9F000B32B4 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0500; - ORGANIZATIONNAME = "Rudi Farkas"; - }; - buildConfigurationList = 9DE5668418259D9F000B32B4 /* Build configuration list for PBXProject "xcode5" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 9DE5668018259D9F000B32B4; - productRefGroup = 9DE5668A18259D9F000B32B4 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 9DE5668818259D9F000B32B4 /* xcode5 */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 9DE5668518259D9F000B32B4 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 9D82EB99182AA0A600296124 /* nix-main.cpp in Sources */, - 9D82EB9A182AA0A600296124 /* testcases.cpp in Sources */, - 9D82EB98182AA0A600296124 /* example.cpp in Sources */, - 9D82EB9C182AA0A600296124 /* JSON.cpp in Sources */, - 9D82EB9D182AA0A600296124 /* JSONValue.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 9DE5669018259D9F000B32B4 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - 9DE5669118259D9F000B32B4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; - SDKROOT = macosx; - }; - name = Release; - }; - 9DE5669318259D9F000B32B4 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - PRODUCT_NAME = SimpleJSONdemo; - }; - name = Debug; - }; - 9DE5669418259D9F000B32B4 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - PRODUCT_NAME = SimpleJSONdemo; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 9DE5668418259D9F000B32B4 /* Build configuration list for PBXProject "xcode5" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 9DE5669018259D9F000B32B4 /* Debug */, - 9DE5669118259D9F000B32B4 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 9DE5669218259D9F000B32B4 /* Build configuration list for PBXNativeTarget "xcode5" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 9DE5669318259D9F000B32B4 /* Debug */, - 9DE5669418259D9F000B32B4 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 9DE5668118259D9F000B32B4 /* Project object */; -} From daeaa8633cab50e4a3910ce8bd8cd0e6e90a2a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20de=20Celis=20Hern=C3=A1ndez?= Date: Wed, 30 Sep 2015 16:16:30 +0200 Subject: [PATCH 06/16] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a569fcc..22e8a24 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ these are simply type definitions as outlined below: Compiling crossplatform with CMake ------------------------------------- -1º Set this path in source -2º Choose a toolchain if is needed and you IDE configuration (MSVS, Eclipse, Makefile...) -3º Choose a path where set your build -4º Configure & generate +1. Set this path in source +2. Choose a toolchain if is needed and your IDE configuration (MSVS, Eclipse, Makefile...) +3. Choose the build path where the project will be built +4. Configure & generate + -``` From 6c2078d6ac09da9a9c779e95637c8f8850ce3a3c Mon Sep 17 00:00:00 2001 From: Piperoman Date: Mon, 5 Oct 2015 20:25:10 +0200 Subject: [PATCH 07/16] Added installation cmake --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 747e0bf..2452006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,16 @@ FILE(GLOB ${PROJ_NAME}_HEADERS # Create Library #-----------------------------------------------------------------------# -ADD_LIBRARY(${PROJ_NAME} STATIC ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) +ADD_LIBRARY(${PROJ_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) +# Installation files in path +#---------------------------------------------------# +INSTALL(TARGETS ${PROJ_NAME} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/lib" + ) +INSTALL(FILES ${${PROJ_NAME}_HEADERS} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/include" + ) + +#PRINTBASICINFO(${PROJ_NAME}) MESSAGE(" * Project ${PROJ_NAME} done!") # Out info From 30fc7dffd64882ea24638cc7f774ec43cefce1dc Mon Sep 17 00:00:00 2001 From: Piperoman Date: Mon, 5 Oct 2015 22:34:35 +0200 Subject: [PATCH 08/16] Install files --- CMakeLists.txt | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2452006..e69de29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 2.8.0) - -# Header -#-----------------------------------------------------------------------# -SET(PROJ_NAME SimpleJSON) -PROJECT(${PROJ_NAME}) - -INCLUDE_DIRECTORIES("code/include") - -# Source, macro to find all files. If you add more, regenerate project -#-----------------------------------------------------------------------# -FILE(GLOB ${PROJ_NAME}_SRC - "code/src/*.cpp" -) -FILE(GLOB ${PROJ_NAME}_HEADERS - "code/include/*.h" -) - -# Create Library -#-----------------------------------------------------------------------# -ADD_LIBRARY(${PROJ_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) - -# Installation files in path -#---------------------------------------------------# -INSTALL(TARGETS ${PROJ_NAME} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/lib" - ) -INSTALL(FILES ${${PROJ_NAME}_HEADERS} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/include" - ) - -#PRINTBASICINFO(${PROJ_NAME}) -MESSAGE(" * Project ${PROJ_NAME} done!") # Out info From 43d04dc4f590d311c7669757e8757815ebf847e4 Mon Sep 17 00:00:00 2001 From: Piperoman Date: Sat, 10 Oct 2015 17:16:59 +0200 Subject: [PATCH 09/16] Fixed strange cmakelist dissapear code --- CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e69de29..2452006 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 2.8.0) + +# Header +#-----------------------------------------------------------------------# +SET(PROJ_NAME SimpleJSON) +PROJECT(${PROJ_NAME}) + +INCLUDE_DIRECTORIES("code/include") + +# Source, macro to find all files. If you add more, regenerate project +#-----------------------------------------------------------------------# +FILE(GLOB ${PROJ_NAME}_SRC + "code/src/*.cpp" +) +FILE(GLOB ${PROJ_NAME}_HEADERS + "code/include/*.h" +) + +# Create Library +#-----------------------------------------------------------------------# +ADD_LIBRARY(${PROJ_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) + +# Installation files in path +#---------------------------------------------------# +INSTALL(TARGETS ${PROJ_NAME} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/lib" + ) +INSTALL(FILES ${${PROJ_NAME}_HEADERS} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/include" + ) + +#PRINTBASICINFO(${PROJ_NAME}) +MESSAGE(" * Project ${PROJ_NAME} done!") # Out info From 1c0834c84569693c8bdedd9eee72ef2342e6a7b9 Mon Sep 17 00:00:00 2001 From: rdcelis Date: Fri, 15 Jan 2016 15:42:31 +0100 Subject: [PATCH 10/16] Added some missing methods in JSONString Signed-off-by: rdcelis --- code/include/JSONString.h | 7 ++++++- code/src/JSONString.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/code/include/JSONString.h b/code/include/JSONString.h index 871e975..fda8f7f 100755 --- a/code/include/JSONString.h +++ b/code/include/JSONString.h @@ -19,10 +19,15 @@ class JSONString void startArray(); void finishArray(); - void addInt(std::string id, int data); + void addBool(std::string id, int data); + void addInt(std::string id, int data); void addUnsignedInt(std::string id, unsigned int data); + void addFloat(std::string id, unsigned int data); void addString(std::string id, std::string data); void addArray(std::string id, std::string data); + void addArrayData(std::string data); + void addObject(std::string id, std::string data); + void addObjectData(std::string data); std::string getString() { return _jsonstring; }; const char* getChar() { return _jsonstring.c_str(); }; diff --git a/code/src/JSONString.cpp b/code/src/JSONString.cpp index 6ae879b..5553115 100755 --- a/code/src/JSONString.cpp +++ b/code/src/JSONString.cpp @@ -26,6 +26,18 @@ void JSONString::finishArray() _jsonstring += "]"; } +void JSONString::addBool(std::string id, int data) +{ + std::ostringstream os; + os << data ; + + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += os.str(); +} + void JSONString::addInt(std::string id, int data) { std::ostringstream os; @@ -50,6 +62,18 @@ void JSONString::addUnsignedInt(std::string id, unsigned int data) _jsonstring += os.str(); } +void JSONString::addFloat(std::string id, unsigned int data) +{ + std::ostringstream os; + os << data ; + + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += os.str(); +} + void JSONString::addString(std::string id, std::string data) { _jsonstring += "\""; @@ -70,6 +94,25 @@ void JSONString::addArray(std::string id, std::string data) _jsonstring += data; } +void JSONString::addArrayData(std::string data) +{ + _jsonstring += data; +} + +void JSONString::addObject(std::string id, std::string data) +{ + _jsonstring += "\""; + _jsonstring += id; + _jsonstring += "\""; + _jsonstring += ":"; + _jsonstring += data; +} + +void JSONString::addObjectData(std::string data) +{ + _jsonstring += data; +} + void JSONString::printString() { printf("%s", _jsonstring.c_str()); From e70d00de6ecf8959ff8480196afdb2ce7aae6317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20de=20Celis=20Hern=C3=A1ndez?= Date: Sat, 16 Jan 2016 12:49:14 +0100 Subject: [PATCH 11/16] Added test build in CMake --- CMakeLists.txt | 37 ++++-- code/demo/win-main.cpp | 145 ------------------------ test/CMakeLists.txt | 36 ++++++ {code/demo => test/include}/functions.h | 0 {code/demo => test/src}/example.cpp | 2 +- {code/demo => test/src}/nix-main.cpp | 5 +- {code/demo => test/src}/testcases.cpp | 2 +- test/{ => test_cases}/fail1.json | 0 test/{ => test_cases}/fail10.json | 0 test/{ => test_cases}/fail11.json | 0 test/{ => test_cases}/fail12.json | 0 test/{ => test_cases}/fail13.json | 0 test/{ => test_cases}/fail14.json | 0 test/{ => test_cases}/fail15.json | 0 test/{ => test_cases}/fail16.json | 0 test/{ => test_cases}/fail17.json | 0 test/{ => test_cases}/fail18.json | 0 test/{ => test_cases}/fail19.json | 0 test/{ => test_cases}/fail2.json | 0 test/{ => test_cases}/fail20.json | 0 test/{ => test_cases}/fail21.json | 0 test/{ => test_cases}/fail22.json | 0 test/{ => test_cases}/fail23.json | 0 test/{ => test_cases}/fail3.json | 0 test/{ => test_cases}/fail4.json | 0 test/{ => test_cases}/fail5.json | 0 test/{ => test_cases}/fail6.json | 0 test/{ => test_cases}/fail7.json | 0 test/{ => test_cases}/fail8.json | 0 test/{ => test_cases}/fail9.json | 0 test/{ => test_cases}/pass1.json | 0 test/{ => test_cases}/pass2.json | 0 test/{ => test_cases}/pass3.json | 0 test/{ => test_cases}/pass4.json | 0 test/{ => test_cases}/pass5.json | 0 35 files changed, 68 insertions(+), 159 deletions(-) delete mode 100644 code/demo/win-main.cpp create mode 100644 test/CMakeLists.txt rename {code/demo => test/include}/functions.h (100%) rename {code/demo => test/src}/example.cpp (99%) rename {code/demo => test/src}/nix-main.cpp (97%) rename {code/demo => test/src}/testcases.cpp (99%) rename test/{ => test_cases}/fail1.json (100%) rename test/{ => test_cases}/fail10.json (100%) rename test/{ => test_cases}/fail11.json (100%) rename test/{ => test_cases}/fail12.json (100%) rename test/{ => test_cases}/fail13.json (100%) rename test/{ => test_cases}/fail14.json (100%) rename test/{ => test_cases}/fail15.json (100%) rename test/{ => test_cases}/fail16.json (100%) rename test/{ => test_cases}/fail17.json (100%) rename test/{ => test_cases}/fail18.json (100%) rename test/{ => test_cases}/fail19.json (100%) rename test/{ => test_cases}/fail2.json (100%) rename test/{ => test_cases}/fail20.json (100%) rename test/{ => test_cases}/fail21.json (100%) rename test/{ => test_cases}/fail22.json (100%) rename test/{ => test_cases}/fail23.json (100%) rename test/{ => test_cases}/fail3.json (100%) rename test/{ => test_cases}/fail4.json (100%) rename test/{ => test_cases}/fail5.json (100%) rename test/{ => test_cases}/fail6.json (100%) rename test/{ => test_cases}/fail7.json (100%) rename test/{ => test_cases}/fail8.json (100%) rename test/{ => test_cases}/fail9.json (100%) rename test/{ => test_cases}/pass1.json (100%) rename test/{ => test_cases}/pass2.json (100%) rename test/{ => test_cases}/pass3.json (100%) rename test/{ => test_cases}/pass4.json (100%) rename test/{ => test_cases}/pass5.json (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2452006..ffde7f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,32 +2,47 @@ cmake_minimum_required(VERSION 2.8.0) # Header #-----------------------------------------------------------------------# -SET(PROJ_NAME SimpleJSON) -PROJECT(${PROJ_NAME}) +SET(PROJ_MAIN_NAME SimpleJSON) +PROJECT(${PROJ_MAIN_NAME}) + +# Configure variables +# ------------------------------------------------------------------------------------------------------ + +# Paths +SET(${PROJ_MAIN_NAME}_PATH_MAIN ${CMAKE_SOURCE_DIR} CACHE PATH "This directory contains initial Path") + + +# Configure options +# ------------------------------------------------------------------------------------------------------ +SET(${PROJ_MAIN_NAME}_BUILD_TEST "Build test" OFF ) INCLUDE_DIRECTORIES("code/include") # Source, macro to find all files. If you add more, regenerate project #-----------------------------------------------------------------------# -FILE(GLOB ${PROJ_NAME}_SRC +FILE(GLOB ${PROJ_MAIN_NAME}_SRC "code/src/*.cpp" ) -FILE(GLOB ${PROJ_NAME}_HEADERS +FILE(GLOB ${PROJ_MAIN_NAME}_HEADERS "code/include/*.h" ) # Create Library #-----------------------------------------------------------------------# -ADD_LIBRARY(${PROJ_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) +ADD_LIBRARY(${PROJ_MAIN_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_MAIN_NAME}_HEADERS} ${${PROJ_MAIN_NAME}_SRC} ) + +# Create Project +#-----------------------------------------------------------------------# +#IF(${${PROJ_MAIN_NAME}_BUILD_TEST}) + ADD_SUBDIRECTORY(test) # Installation files in path #---------------------------------------------------# -INSTALL(TARGETS ${PROJ_NAME} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/lib" +INSTALL(TARGETS ${PROJ_MAIN_NAME} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/lib" ) -INSTALL(FILES ${${PROJ_NAME}_HEADERS} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/include" +INSTALL(FILES ${${PROJ_MAIN_NAME}_HEADERS} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/include" ) -#PRINTBASICINFO(${PROJ_NAME}) -MESSAGE(" * Project ${PROJ_NAME} done!") # Out info +MESSAGE(" * Project ${PROJ_MAIN_NAME} done!") # Out info diff --git a/code/demo/win-main.cpp b/code/demo/win-main.cpp deleted file mode 100644 index 89f96d1..0000000 --- a/code/demo/win-main.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * File demo/win-main.cpp part of the SimpleJSON Library Demo - http://mjpa.in/json - * - * Copyright (C) 2010 Mike Anchor - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include -#include "..\..\vs2008\resource.h" -#include "..\JSON.h" -#include "functions.h" - -// Handle to the window -static HWND hDlg = NULL; - -// A function to display output -void print_out(const wchar_t *output) -{ - if (hDlg != NULL) - { - size_t size = GetWindowTextLength(GetDlgItem(hDlg, IDC_OUTPUT)) + 1 + wcslen(output); - wchar_t *current = new wchar_t[size]; - GetWindowText(GetDlgItem(hDlg, IDC_OUTPUT), current, size); - wcscat_s(current, size, output); - SetWindowText(GetDlgItem(hDlg, IDC_OUTPUT), current); - } -} - -// Dialog proc for the Windows window -int CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_INITDIALOG: - hDlg = hWnd; - break; - - case WM_CLOSE: - EndDialog(hWnd, 0); - break; - - case WM_DESTROY: - PostQuitMessage(0); - break; - - case WM_COMMAND: - { - if (HIWORD(wParam) != BN_CLICKED) - break; - - SetWindowText(GetDlgItem(hWnd, IDC_OUTPUT), L""); - - switch (LOWORD(wParam)) - { - case IDC_VERIFY: - case IDC_ECHO: - { - int size = GetWindowTextLength(GetDlgItem(hWnd, IDC_INPUT)); - wchar_t* text = new wchar_t[size + 1]; - GetWindowText(GetDlgItem(hWnd, IDC_INPUT), text, size + 1); - - JSONValue *value = JSON::Parse(text); - - if (value == NULL) - { - SetWindowText(GetDlgItem(hWnd, IDC_OUTPUT), L"The JSON text *is not* valid"); - } - else - { - if (LOWORD(wParam) == IDC_ECHO) - SetWindowText(GetDlgItem(hWnd, IDC_OUTPUT), value->Stringify().c_str()); - else - SetWindowText(GetDlgItem(hWnd, IDC_OUTPUT), L"The JSON text *is* valid"); - delete value; - } - - delete[] text; - break; - } - - case IDC_EX1: - extern const wchar_t *EXAMPLE; - SetWindowText(GetDlgItem(hDlg, IDC_INPUT), EXAMPLE); - example1(); - break; - - case IDC_EX2: - SetWindowText(GetDlgItem(hDlg, IDC_INPUT), L"Example 2:\r\n\r\nKey 'test_string' has a value 'hello world'\r\nKey 'sample_array' is an array of 10 random numbers"); - example2(); - break; - - case IDC_EX3: - extern const wchar_t *EXAMPLE; - SetWindowText(GetDlgItem(hDlg, IDC_INPUT), EXAMPLE); - example3(); - break; - - case IDC_EX4: - extern const wchar_t *EXAMPLE; - SetWindowText(GetDlgItem(hDlg, IDC_INPUT), EXAMPLE); - example4(); - break; - - case IDC_TESTCASES: - SetWindowText(GetDlgItem(hWnd, IDC_INPUT), L""); - run_tests(); - break; - } - - break; - } - } - - return 0; -} - -// Windows entry point -int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) -{ - wchar_t progdir[_MAX_PATH + 1]; - progdir[GetModuleFileName(hInstance, progdir, _MAX_PATH + 1)] = 0; - wchar_t *last_slash = wcsrchr(progdir, L'\\'); - if (last_slash) *(++last_slash) = 0; - SetCurrentDirectory(progdir); - - DialogBox(hInstance, MAKEINTRESOURCE(IDD_JSONDEMO), NULL, DialogProc); - return 0; -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..cfea794 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,36 @@ +# Header +#-----------------------------------------------------------------------# +SET(PROJ_NAME SimpleJSON_test) +PROJECT(${PROJ_NAME}) +MESSAGE(" + Adding test ${PROJ_NAME} ") # In info + +# Include directories with headers +#-----------------------------------------------------------------------# +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ) # This project includes +INCLUDE_DIRECTORIES( ${${PROJ_MAIN_NAME}_PATH_MAIN}/code/include ) + + +# Source, macro to find all files. If you add more, regenerate project +#-----------------------------------------------------------------------# +file(GLOB ${PROJ_NAME}_INCLUDE + ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/*.rc +) + +file(GLOB ${PROJ_NAME}_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp +) + +file(GLOB ${PROJ_NAME}_JSON + ${CMAKE_CURRENT_SOURCE_DIR}/test_cases/*.json +) + +add_executable(${PROJ_NAME} ${${PROJ_NAME}_INCLUDE} ${${PROJ_NAME}_SRC} ${${PROJ_NAME}_JSON}) + +# Link libraries with Project +#-----------------------------------------------------------------------# +target_link_libraries( ${PROJ_NAME} + SimpleJSON +) + +MESSAGE(" - Project ${PROJ_NAME} added!") # Out info \ No newline at end of file diff --git a/code/demo/functions.h b/test/include/functions.h similarity index 100% rename from code/demo/functions.h rename to test/include/functions.h diff --git a/code/demo/example.cpp b/test/src/example.cpp similarity index 99% rename from code/demo/example.cpp rename to test/src/example.cpp index d06f21d..a1d86b2 100644 --- a/code/demo/example.cpp +++ b/test/src/example.cpp @@ -25,7 +25,7 @@ #include #include #include -#include "../JSON.h" +#include "JSON.h" #include "functions.h" using namespace std; diff --git a/code/demo/nix-main.cpp b/test/src/nix-main.cpp similarity index 97% rename from code/demo/nix-main.cpp rename to test/src/nix-main.cpp index 0d56398..2188d76 100644 --- a/code/demo/nix-main.cpp +++ b/test/src/nix-main.cpp @@ -26,7 +26,7 @@ #include #include -#include "../JSON.h" +#include "JSON.h" #include "functions.h" using namespace std; @@ -131,5 +131,8 @@ int main(int argc, char **argv) wcout << L"Only one option can be used at a time." << endl; } + printf("\n%s", "Press 'Enter' to continue: ... "); + while ( getchar() != '\n'); + return 0; } diff --git a/code/demo/testcases.cpp b/test/src/testcases.cpp similarity index 99% rename from code/demo/testcases.cpp rename to test/src/testcases.cpp index 5fe28a5..be62b53 100644 --- a/code/demo/testcases.cpp +++ b/test/src/testcases.cpp @@ -31,7 +31,7 @@ #include #include #include -#include "../JSON.h" +#include "JSON.h" #include "functions.h" // Set to the width of the description column diff --git a/test/fail1.json b/test/test_cases/fail1.json similarity index 100% rename from test/fail1.json rename to test/test_cases/fail1.json diff --git a/test/fail10.json b/test/test_cases/fail10.json similarity index 100% rename from test/fail10.json rename to test/test_cases/fail10.json diff --git a/test/fail11.json b/test/test_cases/fail11.json similarity index 100% rename from test/fail11.json rename to test/test_cases/fail11.json diff --git a/test/fail12.json b/test/test_cases/fail12.json similarity index 100% rename from test/fail12.json rename to test/test_cases/fail12.json diff --git a/test/fail13.json b/test/test_cases/fail13.json similarity index 100% rename from test/fail13.json rename to test/test_cases/fail13.json diff --git a/test/fail14.json b/test/test_cases/fail14.json similarity index 100% rename from test/fail14.json rename to test/test_cases/fail14.json diff --git a/test/fail15.json b/test/test_cases/fail15.json similarity index 100% rename from test/fail15.json rename to test/test_cases/fail15.json diff --git a/test/fail16.json b/test/test_cases/fail16.json similarity index 100% rename from test/fail16.json rename to test/test_cases/fail16.json diff --git a/test/fail17.json b/test/test_cases/fail17.json similarity index 100% rename from test/fail17.json rename to test/test_cases/fail17.json diff --git a/test/fail18.json b/test/test_cases/fail18.json similarity index 100% rename from test/fail18.json rename to test/test_cases/fail18.json diff --git a/test/fail19.json b/test/test_cases/fail19.json similarity index 100% rename from test/fail19.json rename to test/test_cases/fail19.json diff --git a/test/fail2.json b/test/test_cases/fail2.json similarity index 100% rename from test/fail2.json rename to test/test_cases/fail2.json diff --git a/test/fail20.json b/test/test_cases/fail20.json similarity index 100% rename from test/fail20.json rename to test/test_cases/fail20.json diff --git a/test/fail21.json b/test/test_cases/fail21.json similarity index 100% rename from test/fail21.json rename to test/test_cases/fail21.json diff --git a/test/fail22.json b/test/test_cases/fail22.json similarity index 100% rename from test/fail22.json rename to test/test_cases/fail22.json diff --git a/test/fail23.json b/test/test_cases/fail23.json similarity index 100% rename from test/fail23.json rename to test/test_cases/fail23.json diff --git a/test/fail3.json b/test/test_cases/fail3.json similarity index 100% rename from test/fail3.json rename to test/test_cases/fail3.json diff --git a/test/fail4.json b/test/test_cases/fail4.json similarity index 100% rename from test/fail4.json rename to test/test_cases/fail4.json diff --git a/test/fail5.json b/test/test_cases/fail5.json similarity index 100% rename from test/fail5.json rename to test/test_cases/fail5.json diff --git a/test/fail6.json b/test/test_cases/fail6.json similarity index 100% rename from test/fail6.json rename to test/test_cases/fail6.json diff --git a/test/fail7.json b/test/test_cases/fail7.json similarity index 100% rename from test/fail7.json rename to test/test_cases/fail7.json diff --git a/test/fail8.json b/test/test_cases/fail8.json similarity index 100% rename from test/fail8.json rename to test/test_cases/fail8.json diff --git a/test/fail9.json b/test/test_cases/fail9.json similarity index 100% rename from test/fail9.json rename to test/test_cases/fail9.json diff --git a/test/pass1.json b/test/test_cases/pass1.json similarity index 100% rename from test/pass1.json rename to test/test_cases/pass1.json diff --git a/test/pass2.json b/test/test_cases/pass2.json similarity index 100% rename from test/pass2.json rename to test/test_cases/pass2.json diff --git a/test/pass3.json b/test/test_cases/pass3.json similarity index 100% rename from test/pass3.json rename to test/test_cases/pass3.json diff --git a/test/pass4.json b/test/test_cases/pass4.json similarity index 100% rename from test/pass4.json rename to test/test_cases/pass4.json diff --git a/test/pass5.json b/test/test_cases/pass5.json similarity index 100% rename from test/pass5.json rename to test/test_cases/pass5.json From 2629759084b84c6e1c9f0bd939ee6d1f134d67d9 Mon Sep 17 00:00:00 2001 From: piperoman Date: Sun, 17 Jan 2016 22:30:45 +0100 Subject: [PATCH 12/16] Added crossplatform configuration --- CMakeLists.txt | 102 ++++++++++------ cmake/scripts.cmake | 273 ++++++++++++++++++++++++++++++++++++++++++ code/CMakeLists.txt | 38 ++++++ test/CMakeLists.txt | 7 +- test/src/nix-main.cpp | 2 + 5 files changed, 383 insertions(+), 39 deletions(-) create mode 100644 cmake/scripts.cmake create mode 100644 code/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index ffde7f7..08eb0f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,48 +1,80 @@ +# TOP Level Configuration +# ------------------------------------------------------------------------------------------------------ cmake_minimum_required(VERSION 2.8.0) -# Header -#-----------------------------------------------------------------------# -SET(PROJ_MAIN_NAME SimpleJSON) + +# Project name & Configuration & Version +# ------------------------------------------------------------------------------------------------------ +SET(PROJ_MAIN_NAME "SimpleJSON-Configuration") +SET( ${PROJ_MAIN_NAME}_MAJOR_VERSION 0 CACHE STRING "Major version" FORCE) +SET( ${PROJ_MAIN_NAME}_MINOR_VERSION 8 CACHE STRING "Minor version" FORCE) +SET( ${PROJ_MAIN_NAME}_PATCH_VERSION 0 CACHE STRING "Patch version" FORCE) + PROJECT(${PROJ_MAIN_NAME}) -# Configure variables +# Include Cmake helpers # ------------------------------------------------------------------------------------------------------ +INCLUDE( cmake/scripts.cmake) +SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) -# Paths -SET(${PROJ_MAIN_NAME}_PATH_MAIN ${CMAKE_SOURCE_DIR} CACHE PATH "This directory contains initial Path") +# Configure variables +# ------------------------------------------------------------------------------------------------------ +# Our custom Paths +SET(${PROJ_MAIN_NAME}_PATH_MAIN ${CMAKE_SOURCE_DIR} CACHE PATH "This directory contains initial Path") +SET(${PROJ_MAIN_NAME}_PATH_LIBS ${PROJECT_BINARY_DIR}/bin CACHE PATH "This directory contains all libs") +SET(${PROJ_MAIN_NAME}_PATH_EXE ${PROJECT_BINARY_DIR}/bin CACHE PATH "This directory contains executables") +#SET(${PROJ_MAIN_NAME}_PATH_3RDPARTY ${CMAKE_SOURCE_DIR}/3rdParty CACHE PATH "This directory contains 3rdparty libraries") +SET(${PROJ_MAIN_NAME}_PATH_INSTALL ${PROJECT_BINARY_DIR}/install/${PROJ_MAIN_NAME} CACHE PATH "This directory to install prebuilt") # Configure options # ------------------------------------------------------------------------------------------------------ SET(${PROJ_MAIN_NAME}_BUILD_TEST "Build test" OFF ) -INCLUDE_DIRECTORIES("code/include") - -# Source, macro to find all files. If you add more, regenerate project -#-----------------------------------------------------------------------# -FILE(GLOB ${PROJ_MAIN_NAME}_SRC - "code/src/*.cpp" -) -FILE(GLOB ${PROJ_MAIN_NAME}_HEADERS - "code/include/*.h" -) - -# Create Library -#-----------------------------------------------------------------------# -ADD_LIBRARY(${PROJ_MAIN_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_MAIN_NAME}_HEADERS} ${${PROJ_MAIN_NAME}_SRC} ) - -# Create Project -#-----------------------------------------------------------------------# -#IF(${${PROJ_MAIN_NAME}_BUILD_TEST}) - ADD_SUBDIRECTORY(test) - -# Installation files in path -#---------------------------------------------------# -INSTALL(TARGETS ${PROJ_MAIN_NAME} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/lib" - ) -INSTALL(FILES ${${PROJ_MAIN_NAME}_HEADERS} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/include" - ) - +# Library type +IF(TARGET_PLATFORM STREQUAL TARGET_ANDROID) + SET(${PROJ_MAIN_NAME}_LIB_TYPE "STATIC" CACHE STRING "Choose static or shared") +ELSEIF(TARGET_PLATFORM STREQUAL TARGET_WIN32) + SET(${PROJ_MAIN_NAME}_LIB_TYPE "SHARED" CACHE STRING "Choose static or shared") +ELSEIF(TARGET_PLATFORM STREQUAL TARGET_LINUX) + SET(${PROJ_MAIN_NAME}_LIB_TYPE "SHARED" CACHE STRING "Choose static or shared") +ELSEIF(TARGET_PLATFORM STREQUAL TARGET_APPLE) + SET(${PROJ_MAIN_NAME}_LIB_TYPE "STATIC" CACHE STRING "Choose static or shared") +ELSEIF(TARGET_PLATFORM STREQUAL TARGET_IOS) + SET(${PROJ_MAIN_NAME}_LIB_TYPE "STATIC" CACHE STRING "Choose static or shared") +ELSE() + MESSAGE(FATAL_ERROR "ERROR ${PROJ_MAIN_NAME}_LIB_TYPE") +ENDIF() + +# Project Logic +# ------------------------------------------------------------------------------------------------------ +IF(NOT TARGET_PLATFORM STREQUAL TARGET_NONE) + ###################################################################################### + # Logic configuration + ###################################################################################### + MESSAGE("Adding C++11 flags, NEEDED to be supported by compiler") + IF(TARGET_PLATFORM STREQUAL TARGET_APPLE) + SET(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS} ") + ELSE() + SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS} ") + ENDIF() + + ###################################################################################### + # Print info + ###################################################################################### + PRINTADVANCEDINFO(${PROJ_MAIN_NAME}) + + ADD_SUBDIRECTORY("code") + + IF(${PROJ_MAIN_NAME}_BUILD_TEST) + MESSAGE(" + Test enabled!") + ADD_SUBDIRECTORY(test) + ELSE() + MESSAGE(" - Test disabled!") + ENDIF() + +ELSE() + message(FATAL_ERROR " TARGET no autodetected. Please, select a TARGET manually. ") +ENDIF() + MESSAGE(" * Project ${PROJ_MAIN_NAME} done!") # Out info diff --git a/cmake/scripts.cmake b/cmake/scripts.cmake new file mode 100644 index 0000000..9223cd8 --- /dev/null +++ b/cmake/scripts.cmake @@ -0,0 +1,273 @@ +# -------------------------------------------------------------- +# Indicate CMake 2.7 and above that we don't want to mix relative +# and absolute paths in linker lib lists. +# Run "cmake --help-policy CMP0003" for more information. +# -------------------------------------------------------------- +IF(COMMAND cmake_policy) + #cmake_policy(SET CMP0003 NEW) +ENDIF() + +# 1º Select only one target to compile the code, easier for cross-compiling +# Try to auto detect and set the target parameter +# ------------------------------------------------------------------------------------------------------ +SET(TARGET_PLATFORM CACHE STRING "TARGET_NONE") +SET_PROPERTY(CACHE TARGET_PLATFORM PROPERTY STRINGS "TARGET_NONE" "TARGET_ANDROID" "TARGET_WIN32" "TARGET_LINUX" "TARGET_IOS" "TARGET_APPLE") # List with targets types + +MESSAGE("* Autodetecting platform . . .") + +IF(NOT CMAKE_TOOLCHAIN_FILE) + IF(WIN32) + MESSAGE(" Win32 detected.") + SET(TARGET_PLATFORM TARGET_WIN32 CACHE STRING "Target Platform" FORCE) + ELSEIF(APPLE) + MESSAGE(" APPLE detected.") + SET(TARGET_PLATFORM TARGET_APPLE CACHE STRING "Target Platform" FORCE) + ELSE(WIN32) + MESSAGE(" Linux detected.") + SET(TARGET_PLATFORM TARGET_LINUX CACHE STRING "Target Platform" FORCE) + ENDIF(WIN32) +ELSE() + IF(APPLE) + MESSAGE(" iOS detected.") + SET(TARGET_PLATFORM TARGET_IOS CACHE STRING "Target Platform" FORCE) + ELSE(APPLE) + MESSAGE(" Android detected.") + SET(TARGET_PLATFORM TARGET_ANDROID CACHE STRING "Target Platform" FORCE) + ENDIF(APPLE) +ENDIF() +MESSAGE("") + +# 2º Configuration custom build type +# ------------------------------------------------------------------------------------------------------ +SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE) +IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8") + SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES}) +ENDIF() + +# 3º Configuration custom type configuration, git status(Shared, static) +# ------------------------------------------------------------------------------------------------------ +SET(${PROJ_MAIN_NAME}_LIB_TYPE "STATIC" CACHE STRING "Type of lib") +SET_PROPERTY(CACHE ${PROJ_MAIN_NAME}_LIB_TYPE PROPERTY STRINGS "SHARED" "STATIC") + +# 4º Configuration default CMake options +# ------------------------------------------------------------------------------------------------------ +SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Library output" FORCE) +SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH "Executable output" FORCE) +SET(CMAKE_DEBUG_POSTFIX ) # No postfix + +# 5º Add these standard paths to the search paths for FIND_LIBRARY +# to find libraries from these locations first +# ------------------------------------------------------------------------------------------------------ + if(UNIX AND NOT ANDROID) + if(X86_64 OR CMAKE_SIZEOF_VOID_P EQUAL 8) + if(EXISTS /lib64) + list(APPEND CMAKE_LIBRARY_PATH /lib64) + else() + list(APPEND CMAKE_LIBRARY_PATH /lib) + endif() + if(EXISTS /usr/lib64) + list(APPEND CMAKE_LIBRARY_PATH /usr/lib64) + else() + list(APPEND CMAKE_LIBRARY_PATH /usr/lib) + endif() + elseif(X86 OR CMAKE_SIZEOF_VOID_P EQUAL 4) + if(EXISTS /lib32) + list(APPEND CMAKE_LIBRARY_PATH /lib32) + else() + list(APPEND CMAKE_LIBRARY_PATH /lib) + endif() + if(EXISTS /usr/lib32) + list(APPEND CMAKE_LIBRARY_PATH /usr/lib32) + else() + list(APPEND CMAKE_LIBRARY_PATH /usr/lib) + endif() + endif() + endif() + +# 5º Support C++11 crossplatform +# ------------------------------------------------------------------------------------------------------ + macro(CHECK_FOR_CXX11_COMPILER _VAR) + message(STATUS "Checking for C++11 compiler") + set(${_VAR}) + if((MSVC AND (MSVC10 OR MSVC11 OR MSVC12)) OR + (CMAKE_COMPILER_IS_GNUCXX AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.6) OR + (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.1)) + message(STATUS "Checking for C++11 compiler - available") + # Add C++11 support + SET(${_VAR} TRUE) + else() + message(STATUS "Checking for C++11 compiler - unavailable") + # Add C++11 support + SET(${_VAR} FALSE) + endif() +endmacro() + +# Sets the appropriate flag to enable C++11 support +macro(ENABLE_CXX11) + # Compiler-specific C++11 activation. + IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS} ") + IF(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.7 OR + CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.7 OR + DEFINED CMAKE_TOOLCHAIN_FILE)) + MESSAGE("${PROJECT_NAME} requires g++ 4.7 or greater, your version is ${CMAKE_CXX_COMPILER_VERSION}") + ELSE() + MESSAGE("${PROJECT_NAME} GNU compiler use C++11") + ENDIF() + elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") + find_package(LLVM REQUIRED CONFIG) + MESSAGE("${PROJECT_NAME} Clang compiler use C++11") + else () + MESSAGE("${PROJECT_NAME} c++11 works") + endif () +endmacro() + +macro(ENABLE_SSE) + IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2") + elseif (MSVC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2") + endif() +endmacro() + +MACRO(PRINTADVANCEDINFO PROJ_NAME) + # INFO + #--------------------------------------------------- + MESSAGE("") + MESSAGE("* Project: " ${PROJ_NAME} ) + MESSAGE("*-----------------------------------------------------------------------------------*" ) + MESSAGE("") + MESSAGE(" Platform: ") + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" Host: " ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR}) + MESSAGE(" CrossCompiling: " ${CMAKE_CROSSCOMPILING}) + IF(CMAKE_CROSSCOMPILING) + MESSAGE(" Target: " ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR}) + ENDIF() + MESSAGE("") + MESSAGE(" General Options:" ) + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" CMake: " ${CMAKE_VERSION}) + MESSAGE(" CMake generator: " ${CMAKE_GENERATOR}) + MESSAGE(" CMake build tool: " ${CMAKE_BUILD_TOOL}) + IF(MSVC) + MESSAGE(" MSVC: " ${MSVC_VERSION}) + ENDIF() + IF(CMAKE_GENERATOR MATCHES Xcode) + MESSAGE(" Xcode: " ${XCODE_VERSION}) + ENDIF() + IF(NOT CMAKE_GENERATOR MATCHES "Xcode|Visual Studio") + MESSAGE(" Configuration:" ${CMAKE_BUILD_TYPE}) + ENDIF() + MESSAGE(" Custom platform name: " ${TARGET_PLATFORM_NAME} ) + MESSAGE(" Build Configurations: " ${CMAKE_CONFIGURATION_TYPES} ) + MESSAGE(" Build type: " ${CMAKE_BUILD_TYPE} ) + MESSAGE(" Verbose mode: " ${CMAKE_VERBOSE} ) + MESSAGE(" Target Name: " ${TARGET_PLATFORM} ) + MESSAGE("") + MESSAGE(" Paths " ) + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" Root: " ${${PROJ_NAME}_PATH_MAIN} ) + MESSAGE(" Data: " ${${PROJ_NAME}_PATH_DATA} ) + MESSAGE(" Libs: " ${${PROJ_NAME}_PATH_LIBS} ) + MESSAGE(" Installation: " ${${PROJ_NAME}_PATH_INSTALL} ) + MESSAGE(" Executable: " ${EXECUTABLE_OUTPUT_PATH} ) + MESSAGE(" Binary: " ${PROJECT_BINARY_DIR} ) + MESSAGE("") + + MESSAGE(" Project Bool Options " ) + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" Samples: " ${${PROJECT_NAME}_BUILD_SAMPLES} ) + MESSAGE(" Docs: " ${${PROJECT_NAME}_BUILD_DOCS} ) + MESSAGE("") + + # ========================== C/C++ options ========================== + MESSAGE(" C/C++:") + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO) + MESSAGE(" Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO) + MESSAGE(" C++ Compiler:" CMAKE_COMPILER_IS_GNUCXX THEN "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_GCC_REGEX_VERSION})" ELSE "${CMAKE_CXX_COMPILER}" ) + MESSAGE(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}) + MESSAGE(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}) + MESSAGE(" C Compiler:" ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}) + MESSAGE(" C flags (Release):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}) + MESSAGE(" C flags (Debug):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}) + MESSAGE(" Linker flags exe (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) + MESSAGE(" Linker flags exe (Debug):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG}) + MESSAGE(" Linker flags shared (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}) + MESSAGE(" Linker flags shared (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}) + MESSAGE("") + + # ========================== Android details ========================== +IF(TARGET_PLATFORM STREQUAL TARGET_ANDROID) + MESSAGE(" Android: ") + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" Android ABI:" ${ANDROID_ABI}) + MESSAGE(" Native API level:" android-${ANDROID_NATIVE_API_LEVEL}) + MESSAGE(" SDK target:" "${ANDROID_SDK_TARGET}") + MESSAGE(" Android NDK:" "${ANDROID_NDK} (toolchain: ${ANDROID_TOOLCHAIN_NAME})") + MESSAGE("") +ENDIF(TARGET_PLATFORM STREQUAL TARGET_ANDROID) + + # ========================== iOS details ========================== +IF( TARGET_PLATFORM_NAME STREQUAL iOS ) + MESSAGE(" iOS: ") + MESSAGE(" -------------------------------------------------------------------------------") + MESSAGE(" Platform:" ${IOS_PLATFORM} ) + MESSAGE(" SDK Root:" ${CMAKE_IOS_SDK_ROOT} ) + MESSAGE(" Architectures:" ${CMAKE_OSX_ARCHITECTURES} ) + MESSAGE(" Deployment Target:" ${CMAKE_OSX_DEPLOYMENT_TARGET} ) + MESSAGE(" Framework Search Path:" ${CMAKE_FRAMEWORK_PATH} ) + MESSAGE(" OSX SYSROOT:" ${CMAKE_OSX_SYSROOT} ) + MESSAGE("") +ENDIF() + + MESSAGE("") + MESSAGE(" ***********************************************************************************************") + MESSAGE("") + MESSAGE(" oooOOOOOOOOOOO Piperoman 2010-2016 ${PROJ_NAME} ") + MESSAGE(" o ____ :::::::::::::::::: :::::::::::::::::: __|-----|__") + MESSAGE(" Y_,_|[]| --++++++ |[][][][][][][][]| |[][][][][][][][]| | [] [] |") + MESSAGE(" {|_|_|__|;|______|;|________________|;|________________|;|_________|;") + MESSAGE(" /oo--OO oo oo oo oo oo oo oo oo oo oo oo oo") + MESSAGE(" +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+") + MESSAGE("") + MESSAGE(" ***********************************************************************************************") + MESSAGE("") + +ENDMACRO() + +MACRO(PRINTBASICINFO PROJ_NAME) +# Test printing +MESSAGE(" ") +MESSAGE("--- Project: ${PROJ_NAME} information ------------------------------------------") +MESSAGE("--------------------------------------------------------------------------------") +MESSAGE("*** Include directories:") + # Include DIRECTORIES + GET_PROPERTY(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) + FOREACH(dir ${dirs}) + MESSAGE(" * '${dir}'") + ENDFOREACH() + +MESSAGE("--------------------------------------------------------------------------------") +MESSAGE("*** Link directories:") + # Link DIRECTORIES + GET_PROPERTY(targetdirlinks DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_DIRECTORIES) + FOREACH(linkdir ${targetdirlinks}) + MESSAGE(" * '${linkdir}'") + ENDFOREACH() + +MESSAGE("--------------------------------------------------------------------------------") +MESSAGE("*** Link libraries:") + # Linking against + GET_TARGET_PROPERTY(libtargets ${PROJ_NAME} LINK_LIBRARIES) + FOREACH(libtarget ${libtargets}) + MESSAGE(" * '${libtarget}'") + ENDFOREACH() + +MESSAGE("--------------------------------------------------------------------------------") +MESSAGE(" ") +ENDMACRO() diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt new file mode 100644 index 0000000..3591116 --- /dev/null +++ b/code/CMakeLists.txt @@ -0,0 +1,38 @@ +# Header +#-----------------------------------------------------------------------# +SET(PROJ_MAIN_NAME "simpleJSON") +PROJECT(${PROJ_MAIN_NAME}) + +# Include directories with headers +#-----------------------------------------------------------------------# +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ) # This projects' includes + +# Source, macro to find all files. If you add more, regenerate project +#-----------------------------------------------------------------------# +FILE(GLOB ${PROJ_MAIN_NAME}_HEADERS + "include/*.h" +) + +FILE(GLOB ${PROJ_MAIN_NAME}_SRC + "src/*.cpp" +) + +# Create Library +#-----------------------------------------------------------------------# +ADD_LIBRARY(${PROJ_MAIN_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_MAIN_NAME}_HEADERS} ${${PROJ_MAIN_NAME}_SRC} ) + +# Link libraries with Project +#-----------------------------------------------------------------------# +#TARGET_LINK_LIBRARIES(${PROJ_NAME} dependencyName) + +# Installation files in path +#---------------------------------------------------# +INSTALL(TARGETS ${PROJ_MAIN_NAME} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/lib" + ) +INSTALL(FILES ${${PROJ_MAIN_NAME}_HEADERS} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/include" + ) + +#PRINTBASICINFO(${PROJ_NAME}) # Macro cmake_tools to print, uncomment to add info +MESSAGE(" - Module ${PROJ_NAME} added!") # Out info diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cfea794..89448a3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ # Header #-----------------------------------------------------------------------# -SET(PROJ_NAME SimpleJSON_test) +SET(PROJ_NAME simpleJSON_test) PROJECT(${PROJ_NAME}) MESSAGE(" + Adding test ${PROJ_NAME} ") # In info @@ -9,7 +9,6 @@ MESSAGE(" + Adding test ${PROJ_NAME} ") # In info INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ) # This project includes INCLUDE_DIRECTORIES( ${${PROJ_MAIN_NAME}_PATH_MAIN}/code/include ) - # Source, macro to find all files. If you add more, regenerate project #-----------------------------------------------------------------------# file(GLOB ${PROJ_NAME}_INCLUDE @@ -30,7 +29,7 @@ add_executable(${PROJ_NAME} ${${PROJ_NAME}_INCLUDE} ${${PROJ_NAME}_SRC} ${${PROJ # Link libraries with Project #-----------------------------------------------------------------------# target_link_libraries( ${PROJ_NAME} - SimpleJSON + simpleJSON ) -MESSAGE(" - Project ${PROJ_NAME} added!") # Out info \ No newline at end of file +MESSAGE(" - Project ${PROJ_NAME} added!") # Out info diff --git a/test/src/nix-main.cpp b/test/src/nix-main.cpp index 2188d76..ef9ecd6 100644 --- a/test/src/nix-main.cpp +++ b/test/src/nix-main.cpp @@ -29,6 +29,8 @@ #include "JSON.h" #include "functions.h" +#include + using namespace std; // Print out function From 4dfb67e5343ccdb399fad1be8372ca5339b86bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20de=20Celis=20Hern=C3=A1ndez?= Date: Sun, 17 Jan 2016 23:42:20 +0100 Subject: [PATCH 13/16] Fixed BUILD_TEST option in the CMAKE configuration Minor fixes in the CMAKE files --- CMakeLists.txt | 11 ++++++----- code/CMakeLists.txt | 5 +++-- test/CMakeLists.txt | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08eb0f7..637cd05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 2.8.0) # Project name & Configuration & Version # ------------------------------------------------------------------------------------------------------ -SET(PROJ_MAIN_NAME "SimpleJSON-Configuration") +SET(PROJ_MAIN_NAME "SimpleJSON-Solution") SET( ${PROJ_MAIN_NAME}_MAJOR_VERSION 0 CACHE STRING "Major version" FORCE) SET( ${PROJ_MAIN_NAME}_MINOR_VERSION 8 CACHE STRING "Minor version" FORCE) SET( ${PROJ_MAIN_NAME}_PATCH_VERSION 0 CACHE STRING "Patch version" FORCE) @@ -29,7 +29,7 @@ SET(${PROJ_MAIN_NAME}_PATH_INSTALL ${PROJECT_BINARY_DIR}/install/${PROJ_MAIN_NA # Configure options # ------------------------------------------------------------------------------------------------------ -SET(${PROJ_MAIN_NAME}_BUILD_TEST "Build test" OFF ) +SET(${PROJ_MAIN_NAME}_BUILD_TEST OFF CACHE BOOL "Build test" ) # Library type IF(TARGET_PLATFORM STREQUAL TARGET_ANDROID) @@ -67,14 +67,15 @@ IF(NOT TARGET_PLATFORM STREQUAL TARGET_NONE) ADD_SUBDIRECTORY("code") IF(${PROJ_MAIN_NAME}_BUILD_TEST) - MESSAGE(" + Test enabled!") + MESSAGE(" Info: Test enabled!") ADD_SUBDIRECTORY(test) ELSE() - MESSAGE(" - Test disabled!") + MESSAGE(" Info: Test disabled!") ENDIF() ELSE() message(FATAL_ERROR " TARGET no autodetected. Please, select a TARGET manually. ") ENDIF() -MESSAGE(" * Project ${PROJ_MAIN_NAME} done!") # Out info +#PRINTBASICINFO(${PROJ_MAIN_NAME}) # Macro cmake_tools to print, uncomment to add info +MESSAGE(" * Solution ${PROJ_MAIN_NAME} done!") # Out info diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 3591116..8ff6083 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -2,6 +2,7 @@ #-----------------------------------------------------------------------# SET(PROJ_MAIN_NAME "simpleJSON") PROJECT(${PROJ_MAIN_NAME}) +MESSAGE(" + Adding ${PROJ_NAME} ") # In info # Include directories with headers #-----------------------------------------------------------------------# @@ -34,5 +35,5 @@ INSTALL(FILES ${${PROJ_MAIN_NAME}_HEADERS} DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/include" ) -#PRINTBASICINFO(${PROJ_NAME}) # Macro cmake_tools to print, uncomment to add info -MESSAGE(" - Module ${PROJ_NAME} added!") # Out info +#PRINTBASICINFO(${PROJ_MAIN_NAME}) # Macro cmake_tools to print, uncomment to add info +MESSAGE(" - Project ${PROJ_MAIN_NAME} added!") # Out info diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 89448a3..c4167fd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,7 +2,7 @@ #-----------------------------------------------------------------------# SET(PROJ_NAME simpleJSON_test) PROJECT(${PROJ_NAME}) -MESSAGE(" + Adding test ${PROJ_NAME} ") # In info +MESSAGE(" + Adding ${PROJ_NAME} ") # In info # Include directories with headers #-----------------------------------------------------------------------# @@ -13,7 +13,6 @@ INCLUDE_DIRECTORIES( ${${PROJ_MAIN_NAME}_PATH_MAIN}/code/include ) #-----------------------------------------------------------------------# file(GLOB ${PROJ_NAME}_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/*.rc ) file(GLOB ${PROJ_NAME}_SRC @@ -32,4 +31,5 @@ target_link_libraries( ${PROJ_NAME} simpleJSON ) +#PRINTBASICINFO(${PROJ_MAIN_NAME}) # Macro cmake_tools to print, uncomment to add info MESSAGE(" - Project ${PROJ_NAME} added!") # Out info From 3adad11fe723df14947db555b2eac81b8c986395 Mon Sep 17 00:00:00 2001 From: rdcelis Date: Mon, 18 Jan 2016 19:49:40 +0100 Subject: [PATCH 14/16] Fixed wrong data type used as parameter in addBool and addFloat Signed-off-by: rdcelis --- code/include/JSONString.h | 4 ++-- code/src/JSONString.cpp | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/code/include/JSONString.h b/code/include/JSONString.h index fda8f7f..e4b77e7 100755 --- a/code/include/JSONString.h +++ b/code/include/JSONString.h @@ -19,10 +19,10 @@ class JSONString void startArray(); void finishArray(); - void addBool(std::string id, int data); + void addBool(std::string id, bool data); void addInt(std::string id, int data); void addUnsignedInt(std::string id, unsigned int data); - void addFloat(std::string id, unsigned int data); + void addFloat(std::string id, float data); void addString(std::string id, std::string data); void addArray(std::string id, std::string data); void addArrayData(std::string data); diff --git a/code/src/JSONString.cpp b/code/src/JSONString.cpp index 5553115..01a27f9 100755 --- a/code/src/JSONString.cpp +++ b/code/src/JSONString.cpp @@ -1,5 +1,4 @@ #include "JSONString.h" -#include void JSONString::startJSON() { @@ -26,10 +25,18 @@ void JSONString::finishArray() _jsonstring += "]"; } -void JSONString::addBool(std::string id, int data) +void JSONString::addBool(std::string id, bool data) { std::ostringstream os; - os << data ; + + if(data) + { + os << "true" ; + + }else + { + os << "false"; + } _jsonstring += "\""; _jsonstring += id; @@ -62,7 +69,7 @@ void JSONString::addUnsignedInt(std::string id, unsigned int data) _jsonstring += os.str(); } -void JSONString::addFloat(std::string id, unsigned int data) +void JSONString::addFloat(std::string id, float data) { std::ostringstream os; os << data ; From 6896eaf022a301427da5d770d48023f86b8c32bc Mon Sep 17 00:00:00 2001 From: rdcelis Date: Tue, 19 Jan 2016 14:15:05 +0100 Subject: [PATCH 15/16] Added option prettyprint in Stringify and StringifyToString methods in the JSON class Signed-off-by: rdcelis --- code/include/JSON.h | 4 ++-- code/src/JSON.cpp | 15 +++++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/code/include/JSON.h b/code/include/JSON.h index 60ddc8d..0d1bcf5 100644 --- a/code/include/JSON.h +++ b/code/include/JSON.h @@ -99,8 +99,8 @@ class JSON public: static JSONValue* Parse(const char *data); static JSONValue* Parse(const wchar_t *data); - static std::wstring Stringify(const JSONValue *value); - static std::string StringifyToString(const JSONValue *value); + static std::wstring Stringify(const JSONValue *value, bool const prettyprint = false); + static std::string StringifyToString(const JSONValue *value, bool const prettyprint = false); protected: static bool SkipWhitespace(const wchar_t **data); static bool ExtractString(const wchar_t **data, std::wstring &str); diff --git a/code/src/JSON.cpp b/code/src/JSON.cpp index 07251d4..42aa7a9 100644 --- a/code/src/JSON.cpp +++ b/code/src/JSON.cpp @@ -113,10 +113,10 @@ JSONValue *JSON::Parse(const wchar_t *data) * * @return std::wstring Returns a JSON encoded string representation of the given value */ -std::wstring JSON::Stringify(const JSONValue *value) +std::wstring JSON::Stringify(const JSONValue *value, bool const prettyprint) { if (value != NULL) - return value->Stringify(); + return value->Stringify(prettyprint); else return L""; } @@ -130,15 +130,10 @@ std::wstring JSON::Stringify(const JSONValue *value) * * @return std::string Returns a JSON encoded string representation of the given value */ -std::string JSON::StringifyToString(const JSONValue *value) +std::string JSON::StringifyToString(const JSONValue *value, bool const prettyprint) { - if (value != NULL){ - - std::string result; - result.assign(value->Stringify().begin(), value->Stringify().end()); - return result; - } - + if (value != NULL) + return value->StringifyToString(prettyprint); else return ""; } From 6f2a793542b5375602d55ae91da26d42d60603d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Go=C3=B1i=20Sanz?= Date: Thu, 28 Jan 2016 18:43:33 +0100 Subject: [PATCH 16/16] Fixed variables cmake to install propertly --- code/CMakeLists.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 8ff6083..eb39270 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -1,7 +1,7 @@ # Header #-----------------------------------------------------------------------# -SET(PROJ_MAIN_NAME "simpleJSON") -PROJECT(${PROJ_MAIN_NAME}) +SET(PROJ_NAME "simpleJSON") +PROJECT(${PROJ_NAME}) MESSAGE(" + Adding ${PROJ_NAME} ") # In info # Include directories with headers @@ -10,30 +10,30 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ) # This projects' inc # Source, macro to find all files. If you add more, regenerate project #-----------------------------------------------------------------------# -FILE(GLOB ${PROJ_MAIN_NAME}_HEADERS +FILE(GLOB ${PROJ_NAME}_HEADERS "include/*.h" ) -FILE(GLOB ${PROJ_MAIN_NAME}_SRC +FILE(GLOB ${PROJ_NAME}_SRC "src/*.cpp" ) # Create Library #-----------------------------------------------------------------------# -ADD_LIBRARY(${PROJ_MAIN_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_MAIN_NAME}_HEADERS} ${${PROJ_MAIN_NAME}_SRC} ) +ADD_LIBRARY(${PROJ_NAME} ${${PROJ_NAME}_LIB_TYPE} ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) # Link libraries with Project #-----------------------------------------------------------------------# #TARGET_LINK_LIBRARIES(${PROJ_NAME} dependencyName) -# Installation files in path +# Installation files in path #---------------------------------------------------# -INSTALL(TARGETS ${PROJ_MAIN_NAME} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/lib" +INSTALL(TARGETS ${PROJ_NAME} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/lib" ) -INSTALL(FILES ${${PROJ_MAIN_NAME}_HEADERS} - DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_MAIN_NAME}/include" +INSTALL(FILES ${${PROJ_NAME}_HEADERS} + DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/include" ) -#PRINTBASICINFO(${PROJ_MAIN_NAME}) # Macro cmake_tools to print, uncomment to add info -MESSAGE(" - Project ${PROJ_MAIN_NAME} added!") # Out info +#PRINTBASICINFO(${PROJ_NAME}) # Macro cmake_tools to print, uncomment to add info +MESSAGE(" - Project ${PROJ_NAME} added!") # Out info