LibrePCB Developers Documentation
SExpression Class Referencefinal

The SExpression class. More...

#include <sexpression.h>

+ Collaboration diagram for SExpression:

Public Types

enum  Type
 

Public Member Functions

 SExpression () noexcept
 
 SExpression (const SExpression &other) noexcept
 
 ~SExpression () noexcept
 
const FilePathgetFilePath () const noexcept
 
Type getType () const noexcept
 
bool isList () const noexcept
 
bool isToken () const noexcept
 
bool isString () const noexcept
 
bool isLineBreak () const noexcept
 
bool isMultiLineList () const noexcept
 
const QString & getName () const
 
const QString & getValue () const
 
const QList< SExpression > & getChildren () const noexcept
 
QList< SExpressiongetChildren (const QString &name) const noexcept
 
const SExpressiongetChild (const QString &path) const
 Get a child by path. More...
 
const SExpressiontryGetChild (const QString &path) const noexcept
 Try get a child by path. More...
 
SExpressionappendLineBreak ()
 
SExpressionappendList (const QString &name, bool linebreak)
 
SExpressionappendChild (const SExpression &child, bool linebreak)
 
template<typename T >
SExpressionappendChild (const T &obj)
 
template<typename T >
SExpressionappendChild (const QString &child, const T &obj, bool linebreak)
 
void removeLineBreaks () noexcept
 
QByteArray toByteArray () const
 
SExpressionoperator= (const SExpression &rhs) noexcept
 

Static Public Member Functions

static SExpression createList (const QString &name)
 
static SExpression createToken (const QString &token)
 
static SExpression createString (const QString &string)
 
static SExpression createLineBreak ()
 
static SExpression parse (const QByteArray &content, const FilePath &filePath)
 

Private Member Functions

 SExpression (Type type, const QString &value)
 
QString toString (int indent) const
 

Static Private Member Functions

static SExpression parse (const QString &content, int &index, const FilePath &filePath)
 
static SExpression parseList (const QString &content, int &index, const FilePath &filePath)
 
static QString parseToken (const QString &content, int &index, const FilePath &filePath)
 
static QString parseString (const QString &content, int &index, const FilePath &filePath)
 
static void skipWhitespaceAndComments (const QString &content, int &index)
 
static QString escapeString (const QString &string) noexcept
 
static bool isValidToken (const QString &token) noexcept
 
static bool isValidTokenChar (const QChar &c) noexcept
 

Private Attributes

Type mType
 
QString mValue
 either a list name, a token or a string More...
 
QList< SExpressionmChildren
 
FilePath mFilePath
 

Detailed Description

The SExpression class.

Member Enumeration Documentation

◆ Type

enum Type
strong
Enumerator
List 

has a tag name and an arbitrary number of children

Token 

values without quotes (e.g. -12.34)

String 

values with double quotes (e.g. "Foo!")

LineBreak 

manual line break inside a List

Constructor & Destructor Documentation

◆ SExpression() [1/3]

SExpression ( )
noexcept
+ Here is the caller graph for this function:

◆ SExpression() [2/3]

SExpression ( const SExpression other)
noexcept

◆ ~SExpression()

~SExpression ( )
noexcept

◆ SExpression() [3/3]

SExpression ( Type  type,
const QString &  value 
)
private

Member Function Documentation

◆ getFilePath()

const FilePath& getFilePath ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ getType()

Type getType ( ) const
inlinenoexcept

◆ isList()

bool isList ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ isToken()

bool isToken ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ isString()

bool isString ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ isLineBreak()

bool isLineBreak ( ) const
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isMultiLineList()

bool isMultiLineList ( ) const
noexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getName()

const QString & getName ( ) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValue()

const QString & getValue ( ) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildren() [1/2]

const QList<SExpression>& getChildren ( ) const
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildren() [2/2]

QList< SExpression > getChildren ( const QString &  name) const
noexcept
+ Here is the call graph for this function:

