Gaia
gaia2::DescriptorTree Class Reference

#include <descriptortree.h>

Classes

struct  CachedValues
 

Public Member Functions

 DescriptorTree (const QString &name, DescriptorType type, DescriptorLengthType ltype=VariableLength, int size=1)
 
bool operator== (const DescriptorTree &rhs) const
 
bool subtreeOf (const DescriptorTree *other) const
 Returns whether this tree is a subset of the given one (e.g. More...
 
DescriptorTreecopy () const
 Make a deep-copy of this region-tree. More...
 
void clear ()
 Resets this tree to a single root node. More...
 
QString name () const
 Returns the name of the current node.
 
QString fullName (bool recurseDown=true) const
 Returns the fully-qualified name of this node, eg: using the names of the nodes from the root down to this one. More...
 
DescriptorType type () const
 Returns the type of this node. More...
 
DescriptorLengthType lengthType () const
 Returns the length type of this node. More...
 
const DescriptorTreeparent () const
 
DescriptorTreeparent ()
 
bool isLeaf () const
 Returns whether this node is a leaf (terminal node) or not.
 
const DescriptorTreeroot () const
 Returns the root of the tree which this node pertains to. More...
 
DescriptorTreeroot ()
 Returns the root of the tree which this node pertains to.
 
void addChild (DescriptorTree *t)
 Add the given DescriptorTree to this node's children. More...
 
bool addChild (const QString &name, DescriptorType type, DescriptorLengthType ltype=VariableLength, int size=1)
 Add a child with specified name, type and lengthType. More...
 
void removeChild (DescriptorTree *child)
 Removes given DescriptorTree from this node's children. More...
 
void removeNode (const QString &name, bool recurse=true)
 Remove the node with the given fully-qualified name. More...
 
void removeNodes (const QStringList &names, bool recurse=true)
 Remove the list of nodes with the given fully-qualified name. More...
 
void fixLength (int length)
 Sets this descriptor to be of the specified fixed length. More...
 
void enumerate ()
 Sets this descriptor to be an enumeration. More...
 
QString descriptorName (DescriptorType type, DescriptorLengthType ltype, int index) const
 Returns the name of the descriptor which is located at given position.
 
QStringList descriptorNames () const
 Returns a list of all the descriptor names contained in this layout. More...
 
Region correspondingRegion () const
 Returns a Region formed by the merged segments of all the children of this node.
 
void updateLayout ()
 This function takes all the segments of the current DescriptorTree, orders them by type and by alphabetical order, and assign new Segments to each leaf so that they are contiguous.
 
DescriptorTreefindSimple (const QString &name)
 Find the node in this tree that has the given (short) name. More...
 
const DescriptorTreefind (const QString &name) const
 Find the node with given name (be it a leaf or not). More...
 
DescriptorTreefind (const QString &name)
 
const DescriptorTreefindFromRoot (const QString &name) const
 Find the node with the given name (be it a leaf or not). More...
 
DescriptorTreefindFromRoot (const QString &name)
 
const DescriptorTreefindLeaf (const QString &name) const
 Find the leaf with given name.
 
DescriptorTreefindLeaf (const QString &name)
 
int regionSize (DescriptorType type, DescriptorLengthType ltype) const
 
void printLeafSegments () const
 
QString toYaml (int spaces=0) const
 Returns a yaml string representing the hierachy of descriptors that this tree represents. More...
 
void checkConsistency () const
 
void modify ()
 Function to be called by each non const function as soon as it modifies the tree, so as to know when to regenerate cached values.
 

Protected Member Functions

 DescriptorTree (const DescriptorTree &rhs)
 
DescriptorTreeoperator= (const DescriptorTree &rhs)
 
QList< DescriptorTree * > nodes ()
 Returns all the nodes of this tree in a list, corresponding to a DFS search.
 
QList< DescriptorTree * > leaves ()
 
QList< const DescriptorTree * > nodes () const
 
QList< const DescriptorTree * > leaves () const
 
QList< const DescriptorTree * > dfsNoCache () const
 
int regionSizeNoCache (DescriptorType type, DescriptorLengthType ltype) const
 
void reorder () const
 
void recomputeCaches () const
 
void recomputeHash () const
 
uint hash () const
 Returns a hash value for this DescriptorTree, which makes comparisons really fast.
 
void detach ()
 detach this tree from its (possible) current parent.
 
void updateSegments (const QList< DescriptorTree * > &lrt) const
 Updates the segments' begin and end indices so that all segments are contiguous and sorted alphabetically.
 
const DescriptorTreefind (const QStringList &nodeList, bool onlyLeaves, int i=0) const
 

Protected Attributes

Segment _segment
 
DescriptorTree_parent
 
QList< DescriptorTree * > _children
 
bool _modified
 
bool _hashModified
 
struct CachedValues _cache
 

Friends

QDataStream & operator<< (QDataStream &out, const DescriptorTree &tree)
 
QDataStream & operator>> (QDataStream &in, DescriptorTree &tree)
 

Detailed Description

Member Function Documentation

void DescriptorTree::addChild ( DescriptorTree t)

Add the given DescriptorTree to this node's children.

Takes ownership of the child passed as argument.

References detach().

Referenced by gaia2::PointLayout::regionSize(), root(), and toYaml().

bool DescriptorTree::addChild ( const QString &  name,
DescriptorType  type,
DescriptorLengthType  ltype = VariableLength,
int  size = 1 
)

Add a child with specified name, type and lengthType.

If ltype = VariableLength, then the size argument has to be 1. If child already existed before return false (and do nothing), else if the new child was succesfully inserted, return true.

References name().

void DescriptorTree::clear ( )

Resets this tree to a single root node.

Deletes all the children it had before.

References clear(), and gaia2::Segment::undefined.

Referenced by clear(), and toYaml().

DescriptorTree * DescriptorTree::copy ( ) const

Make a deep-copy of this region-tree.

If this operation is called on a node which is not the root of the tree in which it belongs, it will throw an exception. You need to call this function if you want to make a copy of a DescriptorTree as the copy-constructor is protected.

QStringList DescriptorTree::descriptorNames ( ) const

Returns a list of all the descriptor names contained in this layout.

If this layout contains only the root node, the returned list is empty.

References fullName().

Referenced by root().

void DescriptorTree::enumerate ( )

Sets this descriptor to be an enumeration.

This method will throw an exception if this DescriptorTree does not correspond to a single descriptor of if it is not of type StringType.

Referenced by gaia2::PointLayout::enumerate(), and root().

const DescriptorTree * DescriptorTree::find ( const QString &  name) const

Find the node with given name (be it a leaf or not).

If the string is empty, returns the root node.

References find(), and gaia2::splitName().

Referenced by find(), findLeaf(), gaia2::PointLayout::regionSize(), and root().

const DescriptorTree * DescriptorTree::findFromRoot ( const QString &  name) const

Find the node with the given name (be it a leaf or not).

The given name must the the full name, anchored at the root node. If the string is empty, returns the root node.

References hash(), isLeaf(), lengthType(), name(), gaia2::splitName(), and type().

Referenced by gaia2::PointLayout::regionSize(), and root().

DescriptorTree * DescriptorTree::findSimple ( const QString &  name)

Find the node in this tree that has the given (short) name.

References name().

Referenced by root().

void DescriptorTree::fixLength ( int  length)

Sets this descriptor to be of the specified fixed length.

This method will throw an exception if this DescriptorTree does not correspond to a single descriptor (ie: is not a leaf).

Referenced by root().

QString DescriptorTree::fullName ( bool  recurseDown = true) const

Returns the fully-qualified name of this node, eg: using the names of the nodes from the root down to this one.

Parameters
recurseDownif this node only leads to a single leaf node and recurseDown is true, then this method returns the full name of the leaf node; otherwise it returns the full name of the current node.

Referenced by descriptorName(), descriptorNames(), name(), subtreeOf(), updateLayout(), and updateSegments().

DescriptorLengthType DescriptorTree::lengthType ( ) const

Returns the length type of this node.

This method will throw an exception if it is not called on a leaf (terminal node).

Referenced by findFromRoot(), and name().

void DescriptorTree::removeChild ( DescriptorTree child)

Removes given DescriptorTree from this node's children.

This method throws an exception if the given tree was not a child of this node.

References name().

Referenced by root().

void DescriptorTree::removeNode ( const QString &  name,
bool  recurse = true 
)

Remove the node with the given fully-qualified name.

If recurse is true, and the node removed was the last child of its parent, then also remove the parent (and go on recursively until the node removed wasn't the last child).

Referenced by root().

void DescriptorTree::removeNodes ( const QStringList &  names,
bool  recurse = true 
)

Remove the list of nodes with the given fully-qualified name.

If recurse is true and a removed node was the last child of its parent, then also remove the parent (and go on recursively until the node removed wasn't the last child).

References detach(), and isLeaf().

Referenced by root().

const DescriptorTree * DescriptorTree::root ( ) const

Returns the root of the tree which this node pertains to.

Const version.

References root().

Referenced by isLeaf(), and root().

bool DescriptorTree::subtreeOf ( const DescriptorTree other) const

Returns whether this tree is a subset of the given one (e.g.

: all the branches and leaves of this tree are also contained in the given one).

References fullName().

QString DescriptorTree::toYaml ( int  spaces = 0) const

Returns a yaml string representing the hierachy of descriptors that this tree represents.

The root node is called "descriptors" (instead of the empty string).

References addChild(), clear(), modify(), and toYaml().

Referenced by root(), and toYaml().

DescriptorType DescriptorTree::type ( ) const

Returns the type of this node.

This method will throw an exception if it is not called on a leaf (terminal node).

Referenced by findFromRoot(), name(), and updateLayout().


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