-
-
Save yossi-tahara/83d2fb23ababfe8e7e831fb5a43635e0 to your computer and use it in GitHub Desktop.
Theolizer技術解説(2016/09/16) 構造体やクラス、enum型の定義を変更する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[[########################################################################### | |
Theolizer紹介用サンプルCMakeLists.txt | |
]]############################################################################ | |
if("${CMAKE_VERSION}" STREQUAL "") | |
set(CMAKE_VERSION, 3.5.0) | |
endif() | |
cmake_minimum_required(VERSION ${CMAKE_VERSION}) | |
message(STATUS "BOOST_ROOT=${BOOST_ROOT}") | |
#----------------------------------------------------------------------------- | |
# プロジェクト設定 | |
#----------------------------------------------------------------------------- | |
set(TARGET_NAME sample) | |
project(${TARGET_NAME} VERSION 1.0.0) | |
#----------------------------------------------------------------------------- | |
# ビルド設定 | |
#----------------------------------------------------------------------------- | |
# MSVCの通常使わないビルド・モードとZERO_CHECKプロジェクトの削除 | |
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE) | |
set(CMAKE_SUPPRESS_REGENERATION TRUE) | |
# Theolizer | |
find_package(THEOLIZER) | |
# Options | |
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) | |
add_definitions(-D_UNICODE -DUNICODE) | |
set(CMAKE_DEBUG_POSTFIX "d") | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") | |
else() | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
# MinGWの不具合(https://sourceforge.net/p/mingw-w64/discussion/723797/thread/c6b70624/#7f0a)暫定対処 | |
if((CMAKE_COMPILER_IS_MINGW) AND (CMAKE_SIZEOF_VOID_P EQUAL 8)) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj") | |
endif() | |
endif() | |
# ---<<< ターゲットa >>>--- | |
set(SOURCE_LIST main_a.cpp) | |
set(HEADER_LIST main_a.h) | |
add_executable(${TARGET_NAME}_a ${SOURCE_LIST} ${HEADER_LIST}) | |
setup_theolizer(${TARGET_NAME}_a StaticWithBoost) | |
# ---<<< ターゲットb >>>--- | |
set(SOURCE_LIST main_b.cpp) | |
set(HEADER_LIST main_b.h) | |
add_executable(${TARGET_NAME}_b ${SOURCE_LIST} ${HEADER_LIST}) | |
setup_theolizer(${TARGET_NAME}_b StaticWithBoost) | |
#----------------------------------------------------------------------------- | |
# テスト実行 | |
#----------------------------------------------------------------------------- | |
enable_testing() | |
add_test(NAME ${TARGET_NAME}_a COMMAND $<TARGET_FILE:${TARGET_NAME}_a>) | |
add_test(NAME ${TARGET_NAME}_b COMMAND $<TARGET_FILE:${TARGET_NAME}_b>) | |
add_custom_target(BuildTest COMMAND "ctest" "-V" "-C" $<CONFIG>) | |
add_dependencies(BuildTest ${TARGET_NAME}_a) | |
add_dependencies(BuildTest ${TARGET_NAME}_b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//############################################################################ | |
// Theolizer解説用サンプル・プログラムExtra-1 | |
//############################################################################ | |
#define THEOLIZER_GLOBAL_VERSION_TABLE | |
// *************************************************************************** | |
// インクルード | |
// *************************************************************************** | |
// 標準ライブラリ | |
#include <fstream> | |
// 共通定義 | |
#include "main_a.h" | |
// Theolizer自動生成先 | |
#include "main_a.cpp.theolizer.hpp" | |
// *************************************************************************** | |
// メイン | |
// *************************************************************************** | |
int main(int argc, char* argv[]) | |
{ | |
//---------------------------------------------------------------------------- | |
// バラメータ解析 | |
//---------------------------------------------------------------------------- | |
bool aLoadOnly=false; | |
if (1 < argc) | |
{ | |
std::string argv1=argv[1]; | |
if ((argv1 == "l") || (argv1 == "L")) | |
{ | |
aLoadOnly=true; | |
} | |
} | |
std::cout << theolizer::print("LoadOnly:%d\n", aLoadOnly); | |
//---------------------------------------------------------------------------- | |
// 保存 | |
//---------------------------------------------------------------------------- | |
if (!aLoadOnly) | |
{ | |
// データを生成する | |
Foo aFooA=eFoo0; | |
Foo aFooB=eFoo1; | |
Bar aBar; | |
aBar.mBar0=10; | |
aBar.mBar1=11; | |
aBar.mBar2="12"; | |
// 保存先のファイルをオープンする | |
std::ofstream aStream("test.json"); | |
// シリアライザを用意する | |
theolizer::JsonOSerializer<> js(aStream); | |
// test.jsonファイルへ保存する | |
THEOLIZER_PROCESS(js, aFooA); | |
THEOLIZER_PROCESS(js, aFooB); | |
THEOLIZER_PROCESS(js, aBar); | |
} | |
//---------------------------------------------------------------------------- | |
// 回復 | |
//---------------------------------------------------------------------------- | |
// 回復処理 | |
{ | |
// データ領域を獲得する | |
Foo aFooA; | |
Foo aFooB; | |
Bar aBar; | |
// 回復元のファイルをオープンする | |
std::ifstream aStream("test.json"); | |
// シリアライザを用意する | |
theolizer::JsonISerializer<> js(aStream); | |
// test.jsonファイルから回復する | |
THEOLIZER_PROCESS(js, aFooA); | |
THEOLIZER_PROCESS(js, aFooB); | |
THEOLIZER_PROCESS(js, aBar); | |
// Json形式で表示する | |
theolizer::JsonOSerializer<> jout(std::cout); | |
THEOLIZER_PROCESS(jout, aFooA); | |
THEOLIZER_PROCESS(jout, aFooB); | |
THEOLIZER_PROCESS(jout, aBar); | |
// 普通に表示する | |
std::cout << theolizer::print(u8"(eFoo0=%d, eFoo1=%d)\n", eFoo0, eFoo1); | |
std::cout << theolizer::print(u8"aFooA=%d\n", aFooA); | |
std::cout << theolizer::print(u8"aFooB=%d\n", aFooB); | |
std::cout << theolizer::print(u8"aBar.mBar0=%d\n", aBar.mBar0); | |
std::cout << theolizer::print(u8"aBar.mBar1=%d\n", aBar.mBar1); | |
std::cout << theolizer::print(u8"aBar.mBar2=%s\n", aBar.mBar2); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef THEOLIZER_WRITE_CODE // ###### Foo ###### | |
#define THEOLIZER_GENERATED_LAST_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kLastVersionNo,1) | |
#define THEOLIZER_GENERATED_FULL_AUTO Foo | |
// ---<<< Version.1 >>>--- | |
#define THEOLIZER_GENERATED_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kVersionNo,1) | |
#define THEOLIZER_GENERATED_ENUM_NAME u8"Foo" | |
#define THEOLIZER_GENERATED_SAVE_TYPE estName | |
#define THEOLIZER_GENERATED_BASE_TYPE int | |
#define THEOLIZER_GENERATED_ENUM_LIST()\ | |
THEOLIZER_GENERATED_ELEMENT((u8"eFoo0"),(0),(0))\ | |
THEOLIZER_GENERATED_ELEMENT((u8"eFoo1"),(1),(1)) | |
#define THEOLIZER_GENERATED_DEFAULT_VALUE 0 | |
#include <theolizer/internal/version_enum.inc> | |
#undef THEOLIZER_GENERATED_VERSION_NO | |
#endif//THEOLIZER_WRITE_CODE // ###### Foo ###### | |
#ifdef THEOLIZER_WRITE_CODE // ###### Bar ###### | |
#define THEOLIZER_GENERATED_LAST_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kLastVersionNo,1) | |
#define THEOLIZER_GENERATED_FULL_AUTO Bar | |
// ---<<< Version.1 >>>--- | |
#define THEOLIZER_GENERATED_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kVersionNo,1) | |
#define THEOLIZER_GENERATED_CLASS_NAME()\ | |
THEOLIZER_INTERNAL_CLASS_NAME((u8"Bar")) | |
#define THEOLIZER_GENERATED_ELEMENT_MAP emName | |
#define THEOLIZER_GENERATED_ELEMENT_LIST()\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mBar0),mBar0,etmDefault,\ | |
(theolizerD::All),\ | |
(int))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mBar1),mBar1,etmDefault,\ | |
(theolizerD::All),\ | |
(short))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mBar2),mBar2,etmDefault,\ | |
(theolizerD::All),\ | |
(std::string)) | |
#include <theolizer/internal/version_auto.inc> | |
#undef THEOLIZER_GENERATED_VERSION_NO | |
#endif//THEOLIZER_WRITE_CODE // ###### Bar ###### | |
#ifdef THEOLIZER_WRITE_CODE // ###### Global VersionNo. Table ###### | |
THEOLIZER_GENERATED_GLOBAL_TABLE(); | |
#endif//THEOLIZER_WRITE_CODE // ###### Global VersionNo. Table ###### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//############################################################################ | |
// Theolizer解説用サンプル・プログラムExtra-1 | |
//############################################################################ | |
#if !defined(MAIN_H) | |
#define MAIN_H | |
// *************************************************************************** | |
// インクルード | |
// *************************************************************************** | |
// 標準ライブラリ | |
#include <string> | |
// Theolizerライブラリ | |
#include <theolizer/serializer_json.h> | |
// *************************************************************************** | |
// サンプルenum型定義 | |
// *************************************************************************** | |
enum Foo | |
{ | |
eFoo0, | |
eFoo1 | |
}; | |
// *************************************************************************** | |
// サンプル構造体定義 | |
// *************************************************************************** | |
struct Bar | |
{ | |
int mBar0; | |
short mBar1; | |
std::string mBar2; | |
Bar() | |
{ | |
mBar0=0; | |
mBar1=0; | |
mBar2=""; | |
} | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//############################################################################ | |
// Theolizer解説用サンプル・プログラムExtra-2 | |
//############################################################################ | |
#define THEOLIZER_GLOBAL_VERSION_TABLE | |
// *************************************************************************** | |
// インクルード | |
// *************************************************************************** | |
// 標準ライブラリ | |
#include <fstream> | |
// 共通定義 | |
#include "main_b.h" | |
// Theolizer自動生成先 | |
#include "main_b.cpp.theolizer.hpp" | |
// *************************************************************************** | |
// メイン | |
// *************************************************************************** | |
int main(int argc, char* argv[]) | |
{ | |
//---------------------------------------------------------------------------- | |
// バラメータ解析 | |
//---------------------------------------------------------------------------- | |
bool aLoadOnly=false; | |
if (1 < argc) | |
{ | |
std::string argv1=argv[1]; | |
if ((argv1 == "l") || (argv1 == "L")) | |
{ | |
aLoadOnly=true; | |
} | |
} | |
std::cout << theolizer::print("LoadOnly:%d\n", aLoadOnly); | |
//---------------------------------------------------------------------------- | |
// 保存 | |
//---------------------------------------------------------------------------- | |
if (!aLoadOnly) | |
{ | |
// データを生成する | |
Foo aFooA=eFoo1; | |
Foo aFooB=eFoo2; | |
Bar aBar; | |
// aBar.mBar0=100; | |
aBar.mBar1=101; | |
aBar.mBar2="102"; | |
aBar.mBar3=103; | |
// 保存先のファイルをオープンする | |
std::ofstream aStream("test.json"); | |
// シリアライザを用意する | |
theolizer::JsonOSerializer<> js(aStream); | |
// aBarをtest.jsonファイルへ保存する | |
THEOLIZER_PROCESS(js, aFooA); | |
THEOLIZER_PROCESS(js, aFooB); | |
THEOLIZER_PROCESS(js, aBar); | |
} | |
//---------------------------------------------------------------------------- | |
// 回復 | |
//---------------------------------------------------------------------------- | |
// 回復処理 | |
{ | |
// データ領域を獲得する | |
Foo aFooA=eNone; | |
Foo aFooB=eNone; | |
Bar aBar; | |
// 回復元のファイルをオープンする | |
std::ifstream aStream("test.json"); | |
// シリアライザを用意する | |
theolizer::JsonISerializer<> js(aStream); | |
// aBarをtest.jsonファイルから回復する | |
THEOLIZER_PROCESS(js, aFooA); | |
THEOLIZER_PROCESS(js, aFooB); | |
THEOLIZER_PROCESS(js, aBar); | |
// Json形式で表示する | |
theolizer::JsonOSerializer<> jout(std::cout); | |
THEOLIZER_PROCESS(jout, aFooA); | |
THEOLIZER_PROCESS(jout, aFooB); | |
THEOLIZER_PROCESS(jout, aBar); | |
// 普通に表示する | |
std::cout << theolizer::print( | |
u8"(eNone=%d, eFoo0=%d, eFoo1=%d, eFoo2=%d)\n", | |
eNone, eFoo0, eFoo1, eFoo2); | |
std::cout << theolizer::print(u8"aFooA=%d\n", aFooA); | |
std::cout << theolizer::print(u8"aFooB=%d\n", aFooB); | |
// std::cout << theolizer::print(u8"aBar.mBar0=%d\n", aBar.mBar0); | |
std::cout << theolizer::print(u8"aBar.mBar1=%d\n", aBar.mBar1); | |
std::cout << theolizer::print(u8"aBar.mBar2=%s\n", aBar.mBar2); | |
std::cout << theolizer::print(u8"aBar.mBar3=%s\n", aBar.mBar3); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef THEOLIZER_WRITE_CODE // ###### Foo ###### | |
#define THEOLIZER_GENERATED_LAST_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kLastVersionNo,1) | |
#define THEOLIZER_GENERATED_FULL_AUTO Foo | |
// ---<<< Version.1 >>>--- | |
#define THEOLIZER_GENERATED_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kVersionNo,1) | |
#define THEOLIZER_GENERATED_ENUM_NAME u8"Foo" | |
#define THEOLIZER_GENERATED_SAVE_TYPE estName | |
#define THEOLIZER_GENERATED_BASE_TYPE int | |
#define THEOLIZER_GENERATED_ENUM_LIST()\ | |
THEOLIZER_GENERATED_ELEMENT((u8"eNone"),(0),(0))\ | |
THEOLIZER_GENERATED_ELEMENT((u8"eFoo0"),(1000),(1000))\ | |
THEOLIZER_GENERATED_ELEMENT((u8"eFoo1"),(1001),(1001))\ | |
THEOLIZER_GENERATED_ELEMENT((u8"eFoo2"),(1002),(1002)) | |
#define THEOLIZER_GENERATED_DEFAULT_VALUE 0 | |
#include <theolizer/internal/version_enum.inc> | |
#undef THEOLIZER_GENERATED_VERSION_NO | |
#endif//THEOLIZER_WRITE_CODE // ###### Foo ###### | |
#ifdef THEOLIZER_WRITE_CODE // ###### Bar ###### | |
#define THEOLIZER_GENERATED_LAST_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kLastVersionNo,1) | |
#define THEOLIZER_GENERATED_FULL_AUTO Bar | |
// ---<<< Version.1 >>>--- | |
#define THEOLIZER_GENERATED_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kVersionNo,1) | |
#define THEOLIZER_GENERATED_CLASS_NAME()\ | |
THEOLIZER_INTERNAL_CLASS_NAME((u8"Bar")) | |
#define THEOLIZER_GENERATED_ELEMENT_MAP emName | |
#define THEOLIZER_GENERATED_ELEMENT_LIST()\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mBar3),mBar3,etmDefault,\ | |
(theolizerD::All),\ | |
(unsigned int))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mBar2),mBar2,etmDefault,\ | |
(theolizerD::All),\ | |
(std::string))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mBar1),mBar1,etmDefault,\ | |
(theolizerD::All),\ | |
(short)) | |
#include <theolizer/internal/version_auto.inc> | |
#undef THEOLIZER_GENERATED_VERSION_NO | |
#endif//THEOLIZER_WRITE_CODE // ###### Bar ###### | |
#ifdef THEOLIZER_WRITE_CODE // ###### Global VersionNo. Table ###### | |
THEOLIZER_GENERATED_GLOBAL_TABLE(); | |
#endif//THEOLIZER_WRITE_CODE // ###### Global VersionNo. Table ###### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//############################################################################ | |
// Theolizer解説用サンプル・プログラムExtra-2 | |
//############################################################################ | |
#if !defined(MAIN_H) | |
#define MAIN_H | |
// *************************************************************************** | |
// インクルード | |
// *************************************************************************** | |
// 標準ライブラリ | |
#include <string> | |
// Theolizerライブラリ | |
#include <theolizer/serializer_json.h> | |
// *************************************************************************** | |
// サンプルenum型定義 | |
// *************************************************************************** | |
enum Foo | |
{ | |
eNone, | |
eFoo0=1000, | |
eFoo1, | |
eFoo2 | |
}; | |
// *************************************************************************** | |
// サンプル構造体定義 | |
// *************************************************************************** | |
struct Bar | |
{ | |
unsigned mBar3; // 新規追加 | |
std::string mBar2; // 順序変更 | |
// int mBar0; // 削除 | |
short mBar1; | |
Bar() | |
{ | |
mBar1=0; | |
mBar2=""; | |
mBar3=0; | |
} | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoadOnly:0 | |
{ | |
"SerialzierName":"JsonTheolizer", | |
"GlobalVersionNo":1, | |
"TypeInfoList":[1] | |
} | |
"eFoo0" | |
"eFoo1" | |
{ | |
"mBar0":10, | |
"mBar1":11, | |
"mBar2":"12" | |
} | |
(eFoo0=0, eFoo1=1) | |
aFooA=0 | |
aFooB=1 | |
aBar.mBar0=10 | |
aBar.mBar1=11 | |
aBar.mBar2=12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoadOnly:0 | |
{ | |
"SerialzierName":"JsonTheolizer", | |
"GlobalVersionNo":1, | |
"TypeInfoList":[1] | |
} | |
"eFoo1" | |
"eFoo2" | |
{ | |
"mBar3":103, | |
"mBar2":"102", | |
"mBar1":101 | |
} | |
(eNone=0, eFoo0=1000, eFoo1=1001, eFoo2=1002) | |
aFooA=1001 | |
aFooB=1002 | |
aBar.mBar1=101 | |
aBar.mBar2=102 | |
aBar.mBar3=103 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoadOnly:1 | |
{ | |
"SerialzierName":"JsonTheolizer", | |
"GlobalVersionNo":1, | |
"TypeInfoList":[1] | |
} | |
"eFoo0" | |
"eFoo1" | |
{ | |
"mBar3":0, | |
"mBar2":"12", | |
"mBar1":11 | |
} | |
(eNone=0, eFoo0=1000, eFoo1=1001, eFoo2=1002) | |
aFooA=1000 | |
aFooB=1001 | |
aBar.mBar1=11 | |
aBar.mBar2=12 | |
aBar.mBar3=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"SerialzierName":"JsonTheolizer", | |
"GlobalVersionNo":1, | |
"TypeInfoList":[1] | |
} | |
"eFoo0" | |
"eFoo1" | |
{ | |
"mBar0":10, | |
"mBar1":11, | |
"mBar2":"12" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"SerialzierName":"JsonTheolizer", | |
"GlobalVersionNo":1, | |
"TypeInfoList":[1] | |
} | |
"eFoo1" | |
"eFoo2" | |
{ | |
"mBar3":103, | |
"mBar2":"102", | |
"mBar1":101 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment