KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ptree.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 (C) 2013 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
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 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
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#ifndef PTREE_H_
22#define PTREE_H_
23
24/*
25Implement "KiCad s-expression" support for boost::property_tree's ptree, the 8
26bit string version of property_tree. The ram resident structure of the ptree is
27mostly compatible with one created using the xml_parser from
28boost::property_tree, with slight differences in the way atoms are stored. The
29result is you can use Format() to convert from xml to s-expression, but not the
30other way around. You can write a simple s-expression beautifier in just a few
31lines of code.
32
33The main value however is the s-expression parser, i.e. Scan(), which is an
34alternative to crafting a custom recursive descent parser for a particular
35grammar. The tipping point depends on whether you want to read only a small
36portion of a much larger document. If so, then using the ptree will likely be a
37"faster to code" route. Documentation on how to navigate a ptree can be found on
38the boost website and there are a number of examples in the
39pcbnew/pcb_io_eagle.cpp file in this project. Powerful path navigation support
40makes it easy to extract a subset of a ptree.
41*/
42
43
44#include <boost/property_tree/ptree_fwd.hpp>
45#include <richio.h>
46#include <dsnlexer.h>
47
48typedef boost::property_tree::ptree PTREE;
49typedef const PTREE CPTREE;
50typedef boost::property_tree::ptree_error PTREE_ERROR;
51
81void Scan( PTREE* aTree, DSNLEXER* aLexer );
82
86void Format( OUTPUTFORMATTER* out, int aNestLevel, int aCtl, const CPTREE& aTree );
87
88#endif // PTREE_H_
Implement a lexical analyzer for the SPECCTRA DSN file format.
Definition dsnlexer.h:75
An interface used to output 8 bit text in a convenient way.
Definition richio.h:291
const PTREE CPTREE
Definition ptree.h:49
boost::property_tree::ptree_error PTREE_ERROR
Definition ptree.h:50
boost::property_tree::ptree PTREE
Definition ptree.h:48
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:194
void Scan(PTREE *aTree, DSNLEXER *aLexer)
Fill an empty PTREE with information from a KiCad s-expression stream.
Definition ptree.cpp:80