source: dev/branches/egtra/ab5.0/abdev/ab_common/src/Lexical/ObjectModule.cpp@ 776

Last change on this file since 776 was 776, checked in by イグトランス (egtra), 13 years ago

Boostのバージョンを1.45へ更新

File size: 6.3 KB
RevLine 
[520]1#pragma warning(disable : 4996)
2
3#include <map>
[404]4#include <string>
5#include <vector>
6#include <fstream>
[520]7#include <iostream>
[522]8#include <iomanip>
9#include <ios>
10#include <streambuf>
11#include <sstream>
[274]12
[750]13#define WIN32_LEAN_AND_MEAN
[404]14#include <windows.h>
15#include <stdio.h>
16#include <string.h>
17#include <math.h>
18#include <time.h>
19#include <limits.h>
20#include <shlobj.h>
[522]21#include <tchar.h>
[404]22
23//boost libraries
24#include <boost/foreach.hpp>
25
26
27// ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
28//#define OBJECT_MODULE_IS_NOT_BINARY
29
30
31#ifdef OBJECT_MODULE_IS_NOT_BINARY
32#include <boost/archive/xml_oarchive.hpp>
33#include <boost/archive/xml_iarchive.hpp>
34#else
35#include <boost/archive/binary_oarchive.hpp>
36#include <boost/archive/binary_iarchive.hpp>
37#endif
38#include <boost/serialization/string.hpp>
39#include <boost/serialization/access.hpp>
40#include <boost/serialization/level.hpp>
41#include <boost/serialization/vector.hpp>
42#include <boost/serialization/map.hpp>
43#include <boost/serialization/version.hpp>
[523]44#include <boost/serialization/serialization.hpp>
45#include <boost/serialization/nvp.hpp>
46#include <boost/serialization/export.hpp>
[404]47
[750]48#define foreach(v, c) for each (v in c)
49
[520]50#include <jenga/include/jenga.h>
[600]51#include <abdev/ab_common/include/ab_common.h>
[505]52
[520]53
[637]54void ObjectModule::StaticLink( ObjectModule &objectModule, bool isSll )
[274]55{
[636]56 const std::vector<int> relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames );
57
[587]58 long dataSectionBaseOffset = dataTable.GetSize();
[280]59
[274]60 // メタ情報を結合
[636]61 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable );
[274]62
[637]63 if( !isSll )
64 {
65 // グローバル ネイティブコードを結合
66 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
67 objectModule.globalNativeCode.ResetRelationalObjectModuleIndex( relationTable );
68 globalNativeCode.PutEx( objectModule.globalNativeCode );
[276]69
[637]70 // データテーブルを結合
71 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
72 dataTable.Add( objectModule.dataTable );
73 }
[280]74
[636]75 // TODO: basbufがいらなくなったら消す
76 extern char *basbuf;
77 basbuf = this->source.GetBuffer();
78}
79
[640]80void ObjectModule::Resolve( ResolveErrors &resolveErrors )
[637]81{
[640]82 this->meta.Resolve( *this, resolveErrors );
[637]83
84 // グローバルネイティブコードを解決(スケジュールを解決する)
[640]85 this->globalNativeCode.Resolve( *this, resolveErrors );
[637]86
87 // データテーブルを解決(スケジュールを解決する)
[640]88 this->dataTable.Resolve( *this, resolveErrors );
[637]89}
90
[636]91const std::vector<int> ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames )
92{
93 // 要素 = 古いインデックス、値 = 新しいインデックス
94 std::vector<int> relationTable;
95
96 // リレーションテーブルを構築
[750]97 foreach( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames )
[280]98 {
[636]99 bool isMatch = false;
100 for( int i=0; i<static_cast<int>(this->relationalObjectModuleNames.size()); i++ )
101 {
102 if( oldRelationalObjectModuleName == this->relationalObjectModuleNames[i] )
103 {
104 isMatch = true;
105 relationTable.push_back( i );
106 break;
107 }
108 }
109
110 if( !isMatch )
111 {
112 // エラー
113 _ASSERT( false );
114 }
[280]115 }
[282]116
[636]117 return relationTable;
[274]118}
[279]119
120bool ObjectModule::Read( const std::string &filePath )
121{
[587]122 // XMLとして読み込む
123 bool isSuccessful = false;
[404]124
[587]125 try{
126#ifdef OBJECT_MODULE_IS_NOT_BINARY
127 std::ifstream ifs( filePath.c_str() );
128 boost::archive::xml_iarchive ia(ifs);
129#else
130 std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary );
131 boost::archive::binary_iarchive ia(ifs);
132#endif
133
134 // ファイルから読込
135 ia >> boost::serialization::make_nvp( RootTagName(), *this );
136
137 isSuccessful = true;
138 }
[750]139 catch( boost::archive::archive_exception& e )
[279]140 {
[587]141 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
142 }
143 catch(...){
144 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
145 }
146
147 if( !isSuccessful )
148 {
[404]149 return false;
150 }
151
[587]152 return true;
[279]153}
154bool ObjectModule::Write( const std::string &filePath ) const
155{
[587]156 bool isSuccessful = false;
[404]157
[587]158 try{
159#ifdef OBJECT_MODULE_IS_NOT_BINARY
160 std::ofstream ofs( filePath.c_str() );
161 boost::archive::xml_oarchive oa(ofs);
162#else
163 std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary );
164 boost::archive::binary_oarchive oa(ofs);
165#endif
166
167 // ファイルに書き出し
168 oa << boost::serialization::make_nvp( RootTagName(), *this );
169
170 isSuccessful = true;
171 }
[750]172 catch( boost::archive::archive_exception& e )
[279]173 {
[587]174 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
175 }
176 catch(...){
177 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
178 }
179
180 if( !isSuccessful )
181 {
[404]182 return false;
183 }
184
[587]185 return true;
[279]186}
[587]187bool ObjectModule::ReadString( const std::string &str )
[279]188{
[404]189 bool isSuccessful = false;
190
191 // 入力アーカイブの作成
192
193 try{
194#ifdef OBJECT_MODULE_IS_NOT_BINARY
195 std::istringstream iss( str );
196 boost::archive::xml_iarchive ia(iss);
197#else
[523]198 std::istringstream iss( str, std::ios::in | std::ios::binary );
[404]199 boost::archive::binary_iarchive ia(iss);
200#endif
201
202 // 文字列ストリームから読込
203 ia >> boost::serialization::make_nvp( RootTagName(), *this );
204
205 isSuccessful = true;
206 }
[750]207 catch( boost::archive::archive_exception& e )
[279]208 {
[404]209 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]210 }
[404]211 catch(...){
212 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
213 }
214
215 if( !isSuccessful )
216 {
217 return false;
218 }
219
220 return true;
[279]221}
[587]222bool ObjectModule::WriteString( std::string &str ) const
[279]223{
[404]224 // 出力アーカイブの作成
225
226 bool isSuccessful = false;
227 try{
228#ifdef OBJECT_MODULE_IS_NOT_BINARY
229 std::ostringstream oss;
230 boost::archive::xml_oarchive oa(oss);
231#else
[523]232 std::ostringstream oss( "", std::ios::out | std::ios::binary );
[404]233 boost::archive::binary_oarchive oa(oss);
234#endif
235
236 // 文字列ストリームに書き出し
237 oa << boost::serialization::make_nvp( RootTagName(), *this );
238
[587]239 str = oss.str();
[404]240
241 isSuccessful = true;
242 }
[750]243 catch( boost::archive::archive_exception &e )
[279]244 {
[404]245 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
[279]246 }
[404]247 catch(...){
248 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
249 }
250
251 return isSuccessful;
[279]252}
[776]253
254BOOST_CLASS_EXPORT_IMPLEMENT( DynamicMethod );
255BOOST_CLASS_EXPORT_IMPLEMENT( StaticMethod );
Note: See TracBrowser for help on using the repository browser.