source: dev/trunk/abdev/BasicCompiler_Common/src/BoostSerializationSupport.cpp@ 237

Last change on this file since 237 was 215, checked in by dai_9181, 17 years ago

BoostSerializationSupportのクラステンプレートインスタンスを明示的に生成するようにした(コンパイル時間の短縮)

File size: 6.4 KB
Line 
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 <MetaImpl.h>
20#include <logger.h>
21
22#include <windows.h>
23
24using namespace Jenga::Common;
25
26template<class T_xml_schema> void BoostSerializationSupport<T_xml_schema>::echo( const char *msg ) const
27{
28 MessageBox( NULL, msg, "XMLシリアライズの例外", MB_OK );
29}
30template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXml( istream& ifs, bool isShowExceptionMessage )
31{
32 bool isSuccessful = false;
33
34 try{
35 boost::archive::xml_iarchive ia(ifs);
36
37 // ファイルから読込
38 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
39
40 isSuccessful = true;
41 }
42 catch( boost::archive::archive_exception e )
43 {
44 if( isShowExceptionMessage )
45 {
46 echo( e.what() );
47 }
48 }
49 catch(...){
50 if( isShowExceptionMessage )
51 {
52 echo( "archive_exception以外の不明な例外" );
53 }
54 }
55
56 if( !isSuccessful )
57 {
58 return false;
59 }
60
61 return true;
62}
63template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteXml( ostream& ofs, bool isShowExceptionMessage ) const
64{
65 bool isSuccessful = false;
66
67 try{
68 boost::archive::xml_oarchive oa(ofs);
69
70 // ファイルに書き出し
71 oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
72
73 isSuccessful = true;
74 }
75 catch( boost::archive::archive_exception e )
76 {
77 if( isShowExceptionMessage )
78 {
79 echo( e.what() );
80 }
81 }
82 catch(...){
83 if( isShowExceptionMessage )
84 {
85 echo( "archive_exception以外の不明な例外" );
86 }
87 }
88
89 if( !isSuccessful )
90 {
91 return false;
92 }
93
94 return true;
95}
96template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXml( const string &xmlFilePath, bool isShowExceptionMessage )
97{
98 // 入力アーカイブの作成
99 std::ifstream ifs( xmlFilePath.c_str() );
100
101 bool result = ReadXml(ifs,isShowExceptionMessage);
102
103 // 入力を閉じる
104 ifs.close();
105
106 return result;
107}
108template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteXml( const string &xmlFilePath, bool isShowExceptionMessage ) const
109{
110 // 出力アーカイブの作成
111 std::ofstream ofs( xmlFilePath.c_str() );
112
113 bool result = WriteXml(ofs,isShowExceptionMessage);
114
115 // 出力を閉じる
116 ofs.close();
117
118 return result;
119}
120
121template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadBinaly( const string &filePath, bool isShowExceptionMessage )
122{
123 // 入力アーカイブの作成
124 std::ifstream ifs( filePath.c_str() );
125
126 bool isSuccessful = false;
127 try{
128 boost::archive::binary_iarchive ia(ifs);
129
130 // ファイルから読込
131 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
132
133 isSuccessful = true;
134 }
135 catch( boost::archive::archive_exception e )
136 {
137 if( isShowExceptionMessage )
138 {
139 echo( e.what() );
140 }
141 }
142 catch(...){
143 if( isShowExceptionMessage )
144 {
145 echo( "archive_exception以外の不明な例外" );
146 }
147 }
148
149 // 入力を閉じる
150 ifs.close();
151
152 if( !isSuccessful )
153 {
154 return false;
155 }
156
157 return true;
158}
159template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteBinaly( const string &filePath, bool isShowExceptionMessage ) const
160{
161 // 出力アーカイブの作成
162 std::ofstream ofs( filePath.c_str() );
163
164 bool isSuccessful = false;
165 try{
166 boost::archive::binary_oarchive oa(ofs);
167
168 // ファイルに書き出し
169 oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
170
171 isSuccessful = true;
172 }
173 catch( boost::archive::archive_exception e )
174 {
175 if( isShowExceptionMessage )
176 {
177 echo( e.what() );
178 }
179 }
180 catch(...){
181 if( isShowExceptionMessage )
182 {
183 echo( "archive_exception以外の不明な例外" );
184 }
185 }
186
187 // 出力を閉じる
188 ofs.close();
189
190 if( !isSuccessful )
191 {
192 return false;
193 }
194
195 return true;
196}
197
198template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadText( const string &filePath, bool isShowExceptionMessage )
199{
200 // 入力アーカイブの作成
201 std::ifstream ifs( filePath.c_str() );
202
203 bool isSuccessful = false;
204 try{
205 boost::archive::text_iarchive ia(ifs);
206
207 // ファイルから読込
208 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
209
210 isSuccessful = true;
211 }
212 catch( boost::archive::archive_exception e )
213 {
214 if( isShowExceptionMessage )
215 {
216 echo( e.what() );
217 }
218 }
219 catch(...){
220 if( isShowExceptionMessage )
221 {
222 echo( "archive_exception以外の不明な例外" );
223 }
224 }
225
226 // 入力を閉じる
227 ifs.close();
228
229 if( !isSuccessful )
230 {
231 return false;
232 }
233
234 return true;
235}
236template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::WriteText( const string &filePath, bool isShowExceptionMessage ) const
237{
238 // 出力アーカイブの作成
239 std::ofstream ofs( filePath.c_str() );
240
241 bool isSuccessful = false;
242 try{
243 boost::archive::text_oarchive oa(ofs);
244
245 // ファイルに書き出し
246 oa << boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
247
248 isSuccessful = true;
249 }
250 catch( boost::archive::archive_exception e )
251 {
252 if( isShowExceptionMessage )
253 {
254 echo( e.what() );
255 }
256 }
257 catch(...){
258 if( isShowExceptionMessage )
259 {
260 echo( "archive_exception以外の不明な例外" );
261 }
262 }
263
264 // 出力を閉じる
265 ofs.close();
266
267 if( !isSuccessful )
268 {
269 return false;
270 }
271
272 return true;
273}
274
275template<class T_xml_schema> bool BoostSerializationSupport<T_xml_schema>::ReadXmlFromString( const string &xmlBuffer )
276{
277 bool isSuccessful = false;
278
279 // 入力アーカイブの作成
280 std::istringstream iss( xmlBuffer );
281
282 try{
283 boost::archive::xml_iarchive ia(iss);
284
285 // 文字列ストリームから読込
286 ia >> boost::serialization::make_nvp( RootTagName(), *(T_xml_schema *)this );
287
288 isSuccessful = true;
289 }
290 catch(...){
291 // 失敗
292 }
293
294 if( !isSuccessful )
295 {
296 return false;
297 }
298
299 return true;
300}
301
302
303template class Jenga::Common::BoostSerializationSupport<MetaImpl>;
304template class Jenga::Common::BoostSerializationSupport<LoggerSetting>;
Note: See TracBrowser for help on using the repository browser.