[215] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <boost/archive/xml_oarchive.hpp>
|
---|
| 4 | #include <boost/archive/xml_iarchive.hpp>
|
---|
| 5 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 6 | #include <boost/archive/text_iarchive.hpp>
|
---|
| 7 | #include <boost/archive/binary_oarchive.hpp>
|
---|
| 8 | #include <boost/archive/binary_iarchive.hpp>
|
---|
| 9 | #include <boost/serialization/string.hpp>
|
---|
| 10 | #include <boost/serialization/access.hpp>
|
---|
| 11 | #include <boost/serialization/level.hpp>
|
---|
| 12 | #include <boost/serialization/vector.hpp>
|
---|
| 13 | #include <boost/serialization/map.hpp>
|
---|
| 14 | #include <boost/serialization/version.hpp>
|
---|
| 15 | #include <boost/serialization/is_abstract.hpp>
|
---|
| 16 |
|
---|
| 17 | #include <BoostSerializationSupport.h>
|
---|
| 18 |
|
---|
| 19 | #include <windows.h>
|
---|
| 20 |
|
---|
| 21 | using namespace Jenga::Common;
|
---|
| 22 |
|
---|
| 23 | template<class T_xml_schema> void BoostSerializationSupport<T_xml_schema>::echo( const char *msg ) const
|
---|
| 24 | {
|
---|
| 25 | MessageBox( NULL, msg, "XMLシリアライズの例外", MB_OK );
|
---|
| 26 | }
|
---|
| 27 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXml( istream& ifs, bool isShowExceptionMessage )
|
---|
| 28 | {
|
---|
| 29 | bool isSuccessful = false;
|
---|
| 30 |
|
---|
| 31 | try{
|
---|
| 32 | boost::archive::xml_iarchive ia(ifs);
|
---|
| 33 |
|
---|
| 34 | // ファイルから読込
|
---|
| 35 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 36 |
|
---|
| 37 | isSuccessful = true;
|
---|
| 38 | }
|
---|
| 39 | catch( boost::archive::archive_exception e )
|
---|
| 40 | {
|
---|
| 41 | if( isShowExceptionMessage )
|
---|
| 42 | {
|
---|
| 43 | echo( e.what() );
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | catch(...){
|
---|
| 47 | if( isShowExceptionMessage )
|
---|
| 48 | {
|
---|
| 49 | echo( "archive_exception以外の不明な例外" );
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | if( !isSuccessful )
|
---|
| 54 | {
|
---|
| 55 | return false;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | return true;
|
---|
| 59 | }
|
---|
| 60 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteXml( ostream& ofs, bool isShowExceptionMessage ) const
|
---|
| 61 | {
|
---|
| 62 | bool isSuccessful = false;
|
---|
| 63 |
|
---|
| 64 | try{
|
---|
| 65 | boost::archive::xml_oarchive oa(ofs);
|
---|
| 66 |
|
---|
| 67 | // ファイルに書き出し
|
---|
| 68 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 69 |
|
---|
| 70 | isSuccessful = true;
|
---|
| 71 | }
|
---|
| 72 | catch( boost::archive::archive_exception e )
|
---|
| 73 | {
|
---|
| 74 | if( isShowExceptionMessage )
|
---|
| 75 | {
|
---|
| 76 | echo( e.what() );
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | catch(...){
|
---|
| 80 | if( isShowExceptionMessage )
|
---|
| 81 | {
|
---|
| 82 | echo( "archive_exception以外の不明な例外" );
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | if( !isSuccessful )
|
---|
| 87 | {
|
---|
| 88 | return false;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | return true;
|
---|
| 92 | }
|
---|
| 93 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXml( const string &xmlFilePath, bool isShowExceptionMessage )
|
---|
| 94 | {
|
---|
| 95 | // 入力アーカイブの作成
|
---|
| 96 | std::ifstream ifs( xmlFilePath.c_str() );
|
---|
| 97 |
|
---|
| 98 | bool result = ReadXml(ifs,isShowExceptionMessage);
|
---|
| 99 |
|
---|
| 100 | // 入力を閉じる
|
---|
| 101 | ifs.close();
|
---|
| 102 |
|
---|
| 103 | return result;
|
---|
| 104 | }
|
---|
| 105 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteXml( const string &xmlFilePath, bool isShowExceptionMessage ) const
|
---|
| 106 | {
|
---|
| 107 | // 出力アーカイブの作成
|
---|
| 108 | std::ofstream ofs( xmlFilePath.c_str() );
|
---|
| 109 |
|
---|
| 110 | bool result = WriteXml(ofs,isShowExceptionMessage);
|
---|
| 111 |
|
---|
| 112 | // 出力を閉じる
|
---|
| 113 | ofs.close();
|
---|
| 114 |
|
---|
| 115 | return result;
|
---|
| 116 | }
|
---|
[279] | 117 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXmlString( const std::string &xmlString )
|
---|
| 118 | {
|
---|
| 119 | bool isSuccessful = false;
|
---|
[215] | 120 |
|
---|
[279] | 121 | // 入力アーカイブの作成
|
---|
| 122 | std::istringstream iss( xmlString );
|
---|
| 123 |
|
---|
| 124 | try{
|
---|
| 125 | boost::archive::xml_iarchive ia(iss);
|
---|
| 126 |
|
---|
| 127 | // 文字列ストリームから読込
|
---|
| 128 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 129 |
|
---|
| 130 | isSuccessful = true;
|
---|
| 131 | }
|
---|
| 132 | catch(...){
|
---|
| 133 | // 失敗
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | if( !isSuccessful )
|
---|
| 137 | {
|
---|
| 138 | return false;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | return true;
|
---|
| 142 | }
|
---|
| 143 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteXmlString( std::string &xmlString ) const
|
---|
| 144 | {
|
---|
| 145 | // 出力アーカイブの作成
|
---|
| 146 | std::ostringstream oss;
|
---|
| 147 |
|
---|
| 148 | bool isSuccessful = false;
|
---|
| 149 | try{
|
---|
| 150 | boost::archive::xml_oarchive oa(oss);
|
---|
| 151 |
|
---|
| 152 | // 文字列ストリームに書き出し
|
---|
| 153 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 154 |
|
---|
| 155 | isSuccessful = true;
|
---|
| 156 | }
|
---|
| 157 | catch( boost::archive::archive_exception e )
|
---|
| 158 | {
|
---|
| 159 | echo( e.what() );
|
---|
| 160 | }
|
---|
| 161 | catch(...){
|
---|
| 162 | echo( "archive_exception以外の不明な例外" );
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | if( !isSuccessful )
|
---|
| 166 | {
|
---|
| 167 | return false;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | xmlString = oss.str();
|
---|
| 171 |
|
---|
| 172 | return true;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
[256] | 175 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadBinary( const string &filePath, bool isShowExceptionMessage )
|
---|
[215] | 176 | {
|
---|
| 177 | // 入力アーカイブの作成
|
---|
| 178 | std::ifstream ifs( filePath.c_str() );
|
---|
| 179 |
|
---|
| 180 | bool isSuccessful = false;
|
---|
| 181 | try{
|
---|
| 182 | boost::archive::binary_iarchive ia(ifs);
|
---|
| 183 |
|
---|
| 184 | // ファイルから読込
|
---|
| 185 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 186 |
|
---|
| 187 | isSuccessful = true;
|
---|
| 188 | }
|
---|
| 189 | catch( boost::archive::archive_exception e )
|
---|
| 190 | {
|
---|
| 191 | if( isShowExceptionMessage )
|
---|
| 192 | {
|
---|
| 193 | echo( e.what() );
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | catch(...){
|
---|
| 197 | if( isShowExceptionMessage )
|
---|
| 198 | {
|
---|
| 199 | echo( "archive_exception以外の不明な例外" );
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | // 入力を閉じる
|
---|
| 204 | ifs.close();
|
---|
| 205 |
|
---|
| 206 | if( !isSuccessful )
|
---|
| 207 | {
|
---|
| 208 | return false;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return true;
|
---|
| 212 | }
|
---|
[256] | 213 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteBinary( const string &filePath, bool isShowExceptionMessage ) const
|
---|
[215] | 214 | {
|
---|
| 215 | // 出力アーカイブの作成
|
---|
| 216 | std::ofstream ofs( filePath.c_str() );
|
---|
| 217 |
|
---|
| 218 | bool isSuccessful = false;
|
---|
| 219 | try{
|
---|
| 220 | boost::archive::binary_oarchive oa(ofs);
|
---|
| 221 |
|
---|
| 222 | // ファイルに書き出し
|
---|
| 223 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 224 |
|
---|
| 225 | isSuccessful = true;
|
---|
| 226 | }
|
---|
| 227 | catch( boost::archive::archive_exception e )
|
---|
| 228 | {
|
---|
| 229 | if( isShowExceptionMessage )
|
---|
| 230 | {
|
---|
| 231 | echo( e.what() );
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 | catch(...){
|
---|
| 235 | if( isShowExceptionMessage )
|
---|
| 236 | {
|
---|
| 237 | echo( "archive_exception以外の不明な例外" );
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | // 出力を閉じる
|
---|
| 242 | ofs.close();
|
---|
| 243 |
|
---|
| 244 | if( !isSuccessful )
|
---|
| 245 | {
|
---|
| 246 | return false;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | return true;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadText( const string &filePath, bool isShowExceptionMessage )
|
---|
| 253 | {
|
---|
| 254 | // 入力アーカイブの作成
|
---|
| 255 | std::ifstream ifs( filePath.c_str() );
|
---|
| 256 |
|
---|
| 257 | bool isSuccessful = false;
|
---|
| 258 | try{
|
---|
| 259 | boost::archive::text_iarchive ia(ifs);
|
---|
| 260 |
|
---|
| 261 | // ファイルから読込
|
---|
| 262 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 263 |
|
---|
| 264 | isSuccessful = true;
|
---|
| 265 | }
|
---|
| 266 | catch( boost::archive::archive_exception e )
|
---|
| 267 | {
|
---|
| 268 | if( isShowExceptionMessage )
|
---|
| 269 | {
|
---|
| 270 | echo( e.what() );
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 | catch(...){
|
---|
| 274 | if( isShowExceptionMessage )
|
---|
| 275 | {
|
---|
| 276 | echo( "archive_exception以外の不明な例外" );
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | // 入力を閉じる
|
---|
| 281 | ifs.close();
|
---|
| 282 |
|
---|
| 283 | if( !isSuccessful )
|
---|
| 284 | {
|
---|
| 285 | return false;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | return true;
|
---|
| 289 | }
|
---|
| 290 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteText( const string &filePath, bool isShowExceptionMessage ) const
|
---|
| 291 | {
|
---|
| 292 | // 出力アーカイブの作成
|
---|
| 293 | std::ofstream ofs( filePath.c_str() );
|
---|
| 294 |
|
---|
| 295 | bool isSuccessful = false;
|
---|
| 296 | try{
|
---|
| 297 | boost::archive::text_oarchive oa(ofs);
|
---|
| 298 |
|
---|
| 299 | // ファイルに書き出し
|
---|
| 300 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 301 |
|
---|
| 302 | isSuccessful = true;
|
---|
| 303 | }
|
---|
| 304 | catch( boost::archive::archive_exception e )
|
---|
| 305 | {
|
---|
| 306 | if( isShowExceptionMessage )
|
---|
| 307 | {
|
---|
| 308 | echo( e.what() );
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
| 311 | catch(...){
|
---|
| 312 | if( isShowExceptionMessage )
|
---|
| 313 | {
|
---|
| 314 | echo( "archive_exception以外の不明な例外" );
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | // 出力を閉じる
|
---|
| 319 | ofs.close();
|
---|
| 320 |
|
---|
| 321 | if( !isSuccessful )
|
---|
| 322 | {
|
---|
| 323 | return false;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | return true;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[264] | 329 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadTextString( const std::string &textString )
|
---|
[215] | 330 | {
|
---|
| 331 | bool isSuccessful = false;
|
---|
| 332 |
|
---|
| 333 | // 入力アーカイブの作成
|
---|
[264] | 334 | std::istringstream iss( textString );
|
---|
[215] | 335 |
|
---|
| 336 | try{
|
---|
[264] | 337 | boost::archive::text_iarchive ia(iss);
|
---|
| 338 |
|
---|
| 339 | // 文字列ストリームから読込
|
---|
| 340 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 341 |
|
---|
| 342 | isSuccessful = true;
|
---|
| 343 | }
|
---|
| 344 | catch(...){
|
---|
| 345 | // 失敗
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | if( !isSuccessful )
|
---|
| 349 | {
|
---|
| 350 | return false;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | return true;
|
---|
| 354 | }
|
---|
| 355 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteTextString( std::string &textString ) const
|
---|
| 356 | {
|
---|
| 357 | // 出力アーカイブの作成
|
---|
| 358 | std::ostringstream oss;
|
---|
| 359 |
|
---|
| 360 | bool isSuccessful = false;
|
---|
| 361 | try{
|
---|
| 362 | boost::archive::text_oarchive oa(oss);
|
---|
| 363 |
|
---|
| 364 | // 文字列ストリームに書き出し
|
---|
| 365 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 366 |
|
---|
| 367 | isSuccessful = true;
|
---|
| 368 | }
|
---|
| 369 | catch( boost::archive::archive_exception e )
|
---|
| 370 | {
|
---|
| 371 | echo( e.what() );
|
---|
| 372 | }
|
---|
| 373 | catch(...){
|
---|
| 374 | echo( "archive_exception以外の不明な例外" );
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | if( !isSuccessful )
|
---|
| 378 | {
|
---|
| 379 | return false;
|
---|
| 380 | }
|
---|
| 381 |
|
---|
| 382 | textString = oss.str();
|
---|
| 383 |
|
---|
| 384 | return true;
|
---|
| 385 | }
|
---|
| 386 |
|
---|
| 387 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXmlFromString( const std::string &textString )
|
---|
| 388 | {
|
---|
| 389 | bool isSuccessful = false;
|
---|
| 390 |
|
---|
| 391 | // 入力アーカイブの作成
|
---|
| 392 | std::istringstream iss( textString );
|
---|
| 393 |
|
---|
| 394 | try{
|
---|
[215] | 395 | boost::archive::xml_iarchive ia(iss);
|
---|
| 396 |
|
---|
| 397 | // 文字列ストリームから読込
|
---|
| 398 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 399 |
|
---|
| 400 | isSuccessful = true;
|
---|
| 401 | }
|
---|
| 402 | catch(...){
|
---|
| 403 | // 失敗
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | if( !isSuccessful )
|
---|
| 407 | {
|
---|
| 408 | return false;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | return true;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 |
|
---|
[256] | 415 | #include <Compiler.h>
|
---|
| 416 | #include <logger.h>
|
---|
| 417 |
|
---|
| 418 | template class Jenga::Common::BoostSerializationSupport<ObjectModule>;
|
---|
[215] | 419 | template class Jenga::Common::BoostSerializationSupport<LoggerSetting>;
|
---|