KiCad PCB EDA Suite
Loading...
Searching...
No Matches
allegro_parser.h
Go to the documentation of this file.
1/*
2* This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright Quilter
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23#include <memory>
24
25#include <convert/allegro_db.h>
28
29#include <progress_reporter.h>
30
31namespace ALLEGRO
32{
33
34
41{
42public:
44 m_stream( aStream ),
46 {
47 }
48
49 std::unique_ptr<FILE_HEADER> ParseHeader();
50
56 FMT_VER GetFormatVersion() const { return m_fmtVer; }
57
61 static FMT_VER FormatFromMagic( uint32_t aMagic );
62
63private:
66};
67
68
76{
77public:
78 BLOCK_PARSER( FILE_STREAM& aStream, FMT_VER aVer, size_t aX27End = 0 ) :
79 m_stream( aStream ),
80 m_ver( aVer ),
81 m_x27_end( aX27End )
82 {
83 }
84
92 std::unique_ptr<BLOCK_BASE> ParseBlock( bool& aEndOfObjectsMarker );
93
94private:
97
102 const size_t m_x27_end;
103};
104
105
115{
116public:
117 PARSER( FILE_STREAM& aStream, PROGRESS_REPORTER* aProgressReporter ) :
118 m_stream( aStream ),
119 m_progressReporter( aProgressReporter )
120 {
121 }
122
131 void EndAtUnknownBlock( bool aEndAtUnknownBlock )
132 {
133 m_endAtUnknownBlock = aEndAtUnknownBlock;
134 }
135
136 std::unique_ptr<BRD_DB> Parse();
137
138private:
139 void readObjects( BRD_DB& aDb );
140
142
145};
146
147} // namespace ALLEGRO
BLOCK_PARSER(FILE_STREAM &aStream, FMT_VER aVer, size_t aX27End=0)
std::unique_ptr< BLOCK_BASE > ParseBlock(bool &aEndOfObjectsMarker)
Parse one block from the stream, returning a BLOCK_BASE representing the raw data of the block.
const size_t m_x27_end
To parse an 0x27 block, we need to know where the end of the block is in the stream.
An Allegro board database representing the contents of a .brd (and presumably .dra) file.
Definition allegro_db.h:43
Stream that reads primitive types from a memory buffer containing Allegro .brd (or ....
HEADER_PARSER(FILE_STREAM &aStream)
std::unique_ptr< FILE_HEADER > ParseHeader()
FMT_VER GetFormatVersion() const
Get the parsed format version.
static FMT_VER FormatFromMagic(uint32_t aMagic)
Determine the format version from the magic number.
PROGRESS_REPORTER * m_progressReporter
void readObjects(BRD_DB &aDb)
FILE_STREAM & m_stream
std::unique_ptr< BRD_DB > Parse()
void EndAtUnknownBlock(bool aEndAtUnknownBlock)
When set to true, the parser will stop at the first unknown block, rather than throwing an error.
PARSER(FILE_STREAM &aStream, PROGRESS_REPORTER *aProgressReporter)
A progress reporter interface for use in multi-threaded environments.
FMT_VER
The format of an Allegro file.