#pragma warning(disable : 4996) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //boost libraries #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../common.h" using namespace Jenga::Common; template void BoostSerializationSupport::echo( const char *msg ) const { MessageBox( NULL, msg, "XMLシリアライズの例外", MB_OK ); } template bool BoostSerializationSupport::ReadXml( std::istream& ifs, bool isShowExceptionMessage ) { bool isSuccessful = false; try{ boost::archive::xml_iarchive ia(ifs); // ファイルから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { if( isShowExceptionMessage ) { echo( e.what() ); } } catch(...){ if( isShowExceptionMessage ) { echo( "archive_exception以外の不明な例外" ); } } if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::WriteXml( std::ostream& ofs, bool isShowExceptionMessage ) const { bool isSuccessful = false; try{ boost::archive::xml_oarchive oa(ofs); // ファイルに書き出し oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { if( isShowExceptionMessage ) { echo( e.what() ); } } catch(...){ if( isShowExceptionMessage ) { echo( "archive_exception以外の不明な例外" ); } } if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::ReadXml( const std::string &xmlFilePath, bool isShowExceptionMessage ) { // 入力アーカイブの作成 std::ifstream ifs( xmlFilePath.c_str() ); bool result = ReadXml(ifs,isShowExceptionMessage); // 入力を閉じる ifs.close(); return result; } template bool BoostSerializationSupport::WriteXml( const std::string &xmlFilePath, bool isShowExceptionMessage ) const { // 出力アーカイブの作成 std::ofstream ofs( xmlFilePath.c_str() ); bool result = WriteXml(ofs,isShowExceptionMessage); // 出力を閉じる ofs.close(); return result; } template bool BoostSerializationSupport::ReadXmlString( const std::string &xmlString ) { bool isSuccessful = false; // 入力アーカイブの作成 std::istringstream iss( xmlString ); try{ boost::archive::xml_iarchive ia(iss); // 文字列ストリームから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch(...){ // 失敗 } if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::WriteXmlString( std::string &xmlString ) const { // 出力アーカイブの作成 std::ostringstream oss; bool isSuccessful = false; try{ boost::archive::xml_oarchive oa(oss); // 文字列ストリームに書き出し oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { echo( e.what() ); } catch(...){ echo( "archive_exception以外の不明な例外" ); } if( !isSuccessful ) { return false; } xmlString = oss.str(); return true; } template bool BoostSerializationSupport::ReadBinaryFile( const std::string &filePath, bool isShowExceptionMessage ) { // 入力アーカイブの作成 std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary ); bool isSuccessful = false; try{ boost::archive::binary_iarchive ia(ifs); // ファイルから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { if( isShowExceptionMessage ) { echo( e.what() ); } } catch(...){ if( isShowExceptionMessage ) { echo( "archive_exception以外の不明な例外" ); } } // 入力を閉じる ifs.close(); if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::WriteBinaryFile( const std::string &filePath, bool isShowExceptionMessage ) const { // 出力アーカイブの作成 std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary ); bool isSuccessful = false; try{ boost::archive::binary_oarchive oa(ofs); // ファイルに書き出し oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { if( isShowExceptionMessage ) { echo( e.what() ); } } catch(...){ if( isShowExceptionMessage ) { echo( "archive_exception以外の不明な例外" ); } } // 出力を閉じる ofs.close(); if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::ReadBinaryString( const std::string &binaryString ) { bool isSuccessful = false; // 入力アーカイブの作成 std::istringstream iss( binaryString, std::ios::in | std::ios::binary ); try{ boost::archive::binary_iarchive ia(iss); // 文字列ストリームから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { echo( e.what() ); } catch(...){ echo( "archive_exception以外の不明な例外" ); } return isSuccessful; } template bool BoostSerializationSupport::WriteBinaryString( std::string &binaryString ) const { // 出力アーカイブの作成 std::ostringstream oss( "", std::ios::out | std::ios::binary ); bool isSuccessful = false; try{ boost::archive::binary_oarchive oa(oss); // 文字列ストリームに書き出し oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { echo( e.what() ); } catch(...){ echo( "archive_exception以外の不明な例外" ); } binaryString = oss.str(); return isSuccessful; } /* ビルドに時間がかかるので外しておく template bool BoostSerializationSupport::ReadText( const std::string &filePath, bool isShowExceptionMessage ) { // 入力アーカイブの作成 std::ifstream ifs( filePath.c_str() ); bool isSuccessful = false; try{ boost::archive::text_iarchive ia(ifs); // ファイルから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { if( isShowExceptionMessage ) { echo( e.what() ); } } catch(...){ if( isShowExceptionMessage ) { echo( "archive_exception以外の不明な例外" ); } } // 入力を閉じる ifs.close(); if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::WriteText( const std::string &filePath, bool isShowExceptionMessage ) const { // 出力アーカイブの作成 std::ofstream ofs( filePath.c_str() ); bool isSuccessful = false; try{ boost::archive::text_oarchive oa(ofs); // ファイルに書き出し oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { if( isShowExceptionMessage ) { echo( e.what() ); } } catch(...){ if( isShowExceptionMessage ) { echo( "archive_exception以外の不明な例外" ); } } // 出力を閉じる ofs.close(); if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::ReadTextString( const std::string &textString ) { bool isSuccessful = false; // 入力アーカイブの作成 std::istringstream iss( textString ); try{ boost::archive::text_iarchive ia(iss); // 文字列ストリームから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch(...){ // 失敗 } if( !isSuccessful ) { return false; } return true; } template bool BoostSerializationSupport::WriteTextString( std::string &textString ) const { // 出力アーカイブの作成 std::ostringstream oss; bool isSuccessful = false; try{ boost::archive::text_oarchive oa(oss); // 文字列ストリームに書き出し oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch( boost::archive::archive_exception e ) { echo( e.what() ); } catch(...){ echo( "archive_exception以外の不明な例外" ); } if( !isSuccessful ) { return false; } textString = oss.str(); return true; } template bool BoostSerializationSupport::ReadXmlFromString( const std::string &textString ) { bool isSuccessful = false; // 入力アーカイブの作成 std::istringstream iss( textString ); try{ boost::archive::xml_iarchive ia(iss); // 文字列ストリームから読込 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this ); isSuccessful = true; } catch(...){ // 失敗 } if( !isSuccessful ) { return false; } return true; } */ #include #include template class Jenga::Common::BoostSerializationSupport; template class Jenga::Common::BoostSerializationSupport;