Gaia
gaia2::PointLayout Class Reference

This class describes the layout of a point. More...

#include <pointlayout.h>

Public Member Functions

 PointLayout (const PointLayout &other)
 
PointLayout copy () const
 
Region descriptorLocation (const QString &name) const
 Returns the region corresponding to the location of the specified descriptor or group of descriptors.
 
Region descriptorLocation (const QStringList &names) const
 Returns the locations of all the specified descriptors merged into one region.
 
QString descriptorName (DescriptorType type, DescriptorLengthType ltype, int index) const
 Returns the name of the descriptor located at specified position.
 
QStringList descriptorNames () const
 Returns all descriptor names from this layout.
 
QStringList descriptorNames (const Region &region) const
 Returns the names of the descriptors which are contained in the given region.
 
QStringList descriptorNames (const QStringList &patterns) const
 Returns the descriptor names from this layout which match any of the given patterns. More...
 
QStringList descriptorNames (DescriptorType type, const QString &pattern) const
 Returns the descriptor names from this layout which match the given pattern and which also are of the specified type. More...
 
QStringList descriptorNames (DescriptorType type, const QStringList &patterns=QStringList("*"), bool failOnUnmatched=true) const
 Returns the descriptor names from this layout which match any of the given patterns and which also are of the specified type. More...
 
StringDescriptor enumToString (const QString &name, const EnumDescriptor &value) const
 Converts the given Enum descriptor into its String representation.
 
QString enumToString (const QString &name, const Enum &value) const
 Converts the given single Enum value into its String representation.
 
EnumDescriptor stringToEnum (const QString &name, const StringDescriptor &str) const
 Converts the given String descriptor into an enum. More...
 
Enum stringToEnum (const QString &name, const QString &str) const
 Converts the given single String value into an enum. More...
 
bool isEmpty () const
 Returns true when this layout is the empty layout (eg: just contains a root node without children).
 
bool subsetOf (const PointLayout &layout) const
 Returns whether the given layout is a subset of this one.
 
void add (const QString &nodeName, DescriptorType type=UndefinedType, DescriptorLengthType ltype=VariableLength, int size=1)
 Adds the given node to this PointLayout. More...
 
void add (const QString &parentName, const QString &childName, DescriptorType type=UndefinedType, DescriptorLengthType ltype=VariableLength, int size=1)
 Adds the given node to this PointLayout, attaching it to the node called parentName. More...
 
void remove (const QString &name)
 Remove the given node from this PointLayout.
 
void remove (const QStringList &names)
 Remove the given list of nodes from this PointLayout. More...
 
void fixLength (const QString &name, int size)
 Fixes the length of the specified descriptor by changing its length type from VariableLength to FixedLength. More...
 
void fixLength (const QList< QPair< QString, int > > &descs)
 Fixes the length of the specified descriptors by changing their length type from VariableLength to FixedLength using the associated size.
 
void enumerate (const QString &name)
 Changes the type of the specified descriptor from StringType to EnumType. More...
 
PointLayout operator& (const PointLayout &other) const
 Returns a new layout which contains the intersection of this layout with the given one.
 
QStringList symmetricDifferenceWith (const PointLayout &layout) const
 Returns the list of descriptors which are different in these two layouts. More...
 
QStringList differenceWith (const PointLayout &layout) const
 Returns the list of descriptors which are in this layout, but not in the other one. More...
 
bool canMorphInto (const PointLayout &targetLayout) const
 Returns whether this layout can morph into the given target layout. More...
 
PointmorphPoint (const Point *point) const
 Morphs the Point given as input so that the returned Point has the same layout as this layout. More...
 
void filter (const QStringList &select, const QStringList &exclude)
 Filters the elements contained in this layout so that the resulting layout only contains those which name match one of the pattern in the select argument and doesn't match any of the patterns in the exclude argument. More...
 
void debug () const
 
