| 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 | long dataSectionBaseOffset = dataTable.GetSize(); | 
|---|
| 61 | int sourceIndexBase = (int)sources.size(); | 
|---|
| 62 |  | 
|---|
| 63 | // メタ情報を結合 | 
|---|
| 64 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase ); | 
|---|
| 65 |  | 
|---|
| 66 | // グローバル ネイティブコードを結合 | 
|---|
| 67 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset ); | 
|---|
| 68 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase ); | 
|---|
| 69 | globalNativeCode.PutEx( objectModule.globalNativeCode ); | 
|---|
| 70 |  | 
|---|
| 71 | // データテーブルを結合 | 
|---|
| 72 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset ); | 
|---|
| 73 | dataTable.Add( objectModule.dataTable ); | 
|---|
| 74 |  | 
|---|
| 75 | // ソースコードを結合 | 
|---|
| 76 | BOOST_FOREACH( const BasicSource &source, objectModule.sources ) | 
|---|
| 77 | { | 
|---|
| 78 | this->sources.push_back( source ); | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | // TODO: basbufがいらなくなったら消す | 
|---|
| 82 | extern char *basbuf; | 
|---|
| 83 | basbuf = this->sources[0].GetBuffer(); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | bool ObjectModule::Read( const std::string &filePath ) | 
|---|
| 87 | { | 
|---|
| 88 | // XMLとして読み込む | 
|---|
| 89 | bool isSuccessful = false; | 
|---|
| 90 |  | 
|---|
| 91 | try{ | 
|---|
| 92 | #ifdef OBJECT_MODULE_IS_NOT_BINARY | 
|---|
| 93 | std::ifstream ifs( filePath.c_str() ); | 
|---|
| 94 | boost::archive::xml_iarchive ia(ifs); | 
|---|
| 95 | #else | 
|---|
| 96 | std::ifstream ifs( filePath.c_str(), std::ios::in | std::ios::binary ); | 
|---|
| 97 | boost::archive::binary_iarchive ia(ifs); | 
|---|
| 98 | #endif | 
|---|
| 99 |  | 
|---|
| 100 | // ファイルから読込 | 
|---|
| 101 | ia >> boost::serialization::make_nvp( RootTagName(), *this ); | 
|---|
| 102 |  | 
|---|
| 103 | isSuccessful = true; | 
|---|
| 104 | } | 
|---|
| 105 | catch( boost::archive::archive_exception e ) | 
|---|
| 106 | { | 
|---|
| 107 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); | 
|---|
| 108 | } | 
|---|
| 109 | catch(...){ | 
|---|
| 110 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | if( !isSuccessful ) | 
|---|
| 114 | { | 
|---|
| 115 | return false; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | return true; | 
|---|
| 119 | } | 
|---|
| 120 | bool ObjectModule::Write( const std::string &filePath ) const | 
|---|
| 121 | { | 
|---|
| 122 | bool isSuccessful = false; | 
|---|
| 123 |  | 
|---|
| 124 | try{ | 
|---|
| 125 | #ifdef OBJECT_MODULE_IS_NOT_BINARY | 
|---|
| 126 | std::ofstream ofs( filePath.c_str() ); | 
|---|
| 127 | boost::archive::xml_oarchive oa(ofs); | 
|---|
| 128 | #else | 
|---|
| 129 | std::ofstream ofs( filePath.c_str(), std::ios::out | std::ios::binary ); | 
|---|
| 130 | boost::archive::binary_oarchive oa(ofs); | 
|---|
| 131 | #endif | 
|---|
| 132 |  | 
|---|
| 133 | // ファイルに書き出し | 
|---|
| 134 | oa << boost::serialization::make_nvp( RootTagName(), *this ); | 
|---|
| 135 |  | 
|---|
| 136 | isSuccessful = true; | 
|---|
| 137 | } | 
|---|
| 138 | catch( boost::archive::archive_exception e ) | 
|---|
| 139 | { | 
|---|
| 140 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); | 
|---|
| 141 | } | 
|---|
| 142 | catch(...){ | 
|---|
| 143 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | if( !isSuccessful ) | 
|---|
| 147 | { | 
|---|
| 148 | return false; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | return true; | 
|---|
| 152 | } | 
|---|
| 153 | bool ObjectModule::ReadString( const std::string &str ) | 
|---|
| 154 | { | 
|---|
| 155 | bool isSuccessful = false; | 
|---|
| 156 |  | 
|---|
| 157 | // 入力アーカイブの作成 | 
|---|
| 158 |  | 
|---|
| 159 | try{ | 
|---|
| 160 | #ifdef OBJECT_MODULE_IS_NOT_BINARY | 
|---|
| 161 | std::istringstream iss( str ); | 
|---|
| 162 | boost::archive::xml_iarchive ia(iss); | 
|---|
| 163 | #else | 
|---|
| 164 | std::istringstream iss( str, std::ios::in | std::ios::binary ); | 
|---|
| 165 | boost::archive::binary_iarchive ia(iss); | 
|---|
| 166 | #endif | 
|---|
| 167 |  | 
|---|
| 168 | // 文字列ストリームから読込 | 
|---|
| 169 | ia >> boost::serialization::make_nvp( RootTagName(), *this ); | 
|---|
| 170 |  | 
|---|
| 171 | isSuccessful = true; | 
|---|
| 172 | } | 
|---|
| 173 | catch( boost::archive::archive_exception e ) | 
|---|
| 174 | { | 
|---|
| 175 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); | 
|---|
| 176 | } | 
|---|
| 177 | catch(...){ | 
|---|
| 178 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); | 
|---|
| 179 | } | 
|---|
| 180 |  | 
|---|
| 181 | if( !isSuccessful ) | 
|---|
| 182 | { | 
|---|
| 183 | return false; | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | return true; | 
|---|
| 187 | } | 
|---|
| 188 | bool ObjectModule::WriteString( std::string &str ) const | 
|---|
| 189 | { | 
|---|
| 190 | // 出力アーカイブの作成 | 
|---|
| 191 |  | 
|---|
| 192 | bool isSuccessful = false; | 
|---|
| 193 | try{ | 
|---|
| 194 | #ifdef OBJECT_MODULE_IS_NOT_BINARY | 
|---|
| 195 | std::ostringstream oss; | 
|---|
| 196 | boost::archive::xml_oarchive oa(oss); | 
|---|
| 197 | #else | 
|---|
| 198 | std::ostringstream oss( "", std::ios::out | std::ios::binary ); | 
|---|
| 199 | boost::archive::binary_oarchive oa(oss); | 
|---|
| 200 | #endif | 
|---|
| 201 |  | 
|---|
| 202 | // 文字列ストリームに書き出し | 
|---|
| 203 | oa << boost::serialization::make_nvp( RootTagName(), *this ); | 
|---|
| 204 |  | 
|---|
| 205 | str = oss.str(); | 
|---|
| 206 |  | 
|---|
| 207 | isSuccessful = true; | 
|---|
| 208 | } | 
|---|
| 209 | catch( boost::archive::archive_exception e ) | 
|---|
| 210 | { | 
|---|
| 211 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK ); | 
|---|
| 212 | } | 
|---|
| 213 | catch(...){ | 
|---|
| 214 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK ); | 
|---|
| 215 | } | 
|---|
| 216 |  | 
|---|
| 217 | return isSuccessful; | 
|---|
| 218 | } | 
|---|