LibrePCB Developers Documentation
SerializableObjectList< T, P, OnEditedArgs > Class Template Reference

The SerializableObjectList class implements a list of serializable objects. More...

#include <serializableobjectlist.h>

+ Inheritance diagram for SerializableObjectList< T, P, OnEditedArgs >:
+ Collaboration diagram for SerializableObjectList< T, P, OnEditedArgs >:

Classes

class  Iterator
 

Public Types

enum class  Event
 
using iterator = Iterator< typename QVector< std::shared_ptr< T > >::iterator, T >
 
using const_iterator = Iterator< typename QVector< std::shared_ptr< T > >::const_iterator, const T >
 
typedef Slot< SerializableObjectList< T, P, OnEditedArgs... >, int, const std::shared_ptr< const T > &, EventOnEditedSlot
 
typedef Slot< SerializableObjectList< T, P, OnEditedArgs... >, int, const std::shared_ptr< const T > &, OnEditedArgs... > OnElementEditedSlot
 

Public Member Functions

 SerializableObjectList () noexcept
 
 SerializableObjectList (const SerializableObjectList< T, P, OnEditedArgs... > &other) noexcept
 
 SerializableObjectList (SerializableObjectList< T, P, OnEditedArgs... > &&other) noexcept
 
 SerializableObjectList (std::initializer_list< std::shared_ptr< T > > elements) noexcept
 
 SerializableObjectList (const SExpression &node)
 
virtual ~SerializableObjectList () noexcept
 
bool isEmpty () const noexcept
 
int count () const noexcept
 
const QVector< std::shared_ptr< T > > & values () noexcept
 
std::vector< UuidgetUuids () const noexcept
 
QSet< UuidgetUuidSet () const noexcept
 
int indexOf (const T *obj) const noexcept
 
int indexOf (const Uuid &key) const noexcept
 