QString toYaml () const
 Returns a yaml string representing:

  1. the enumeration maps ("enums") that are being used by this layout
  2. the hierachy of descriptors ("descriptors") that this layout contains.

 
QString fullName (const QString &name) const
 Returns the fully qualified name of the given descriptor name.
 
int regionSize (DescriptorType type, DescriptorLengthType ltype) const
 Returns the full size of the specified Region. More...
 
Region correspondingRegion () const
 
bool operator== (const PointLayout &rhs) const
 needed for merging DataSets, operation allowed only iff ds1.layout == dss2.layout
 
bool operator!= (const PointLayout &rhs) const
 
bool sameObjectAs (const PointLayout &layout) const
 Return whether both layout point to the same object in memory. More...
 
bool sameEnumMap (const PointLayout &layout, const QString &enumName) const
 
int ref () const
 Reserved for internal testing. More...
 

Protected Member Functions

void addNoUpdate (const QString &parentName, const QString &childName, DescriptorType type=UndefinedType, DescriptorLengthType ltype=VariableLength, int size=1)
 
void addNoUpdateFromRoot (const QString &parentName, const QString &childName, DescriptorType type=UndefinedType, DescriptorLengthType ltype=VariableLength, int size=1)
 
void removeNoUpdate (const QString &name)
 
void update ()
 

Protected Attributes

QExplicitlySharedDataPointer< PointLayoutData_d
 

Friends

class Point
 
QDataStream & operator<< (QDataStream &out, const PointLayout &layout)
 
QDataStream & operator>> (QDataStream &in, PointLayout &layout)
 
PointLayout mergeLayouts (const PointLayout &layout1, const PointLayout &layout2)
 Merges two PointLayouts together, provided that they don't overlap.
 

Detailed Description

This class describes the layout of a point.

It maps identifier names (QString) to Region.

Member Function Documentation

void PointLayout::add ( const QString &  nodeName,
DescriptorType  type = UndefinedType,
DescriptorLengthType  ltype = VariableLength,
int  size = 1 
)

Adds the given node to this PointLayout.

If the name contains dots, this method will split the name on them and add the corresponding intermediate nodes (if necessary).

References gaia2::splitName().

Referenced by gaia2::SVMPredict::mapDataSet(), gaia2::SVMPredict::mapPoint(), and gaia2::mergeLayouts().

void PointLayout::add ( const QString &  parentName,
const QString &  childName,
DescriptorType  type = UndefinedType,
DescriptorLengthType  ltype = VariableLength,
int  size = 1 
)

Adds the given node to this PointLayout, attaching it to the node called parentName.

If the name contains dots, this method will split the name on them and add the corresponding intermediate nodes (if necessary).

References gaia2::mergeName().

bool PointLayout::canMorphInto ( const PointLayout targetLayout) const

Returns whether this layout can morph into the given target layout.

There are various ways one could achieve this, but at the moment the conditions we check for this function to succeed are the following:

  • both layouts have the same descriptor names
  • all the ones which don't have the same type have a Real type in this layout and a String type in the target layout.

This can happen when reading a string which can actually be interpreted as a real value (the yaml parser usually does that if not told otherwise).

References descriptorLocation(), descriptorNames(), gaia2::Region::lengthType(), and gaia2::Region::type().

Referenced by gaia2::DataSet::addPoints().

QStringList PointLayout::descriptorNames ( const QStringList &  patterns) const

Returns the descriptor names from this layout which match any of the given patterns.

Patterns are matched using wildcard matching.

QStringList PointLayout::descriptorNames ( DescriptorType  type,
const QString &  pattern 
) const

Returns the descriptor names from this layout which match the given pattern and which also are of the specified type.

Patterns are matched using wildcard matching. The value UndefinedType for the type matches all types.

QStringList PointLayout::descriptorNames ( DescriptorType  type,
const QStringList &  patterns = QStringList("*"),
bool  failOnUnmatched = true 
) const

