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
Line 
1#pragma warning(disable : 4996)
2
3#include <map>
4#include <string>
5#include <vector>
6#include <fstream>
7#include <iostream>
8#include <iomanip>
9#include <ios>
10#include <streambuf>
11#include <sstream>
12
13#define WIN32_LEAN_AND_MEAN
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>
21#include <tchar.h>
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>
44#include <boost/serialization/serialization.hpp>
45#include <boost/serialization/nvp.hpp>
46#include <boost/serialization/export.hpp>
47
48#define foreach(v, c) for each (v in c)
49
50#include <jenga/include/jenga.h>
51#include <abdev/ab_common/include/ab_common.h>
52
53
54void ObjectModule::StaticLink( ObjectModule &objectModule, bool isSll )
55{
56 const std::vector<int> relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames );
57
58 long dataSectionBaseOffset = dataTable.GetSize();
59
60 // メタ情報を結合
61 meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable );
62
63 if( !isSll )
64 {
65 // グローバル ネイティブコードを結合
66 objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
67 objectModule.globalNativeCode.ResetRelationalObjectModuleIndex( relationTable );
68 globalNativeCode.PutEx( objectModule.globalNativeCode );
69
70 // データテーブルを結合
71 objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
72 dataTable.Add( objectModule.dataTable );
73 }
74
75 // TODO: basbufがいらなくなったら消す
76 extern char *basbuf;
77 basbuf = this->source.GetBuffer();
78}
79
80void ObjectModule::Resolve( ResolveErrors &resolveErrors )
81{
82 this->meta.Resolve( *this, resolveErrors );
83
84 // グローバルネイティブコードを解決(スケジュールを解決する)
85 this->globalNativeCode.Resolve( *this, resolveErrors );
86
87 // データテーブルを解決(スケジュールを解決する)
88 this->dataTable.Resolve( *this, resolveErrors );
89}
90
91const std::vector<int> ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames )
92{
93 // 要素 = 古いインデックス、値 = 新しいインデックス
94 std::vector<int> relationTable;
95
96 // リレーションテーブルを構築
97 foreach( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames )
98 {
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 }
115 }
116
117 return relationTable;
118}
119
120bool ObjectModule::Read( const std::string &filePath )
121{
122 // XMLとして読み込む
123 bool isSuccessful = false;
124
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 }
139 catch( boost::archive::archive_exception& e )
140 {
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 {
149 return false;
150 }
151
152 return true;
153}
154bool ObjectModule::Write( const std::string &filePath ) const
155{
156 bool isSuccessful = false;
157
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 }
172 catch( boost::archive::archive_exception& e )
173 {
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 {
182 return false;
183 }
184
185 return true;
186}
187bool ObjectModule::ReadString( const std::string &str )
188{
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
198 std::istringstream iss( str, std::ios::in | std::ios::binary );
199 boost::archive::binary_iarchive ia(iss);
200#endif
201
202 // 文字列ストリームから読込
203 ia >> boost::serialization::make_nvp( RootTagName(), *this );
204
205 isSuccessful = true;
206 }
207 catch( boost::archive::archive_exception& e )
208 {
209 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
210 }
211 catch(...){
212 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
213 }
214
215 if( !isSuccessful )
216 {
217 return false;
218 }
219
220 return true;
221}
222bool ObjectModule::WriteString( std::string &str ) const
223{
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
232 std::ostringstream oss( "", std::ios::out | std::ios::binary );
233 boost::archive::binary_oarchive oa(oss);
234#endif
235
236 // 文字列ストリームに書き出し
237 oa << boost::serialization::make_nvp( RootTagName(), *this );
238
239 str = oss.str();
240
241 isSuccessful = true;
242 }
243 catch( boost::archive::archive_exception &e )
244 {
245 MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
246 }
247 catch(...){
248 MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
249 }
250
251 return isSuccessful;
252}
253
254BOOST_CLASS_EXPORT_IMPLEMENT( DynamicMethod );
255BOOST_CLASS_EXPORT_IMPLEMENT( StaticMethod );
Note: See TracBrowser for help on using the repository browser.