[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 | }
|
---|
| 117 |
|
---|
[256] | 118 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadBinary( const string &filePath, bool isShowExceptionMessage )
|
---|
[215] | 119 | {
|
---|
| 120 | // 入力アーカイブの作成
|
---|
| 121 | std::ifstream ifs( filePath.c_str() );
|
---|
| 122 |
|
---|
| 123 | bool isSuccessful = false;
|
---|
| 124 | try{
|
---|
| 125 | boost::archive::binary_iarchive ia(ifs);
|
---|
| 126 |
|
---|
| 127 | // ファイルから読込
|
---|
| 128 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 129 |
|
---|
| 130 | isSuccessful = true;
|
---|
| 131 | }
|
---|
| 132 | catch( boost::archive::archive_exception e )
|
---|
| 133 | {
|
---|
| 134 | if( isShowExceptionMessage )
|
---|
| 135 | {
|
---|
| 136 | echo( e.what() );
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | catch(...){
|
---|
| 140 | if( isShowExceptionMessage )
|
---|
| 141 | {
|
---|
| 142 | echo( "archive_exception以外の不明な例外" );
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | // 入力を閉じる
|
---|
| 147 | ifs.close();
|
---|
| 148 |
|
---|
| 149 | if( !isSuccessful )
|
---|
| 150 | {
|
---|
| 151 | return false;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | return true;
|
---|
| 155 | }
|
---|
[256] | 156 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteBinary( const string &filePath, bool isShowExceptionMessage ) const
|
---|
[215] | 157 | {
|
---|
| 158 | // 出力アーカイブの作成
|
---|
| 159 | std::ofstream ofs( filePath.c_str() );
|
---|
| 160 |
|
---|
| 161 | bool isSuccessful = false;
|
---|
| 162 | try{
|
---|
| 163 | boost::archive::binary_oarchive oa(ofs);
|
---|
| 164 |
|
---|
| 165 | // ファイルに書き出し
|
---|
| 166 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 167 |
|
---|
| 168 | isSuccessful = true;
|
---|
| 169 | }
|
---|
| 170 | catch( boost::archive::archive_exception e )
|
---|
| 171 | {
|
---|
| 172 | if( isShowExceptionMessage )
|
---|
| 173 | {
|
---|
| 174 | echo( e.what() );
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | catch(...){
|
---|
| 178 | if( isShowExceptionMessage )
|
---|
| 179 | {
|
---|
| 180 | echo( "archive_exception以外の不明な例外" );
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | // 出力を閉じる
|
---|
| 185 | ofs.close();
|
---|
| 186 |
|
---|
| 187 | if( !isSuccessful )
|
---|
| 188 | {
|
---|
| 189 | return false;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | return true;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadText( const string &filePath, bool isShowExceptionMessage )
|
---|
| 196 | {
|
---|
| 197 | // 入力アーカイブの作成
|
---|
| 198 | std::ifstream ifs( filePath.c_str() );
|
---|
| 199 |
|
---|
| 200 | bool isSuccessful = false;
|
---|
| 201 | try{
|
---|
| 202 | boost::archive::text_iarchive ia(ifs);
|
---|
| 203 |
|
---|
| 204 | // ファイルから読込
|
---|
| 205 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 206 |
|
---|
| 207 | isSuccessful = true;
|
---|
| 208 | }
|
---|
| 209 | catch( boost::archive::archive_exception e )
|
---|
| 210 | {
|
---|
| 211 | if( isShowExceptionMessage )
|
---|
| 212 | {
|
---|
| 213 | echo( e.what() );
|
---|
| 214 | }
|
---|
| 215 | }
|
---|
| 216 | catch(...){
|
---|
| 217 | if( isShowExceptionMessage )
|
---|
| 218 | {
|
---|
| 219 | echo( "archive_exception以外の不明な例外" );
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | // 入力を閉じる
|
---|
| 224 | ifs.close();
|
---|
| 225 |
|
---|
| 226 | if( !isSuccessful )
|
---|
| 227 | {
|
---|
| 228 | return false;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | return true;
|
---|
| 232 | }
|
---|
| 233 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteText( const string &filePath, bool isShowExceptionMessage ) const
|
---|
| 234 | {
|
---|
| 235 | // 出力アーカイブの作成
|
---|
| 236 | std::ofstream ofs( filePath.c_str() );
|
---|
| 237 |
|
---|
| 238 | bool isSuccessful = false;
|
---|
| 239 | try{
|
---|
| 240 | boost::archive::text_oarchive oa(ofs);
|
---|
| 241 |
|
---|
| 242 | // ファイルに書き出し
|
---|
| 243 | oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 244 |
|
---|
| 245 | isSuccessful = true;
|
---|
| 246 | }
|
---|
| 247 | catch( boost::archive::archive_exception e )
|
---|
| 248 | {
|
---|
| 249 | if( isShowExceptionMessage )
|
---|
| 250 | {
|
---|
| 251 | echo( e.what() );
|
---|
| 252 | }
|
---|
| 253 | }
|
---|
| 254 | catch(...){
|
---|
| 255 | if( isShowExceptionMessage )
|
---|
| 256 | {
|
---|
| 257 | echo( "archive_exception以外の不明な例外" );
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | // 出力を閉じる
|
---|
| 262 | ofs.close();
|
---|
| 263 |
|
---|
| 264 | if( !isSuccessful )
|
---|
| 265 | {
|
---|
| 266 | return false;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | return true;
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXmlFromString( const string &xmlBuffer )
|
---|
| 273 | {
|
---|
| 274 | bool isSuccessful = false;
|
---|
| 275 |
|
---|
| 276 | // 入力アーカイブの作成
|
---|
| 277 | std::istringstream iss( xmlBuffer );
|
---|
| 278 |
|
---|
| 279 | try{
|
---|
| 280 | boost::archive::xml_iarchive ia(iss);
|
---|
| 281 |
|
---|
| 282 | // 文字列ストリームから読込
|
---|
| 283 | ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
|
---|
| 284 |
|
---|
| 285 | isSuccessful = true;
|
---|
| 286 | }
|
---|
| 287 | catch(...){
|
---|
| 288 | // 失敗
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | if( !isSuccessful )
|
---|
| 292 | {
|
---|
| 293 | return false;
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | return true;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 |
|
---|
[256] | 300 | #include <Compiler.h>
|
---|
| 301 | #include <logger.h>
|
---|
| 302 |
|
---|
| 303 | template class Jenga::Common::BoostSerializationSupport<ObjectModule>;
|
---|
[215] | 304 | template class Jenga::Common::BoostSerializationSupport<LoggerSetting>;
|
---|