Returns the descriptor names from this layout which match any of the given patterns and which also are of the specified type.

Patterns are matched using wildcard matching. The value UndefinedType for the type matches all types.

Parameters
failOnUnmatchedif set to true, will throw an exception if a pattern didn't match any descriptor. If false, it will ignore this pattern and go on as normal.
QStringList PointLayout::differenceWith ( const PointLayout layout) const

Returns the list of descriptors which are in this layout, but not in the other one.

Also returns the list of descriptors which are in both but with different types.

References descriptorLocation(), descriptorNames(), gaia2::Region::lengthType(), and gaia2::Region::type().

void PointLayout::enumerate ( const QString &  name)

Changes the type of the specified descriptor from StringType to EnumType.

WARNING: you cannot call this method if the layout is already been used by a point or dataset.

References gaia2::DescriptorTree::enumerate(), and gaia2::DescriptorTree::findLeaf().

void PointLayout::filter ( const QStringList &  select,
const QStringList &  exclude 
)

Filters the elements contained in this layout so that the resulting layout only contains those which name match one of the pattern in the select argument and doesn't match any of the patterns in the exclude argument.

You can use shell style globbing in the patterns.

References gaia2::selectDescriptors().

Referenced by gaia2::Point::load().

void PointLayout::fixLength ( const QString &  name,
int  size 
)

Fixes the length of the specified descriptor by changing its length type from VariableLength to FixedLength.

WARNING: you cannot call this method if the layout is already been used by a point or dataset.

Referenced by gaia2::DataSet::simplifyHistory().

Point * PointLayout::morphPoint ( const Point point) const

Morphs the Point given as input so that the returned Point has the same layout as this layout.

Exceptions
GaiaExceptionif point could not be morphed

References descriptorNames(), gaia2::Point::layout(), gaia2::Point::name(), gaia2::Point::setLayout(), and gaia2::Point::setName().

Referenced by gaia2::DataSet::addPoints().

int gaia2::PointLayout::ref ( ) const
inline

Reserved for internal testing.

Should not be used.

References gaia2::mergeLayouts().

int PointLayout::regionSize ( DescriptorType  type,
DescriptorLengthType  ltype 
) const

Returns the full size of the specified Region.

This is mostly useful for the Point class, so it knows how much space it needs to allocate.

References gaia2::DescriptorTree::addChild(), gaia2::DescriptorTree::find(), and gaia2::DescriptorTree::findFromRoot().

Referenced by gaia2::Point::applyLayout().

void PointLayout::remove ( const QStringList &  names)

Remove the given list of nodes from this PointLayout.

This is substantially faster than repeated calls to remove(const QString&).

bool PointLayout::sameObjectAs ( const PointLayout layout) const

Return whether both layout point to the same object in memory.

We might want to distinguish it from operator==() because the latter doesn't check for enum2str and str2enum maps.

References gaia2::gaiaVersion().

EnumDescriptor PointLayout::stringToEnum ( const QString &  name,
const StringDescriptor str 
) const

Converts the given String descriptor into an enum.

If there was no suitable value for it before, add one in the enumMap.

Referenced by gaia2::Point::checkValidSegment(), gaia2::Point::remapLayoutAndEnums(), and gaia2::transferPointData().

Enum PointLayout::stringToEnum ( const QString &  name,
const QString &  str 
) const

Converts the given single String value into an enum.

If there was no suitable value for it before, add one in the enumMap.

QStringList PointLayout::symmetricDifferenceWith ( const PointLayout layout) const

Returns the list of descriptors which are different in these two layouts.

In particular, returns all descriptors which are in one layout and not in the other, or ones which are in both but with different types.

References descriptorLocation(), descriptorNames(), gaia2::Region::lengthType(), and gaia2::Region::type().

Referenced by gaia2::DataSet::addPoints(), gaia2::Applier::checkLayout(), and gaia2::DataSet::simplifyHistory().


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