| 1 | #include <string>
|
|---|
| 2 | #include <vector>
|
|---|
| 3 | #include <fstream>
|
|---|
| 4 |
|
|---|
| 5 | #include <windows.h>
|
|---|
| 6 | #include <stdio.h>
|
|---|
| 7 | #include <string.h>
|
|---|
| 8 | #include <math.h>
|
|---|
| 9 | #include <commctrl.h>
|
|---|
| 10 | #include <time.h>
|
|---|
| 11 | #include <limits.h>
|
|---|
| 12 | #include <shlobj.h>
|
|---|
| 13 |
|
|---|
| 14 | //boost libraries
|
|---|
| 15 | #include <boost/foreach.hpp>
|
|---|
| 16 |
|
|---|
| 17 | #include <jenga/include/common/String.h>
|
|---|
| 18 |
|
|---|
| 19 | #include "../common.h"
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | // ObjectModuleの内容をXmlで生成する場合はこの行を有効にする
|
|---|
| 23 | //#define OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 27 | #include <boost/archive/xml_oarchive.hpp>
|
|---|
| 28 | #include <boost/archive/xml_iarchive.hpp>
|
|---|
| 29 | #else
|
|---|
| 30 | #include <boost/archive/binary_oarchive.hpp>
|
|---|
| 31 | #include <boost/archive/binary_iarchive.hpp>
|
|---|
| 32 | #endif
|
|---|
| 33 | #include <boost/serialization/string.hpp>
|
|---|
| 34 | #include <boost/serialization/access.hpp>
|
|---|
| 35 | #include <boost/serialization/level.hpp>
|
|---|
| 36 | #include <boost/serialization/vector.hpp>
|
|---|
| 37 | #include <boost/serialization/map.hpp>
|
|---|
| 38 | #include <boost/serialization/version.hpp>
|
|---|
| 39 | #include <boost/serialization/is_abstract.hpp>
|
|---|
| 40 |
|
|---|
| 41 | #include <BoostSerializationSupport.h>
|
|---|
| 42 | #include <Hashmap.h>
|
|---|
| 43 | #include <Compiler.h>
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | void ObjectModule::StaticLink( ObjectModule &objectModule )
|
|---|
| 47 | {
|
|---|
| 48 | long dataSectionBaseOffset = dataTable.GetSize();
|
|---|
| 49 | int sourceIndexBase = (int)sources.size();
|
|---|
| 50 |
|
|---|
| 51 | // メタ情報を結合
|
|---|
| 52 | meta.StaticLink( objectModule.meta, dataSectionBaseOffset, sourceIndexBase );
|
|---|
| 53 |
|
|---|
| 54 | // グローバル ネイティブコードを結合
|
|---|
| 55 | objectModule.globalNativeCode.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 56 | objectModule.globalNativeCode.ResetSourceIndexes( sourceIndexBase );
|
|---|
| 57 | globalNativeCode.PutEx( objectModule.globalNativeCode );
|
|---|
| 58 |
|
|---|
| 59 | // データテーブルを結合
|
|---|
| 60 | objectModule.dataTable.ResetDataSectionBaseOffset( dataSectionBaseOffset );
|
|---|
| 61 | dataTable.Add( objectModule.dataTable );
|
|---|
| 62 |
|
|---|
| 63 | // ソースコードを結合
|
|---|
| 64 | BOOST_FOREACH( const BasicSource &source, objectModule.sources )
|
|---|
| 65 | {
|
|---|
| 66 | this->sources.push_back( source );
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | // TODO: basbufがいらなくなったら消す
|
|---|
| 70 | extern char *basbuf;
|
|---|
| 71 | basbuf = this->sources[0].GetBuffer();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | bool ObjectModule::Read( const std::string &filePath )
|
|---|
| 75 | {
|
|---|
| 76 | // XMLとして読み込む
|
|---|
| 77 | bool isSuccessful = false;
|
|---|
| 78 |
|
|---|
| 79 | try{
|
|---|
| 80 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 81 | std::ifstream ifs( filePath.c_str() );
|
|---|
| 82 | boost::archive::xml_iarchive ia(ifs);
|
|---|
| 83 | #else
|
|---|
| 84 | std::ifstream ifs( filePath.c_str(), ios::in | ios::binary );
|
|---|
| 85 | boost::archive::binary_iarchive ia(ifs);
|
|---|
| 86 | #endif
|
|---|
| 87 |
|
|---|
| 88 | // ファイルから読込
|
|---|
| 89 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 90 |
|
|---|
| 91 | isSuccessful = true;
|
|---|
| 92 | }
|
|---|
| 93 | catch( boost::archive::archive_exception e )
|
|---|
| 94 | {
|
|---|
| 95 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 96 | }
|
|---|
| 97 | catch(...){
|
|---|
| 98 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | if( !isSuccessful )
|
|---|
| 102 | {
|
|---|
| 103 | return false;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | return true;
|
|---|
| 107 | }
|
|---|
| 108 | bool ObjectModule::Write( const std::string &filePath ) const
|
|---|
| 109 | {
|
|---|
| 110 | bool isSuccessful = false;
|
|---|
| 111 |
|
|---|
| 112 | try{
|
|---|
| 113 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 114 | std::ofstream ofs( filePath.c_str() );
|
|---|
| 115 | boost::archive::xml_oarchive oa(ofs);
|
|---|
| 116 | #else
|
|---|
| 117 | std::ofstream ofs( filePath.c_str(), ios::out | ios::binary );
|
|---|
| 118 | boost::archive::binary_oarchive oa(ofs);
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | // ファイルに書き出し
|
|---|
| 122 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 123 |
|
|---|
| 124 | isSuccessful = true;
|
|---|
| 125 | }
|
|---|
| 126 | catch( boost::archive::archive_exception e )
|
|---|
| 127 | {
|
|---|
| 128 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 129 | }
|
|---|
| 130 | catch(...){
|
|---|
| 131 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | if( !isSuccessful )
|
|---|
| 135 | {
|
|---|
| 136 | return false;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | return true;
|
|---|
| 140 | }
|
|---|
| 141 | bool ObjectModule::ReadString( const std::string &str )
|
|---|
| 142 | {
|
|---|
| 143 | bool isSuccessful = false;
|
|---|
| 144 |
|
|---|
| 145 | // 入力アーカイブの作成
|
|---|
| 146 |
|
|---|
| 147 | try{
|
|---|
| 148 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 149 | std::istringstream iss( str );
|
|---|
| 150 | boost::archive::xml_iarchive ia(iss);
|
|---|
| 151 | #else
|
|---|
| 152 | std::istringstream iss( str, ios::in | ios::binary );
|
|---|
| 153 | boost::archive::binary_iarchive ia(iss);
|
|---|
| 154 | #endif
|
|---|
| 155 |
|
|---|
| 156 | // 文字列ストリームから読込
|
|---|
| 157 | ia >> boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 158 |
|
|---|
| 159 | isSuccessful = true;
|
|---|
| 160 | }
|
|---|
| 161 | catch( boost::archive::archive_exception e )
|
|---|
| 162 | {
|
|---|
| 163 | MessageBox( NULL, e.what(), "XMLシリアライズの例外", MB_OK );
|
|---|
| 164 | }
|
|---|
| 165 | catch(...){
|
|---|
| 166 | MessageBox( NULL, "archive_exception以外の不明な例外", "XMLシリアライズの例外", MB_OK );
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | if( !isSuccessful )
|
|---|
| 170 | {
|
|---|
| 171 | return false;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | return true;
|
|---|
| 175 | }
|
|---|
| 176 | bool ObjectModule::WriteString( std::string &str ) const
|
|---|
| 177 | {
|
|---|
| 178 | // 出力アーカイブの作成
|
|---|
| 179 |
|
|---|
| 180 | bool isSuccessful = false;
|
|---|
| 181 | try{
|
|---|
| 182 | #ifdef OBJECT_MODULE_IS_NOT_BINARY
|
|---|
| 183 | std::ostringstream oss;
|
|---|
| 184 | boost::archive::xml_oarchive oa(oss);
|
|---|
| 185 | #else
|
|---|
| 186 | std::ostringstream oss( "", ios::out | ios::binary );
|
|---|
| 187 | boost::archive::binary_oarchive oa(oss);
|
|---|
| 188 | #endif
|
|---|
| 189 |
|
|---|
| 190 | // 文字列ストリームに書き出し
|
|---|
| 191 | oa << boost::serialization::make_nvp( RootTagName(), *this );
|
|---|
| 192 |
|
|---|
| 193 | str = oss.str();
|
|---|
| 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 | return isSuccessful;
|
|---|
| 206 | }
|
|---|