LibrePCB Developers Documentation
SExpression Class Referencefinal

The SExpression class. More...

#include <sexpression.h>

+ Collaboration diagram for SExpression:

Public Types

enum class  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
 
std::size_t getChildCount () const noexcept
 
bool containsChild (const SExpression &child) const noexcept
 
SExpressiongetChild (int index)
 
const SExpressiongetChild (int index) const
 
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)
 
void appendChild (std::unique_ptr< SExpression > child)
 
template<typename T >
SExpressionappendChild (const T &obj)
 
void appendChild (const QString &child, std::unique_ptr< SExpression > 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 std::unique_ptr< SExpressioncreateList (const QString &name)
 
static std::unique_ptr< SExpressioncreateToken (const QString &token)
 
static std::unique_ptr< SExpressioncreateString (const QString &string)
 
static std::unique_ptr< SExpressioncreateLineBreak ()
 
static std::unique_ptr< SExpressionparse (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 std::vector< std::unique_ptr< SExpression > > &children, int &index) noexcept
 
static std::unique_ptr< SExpressionparse (const QString &content, int &index, const FilePath &filePath)
 
static std::unique_ptr< SExpressionparseList (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...
 
std::vector< std::unique_ptr< SExpression > > mChildren
 
FilePath mFilePath
 

Friends

uint qHash (const SExpression &node, uint seed) noexcept
 

Detailed Description

The SExpression class.

Member Enumeration Documentation

◆ Type

enum class 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

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

◆ getChildCount()

std::size_t getChildCount ( ) const
inlinenoexcept

◆ containsChild()

bool containsChild ( const SExpression child) const
noexcept

◆ getChild() [1/4]

SExpression & getChild ( int  index)
+ Here is the caller graph for this function:

◆ getChild() [2/4]

const SExpression & getChild ( int  index) const

◆ getChildren() [1/4]

QList< SExpression * > getChildren ( Type  type)
noexcept
+ Here is the caller graph for this function:

◆ getChildren() [2/4]

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

◆ getChildren() [3/4]

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

◆ getChildren() [4/4]

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

◆ getChild() [3/4]

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:

◆ getChild() [4/4]

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 caller graph for this function:

◆ tryGetChild() [2/2]

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

◆ 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:
+ Here is the caller 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/4]

void appendChild ( std::unique_ptr< SExpression child)
+ Here is the caller graph for this function:

◆ appendChild() [2/4]

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

◆ appendChild() [3/4]

void appendChild ( const QString &  child,
std::unique_ptr< SExpression obj 
)
inline
+ Here is the call graph for this function:

◆ appendChild() [4/4]

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:

◆ operator==()

bool operator== ( const SExpression rhs) const
noexcept

◆ operator!=()

bool operator!= ( const SExpression rhs) const
inlinenoexcept

◆ operator<()

bool operator< ( const SExpression rhs) const
noexcept

◆ operator=()

SExpression & operator= ( const SExpression rhs)
noexcept

◆ createList()

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

◆ createToken()

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

◆ createString()

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

◆ createLineBreak()

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

◆ parse() [1/2]

std::unique_ptr< 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:

◆ skipLineBreaks()

bool skipLineBreaks ( const std::vector< std::unique_ptr< SExpression > > &  children,
int &  index 
)
staticprivatenoexcept

◆ parse() [2/2]

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

◆ parseList()

std::unique_ptr< 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 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:

Friends And Related Function Documentation

◆ qHash

uint qHash ( const SExpression node,
uint  seed 
)
friend

Member Data Documentation

◆ mType

Type mType
private

◆ mValue

QString mValue
private

either a list name, a token or a string

◆ mChildren

std::vector<std::unique_ptr<SExpression> > mChildren
private

◆ mFilePath

FilePath mFilePath
private

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