| 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 | #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>
|
|---|
| 21 | #include <process.h>
|
|---|
| 22 | #include <fcntl.h>
|
|---|
| 23 | #include <io.h>
|
|---|
| 24 | #include <shlwapi.h>
|
|---|
| 25 | #include <tchar.h>
|
|---|
| 26 | #include <stdarg.h>
|
|---|
| 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>
|
|---|
| 50 | #include <boost/serialization/serialization.hpp>
|
|---|
| 51 | #include <boost/serialization/nvp.hpp>
|
|---|
| 52 | #include <boost/serialization/export.hpp>
|
|---|
| 53 |
|
|---|
| 54 | #include <jenga/include/jenga.h>
|
|---|
| 55 | #include <abdev/ab_common/include/ab_common.h>
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
|---|
| 59 | {
|
|---|
| 60 | const std::vector<int> relationTable = this->GetRelationTable( objectModule.relationalObjectModuleNames );
|
|---|
| 61 |
|
|---|
| 62 | long dataSectionBaseOffset = dataTable.GetSize();
|
|---|
| 63 |
|
|---|
| 64 | // メタ情報を結合
|
|---|
| 65 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, relationTable );
|
|---|
| 66 |
|
|---|
| 67 | // グローバル ネイティブコードを結合
|
|---|
| 68 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 69 | objectModule.globalNativeCode.ResetSourceIndexes( relationTable );
|
|---|
| 70 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
|---|
| 71 |
|
|---|
| 72 | // データテーブルを結合
|
|---|
| 73 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 74 | dataTable.Add( objectModule.dataTable );
|
|---|
| 75 |
|
|---|
| 76 | // TODO: basbufがいらなくなったら消す
|
|---|
| 77 | extern char *basbuf;
|
|---|
| 78 | basbuf = this->source.GetBuffer();
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | const std::vector<int> ObjectModule::GetRelationTable( const Jenga::Common::Strings &oldRelationalObjectModuleNames )
|
|---|
| 82 | {
|
|---|
| 83 | // 要素 = 古いインデックス、値 = 新しいインデックス
|
|---|
| 84 | std::vector<int> relationTable;
|
|---|
| 85 |
|
|---|
| 86 | // リレーションテーブルを構築
|
|---|
| 87 | BOOST_FOREACH( const std::string &oldRelationalObjectModuleName, oldRelationalObjectModuleNames )
|
|---|
| 88 | {
|
|---|
| 89 | bool isMatch = false;
|
|---|
| 90 | for( int i=0; i<static_cast<int>(this->relationalObjectModuleNames.size()); i++ )
|
|---|
| 91 | {
|
|---|
| 92 | if( oldRelationalObjectModuleName == this->relationalObjectModuleNames[i] )
|
|---|
| 93 | {
|
|---|
| 94 | isMatch = true;
|
|---|
| 95 | relationTable.push_back( i );
|
|---|
| 96 | break;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | if( !isMatch )
|
|---|
| 101 | {
|
|---|
| 102 | // エラー
|
|---|
| 103 | _ASSERT( false );
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | return relationTable;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | bool ObjectModule::Read( const std::string &filePath )
|
|---|
| 111 | {
|
|---|
| 112 | // XMLとして読み込む
|
|---|
| 113 | bool isSuccessful = false;
|
|---|
| 114 |
|
|---|
| 115 | try{
|
|---|
| 116 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 117 | std::ifstream ifs( filePath.c_str() );
|
|---|
| 118 | boost::archive::xml_iarchive ia(ifs);
|
|---|
| 119 | #else
|
|---|
| 120 | std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary );
|
|---|
| 121 | boost::archive::binary_iarchive ia(ifs);
|
|---|
| 122 | #endif
|
|---|
| 123 |
|
|---|
| 124 | // ファイルから読込
|
|---|
| 125 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 126 |
|
|---|
| 127 | isSuccessful = true;
|
|---|
| 128 | }
|
|---|
| 129 | catch( boost::archive::archive_exception e )
|
|---|
| 130 | {
|
|---|
| 131 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 132 | }
|
|---|
| 133 | catch(...){
|
|---|
| 134 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | if( !isSuccessful )
|
|---|
| 138 | {
|
|---|
| 139 | return false;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | return true;
|
|---|
| 143 | }
|
|---|
| 144 | bool ObjectModule::Write( const std::string &filePath ) const
|
|---|
| 145 | {
|
|---|
| 146 | bool isSuccessful = false;
|
|---|
| 147 |
|
|---|
| 148 | try{
|
|---|
| 149 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 150 | std::ofstream ofs( filePath.c_str() );
|
|---|
| 151 | boost::archive::xml_oarchive oa(ofs);
|
|---|
| 152 | #else
|
|---|
| 153 | std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary );
|
|---|
| 154 | boost::archive::binary_oarchive oa(ofs);
|
|---|
| 155 | #endif
|
|---|
| 156 |
|
|---|
| 157 | // ファイルに書き出し
|
|---|
| 158 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 159 |
|
|---|
| 160 | isSuccessful = true;
|
|---|
| 161 | }
|
|---|
| 162 | catch( boost::archive::archive_exception e )
|
|---|
| 163 | {
|
|---|
| 164 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 165 | }
|
|---|
| 166 | catch(...){
|
|---|
| 167 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | if( !isSuccessful )
|
|---|
| 171 | {
|
|---|
| 172 | return false;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | return true;
|
|---|
| 176 | }
|
|---|
| 177 | bool ObjectModule::ReadString( const std::string &str )
|
|---|
| 178 | {
|
|---|
| 179 | bool isSuccessful = false;
|
|---|
| 180 |
|
|---|
| 181 | // 入力アーカイブの作成
|
|---|
| 182 |
|
|---|
| 183 | try{
|
|---|
| 184 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 185 | std::istringstream iss( str );
|
|---|
| 186 | boost::archive::xml_iarchive ia(iss);
|
|---|
| 187 | #else
|
|---|
| 188 | std::istringstream iss( str, std::ios::in | std::ios::binary );
|
|---|
| 189 | boost::archive::binary_iarchive ia(iss);
|
|---|
| 190 | #endif
|
|---|
| 191 |
|
|---|
| 192 | // 文字列ストリームから読込
|
|---|
| 193 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 194 |
|
|---|
| 195 | isSuccessful = true;
|
|---|
| 196 | }
|
|---|
| 197 | catch( boost::archive::archive_exception e )
|
|---|
| 198 | {
|
|---|
| 199 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 200 | }
|
|---|
| 201 | catch(...){
|
|---|
| 202 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | if( !isSuccessful )
|
|---|
| 206 | {
|
|---|
| 207 | return false;
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | return true;
|
|---|
| 211 | }
|
|---|
| 212 | bool ObjectModule::WriteString( std::string &str ) const
|
|---|
| 213 | {
|
|---|
| 214 | // 出力アーカイブの作成
|
|---|
| 215 |
|
|---|
| 216 | bool isSuccessful = false;
|
|---|
| 217 | try{
|
|---|
| 218 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 219 | std::ostringstream oss;
|
|---|
| 220 | boost::archive::xml_oarchive oa(oss);
|
|---|
| 221 | #else
|
|---|
| 222 | std::ostringstream oss( "", std::ios::out | std::ios::binary );
|
|---|
| 223 | boost::archive::binary_oarchive oa(oss);
|
|---|
| 224 | #endif
|
|---|
| 225 |
|
|---|
| 226 | // 文字列ストリームに書き出し
|
|---|
| 227 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 228 |
|
|---|
| 229 | str = oss.str();
|
|---|
| 230 |
|
|---|
| 231 | isSuccessful = true;
|
|---|
| 232 | }
|
|---|
| 233 | catch( boost::archive::archive_exception e )
|
|---|
| 234 | {
|
|---|
| 235 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 236 | }
|
|---|
| 237 | catch(...){
|
|---|
| 238 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | return isSuccessful;
|
|---|
| 242 | }
|
|---|