[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 |
|
---|
[636] | 79 | // TODO: basbufがいらなくなったら消す
|
---|
| 80 | extern char *basbuf;
|
---|
| 81 | basbuf = this->source.GetBuffer();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[640] | 84 | void ObjectModule::Resolve( ResolveErrors &resolveErrors )
|
---|
[637] | 85 | {
|
---|
[640] | 86 | this->meta.Resolve( *this, resolveErrors );
|
---|
[637] | 87 |
|
---|
| 88 | // グローバルネイティブコードを解決(スケジュールを解決する)
|
---|
[640] | 89 | this->globalNativeCode.Resolve( *this, resolveErrors );
|
---|
[637] | 90 |
|
---|
| 91 | // データテーブルを解決(スケジュールを解決する)
|
---|
[640] | 92 | this->dataTable.Resolve( *this, resolveErrors );
|
---|
[637] | 93 | }
|
---|
| 94 |
|
---|
[636] | 95 | const std::vector<int> ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames )
|
---|
| 96 | {
|
---|
| 97 | // 要素 = 古いインデックス、値 = 新しいインデックス
|
---|
| 98 | std::vector<int> relationTable;
|
---|
| 99 |
|
---|
| 100 | // リレーションテーブルを構築
|
---|
| 101 | BOOST_FOREACH( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames )
|
---|
[280] | 102 | {
|
---|
[636] | 103 | bool isMatch = false;
|
---|
| 104 | for( int i=0; i<static_cast<int>(this->relationalObjectModuleNames.size()); i++ )
|
---|
| 105 | {
|
---|
| 106 | if( oldRelationalObjectModuleName == this->relationalObjectModuleNames[i] )
|
---|
| 107 | {
|
---|
| 108 | isMatch = true;
|
---|
| 109 | relationTable.push_back( i );
|
---|
| 110 | break;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | if( !isMatch )
|
---|
| 115 | {
|
---|
| 116 | // エラー
|
---|
| 117 | _ASSERT( false );
|
---|
| 118 | }
|
---|
[280] | 119 | }
|
---|
[282] | 120 |
|
---|
[636] | 121 | return relationTable;
|
---|
[274] | 122 | }
|
---|
[279] | 123 |
|
---|
| 124 | bool ObjectModule::Read( const std::string &filePath )
|
---|
| 125 | {
|
---|
[587] | 126 | // XMLとして読み込む
|
---|
| 127 | bool isSuccessful = false;
|
---|
[404] | 128 |
|
---|
[587] | 129 | try{
|
---|
| 130 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 131 | std::ifstream ifs( filePath.c_str() );
|
---|
| 132 | boost::archive::xml_iarchive ia(ifs);
|
---|
| 133 | #else
|
---|
| 134 | std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary );
|
---|
| 135 | boost::archive::binary_iarchive ia(ifs);
|
---|
| 136 | #endif
|
---|
| 137 |
|
---|
| 138 | // ファイルから読込
|
---|
| 139 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 140 |
|
---|
| 141 | isSuccessful = true;
|
---|
| 142 | }
|
---|
| 143 | catch( boost::archive::archive_exception e )
|
---|
[279] | 144 | {
|
---|
[587] | 145 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
| 146 | }
|
---|
| 147 | catch(...){
|
---|
| 148 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | if( !isSuccessful )
|
---|
| 152 | {
|
---|
[404] | 153 | return false;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[587] | 156 | return true;
|
---|
[279] | 157 | }
|
---|
| 158 | bool ObjectModule::Write( const std::string &filePath ) const
|
---|
| 159 | {
|
---|
[587] | 160 | bool isSuccessful = false;
|
---|
[404] | 161 |
|
---|
[587] | 162 | try{
|
---|
| 163 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 164 | std::ofstream ofs( filePath.c_str() );
|
---|
| 165 | boost::archive::xml_oarchive oa(ofs);
|
---|
| 166 | #else
|
---|
| 167 | std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary );
|
---|
| 168 | boost::archive::binary_oarchive oa(ofs);
|
---|
| 169 | #endif
|
---|
| 170 |
|
---|
| 171 | // ファイルに書き出し
|
---|
| 172 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 173 |
|
---|
| 174 | isSuccessful = true;
|
---|
| 175 | }
|
---|
| 176 | catch( boost::archive::archive_exception e )
|
---|
[279] | 177 | {
|
---|
[587] | 178 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
| 179 | }
|
---|
| 180 | catch(...){
|
---|
| 181 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | if( !isSuccessful )
|
---|
| 185 | {
|
---|
[404] | 186 | return false;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
[587] | 189 | return true;
|
---|
[279] | 190 | }
|
---|
[587] | 191 | bool ObjectModule::ReadString( const std::string &str )
|
---|
[279] | 192 | {
|
---|
[404] | 193 | bool isSuccessful = false;
|
---|
| 194 |
|
---|
| 195 | // 入力アーカイブの作成
|
---|
| 196 |
|
---|
| 197 | try{
|
---|
| 198 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 199 | std::istringstream iss( str );
|
---|
| 200 | boost::archive::xml_iarchive ia(iss);
|
---|
| 201 | #else
|
---|
[523] | 202 | std::istringstream iss( str, std::ios::in | std::ios::binary );
|
---|
[404] | 203 | boost::archive::binary_iarchive ia(iss);
|
---|
| 204 | #endif
|
---|
| 205 |
|
---|
| 206 | // 文字列ストリームから読込
|
---|
| 207 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 208 |
|
---|
| 209 | isSuccessful = true;
|
---|
| 210 | }
|
---|
| 211 | catch( boost::archive::archive_exception e )
|
---|
[279] | 212 | {
|
---|
[404] | 213 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 214 | }
|
---|
[404] | 215 | catch(...){
|
---|
| 216 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | if( !isSuccessful )
|
---|
| 220 | {
|
---|
| 221 | return false;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | return true;
|
---|
[279] | 225 | }
|
---|
[587] | 226 | bool ObjectModule::WriteString( std::string &str ) const
|
---|
[279] | 227 | {
|
---|
[404] | 228 | // 出力アーカイブの作成
|
---|
| 229 |
|
---|
| 230 | bool isSuccessful = false;
|
---|
| 231 | try{
|
---|
| 232 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
---|
| 233 | std::ostringstream oss;
|
---|
| 234 | boost::archive::xml_oarchive oa(oss);
|
---|
| 235 | #else
|
---|
[523] | 236 | std::ostringstream oss( "", std::ios::out | std::ios::binary );
|
---|
[404] | 237 | boost::archive::binary_oarchive oa(oss);
|
---|
| 238 | #endif
|
---|
| 239 |
|
---|
| 240 | // 文字列ストリームに書き出し
|
---|
| 241 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 242 |
|
---|
[587] | 243 | str = oss.str();
|
---|
[404] | 244 |
|
---|
| 245 | isSuccessful = true;
|
---|
| 246 | }
|
---|
| 247 | catch( boost::archive::archive_exception e )
|
---|
[279] | 248 | {
|
---|
[404] | 249 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 250 | }
|
---|
[404] | 251 | catch(...){
|
---|
| 252 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | return isSuccessful;
|
---|
[279] | 256 | }
|
---|