OSDN Git Service

First commitment for the BlackTank LPC1769.
[blacktank/blacktank.git] / kernel / cfg / toppers / text_line.hpp
1 /*
2  *  TOPPERS Software
3  *      Toyohashi Open Platform for Embedded Real-Time Systems
4  *
5  *  Copyright (C) 2005-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 /*!
39  *  \file   toppers/text_line.hpp
40  *  \brief  テキストデータの行に関する宣言定義
41  *
42  *  このファイルで定義されるクラス
43  *  \code
44  *  struct text_line;
45  *  struct basic_line_buf< CharT, Traits, Allocator >;
46  *  \endcode
47  */
48 #ifndef TOPPERS_TEXTLINE_HPP_
49 #define TOPPERS_TEXTLINE_HPP_
50
51 #include <iosfwd>
52 #include <string>
53 #include <algorithm>
54 #include "toppers/config.hpp"
55
56 namespace toppers
57 {
58
59   /*!
60    *  \struct text_line text_line.hpp "toppers/text_line.hpp"
61    *  \brief  ファイル名と行番号の保持クラス
62    */
63   struct text_line
64   {
65     std::string file;   //!< ファイル名
66     long line;          //!< 行番号(1〜)
67
68     /*!
69      *  \brief  デフォルトコンストラクタ
70      */
71     text_line()
72       : line( 0 )
73     {
74     }
75     /*!
76      *  \brief  コンストラクタ
77      *  \param  filename  ファイル名
78      *  \param  lineno    行番号
79      */
80     explicit text_line( std::string const& filename, long lineno = 0 )
81       : file( filename ), line( lineno )
82     {
83     }
84     /*!
85      *  \brief  コンストラクタ
86      *  \param  filename  ファイル名
87      *  \param  lineno    行番号
88      */
89     explicit text_line( char const* filename, long lineno = 0 )
90       : file( filename ), line( lineno )
91     {
92     }
93     /*!
94      *  \brief  オブジェクトの交換
95      *  \param  other   交換対象のオブジェクト
96      */
97     void swap( text_line& other ) throw()
98     {
99       std::swap( line, other.line );
100       file.swap( other.file );
101     }
102   };
103
104   /*!
105    *  \struct line_buf text_line.hpp "toppers/text_line.hpp"
106    *  \brief  1 行テキストの管理クラス
107    */
108   template
109   <
110     typename CharT,
111     class Traits = std::char_traits< CharT >,
112     class Allocator = std::allocator< CharT >
113   >
114   struct basic_line_buf
115   {
116     typedef std::basic_string< CharT, Traits, Allocator > string_type;
117
118     string_type buf; //!< 行データを表す文字列
119     text_line line;  //!< 行番号情報
120
121     /*!
122      *  \brief  デフォルトコンストラクタ
123      */
124     basic_line_buf()
125     {
126     }
127     /*!
128      *  \brief  コンストラクタ
129      *  \param  line  行番号情報
130      */
131     basic_line_buf( text_line const& line )
132       : line( line )
133     {
134     }
135     /*!
136      *  \brief  コンストラクタ
137      *  \param  line  行番号情報
138      *  \param  data  行データ
139      */
140     basic_line_buf( text_line const& line, string_type const& data )
141       : buf( data ), line( line )
142     {
143     }
144   };
145
146   //! char 版の 1 行テキスト管理クラス
147   typedef basic_line_buf< char > line_buf;
148
149   /*!
150    *  \brief  イテレータが保持する行番号情報の取得
151    *  \param  iter  イテレータ
152    *  \return 行番号情報への参照を返す
153    *
154    *  iter で指定したイテレータが行番号情報を保持しているなら、その行番号情報を返します。
155    *  行番号情報を保持していない場合はダミーオブジェクトへの参照を返します。
156    */
157   template < class Iterator >
158   inline text_line const& get_text_line( Iterator iter )
159   {
160     static text_line dummy;
161     return dummy;
162   }
163
164 }
165
166 #endif  // ! TOPPERS_TEXTLINE_HPP_