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