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
 
const QString & getName () const
 
const QString & getValue () const
 
const QList< SExpression > & getChildren () const noexcept
 Get all children of this node. More...
 
QList< SExpression * > getChildren (Type type) noexcept
 
QList< const SExpression * > getChildren (Type type) const noexcept
 
QList< SExpression * > getChildren (const QString &name) noexcept
 
QList< const SExpression * > getChildren (const QString &name) const noexcept
 
SExpressiongetChild (const QString &path)
 Get a child by path. More...
 
const SExpressiongetChild (const QString &path) const
 
SExpressiontryGetChild (const QString &path) noexcept
 Try get a child by path. More...
 
const SExpressiontryGetChild (const QString &path) const noexcept
 
void setName (const QString &name)
 
void setValue (const QString &value)
 
void ensureLineBreak ()
 
SExpressionappendList (const QString &name)
 
SExpressionappendChild (const SExpression &child)
 
template<typename T >
SExpressionappendChild (const T &obj)
 
template<typename T >
SExpressionappendChild (const QString &child, const T &obj)
 
void removeChild (const SExpression &child)
 
void removeChildrenWithNodeRecursive (const SExpression &search) noexcept
 
void replaceRecursive (const SExpression &search, const SExpression &replace) noexcept
 
QByteArray toByteArray () const
 
bool operator== (const SExpression &rhs) const noexcept
 
bool operator!= (const SExpression &rhs) const noexcept
 
bool operator< (const SExpression &rhs) const noexcept
 
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)
 
bool isMultiLine () const noexcept
 
QString toString (int indent) const
 

Static Private Member Functions

static bool skipLineBreaks (const QList< SExpression > &children, int &index) noexcept
 
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, bool skipNewline=false)
 
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

◆ getType()

Type getType ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ 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:

◆ 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/5]

const QList<SExpression>& getChildren ( ) const
inlinenoexcept

Get all children of this node.

Attention
The returned list may even contain linebreak-elements!
Returns
All children
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getChildren() [2/5]

QList< SExpression * > getChildren ( Type  type)
noexcept

◆ getChildren() [3/5]

QList< const SExpression * > getChildren ( Type  type) const
noexcept

◆ getChildren() [4/5]

QList< SExpression * > getChildren ( const QString &  name)
noexcept

◆ getChildren() [5/5]

QList< const SExpression * > getChildren ( const QString &  name) const
noexcept

◆ getChild() [1/2]

SExpression & getChild ( const QString &  path)

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.
Note
In contrast to getChildren(), this method skips linebreak elements. So if you acces an element by index (e.g. "@3"), the n-th child which is not a linebreak will be returned.
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:

◆ getChild() [2/2]

const SExpression & getChild ( const QString &  path) const
+ Here is the call graph for this function:

◆ tryGetChild() [1/2]

SExpression * tryGetChild ( const QString &  path)
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:

◆ tryGetChild() [2/2]

const SExpression * tryGetChild ( const QString &  path) const
noexcept
+ Here is the call graph for this function:

◆ setName()

void setName ( const QString &  name)
+ Here is the caller graph for this function:

◆ setValue()

void setValue ( const QString &  value)
+ Here is the caller graph for this function:

◆ ensureLineBreak()

void ensureLineBreak ( )
+ Here is the call graph for this function:

◆ appendList()

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

◆ appendChild() [1/3]

SExpression & appendChild ( const SExpression child)

◆ 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 
)
inline
+ Here is the call graph for this function:

◆ removeChild()

void removeChild ( const SExpression child)
+ Here is the caller graph for this function:

◆ removeChildrenWithNodeRecursive()

void removeChildrenWithNodeRecursive ( const SExpression search)
noexcept
+ Here is the caller graph for this function:

◆ replaceRecursive()

void replaceRecursive ( const SExpression search,
const SExpression replace 
)
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==()

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

◆ operator!=()

bool operator!= ( const SExpression rhs) const
inlinenoexcept
+ Here is the call graph for this function:

◆ operator<()

bool operator< ( const SExpression rhs) const
noexcept
+ 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:

◆ isMultiLine()

bool isMultiLine ( ) const
privatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipLineBreaks()

bool skipLineBreaks ( const QList< SExpression > &  children,
int &  index 
)
staticprivatenoexcept
+ 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,
bool  skipNewline = false 
)
staticprivate
+ Here is the caller graph for this function:

◆ escapeString()

QString escapeString ( const QString &  string)
staticprivatenoexcept
+ 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: