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, you may find one here:
19 * http://www.gnu.org/licenses/gpl-3.0.html
20 * or you may search the http://www.gnu.org website for the version 3 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#pragma once
26
27#include <memory>
28
29#include <convert/allegro_db.h>
32
33#include <progress_reporter.h>
34
35namespace ALLEGRO
36{
37
38
45{
46public:
48 m_stream( aStream ),
50 {
51 }
52
53 std::unique_ptr<FILE_HEADER> ParseHeader();
54
60 FMT_VER GetFormatVersion() const { return m_fmtVer; }
61
65 static FMT_VER FormatFromMagic( uint32_t aMagic );
66
67private:
70};
71
72
80{
81public:
82 BLOCK_PARSER( FILE_STREAM& aStream, FMT_VER aVer, size_t aX27End = 0 ) :
83 m_stream( aStream ),
84 m_ver( aVer ),
85 m_x27_end( aX27End )
86 {
87 }
88
96 std::unique_ptr<BLOCK_BASE> ParseBlock( bool& aEndOfObjectsMarker );
97
98private:
101
106 const size_t m_x27_end;
107};
108
109
119{
120public:
121 PARSER( FILE_STREAM& aStream, PROGRESS_REPORTER* aProgressReporter ) :
122 m_stream( aStream ),
123 m_progressReporter( aProgressReporter )
124 {
125 }
126
135 void EndAtUnknownBlock( bool aEndAtUnknownBlock )
136 {
137 m_endAtUnknownBlock = aEndAtUnknownBlock;
138 }
139
140 std::unique_ptr<BRD_DB> Parse();
141
142private:
143 void readObjects( BRD_DB& aDb );
144
146
149};
150
151} // 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 database that represents a .brd file (amd presumably .dra)
Definition allegro_db.h:850
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 Allego file.