[8] | 1 | /*
|
---|
| 2 | * TOPPERS Software
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
|
---|
| 6 | *
|
---|
| 7 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 8 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 9 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 10 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 11 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 12 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 13 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 14 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 15 | gip
|
---|
| 16 | * Ò}j
|
---|
| 17 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 18 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 19 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 20 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 21 | * ÆD
|
---|
| 22 | * (a) Äzzɺ¤hL
|
---|
| 23 | gipÒ}j
|
---|
| 24 | AÈÇjÉCãLÌ
|
---|
| 25 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 26 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 27 | * ñ·é±ÆD
|
---|
| 28 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 29 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 30 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 31 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 32 | * ÆÓ·é±ÆD
|
---|
| 33 | *
|
---|
| 34 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 35 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 36 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 37 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
| 38 | * ÌÓCðíÈ¢D
|
---|
| 39 | *
|
---|
| 40 | */
|
---|
| 41 | #include <fstream>
|
---|
| 42 | #include <algorithm>
|
---|
| 43 | #include <iterator>
|
---|
| 44 | #include "toppers/io.hpp"
|
---|
| 45 | #include "toppers/diagnostics.hpp"
|
---|
| 46 | #include <boost/format.hpp>
|
---|
| 47 |
|
---|
| 48 | namespace toppers
|
---|
| 49 | {
|
---|
| 50 |
|
---|
| 51 | void read( std::string const& filename, std::string& buf, std::ios_base::openmode omode )
|
---|
| 52 | {
|
---|
| 53 | std::ifstream ifs( filename.c_str(), std::ios_base::in | omode );
|
---|
| 54 | if ( !ifs.is_open() )
|
---|
| 55 | {
|
---|
| 56 | throw io_error( str( boost::format( _( "cannot open file `%1%\'" ) ) % filename ) );
|
---|
| 57 | }
|
---|
| 58 | std::string t;
|
---|
| 59 | char c;
|
---|
| 60 | while ( ifs.get( c ) )
|
---|
| 61 | {
|
---|
| 62 | t.push_back( c );
|
---|
| 63 | }
|
---|
| 64 | if ( ifs.bad() )
|
---|
| 65 | {
|
---|
| 66 | throw io_error( _( "I/O error" ) );
|
---|
| 67 | }
|
---|
| 68 | buf.swap( t );
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void write( std::string const& filename, std::string const& buf, std::ios_base::openmode omode )
|
---|
| 72 | {
|
---|
| 73 | std::ofstream ofs( filename.c_str(), std::ios_base::out | omode );
|
---|
| 74 | if ( !ofs.is_open() )
|
---|
| 75 | {
|
---|
| 76 | throw io_error( str( boost::format( _( "cannot open file `%1%\'" ) ) % filename ) );
|
---|
| 77 | }
|
---|
| 78 | std::copy( buf.begin(), buf.end(), std::ostream_iterator< char >( ofs ) );
|
---|
| 79 | if ( ofs.bad() )
|
---|
| 80 | {
|
---|
| 81 | throw io_error( _( "I/O error" ) );
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | }
|
---|