Last active
June 6, 2017 15:41
-
-
Save yossi-tahara/13b465181a65557b3ca689dbcdd10a0f to your computer and use it in GitHub Desktop.
Theolizer技術解説(2016/09/01) 簡単な構造体を保存/回復する
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) | |
set(SOURCE_LIST main.cpp) | |
set(HEADER_LIST main.h) | |
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() | |
# example | |
add_executable(${TARGET_NAME} ${SOURCE_LIST} ${HEADER_LIST}) | |
setup_theolizer(${TARGET_NAME} StaticWithBoost) | |
#----------------------------------------------------------------------------- | |
# テスト実行 | |
#----------------------------------------------------------------------------- | |
enable_testing() | |
add_test(NAME ${TARGET_NAME} COMMAND $<TARGET_FILE:${TARGET_NAME}>) | |
add_custom_target(BuildTest COMMAND "ctest" "-V" "-C" $<CONFIG>) | |
add_dependencies(BuildTest ${TARGET_NAME}) |
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解説用サンプル・プログラム | |
// | |
// 簡単な家計簿用データ構造定義 | |
// データの保存と回復のサンプルなので、 | |
// ユーザ・インタフェースは実装しない | |
//############################################################################ | |
// *************************************************************************** | |
// インクルード | |
// *************************************************************************** | |
// 標準ライブラリ | |
#include <iostream> | |
#include <fstream> | |
// 構造体定義 | |
#include "main.h" | |
// Theolizerライブラリ(各種シリアライズ指示する時は構造体定義前に#include) | |
#include <theolizer/serializer_json.h> | |
// Theolizer自動生成先 | |
#include "main.cpp.theolizer.hpp" | |
// *************************************************************************** | |
// メイン | |
// *************************************************************************** | |
int main(int argc, char* argv[]) | |
{ | |
//---------------------------------------------------------------------------- | |
// 保存 | |
//---------------------------------------------------------------------------- | |
// 保存するデータの設定 | |
Trade aTradeSave; | |
aTradeSave.mDate.mYear = 2015; | |
aTradeSave.mDate.mMonth = 1; | |
aTradeSave.mDate.mDay = 1; | |
aTradeSave.mItem = u8"お米10Kg"; | |
aTradeSave.mAmount = 4600; | |
// 保存処理 | |
{ | |
std::ofstream aStream("test.log"); | |
theolizer::JsonOSerializer<> js(aStream); | |
THEOLIZER_PROCESS(js, aTradeSave); | |
} | |
//---------------------------------------------------------------------------- | |
// 回復 | |
//---------------------------------------------------------------------------- | |
// 回復先の領域 | |
Trade aTradeLoad; | |
// 回復処理 | |
{ | |
std::ifstream aStream("test.log"); | |
theolizer::JsonISerializer<> js(aStream); | |
THEOLIZER_PROCESS(js, aTradeLoad); | |
} | |
// 結果表示 | |
std::cout << theolizer::print("%04d/%02d/%02d %s %u\n", | |
aTradeLoad.mDate.mYear, | |
aTradeLoad.mDate.mMonth+0, | |
aTradeLoad.mDate.mDay+0, | |
aTradeLoad.mItem, aTradeLoad.mAmount); | |
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 // ###### Date ###### | |
#define THEOLIZER_GENERATED_LAST_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kLastVersionNo,1) | |
#define THEOLIZER_GENERATED_FULL_AUTO Date | |
// ---<<< Version.1 >>>--- | |
#define THEOLIZER_GENERATED_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kVersionNo,1) | |
#define THEOLIZER_GENERATED_CLASS_NAME()\ | |
THEOLIZER_INTERNAL_CLASS_NAME((u8"Date")) | |
#define THEOLIZER_GENERATED_ELEMENT_MAP emName | |
#define THEOLIZER_GENERATED_ELEMENT_LIST()\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mYear),mYear,etmDefault,\ | |
(theolizerD::All),\ | |
(short))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mMonth),mMonth,etmDefault,\ | |
(theolizerD::All),\ | |
(char))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mDay),mDay,etmDefault,\ | |
(theolizerD::All),\ | |
(char)) | |
#include <theolizer/internal/version_auto.inc> | |
#undef THEOLIZER_GENERATED_VERSION_NO | |
#endif//THEOLIZER_WRITE_CODE // ###### Date ###### | |
#ifdef THEOLIZER_WRITE_CODE // ###### Trade ###### | |
#define THEOLIZER_GENERATED_LAST_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kLastVersionNo,1) | |
#define THEOLIZER_GENERATED_FULL_AUTO Trade | |
// ---<<< Version.1 >>>--- | |
#define THEOLIZER_GENERATED_VERSION_NO THEOLIZER_INTERNAL_DEFINE(kVersionNo,1) | |
#define THEOLIZER_GENERATED_CLASS_NAME()\ | |
THEOLIZER_INTERNAL_CLASS_NAME((u8"Trade")) | |
#define THEOLIZER_GENERATED_ELEMENT_MAP emName | |
#define THEOLIZER_GENERATED_ELEMENT_LIST()\ | |
THEOLIZER_INTERNAL_ELEMENT_KN((mDate),mDate,etmDefault,\ | |
(theolizerD::All),\ | |
(Date),1)\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mItem),mItem,etmDefault,\ | |
(theolizerD::All),\ | |
(std::string))\ | |
THEOLIZER_INTERNAL_ELEMENT_N((mAmount),mAmount,etmDefault,\ | |
(theolizerD::All),\ | |
(int)) | |
#include <theolizer/internal/version_auto.inc> | |
#undef THEOLIZER_GENERATED_VERSION_NO | |
#endif//THEOLIZER_WRITE_CODE // ###### Trade ###### | |
#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解説用サンプル・プログラム | |
// | |
// 簡単な家計簿用データ構造定義 | |
// データの保存と回復のサンプルなので、 | |
// ユーザ・インタフェースは実装しない | |
//############################################################################ | |
#if !defined(MAIN_H) | |
#define MAIN_H | |
// *************************************************************************** | |
// インクルード | |
// *************************************************************************** | |
// 標準ライブラリ | |
#include <string> | |
// *************************************************************************** | |
// 構造体定義 | |
// *************************************************************************** | |
struct Date | |
{ | |
short mYear; // 年 | |
char mMonth; // 月(1-12) | |
char mDay; // 日(1-31) | |
}; | |
struct Trade | |
{ | |
Date mDate; // 取引日 | |
std::string mItem; // 費目 | |
int mAmount; // 金額 | |
}; | |
#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
{ | |
"SerialzierName":"JsonTheolizer", | |
"GlobalVersionNo":1, | |
"TypeInfoList":[1] | |
} | |
{ | |
"mDate":{ | |
"mYear":2015, | |
"mMonth":1, | |
"mDay":1 | |
}, | |
"mItem":"お米10Kg", | |
"mAmount":4600 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment