KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ptree.cpp File Reference
#include <macros.h>
#include <boost/property_tree/ptree.hpp>
#include <cassert>
#include <ptree.h>

Go to the source code of this file.

Macros

#define D(x)
 
#define CTL_OMIT_NL   (1<<0)
 
#define CTL_IN_ATTRS   (1<<1)
 

Typedefs

typedef PTREE::const_iterator CITER
 
typedef PTREE::iterator ITER
 

Functions

void scanList (PTREE *aTree, DSNLEXER *aLexer)
 Function scanList reads a sexpr list from the input stream into a new node with key aLexer->CurText(). More...
 
void scanAtom (PTREE *aTree, const DSNLEXER *aLexer)
 
void Scan (PTREE *aTree, DSNLEXER *aLexer)
 Fill an empty PTREE with information from a KiCad s-expression stream. More...
 
bool isAtom (const CPTREE &aTree)
 
bool isLast (const CPTREE &aTree, CITER it)
 
CITER next (CITER it)
 
static void formatNode (OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const std::string &aKey, const CPTREE &aTree)
 
static void formatList (OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
 
void Format (OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
 Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative. More...
 

Macro Definition Documentation

◆ CTL_IN_ATTRS

#define CTL_IN_ATTRS   (1<<1)

Definition at line 45 of file ptree.cpp.

◆ CTL_OMIT_NL

#define CTL_OMIT_NL   (1<<0)

Definition at line 44 of file ptree.cpp.

◆ D

#define D (   x)

Definition at line 41 of file ptree.cpp.

Typedef Documentation

◆ CITER

typedef PTREE::const_iterator CITER

Definition at line 35 of file ptree.cpp.

◆ ITER

typedef PTREE::iterator ITER

Definition at line 36 of file ptree.cpp.

Function Documentation

◆ Format()

void Format ( OUTPUTFORMATTER out,
int  aNestLevel,
int  aCtl,
const CPTREE aTree 
)

◆ formatList()

static void formatList ( OUTPUTFORMATTER out,
int  aNestLevel,
int  aCtl,
const CPTREE aTree 
)
static

Definition at line 137 of file ptree.cpp.

References CTL_IN_ATTRS, CTL_OMIT_NL, formatList(), formatNode(), isAtom(), isLast(), and next().

Referenced by formatList(), and formatNode().

◆ formatNode()

static void formatNode ( OUTPUTFORMATTER out,
int  aNestLevel,
int  aCtl,
const std::string &  aKey,
const CPTREE aTree 
)
static

Definition at line 166 of file ptree.cpp.

References CTL_OMIT_NL, formatList(), isAtom(), OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotes().

Referenced by Format(), and formatList().

◆ isAtom()

bool isAtom ( const CPTREE aTree)
inline

Definition at line 112 of file ptree.cpp.

Referenced by formatList(), and formatNode().

◆ isLast()

bool isLast ( const CPTREE aTree,
CITER  it 
)
inline

Definition at line 118 of file ptree.cpp.

References next().

Referenced by formatList().

◆ next()

◆ Scan()

void Scan ( PTREE aTree,
DSNLEXER aLexer 
)

Fill an empty PTREE with information from a KiCad s-expression stream.

Use a DSNLEXER with an empty keyword table as aLexer. Useful for parsing s-expression files or strings of arbitrary grammars, say from a file or clipboard. The s-expression must be "KiCad compatible". See Documentation/s-expressions.txt for this KiCad compatible definition (it is the non-specctra mode). And also see in tools/property_tree.cpp for example usage.

FILE* fp = fopen( argv[1], "r" );

static const KEYWORD empty_keywords[1] = {};

DSNLEXER lexer( empty_keywords, 0, fp, wxString( From_UTF8( argv[1] ) ) );

try { PTREE doc; Scan( &doc, &lexer ); } catch( const IO_ERROR& ioe ) { fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) ); }

Definition at line 86 of file ptree.cpp.

References DSNLEXER::CurTok(), DSN_EOF, DSN_LEFT, DSN_NONE, DSNLEXER::NextTok(), scanAtom(), scanList(), and DSNLEXER::Unexpected().

Referenced by SCH_EDITOR_CONTROL::AssignFootprints(), BACK_ANNOTATE::getPcbModulesFromString(), and scanList().

◆ scanAtom()

void scanAtom ( PTREE aTree,
const DSNLEXER aLexer 
)
inline

Definition at line 78 of file ptree.cpp.

References DSNLEXER::CurText().

Referenced by Scan().

◆ scanList()

void scanList ( PTREE aTree,
DSNLEXER aLexer 
)
inline

Function scanList reads a sexpr list from the input stream into a new node with key aLexer->CurText().

Definition at line 55 of file ptree.cpp.

References DSNLEXER::CurText(), DSNLEXER::CurTok(), DSN_EOF, DSN_LEFT, DSN_RIGHT, DSNLEXER::NextTok(), Scan(), and DSNLEXER::Unexpected().

Referenced by Scan().