[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 |
|
---|
[274] | 58 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
---|
| 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 |
|
---|
[395] | 67 | // グローバル ネイティブコードを結合
|
---|
[587] | 68 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
[636] | 69 | objectModule.globalNativeCode.ResetSourceIndexes( relationTable );
|
---|
[587] | 70 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
---|
[276] | 71 |
|
---|
[274] | 72 | // データテーブルを結合
|
---|
[587] | 73 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
---|
| 74 | dataTable.Add( objectModule.dataTable );
|
---|
[280] | 75 |
|
---|
[636] | 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 )
|
---|
[280] | 88 | {
|
---|
[636] | 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 | }
|
---|
[280] | 105 | }
|
---|
[282] | 106 |
|
---|
[636] | 107 | return relationTable;
|
---|
[274] | 108 | }
|
---|
[279] | 109 |
|
---|
| 110 | bool ObjectModule::Read( const std::string &filePath )
|
---|
| 111 | {
|
---|
[587] | 112 | // XMLとして読み込む
|
---|
| 113 | bool isSuccessful = false;
|
---|
[404] | 114 |
|
---|
[587] | 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 )
|
---|
[279] | 130 | {
|
---|
[587] | 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 | {
|
---|
[404] | 139 | return false;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[587] | 142 | return true;
|
---|
[279] | 143 | }
|
---|
| 144 | bool ObjectModule::Write( const std::string &filePath ) const
|
---|
| 145 | {
|
---|
[587] | 146 | bool isSuccessful = false;
|
---|
[404] | 147 |
|
---|
[587] | 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 )
|
---|
[279] | 163 | {
|
---|
[587] | 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 | {
|
---|
[404] | 172 | return false;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
[587] | 175 | return true;
|
---|
[279] | 176 | }
|
---|
[587] | 177 | bool ObjectModule::ReadString( const std::string &str )
|
---|
[279] | 178 | {
|
---|
[404] | 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
|
---|
[523] | 188 | std::istringstream iss( str, std::ios::in | std::ios::binary );
|
---|
[404] | 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 )
|
---|
[279] | 198 | {
|
---|
[404] | 199 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 200 | }
|
---|
[404] | 201 | catch(...){
|
---|
| 202 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | if( !isSuccessful )
|
---|
| 206 | {
|
---|
| 207 | return false;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | return true;
|
---|
[279] | 211 | }
|
---|
[587] | 212 | bool ObjectModule::WriteString( std::string &str ) const
|
---|
[279] | 213 | {
|
---|
[404] | 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
|
---|
[523] | 222 | std::ostringstream oss( "", std::ios::out | std::ios::binary );
|
---|
[404] | 223 | boost::archive::binary_oarchive oa(oss);
|
---|
| 224 | #endif
|
---|
| 225 |
|
---|
| 226 | // 文字列ストリームに書き出し
|
---|
| 227 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
---|
| 228 |
|
---|
[587] | 229 | str = oss.str();
|
---|
[404] | 230 |
|
---|
| 231 | isSuccessful = true;
|
---|
| 232 | }
|
---|
| 233 | catch( boost::archive::archive_exception e )
|
---|
[279] | 234 | {
|
---|
[404] | 235 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
---|
[279] | 236 | }
|
---|
[404] | 237 | catch(...){
|
---|
| 238 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | return isSuccessful;
|
---|
[279] | 242 | }
|
---|