diff --git a/.gitignore b/.gitignore index 4581ef2e..fcafeae8 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ *.exe *.out *.app + +build diff --git a/CMakeLists.txt b/CMakeLists.txt index d72e91ff..8442850b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,25 @@ project(iguana) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++14") set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl") +set(IGUANA_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(SOURCE_FILES - example.cpp - ) -add_executable(iguana ${SOURCE_FILES}) \ No newline at end of file +include_directories( + ${IGUANA_DIR} + ${IGUANA_DIR}/third_party/msgpack/include +) + +set(JSON_EXAMPLE + example/json_example.cpp +) + +set(XML_EXAMPLE + example/xml_example.cpp +) + +set(MSGPACK_EXAMPLE + example/msgpack_example.cpp +) + +add_executable(json_example ${JSON_EXAMPLE}) +add_executable(xml_example ${XML_EXAMPLE}) +add_executable(msgpack_example ${MSGPACK_EXAMPLE}) diff --git a/example/json_example.cpp b/example/json_example.cpp index e69de29b..c45315a0 100644 --- a/example/json_example.cpp +++ b/example/json_example.cpp @@ -0,0 +1,29 @@ +#include + +namespace client +{ + struct person + { + std::string name; + int age; + }; + + REFLECTION(person, name, age); +} + +int main(void) +{ + client::person p = { "zombie chow", 31 }; + + iguana::string_stream ss; + iguana::json::to_json(ss, p); + + auto json_str = ss.str(); + std::cout << json_str << std::endl; + + client::person p2; + iguana::json::from_json(p2, json_str.data(), json_str.length()); + + std::cout << p2.name << " - " << p2.age << std::endl; + return 0; +} \ No newline at end of file