KiCad PCB EDA Suite
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 (C) 2013 SoftPLC Corporation, Dick Hollenbeck <>
5  * Copyright (C) 2013 KiCad Developers, see CHANGELOG.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 2
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
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  *
20  * or you may search the website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
25 #ifndef PTREE_H_
26 #define PTREE_H_
28 /*
30 Implement "KiCad s-epression" support for boost::property_tree's ptree, the 8
31 bit string version of property_tree. The ram resident structure of the ptree is
32 mostly compatible with one created using the xml_parser from
33 boost::property_tree, with slight differences in the way atoms are stored. The
34 result is you can use Format() to convert from xml to s-expression, but not the
35 other way around. You can write a simple s-expression beautifier in just a few
36 lines of code.
38 The main value however is the s-expression parser, i.e. Scan(), which is an
39 alternative to crafting a custom recursive descent parser for a particular
40 grammar. The tipping point depends on whether you want to read only a small
41 portion of a much larger document. If so, then using the ptree will likely be a
42 "faster to code" route. Documentation on how to navigate a ptree can be found on
43 the boost website and there are a number of examples in the
44 pcbnew/eagle_plugin.cpp file in this project. Powerful path navigation support
45 makes it easy to extract a subset of a ptree.
47 */
50 #include <boost/property_tree/ptree_fwd.hpp>
51 #include <richio.h>
52 #include <dsnlexer.h>
54 typedef boost::property_tree::ptree PTREE;
55 typedef const PTREE CPTREE;
56 typedef boost::property_tree::ptree_error PTREE_ERROR;
87 void Scan( PTREE* aTree, DSNLEXER* aLexer ) throw ( IO_ERROR );
93 void Format( OUTPUTFORMATTER* out, int aNestLevel, int aCtl, CPTREE& aTree ) throw( IO_ERROR );
95 #endif // PTREE_H_
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
boost::property_tree::ptree PTREE
Definition: ptree.h:54
Definition: ptree.h:55
boost::property_tree::ptree_error PTREE_ERROR
Definition: ptree.h:56
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void Scan(PTREE *aTree, DSNLEXER *aLexer)
Function Scan fills an empty PTREE with information from a KiCad s-expresion stream.
Definition: ptree.cpp:90
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
Class DSNLEXER implements a lexical analyzer for the SPECCTRA DSN file format.
Definition: dsnlexer.h:79