◆ getChild()

const SExpression & getChild ( const QString &  path) const

Get a child by path.

This method allows to get a specific child, even nested child. Consider this S-Expression:

* (netsegment 3115f409-5e6c-4023-a8ab-06428ed0720a
*  (via 2cc45b07-1bef-4340-9292-b54b011c70c5
*   (position 35.91989 46.0375) (size 0.7) (drill 0.3) (shape round)
*  )
* )
* 
  • To get the UUID of the net segment, use the path "@0" (first child).
  • To get the whole "via" element (incl. children), use the path "via".
  • To get the Y coordinate of the via, use the path "via/position/@1".
Attention
If there exist several childs with (the begin of) the specified path, only the first match is returned! So if the example above had more "via" elements, all after the first one would be ignored. And for example if the first "via" element had no "position" child, an exception is raised even if the following "via" elements do have a "position" child.
Parameters
pathThe path to the child to get, separated by forward slashes '/'. To specify a child by index, use '@' followed by the index (e.g. '@1' to get the second child).
Returns
A reference to the child of the specified path.
Exceptions
librepcb::Exceptionif the specified child does not exist.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tryGetChild()

const SExpression * tryGetChild ( const QString &  path) const
noexcept

Try get a child by path.

This is exactly the same as getChild(), but returns nullptr if the specified child does not exist (instead of throwing an exception).

Parameters
pathSee documentation of getChild().
Returns
A pointer to the child of the specified path, if found. If no such child exists, nullptr is returned.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendLineBreak()

SExpression & appendLineBreak ( )
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendList()

SExpression & appendList ( const QString &  name,
bool  linebreak 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendChild() [1/3]

SExpression & appendChild ( const SExpression child,
bool  linebreak 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendChild() [2/3]

SExpression& appendChild ( const T &  obj)
inline
+ Here is the call graph for this function:

◆ appendChild() [3/3]

SExpression& appendChild ( const QString &  child,
const T &  obj,
bool  linebreak 
)
inline
+ Here is the call graph for this function:

◆ removeLineBreaks()

void removeLineBreaks ( )
noexcept
+ Here is the caller graph for this function:

◆ toByteArray()

QByteArray toByteArray ( ) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

SExpression & operator= ( const SExpression rhs)
noexcept
+ Here is the caller graph for this function:

◆ createList()

SExpression createList ( const QString &  name)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createToken()

SExpression createToken ( const QString &  token)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createString()

SExpression createString ( const QString &  string)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createLineBreak()

SExpression createLineBreak ( )
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse() [1/2]

SExpression parse ( const QByteArray &  content,
const FilePath filePath 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse() [2/2]

SExpression parse ( const QString &  content,
int &  index,
const FilePath filePath 
)
staticprivate
+ Here is the call graph for this function:

◆ parseList()

SExpression parseList ( const QString &  content,
int &  index,
const FilePath filePath 
)
staticprivate
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseToken()

QString parseToken ( const QString &  content,
int &  index,
const FilePath filePath 
)
staticprivate
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseString()

QString parseString ( const QString &  content,
int &  index,
const FilePath filePath 
)
staticprivate
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipWhitespaceAndComments()

void skipWhitespaceAndComments ( const QString &  content,
int &  index 
)
staticprivate
+ Here is the caller graph for this function:

◆ escapeString()

QString escapeString ( const QString &  string)
staticprivatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidToken()

bool isValidToken ( const QString &  token)
staticprivatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidTokenChar()

bool isValidTokenChar ( const QChar &  c)
staticprivatenoexcept
+ Here is the caller graph for this function:

◆ toString()

QString toString ( int  indent) const
private
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mType

Type mType
private

◆ mValue

QString mValue
private

either a list name, a token or a string

◆ mChildren

QList<SExpression> mChildren
private

◆ mFilePath

FilePath mFilePath
private

The documentation for this class was generated from the following files: