Changeset 404 in dev for trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp
- Timestamp:
- Mar 1, 2008, 12:00:47 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abdev/BasicCompiler_Common/src/ObjectModule.cpp
r395 r404 1 #include "stdafx.h" 2 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> 3 43 #include <Compiler.h> 4 5 enum ObjectModuleDataType6 {7 ObjectModuleDataTypeXml,8 ObjectModuleDataTypeText,9 ObjectModuleDataTypeBinaly,10 };11 const ObjectModuleDataType objectModuleDataType = ObjectModuleDataTypeBinaly;12 44 13 45 … … 42 74 bool ObjectModule::Read( const std::string &filePath ) 43 75 { 44 switch( objectModuleDataType ) 45 { 46 case ObjectModuleDataTypeXml: 47 return ReadXml( filePath ); 48 case ObjectModuleDataTypeText: 49 return ReadText( filePath ); 50 case ObjectModuleDataTypeBinaly: 51 return ReadBinaryFile( filePath ); 52 default: 53 Jenga::Throw( "" ); 54 break; 55 } 56 return false; 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; 57 107 } 58 108 bool ObjectModule::Write( const std::string &filePath ) const 59 109 { 60 switch( objectModuleDataType ) 61 { 62 case ObjectModuleDataTypeXml: 63 return WriteXml( filePath ); 64 case ObjectModuleDataTypeText: 65 return WriteText( filePath ); 66 case ObjectModuleDataTypeBinaly: 67 return WriteBinaryFile( filePath ); 68 default: 69 Jenga::Throw( "" ); 70 break; 71 } 72 return false; 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; 73 140 } 74 141 bool ObjectModule::ReadString( const std::string &str ) 75 142 { 76 switch( objectModuleDataType ) 77 { 78 case ObjectModuleDataTypeXml: 79 return ReadXmlString( str ); 80 case ObjectModuleDataTypeText: 81 return ReadTextString( str ); 82 case ObjectModuleDataTypeBinaly: 83 return ReadBinaryString( str ); 84 default: 85 Jenga::Throw( "" ); 86 break; 87 } 88 return false; 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; 89 175 } 90 176 bool ObjectModule::WriteString( std::string &str ) const 91 177 { 92 switch( objectModuleDataType ) 93 { 94 case ObjectModuleDataTypeXml: 95 return WriteXmlString( str ); 96 case ObjectModuleDataTypeText: 97 return WriteTextString( str ); 98 case ObjectModuleDataTypeBinaly: 99 return WriteBinaryString( str ); 100 default: 101 Jenga::Throw( "" ); 102 break; 103 } 104 return false; 105 } 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 }
Note:
See TracChangeset
for help on using the changeset viewer.