int indexOf (const QString &name, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
bool contains (int index) const noexcept
 
bool contains (const T *obj) const noexcept
 
bool contains (const Uuid &key) const noexcept
 
bool contains (const QString &name) const noexcept
 
std::shared_ptr< T > value (int index) noexcept
 
std::shared_ptr< const T > value (int index) const noexcept
 
std::shared_ptr< T > find (const T *obj) noexcept
 
std::shared_ptr< T > find (const Uuid &key) noexcept
 
std::shared_ptr< const T > find (const Uuid &key) const noexcept
 
std::shared_ptr< T > find (const QString &name, Qt::CaseSensitivity cs=Qt::CaseSensitive) noexcept
 
std::shared_ptr< const T > find (const QString &name, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
 
std::shared_ptr< const T > at (int index) const noexcept
 
std::shared_ptr< T > & first () noexcept
 
std::shared_ptr< const T > first () const noexcept
 
std::shared_ptr< T > & last () noexcept
 
std::shared_ptr< const T > last () const noexcept
 
std::shared_ptr< T > get (const T *obj)
 
std::shared_ptr< T > get (const Uuid &key)
 
std::shared_ptr< const T > get (const Uuid &key) const
 
std::shared_ptr< T > get (const QString &name)
 
std::shared_ptr< const T > get (const QString &name) const
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () noexcept
 
const_iterator cend () noexcept
 
iterator begin () noexcept
 
iterator end () noexcept
 
int loadFromSExpression (const SExpression &node)
 
void swap (int i, int j) noexcept
 
int insert (int index, const std::shared_ptr< T > &obj) noexcept
 
int append (const std::shared_ptr< T > &obj) noexcept
 
void append (SerializableObjectList &list) noexcept
 
std::shared_ptr< T > take (int index) noexcept
 
std::shared_ptr< T > take (const T *obj) noexcept
 
std::shared_ptr< T > take (const Uuid &uuid) noexcept
 
std::shared_ptr< T > take (const QString &name) noexcept
 
void remove (int index) noexcept
 
void remove (const T *obj) noexcept
 
void remove (const Uuid &uuid) noexcept
 
void remove (const QString &name) noexcept
 
void clear () noexcept
 
void serialize (SExpression &root) const
 Serialize into librepcb::SExpression node. More...
 
template<typename Compare >
SerializableObjectList< T, P, OnEditedArgs... > sorted (Compare lessThan) const noexcept
 
SerializableObjectList< T, P, OnEditedArgs... > sortedByUuid () const noexcept
 
std::shared_ptr< T > operator[] (int i) noexcept
 
std::shared_ptr< const T > operator[] (int i) const noexcept
 
bool operator== (const SerializableObjectList< T, P, OnEditedArgs... > &rhs) const noexcept
 
bool operator!= (const SerializableObjectList< T, P, OnEditedArgs... > &rhs) const noexcept
 
SerializableObjectList< T, P, OnEditedArgs... > & operator= (const SerializableObjectList< T, P, OnEditedArgs... > &rhs) noexcept
 
SerializableObjectList< T, P, OnEditedArgs... > & operator= (SerializableObjectList< T, P, OnEditedArgs... > &&rhs) noexcept
 

Public Attributes

Signal< SerializableObjectList< T, P, OnEditedArgs... >, int, const std::shared_ptr< const T > &, EventonEdited
 
Signal< SerializableObjectList< T, P, OnEditedArgs... >, int, const std::shared_ptr< const T > &, OnEditedArgs... > onElementEdited
 

Protected Member Functions

void insertElement (int index, const std::shared_ptr< T > &obj) noexcept
 
std::shared_ptr< T > takeElement (int index) noexcept
 
void elementEditedHandler (const T &obj, OnEditedArgs... args) noexcept
 
void throwKeyNotFoundException (const Uuid &key) const
 
void throwNameNotFoundException (const QString &name) const
 

Protected Attributes

QVector< std::shared_ptr< T > > mObjects
 
Slot< T, OnEditedArgs... > mOnEditedSlot
 

Private Member Functions

std::shared_ptr< T > copyObject (const T &other, std::true_type copyConstructable) noexcept
 
std::shared_ptr< T > copyObject (const T &other, std::false_type copyConstructable) noexcept
 
template<typename TStr >
const QString & asStr (const TStr &obj) const noexcept
 
const QString & asStr (const QString &obj) const noexcept
 

Detailed Description

template<typename T, typename P, typename... OnEditedArgs>
class librepcb::SerializableObjectList< T, P, OnEditedArgs >

The SerializableObjectList class implements a list of serializable objects.

This template class lets you hold a list of serializable objects and provides some useful features:

Template Parameters
TThe type of the list items. The type must provide following functionality:
  • Optional: A nothrow copy constructor (to make the list copyable). For polymorphic objects, implement a method std::shared_ptr<T> cloneShared() const noexcept
  • Optional: A constructor with one parameter of type const SExpression&
  • Optional: A method void serialize(SExpression&) const
  • Optional: Comparison operator overloadings
  • Optional: A method Uuid getUuid() const noexcept
  • Optional: A method QString getName() const noexcept
PA class which provides the S-Expression node tag name of the list items. Example: struct MyNameProvider {static constexpr const char* tagname = "item";};
Note
Instead of directly storing elements of type T, elements are always wrapped into a std::shared_ptr<T> before adding them to the list. This is done to ensure that elements never have to be copied or moved for adding or removing them to/from the list. Otherwise it would not be possible to use this list in undo commands as references/pointers to elements would become invalid. Using pointers ensures that the objects are located at the same address over the whole lifetime. To still minimize the risk of memory leaks, std::shared_ptr is used instead of raw pointers.
Warning
Using Qt's foreach keyword on a librepcb::SerializableObjectList is not recommended because it always creates a deep copy of the list! You should use range based for loops (since C++11) instead.

Member Typedef Documentation

◆ iterator

using iterator = Iterator<typename QVector<std::shared_ptr<T> >::iterator, T>

◆ const_iterator

using const_iterator = Iterator<typename QVector<std::shared_ptr<T> >::const_iterator, const T>

◆ OnEditedSlot

typedef Slot<SerializableObjectList<T, P, OnEditedArgs...>, int, const std::shared_ptr<const T>&, Event> OnEditedSlot

◆ OnElementEditedSlot

typedef Slot<SerializableObjectList<T, P, OnEditedArgs...>, int, const std::shared_ptr<const T>&, OnEditedArgs...> OnElementEditedSlot

Member Enumeration Documentation

◆ Event

enum class Event
strong
Enumerator
ElementAdded 
ElementRemoved 
ElementEdited 

Constructor & Destructor Documentation

◆ SerializableObjectList() [1/5]

SerializableObjectList ( )
inlinenoexcept

◆ SerializableObjectList() [2/5]

SerializableObjectList ( const SerializableObjectList< T, P, OnEditedArgs... > &  other)
inlinenoexcept

◆ SerializableObjectList() [3/5]

SerializableObjectList ( SerializableObjectList< T, P, OnEditedArgs... > &&  other)
inlinenoexcept
+ Here is the call graph for this function:

◆ SerializableObjectList() [4/5]

SerializableObjectList ( std::initializer_list< std::shared_ptr< T > >  elements)
inlinenoexcept
+ Here is the call graph for this function:

◆ SerializableObjectList() [5/5]

SerializableObjectList ( const SExpression node)
inlineexplicit
+ Here is the call graph for this function:

◆ ~SerializableObjectList()

virtual ~SerializableObjectList ( )
inlinevirtualnoexcept

Member Function Documentation

◆ isEmpty()

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

◆ count()

int count ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ values()

const QVector< std::shared_ptr< T > > & values ( )
inlinenoexcept
+ Here is the caller graph for this function:

◆ getUuids()

std::vector< Uuid > getUuids ( ) const
inlinenoexcept

◆ getUuidSet()

QSet< Uuid > getUuidSet ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ indexOf() [1/3]

int indexOf ( const T *  obj) const
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ indexOf() [2/3]

int indexOf ( const Uuid key) const
inlinenoexcept
+ Here is the call graph for this function:

◆ indexOf() [3/3]

int indexOf ( const QString &  name,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept
+ Here is the call graph for this function:

◆ contains() [1/4]

bool contains ( int  index) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ contains() [2/4]

bool contains ( const T *  obj) const
inlinenoexcept
+ Here is the call graph for this function:

◆ contains() [3/4]

bool contains ( const Uuid key) const
inlinenoexcept
+ Here is the call graph for this function:

◆ contains() [4/4]

bool contains ( const QString &  name) const
inlinenoexcept
+ Here is the call graph for this function:

◆ value() [1/2]

std::shared_ptr< T > value ( int  index)
inlinenoexcept
+ Here is the caller graph for this function:

◆ value() [2/2]

std::shared_ptr< const T > value ( int  index) const
inlinenoexcept

◆ find() [1/5]

std::shared_ptr< T > find ( const T *  obj)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find() [2/5]

std::shared_ptr< T > find ( const Uuid key)
inlinenoexcept
+ Here is the call graph for this function:

◆ find() [3/5]

std::shared_ptr< const T > find ( const Uuid key) const
inlinenoexcept
+ Here is the call graph for this function:

◆ find() [4/5]

std::shared_ptr< T > find ( const QString &  name,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inlinenoexcept
+ Here is the call graph for this function:

◆ find() [5/5]

std::shared_ptr< const T > find ( const QString &  name,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inlinenoexcept
+ Here is the call graph for this function:

◆ at()

std::shared_ptr< const T > at ( int  index) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ first() [1/2]

std::shared_ptr< T > & first ( )
inlinenoexcept
+ Here is the caller graph for this function:

◆ first() [2/2]

std::shared_ptr< const T > first ( ) const
inlinenoexcept

◆ last() [1/2]

std::shared_ptr< T > & last ( )
inlinenoexcept

◆ last() [2/2]

std::shared_ptr< const T > last ( ) const
inlinenoexcept

◆ get() [1/5]

std::shared_ptr< T > get ( const T *  obj)
inline
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [2/5]

std::shared_ptr< T > get ( const Uuid key)
inline
+ Here is the call graph for this function:

◆ get() [3/5]

std::shared_ptr< const T > get ( const Uuid key) const
inline
+ Here is the call graph for this function:

◆ get() [4/5]

std::shared_ptr< T > get ( const QString &  name)
inline
+ Here is the call graph for this function:

◆ get() [5/5]

std::shared_ptr< const T > get ( const QString &  name) const
inline
+ Here is the call graph for this function:

◆ begin() [1/2]

const_iterator begin ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ end() [1/2]

const_iterator end ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ cbegin()

const_iterator cbegin ( )
inlinenoexcept

◆ cend()

const_iterator cend ( )
inlinenoexcept

◆ begin() [2/2]

iterator begin ( )
inlinenoexcept

◆ end() [2/2]

iterator end ( )
inlinenoexcept

◆ loadFromSExpression()

int loadFromSExpression ( const SExpression node)
inline
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap()

void swap ( int  i,
int  j 
)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert()

int insert ( int  index,
const std::shared_ptr< T > &  obj 
)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ append() [1/2]

int append ( const std::shared_ptr< T > &  obj)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ append() [2/2]

void append ( SerializableObjectList< T, P, OnEditedArgs > &  list)
inlinenoexcept
+ Here is the call graph for this function:

◆ take() [1/4]

std::shared_ptr< T > take ( int  index)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ take() [2/4]

std::shared_ptr< T > take ( const T *  obj)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ take() [3/4]

std::shared_ptr< T > take ( const Uuid uuid)
inlinenoexcept
+ Here is the call graph for this function:

◆ take() [4/4]

std::shared_ptr< T > take ( const QString &  name)
inlinenoexcept
+ Here is the call graph for this function:

◆ remove() [1/4]

void remove ( int  index)
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove() [2/4]

void remove ( const T *  obj)
inlinenoexcept
+ Here is the call graph for this function:

◆ remove() [3/4]

void remove ( const Uuid uuid)
inlinenoexcept
+ Here is the call graph for this function:

◆ remove() [4/4]

void remove ( const QString &  name)
inlinenoexcept
+ Here is the call graph for this function:

◆ clear()

void clear ( )
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

void serialize ( SExpression root) const
inline

Serialize into librepcb::SExpression node.

Parameters
rootRoot node to serialize into.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sorted()

SerializableObjectList< T, P, OnEditedArgs... > sorted ( Compare  lessThan) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ sortedByUuid()

SerializableObjectList< T, P, OnEditedArgs... > sortedByUuid ( ) const
inlinenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator[]() [1/2]

std::shared_ptr< T > operator[] ( int  i)
inlinenoexcept
+ Here is the call graph for this function:

◆ operator[]() [2/2]

std::shared_ptr< const T > operator[] ( int  i) const
inlinenoexcept
+ Here is the call graph for this function:

◆ operator==()

bool operator== ( const SerializableObjectList< T, P, OnEditedArgs... > &  rhs) const
inlinenoexcept

◆ operator!=()

bool operator!= ( const SerializableObjectList< T, P, OnEditedArgs... > &  rhs) const
inlinenoexcept

◆ operator=() [1/2]

SerializableObjectList< T, P, OnEditedArgs... > & operator= ( const SerializableObjectList< T, P, OnEditedArgs... > &  rhs)
inlinenoexcept
+ Here is the call graph for this function:

◆ operator=() [2/2]

SerializableObjectList< T, P, OnEditedArgs... > & operator= ( SerializableObjectList< T, P, OnEditedArgs... > &&  rhs)
inlinenoexcept
+ Here is the call graph for this function:

◆ insertElement()

void insertElement ( int  index,
const std::shared_ptr< T > &  obj 
)
inlineprotectednoexcept
+ Here is the caller graph for this function:

◆ takeElement()

std::shared_ptr< T > takeElement ( int  index)
inlineprotectednoexcept
+ Here is the caller graph for this function:

◆ elementEditedHandler()

void elementEditedHandler ( const T &  obj,
OnEditedArgs...  args 
)
inlineprotectednoexcept
+ Here is the call graph for this function:

◆ throwKeyNotFoundException()

void throwKeyNotFoundException ( const Uuid key) const
inlineprotected
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ throwNameNotFoundException()

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

◆ copyObject() [1/2]

std::shared_ptr< T > copyObject ( const T &  other,
std::true_type  copyConstructable 
)
inlineprivatenoexcept
+ Here is the caller graph for this function:

◆ copyObject() [2/2]

std::shared_ptr< T > copyObject ( const T &  other,
std::false_type  copyConstructable 
)
inlineprivatenoexcept

◆ asStr() [1/2]

const QString & asStr ( const TStr &  obj) const
inlineprivatenoexcept
+ Here is the caller graph for this function:

◆ asStr() [2/2]

const QString & asStr ( const QString &  obj) const
inlineprivatenoexcept

Member Data Documentation

◆ onEdited

Signal<SerializableObjectList<T, P, OnEditedArgs...>, int, const std::shared_ptr<const T>&, Event> onEdited

◆ onElementEdited

Signal<SerializableObjectList<T, P, OnEditedArgs...>, int, const std::shared_ptr<const T>&, OnEditedArgs...> onElementEdited

◆ mObjects

QVector<std::shared_ptr<T> > mObjects
protected

◆ mOnEditedSlot

Slot<T, OnEditedArgs...> mOnEditedSlot
protected

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