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/s_record.hpp
|
---|
40 | * \brief モトローラSレコードを扱うための宣言定義
|
---|
41 | *
|
---|
42 | * このファイルで定義されるクラス
|
---|
43 | * \code
|
---|
44 | * class s_record;
|
---|
45 | * struct s_record::record;
|
---|
46 | * class s_record::format_error;
|
---|
47 | * class s_record::checksum_error;
|
---|
48 | * \endcode
|
---|
49 | */
|
---|
50 | #ifndef TOPPERS_S_RECORD_HPP_
|
---|
51 | #define TOPPERS_S_RECORD_HPP_
|
---|
52 |
|
---|
53 | #include "toppers/config.hpp"
|
---|
54 | #include <iosfwd>
|
---|
55 | #include <string>
|
---|
56 | #include <vector>
|
---|
57 | #include <utility>
|
---|
58 | #include <stdexcept>
|
---|
59 | #include <boost/cstdint.hpp>
|
---|
60 |
|
---|
61 | namespace toppers
|
---|
62 | {
|
---|
63 |
|
---|
64 | /*!
|
---|
65 | * \class s_record s_record.hpp "toppers/s_recored.hpp"
|
---|
66 | * \brief モトローラSレコードを扱うためのクラス
|
---|
67 | *
|
---|
68 | * \sa s_record::record, s_record::format_error, s_record::checksum_error
|
---|
69 | */
|
---|
70 | class s_record
|
---|
71 | {
|
---|
72 | public:
|
---|
73 | typedef std::pair< unsigned long, std::vector< unsigned char > > value_type;
|
---|
74 | typedef std::vector< value_type >::size_type size_type;
|
---|
75 |
|
---|
76 | /*!
|
---|
77 | * \struct record s_record.hpp "toppers/s_record.hpp"
|
---|
78 | * \brief Sレコードの1行レコード情報を格納するための構造体
|
---|
79 | */
|
---|
80 | struct record
|
---|
81 | {
|
---|
82 | int type;
|
---|
83 | int length;
|
---|
84 | unsigned long address;
|
---|
85 | std::vector< unsigned char > data;
|
---|
86 | int checksum;
|
---|
87 | };
|
---|
88 |
|
---|
89 | /*!
|
---|
90 | * \class data_error s_record.hpp "toppers/s_record.hpp"
|
---|
91 | * \brief Sレコードのデータエラー例外クラス
|
---|
92 | */
|
---|
93 | class data_error : public std::runtime_error
|
---|
94 | {
|
---|
95 | public:
|
---|
96 | data_error() : std::runtime_error( "S-record data error" ) {}
|
---|
97 | };
|
---|
98 | /*!
|
---|
99 | * \class format_error s_record.hpp "toppers/s_record.hpp"
|
---|
100 | * \brief Sレコードの書式エラー例外クラス
|
---|
101 | */
|
---|
102 | class format_error : public std::runtime_error
|
---|
103 | {
|
---|
104 | public:
|
---|
105 | format_error() : std::runtime_error( "S-record format error" ) {}
|
---|
106 | };
|
---|
107 | /*!
|
---|
108 | * \class checksum_error s_record.hpp "toppers/s_record.hpp"
|
---|
109 | * \brief Sレコードのチェックサムエラー例外クラス
|
---|
110 | */
|
---|
111 | class checksum_error : public std::runtime_error
|
---|
112 | {
|
---|
113 | public:
|
---|
114 | checksum_error() : std::runtime_error( "S-record checksum error" ) {}
|
---|
115 | };
|
---|
116 |
|
---|
117 | /*!
|
---|
118 | * \brief デフォルトコンストラクタ
|
---|
119 | */
|
---|
120 | s_record() : cache_( data_.end() ) {}
|
---|
121 | /*!
|
---|
122 | * \brief コンストラクタ
|
---|
123 | * \param istr 入力ストリーム
|
---|
124 | *
|
---|
125 | * s_record クラスの生成と同時にデータのロードを行います。
|
---|
126 | */
|
---|
127 | explicit s_record( std::istream& istr ) { load( istr ); }
|
---|
128 | /*!
|
---|
129 | * \brief デストラクタ
|
---|
130 | */
|
---|
131 | virtual ~s_record() {}
|
---|
132 |
|
---|
133 | void load( std::istream& istr );
|
---|
134 | int operator[]( size_type address ) const;
|
---|
135 | boost::uintmax_t get_value( std::size_t base, std::size_t size, bool little_endian ) const;
|
---|
136 | unsigned long lower_bound() const;
|
---|
137 | unsigned long upper_bound() const;
|
---|
138 | protected:
|
---|
139 | static record const read_record( std::string const& rec_buf );
|
---|
140 | static int xdigit_to_int( int ch );
|
---|
141 | private:
|
---|
142 | std::vector< value_type > data_;
|
---|
143 | mutable std::vector< value_type >::const_iterator cache_;
|
---|
144 | };
|
---|
145 |
|
---|
146 | }
|
---|
147 |
|
---|
148 | #endif // ! TOPPERS_S_RECORD_HPP_
|
---|