Envision
A visual programming IDE for object-oriented languages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
FilePersistence::GenericTree Class Reference

TODO It might be good to separate trees with piecewise loaders and other "kinds" of trees into subclasses. More...

Public Member Functions

 GenericTree (QString name=QString{})
 
 ~GenericTree ()
 
void buildLookupHash ()
 
GenericNodefind (Model::NodeIdType id, bool lazyLoad=false, bool mayNotExist=false) const
 Returns the node in this tree with the ID id or nullptr if no such node exists. More...
 
const QString & name () const
 
GenericPersistentUnitnewPersistentUnit (QString name, char *data=nullptr, int dataSize=0)
 
GenericPersistentUnitpersistentUnit (const QString &name, bool partial=false) const
 
QList< std::shared_ptr< GenericPersistentUnit > > persistentUnits () const
 
bool remove (Model::NodeIdType id, bool recursive=false)
 
void removePersistentUnit (const GenericPersistentUnit &unit)
 
void removePersistentUnit (const QString &persistentUnitName)
 
GenericNoderoot () const
 
void setPiecewiseLoader (std::shared_ptr< PiecewiseLoader > loader)
 

Private Member Functions

GenericNodeemptyChunk ()
 
QMultiHash< Model::NodeIdType, GenericNode * > & nodesWithoutParents ()
 
const std::shared_ptr< PiecewiseLoader > & piecewiseLoader () const
 
void releaseChunk (GenericNode *unusedChunk)
 

Private Attributes

QList< GenericNode * > emptyChunks_
 
bool hasQuickLookupHash_ {}
 
QString name_
 
QMultiHash< Model::NodeIdType, GenericNode * > nodesWithoutParents_
 If this tree has a piecewise loader, this hash maps IDs of unloaded nodes to all nodes whose parentId = ID. More...
 
QHash< QString, std::shared_ptr< GenericPersistentUnit > > persistentUnits_
 
std::shared_ptr< PiecewiseLoaderpiecewiseLoader_
 
QHash< Model::NodeIdType, GenericNode * > quickLookupHash_
 

Static Private Attributes

static constexpr int ALLOCATION_CHUNK_SIZE = 1000
 num elements to allocate at once More...
 

Friends

class GenericNode
 
class GenericPersistentUnit
 
class PiecewiseLoader
 

Detailed Description

TODO It might be good to separate trees with piecewise loaders and other "kinds" of trees into subclasses.

Constructor & Destructor Documentation

◆ GenericTree()

FilePersistence::GenericTree::GenericTree ( QString  name = QString{})

◆ ~GenericTree()

FilePersistence::GenericTree::~GenericTree ( )

Member Function Documentation

◆ buildLookupHash()

void FilePersistence::GenericTree::buildLookupHash ( )

◆ emptyChunk()

GenericNode * FilePersistence::GenericTree::emptyChunk ( )
private

◆ find()

GenericNode * FilePersistence::GenericTree::find ( Model::NodeIdType  id,
bool  lazyLoad = false,
bool  mayNotExist = false 
) const

Returns the node in this tree with the ID id or nullptr if no such node exists.

If lazyLoad is true, this attempts to lazy-load the node if it does not exist yet.

For trees without a piecewise loader, this will perform a depth first search for the node from the root recursively in all linked nodes. This means on such trees, this method is slow and might not return the node if it's not linked, even if it is loaded in the tree.

If mayNotExist is false (the default) the lazy loader will fail if the node is not found.

◆ name()

const QString & FilePersistence::GenericTree::name ( ) const
inline

◆ newPersistentUnit()

GenericPersistentUnit & FilePersistence::GenericTree::newPersistentUnit ( QString  name,
char *  data = nullptr,
int  dataSize = 0 
)

◆ nodesWithoutParents()

QMultiHash< Model::NodeIdType, GenericNode * > & FilePersistence::GenericTree::nodesWithoutParents ( )
private

◆ persistentUnit()

GenericPersistentUnit * FilePersistence::GenericTree::persistentUnit ( const QString &  name,
bool  partial = false 
) const

◆ persistentUnits()

QList< std::shared_ptr< GenericPersistentUnit > > FilePersistence::GenericTree::persistentUnits ( ) const
inline

◆ piecewiseLoader()

const std::shared_ptr< PiecewiseLoader > & FilePersistence::GenericTree::piecewiseLoader ( ) const
private

◆ releaseChunk()

void FilePersistence::GenericTree::releaseChunk ( GenericNode unusedChunk)
private

◆ remove()

bool FilePersistence::GenericTree::remove ( Model::NodeIdType  id,
bool  recursive = false 
)

◆ removePersistentUnit() [1/2]

void FilePersistence::GenericTree::removePersistentUnit ( const GenericPersistentUnit unit)
inline

◆ removePersistentUnit() [2/2]

void FilePersistence::GenericTree::removePersistentUnit ( const QString &  persistentUnitName)
inline

◆ root()

GenericNode * FilePersistence::GenericTree::root ( ) const

◆ setPiecewiseLoader()

void FilePersistence::GenericTree::setPiecewiseLoader ( std::shared_ptr< PiecewiseLoader loader)

Friends And Related Function Documentation

◆ GenericNode

friend class GenericNode
friend

◆ GenericPersistentUnit

friend class GenericPersistentUnit
friend

◆ PiecewiseLoader

friend class PiecewiseLoader
friend

Member Data Documentation

◆ ALLOCATION_CHUNK_SIZE

constexpr int FilePersistence::GenericTree::ALLOCATION_CHUNK_SIZE = 1000
staticconstexprprivate

num elements to allocate at once

◆ emptyChunks_

QList<GenericNode*> FilePersistence::GenericTree::emptyChunks_
private

◆ hasQuickLookupHash_

bool FilePersistence::GenericTree::hasQuickLookupHash_ {}
private

◆ name_

QString FilePersistence::GenericTree::name_
private

◆ nodesWithoutParents_

QMultiHash<Model::NodeIdType, GenericNode*> FilePersistence::GenericTree::nodesWithoutParents_
private

If this tree has a piecewise loader, this hash maps IDs of unloaded nodes to all nodes whose parentId = ID.

If this tree does not have a piecewise loader, this is empty.

◆ persistentUnits_

QHash<QString, std::shared_ptr<GenericPersistentUnit> > FilePersistence::GenericTree::persistentUnits_
private

◆ piecewiseLoader_

std::shared_ptr<PiecewiseLoader> FilePersistence::GenericTree::piecewiseLoader_
private

◆ quickLookupHash_

QHash<Model::NodeIdType, GenericNode*> FilePersistence::GenericTree::quickLookupHash_
private