[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 | /*!
|
---|
| 42 | * \file toppers/output_file.hpp
|
---|
| 43 | * \brief oÍt@CÇ𵤽ßÌé¾è`
|
---|
| 44 | *
|
---|
| 45 | * ±Ìt@CÅè`³êéNX
|
---|
| 46 | * \code
|
---|
| 47 | * class output_file;
|
---|
| 48 | * \endcode
|
---|
| 49 | */
|
---|
| 50 | #ifndef TOPPERS_OUTPUT_FILE_HPP_
|
---|
| 51 | #define TOPPERS_OUTPUT_FILE_HPP_
|
---|
| 52 |
|
---|
| 53 | #include <ostream>
|
---|
| 54 | #include <string>
|
---|
| 55 | #include "toppers/config.hpp"
|
---|
| 56 |
|
---|
| 57 | namespace toppers
|
---|
| 58 | {
|
---|
| 59 |
|
---|
| 60 | /*!
|
---|
| 61 | * \class output_file output_file.hpp "toppers/output_file.hpp"
|
---|
| 62 | * \brief oÍt@CÇNX
|
---|
| 63 | */
|
---|
| 64 | class output_file
|
---|
| 65 | {
|
---|
| 66 | public:
|
---|
| 67 | output_file() : omode_( static_cast< std::ios_base::openmode >( 0 ) ) {}
|
---|
| 68 | output_file( std::string const& filename, std::ios_base::openmode omode )
|
---|
| 69 | : filename_( filename ), omode_( omode ), enable_( true ) {}
|
---|
| 70 | virtual ~output_file() {}
|
---|
| 71 |
|
---|
| 72 | std::ostream& ostr() const;
|
---|
| 73 | std::string const& file_name() const { return filename_; }
|
---|
| 74 | bool is_enable() const { return enable_; }
|
---|
| 75 | void enable( bool flag = true ) { enable_ = flag; }
|
---|
| 76 | void push_back( char c )
|
---|
| 77 | {
|
---|
| 78 | if ( enable_ )
|
---|
| 79 | {
|
---|
| 80 | ostr() << c;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | static std::string path_name( std::string const& filename );
|
---|
| 85 | static std::string get_file_data( std::string const& filename );
|
---|
| 86 | static bool set_file_data( std::string const& filename, std::string const& data );
|
---|
| 87 | static bool clear_file_data( std::string const& filename );
|
---|
| 88 | static void save();
|
---|
| 89 | private:
|
---|
| 90 | std::string filename_;
|
---|
| 91 | std::ios_base::openmode omode_;
|
---|
| 92 | bool enable_;
|
---|
| 93 | };
|
---|
| 94 |
|
---|
| 95 | template < typename T >
|
---|
| 96 | inline output_file const& operator << ( output_file const& ofile, T const& value )
|
---|
| 97 | {
|
---|
| 98 | if ( ofile.is_enable() )
|
---|
| 99 | {
|
---|
| 100 | ofile.ostr() << value;
|
---|
| 101 | }
|
---|
| 102 | return ofile;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | #endif // ! TOPPERS_OUTPUT_FILE_HPP_
|
---|