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