[54] | 1 | /*
|
---|
| 2 | * TOPPERS Software
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
|
---|
| 6 | *
|
---|
| 7 | * 上記著作権者は,以下の(1)〜(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
| 8 | * ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
| 9 | * 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
| 10 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
| 11 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
| 12 | * スコード中に含まれていること.
|
---|
| 13 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
| 14 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
| 15 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
| 16 | * の無保証規定を掲載すること.
|
---|
| 17 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
| 18 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
| 19 | * と.
|
---|
| 20 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
| 21 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
| 22 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
| 23 | * 報告すること.
|
---|
| 24 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
| 25 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
| 26 | * また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
| 27 | * 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
| 28 | * 免責すること.
|
---|
| 29 | *
|
---|
| 30 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
| 31 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
| 32 | * に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
| 33 | * アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
| 34 | * の責任を負わない.
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
| 37 | /*!
|
---|
| 38 | * \file toppers/output_file.hpp
|
---|
| 39 | * \brief 出力ファイル管理を扱うための宣言定義
|
---|
| 40 | *
|
---|
| 41 | * このファイルで定義されるクラス
|
---|
| 42 | * \code
|
---|
| 43 | * class output_file;
|
---|
| 44 | * \endcode
|
---|
| 45 | */
|
---|
| 46 | #ifndef TOPPERS_OUTPUT_FILE_HPP_
|
---|
| 47 | #define TOPPERS_OUTPUT_FILE_HPP_
|
---|
| 48 |
|
---|
| 49 | #include <ostream>
|
---|
| 50 | #include <string>
|
---|
| 51 | #include "toppers/config.hpp"
|
---|
| 52 |
|
---|
| 53 | namespace toppers
|
---|
| 54 | {
|
---|
| 55 |
|
---|
| 56 | /*!
|
---|
| 57 | * \class output_file output_file.hpp "toppers/output_file.hpp"
|
---|
| 58 | * \brief 出力ファイル管理クラス
|
---|
| 59 | */
|
---|
| 60 | class output_file
|
---|
| 61 | {
|
---|
| 62 | public:
|
---|
| 63 | output_file() : omode_( static_cast< std::ios_base::openmode >( 0 ) ) {}
|
---|
| 64 | output_file( std::string const& filename, std::ios_base::openmode omode )
|
---|
| 65 | : filename_( filename ), omode_( omode ), enable_( true ) {}
|
---|
| 66 | virtual ~output_file() {}
|
---|
| 67 |
|
---|
| 68 | std::ostream& ostr() const;
|
---|
| 69 | std::string const& file_name() const { return filename_; }
|
---|
| 70 | bool is_enable() const { return enable_; }
|
---|
| 71 | void enable( bool flag = true ) { enable_ = flag; }
|
---|
| 72 | void push_back( char c )
|
---|
| 73 | {
|
---|
| 74 | if ( enable_ )
|
---|
| 75 | {
|
---|
| 76 | ostr() << c;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | static std::string path_name( std::string const& filename );
|
---|
| 81 | static std::string get_file_data( std::string const& filename );
|
---|
| 82 | static bool set_file_data( std::string const& filename, std::string const& data );
|
---|
| 83 | static bool clear_file_data( std::string const& filename );
|
---|
| 84 | static void save();
|
---|
| 85 | private:
|
---|
| 86 | std::string filename_;
|
---|
| 87 | std::ios_base::openmode omode_;
|
---|
| 88 | bool enable_;
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | template < typename T >
|
---|
| 92 | inline output_file const& operator << ( output_file const& ofile, T const& value )
|
---|
| 93 | {
|
---|
| 94 | if ( ofile.is_enable() )
|
---|
| 95 | {
|
---|
| 96 | ofile.ostr() << value;
|
---|
| 97 | }
|
---|
| 98 | return ofile;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | #endif // ! TOPPERS_OUTPUT_FILE_HPP_
|
---|