libE57Format 3.1.1
C++ library to read & write the E57 file format for point cloud data
Loading...
Searching...
No Matches
e57::VectorNode Class Reference

An E57 element containing ordered vector of child nodes. More...

#include <E57Format.h>

Public Member Functions

 VectorNode ()=delete
 
 VectorNode (const ImageFile &destImageFile, bool allowHeteroChildren=false)
 Create a new empty Vector node.
 
 VectorNode (const Node &n)
 Downcast a generic Node handle to a VectorNode handle.
 
bool allowHeteroChildren () const
 Get whether child elements are allowed to be different types.
 
void append (const Node &n)
 Append a child element to end of VectorNode.
 
void checkInvariant (bool doRecurse=true, bool doUpcast=true) const
 Check whether VectorNode class invariant is true.
 
int64_t childCount () const
 Get number of child elements in this VectorNode.
 
ImageFile destImageFile () const
 Get the ImageFile that was declared as the destination for the node when it was created.
 
void dump (int indent=0, std::ostream &os=std::cout) const
 Diagnostic function to print internal state of object to output stream in an indented format.
 
ustring elementName () const
 Get elementName string, that identifies the node in its parent.
 
Node get (const ustring &pathName) const
 Get a child element by string path name.
 
Node get (int64_t index) const
 Get a child element by positional index.
 
bool isAttached () const
 Has node been attached into the tree of an ImageFile.
 
bool isDefined (const ustring &pathName) const
 Is the given pathName defined relative to this node.
 
bool isRoot () const
 Is this a root node.
 
 operator Node () const
 Upcast a VectorNode handle to a generic Node handle.
 
Node parent () const
 Return parent of node, or self if a root node.
 
ustring pathName () const
 Get absolute pathname of node.
 

Detailed Description

An E57 element containing ordered vector of child nodes.

A VectorNode is a container of ordered child nodes. The child nodes are automatically assigned an elementName, which is a string version of the positional index of the child starting at "0". Child nodes may only be appended onto the end of a VectorNode.

A VectorNode that is created with a restriction that its children must have the same type is called a "homogeneous VectorNode". A VectorNode without such a restriction is called a "heterogeneous VectorNode".

See Node class discussion for discussion of the common functions that StructureNode supports.

Class Invariant

A class invariant is a list of statements about an object that are always true before and after any operation on the object. An invariant is useful for testing correct operation of an implementation. Statements in an invariant can involve only externally visible state, or can refer to internal implementation-specific state that is not visible to the API user. The following C++ code checks externally visible state for consistency and throws an exception if the invariant is violated:

void VectorNode::checkInvariant( bool doRecurse, bool doUpcast ) const
{
// If destImageFile not open, can't test invariant (almost every call would throw)
if ( !destImageFile().isOpen() )
{
return;
}
// If requested, call Node::checkInvariant
if ( doUpcast )
{
static_cast<Node>( *this ).checkInvariant( false, false );
}
// Check each child
for ( int64_t i = 0; i < childCount(); i++ )
{
Node child = get( i );
// If requested, check children recursively
if ( doRecurse )
{
child.checkInvariant( doRecurse, true );
}
// Child's parent must be this
if ( static_cast<Node>( *this ) != child.parent() )
{
throw E57_EXCEPTION1( ErrorInvarianceViolation );
}
// Child's elementName must be defined
if ( !isDefined( child.elementName() ) )
{
throw E57_EXCEPTION1( ErrorInvarianceViolation );
}
// Getting child by element name must yield same child
Node n = get( child.elementName() );
if ( n != child )
{
throw E57_EXCEPTION1( ErrorInvarianceViolation );
}
}
}
Generic handle to any of the 8 types of E57 element objects.
Definition: E57Format.h:248
void checkInvariant(bool doRecurse=true, bool doDowncast=true)
Check whether Node class invariant is true.
Definition: Node.cpp:62
Node get(int64_t index) const
Get a child element by positional index.
Definition: VectorNode.cpp:299
bool isDefined(const ustring &pathName) const
Is the given pathName defined relative to this node.
Definition: VectorNode.cpp:277
ImageFile destImageFile() const
Get the ImageFile that was declared as the destination for the node when it was created.
Definition: VectorNode.cpp:199
void checkInvariant(bool doRecurse=true, bool doUpcast=true) const
Check whether VectorNode class invariant is true.
Definition: VectorNode.cpp:42
int64_t childCount() const
Get number of child elements in this VectorNode.
Definition: VectorNode.cpp:249
@ ErrorInvarianceViolation
class invariance constraint violation in debug mode
Definition: E57Exception.h:133
See also
Node

Constructor & Destructor Documentation

◆ VectorNode() [1/3]

e57::VectorNode::VectorNode ( )
delete

◆ VectorNode() [2/3]

VectorNode::VectorNode ( const ImageFile destImageFile,
bool  allowHeteroChildren = false 
)
explicit

Create a new empty Vector node.

Parameters
[in]destImageFileThe ImageFile where the new node will eventually be stored.
[in]allowHeteroChildrenWill child elements of differing types be allowed in this VectorNode.

A VectorNode is a ordered container of E57 nodes.

The destImageFile indicates which ImageFile the VectorNode will eventually be attached to. A node is attached to an ImageFile by adding it underneath the predefined root of the ImageFile (gotten from ImageFile::root). It is not an error to fail to attach the VectorNode to the destImageFile. It is an error to attempt to attach the VectorNode to a different ImageFile.

If allowHeteroChildren is false, then the children that are appended to the VectorNode must be identical in every visible characteristic except the stored values. These visible characteristics include number of children (for StructureNode and VectorNode descendents), number of records/prototypes/codecs (for CompressedVectorNode), minimum/maximum attributes (for IntegerNode, ScaledIntegerNode, FloatNode), byteCount (for BlobNode), scale/offset (for ScaledIntegerNode), and all elementNames. The enforcement of this homogeneity rule begins when the second child is appended to the VectorNode, thus it is not an error to modify a child of a homogeneous VectorNode containing only one child.

If allowHeteroChildren is true, then the types of the children of the VectorNode are completely unconstrained.

Precondition
The destImageFile must be open (i.e. destImageFile.isOpen() must be true).
The destImageFile must have been opened in write mode (i.e. destImageFile.isWritable() must be true).
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
Node, VectorNode::allowHeteroChildren, ErrorHomogeneousViolation

◆ VectorNode() [3/3]

VectorNode::VectorNode ( const Node n)
explicit

Downcast a generic Node handle to a VectorNode handle.

Parameters
[in]nThe generic handle to downcast.

The handle n must be for an underlying VectorNode, otherwise an exception is thrown. In designs that need to avoid the exception, use Node::type() to determine the actual type of the n before downcasting. This function must be explicitly called (c++ compiler cannot insert it automatically).

Exceptions
ErrorBadNodeDowncast
See also
Node::type(), VectorNode::operator Node()

Member Function Documentation

◆ allowHeteroChildren()

bool VectorNode::allowHeteroChildren ( ) const

Get whether child elements are allowed to be different types.

See the class discussion at bottom of VectorNode page for details of homogeneous/heterogeneous VectorNode. The returned attribute is determined when the VectorNode is created, and cannot be changed.

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
True if child elements can be different types.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
ErrorHomogeneousViolation

◆ append()

void VectorNode::append ( const Node n)

Append a child element to end of VectorNode.

Parameters
[in]nThe node to be added as a child at end of the VectorNode.

If the VectorNode is homogeneous and already has at least one child, then n must be identical to the existing children in every visible characteristic except the stored values. These visible characteristics include number of children (for StructureNode and VectorNode descendents), number of records/prototypes/codecs (for CompressedVectorNode), minimum/maximum attributes (for IntegerNode, ScaledIntegerNode, FloatNode), byteCount (for BlobNode), scale/offset (for ScaledIntegerNode), and all elementNames.

The VectorNode must not be a descendent of a homogeneous VectorNode with more than one child.

Precondition
The new child node n must be a root node (not already having a parent).
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
The associated destImageFile must have been opened in write mode (i.e. destImageFile().isWritable()).
Postcondition
the childCount is incremented.
Exceptions
ErrorImageFileNotOpen
ErrorHomogeneousViolation
ErrorFileReadOnly
ErrorAlreadyHasParent
ErrorDifferentDestImageFile
ErrorInternalAll objects in undocumented state
See also
VectorNode::childCount, VectorNode::get(int64_t), StructureNode::set

◆ checkInvariant()

void VectorNode::checkInvariant ( bool  doRecurse = true,
bool  doUpcast = true 
) const

Check whether VectorNode class invariant is true.

Parameters
[in]doRecurseIf true, also check invariants of all children or sub-objects recursively.
[in]doUpcastIf true, also check invariants of the generic Node class.

This function checks at least the assertions in the documented class invariant description (see class reference page for this object). Other internal invariants that are implementation-dependent may also be checked. If any invariant clause is violated, an ErrorInvarianceViolation E57Exception is thrown.

Checking the invariant recursively may be expensive if the tree is large, so should be used judiciously, in debug versions of the application.

Postcondition
No visible state is modified.
Exceptions
ErrorInvarianceViolationor any other E57 ErrorCode

◆ childCount()

int64_t VectorNode::childCount ( ) const

Get number of child elements in this VectorNode.

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
Number of child elements in this VectorNode.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
VectorNode::get(int64_t), VectorNode::append, StructureNode::childCount

◆ destImageFile()

ImageFile VectorNode::destImageFile ( ) const

Get the ImageFile that was declared as the destination for the node when it was created.

The first argument of the constructors of each of the 8 types of nodes is an ImageFile that indicates which ImageFile the node will eventually be attached to. This function returns that constructor argument. It is an error to attempt to attach the node to a different ImageFile. However it is not an error to not attach the node to any ImageFile (it's just wasteful). Use Node::isAttached to check if the node actually did get attached.

Postcondition
No visible object state is modified.
Returns
The ImageFile that was declared as the destination for the node when it was created.
See also
Node::isAttached, StructureNode::StructureNode(), VectorNode::VectorNode(), CompressedVectorNode::CompressedVectorNode(), IntegerNode::IntegerNode(), ScaledIntegerNode::ScaledIntegerNode(), FloatNode::FloatNode(), StringNode::StringNode(), BlobNode::BlobNode()

◆ dump()

void VectorNode::dump ( int  indent = 0,
std::ostream &  os = std::cout 
) const

Diagnostic function to print internal state of object to output stream in an indented format.

Parameters
[in]indentNumber of spaces to indent all the printed lines of this object.
[in]osOutput stream to print on.

All objects in the E57 Foundation API (with exception of E57Exception) support a dump() function. These functions print out to the console a detailed listing of the internal state of objects. The content of these printouts is not documented, and is really of interest only to implementation developers/maintainers or the really adventurous users. In implementations of the API other than the Reference Implementation, the dump() functions may produce no output (although the functions should still be defined). The output format may change from version to version.

Postcondition
No visible object state is modified.
Exceptions
NoE57Exceptions

◆ elementName()

ustring VectorNode::elementName ( ) const

Get elementName string, that identifies the node in its parent.

The elementName is a string associated with each parent-child link between nodes. For a given parent, the elementName uniquely identifies each of its children. Thus, any node in a tree can be identified by a sequence of elementNames that form a path from the tree's root node (see Node::pathName for more details).

Three types of nodes (the container node types) can be parents: StructureNode, VectorNode, and CompressedVectorNode. The children of a StructureNode are explicitly given unique elementNames when they are attached to the parent (using StructureNode::set). The children of VectorNode and CompressedVectorNode are implicitly given elementNames based on their position in the list (starting at "0"). In a CompressedVectorNode, the elementName can become quite large: "1000000000" or more. However in a CompressedVectorNode, the elementName string is not stored in the file and is deduced by the position of the child.

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
The element name of the node, or "" if a root node.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
Node::pathName, Node::parent, Node::isRoot

◆ get() [1/2]

Node VectorNode::get ( const ustring pathName) const

Get a child element by string path name.

Parameters
[in]pathNameThe pathname, either absolute or relative, of the object to get.

The pathName may be relative to this node, or absolute (starting with a "/"). The origin of the absolute path name is the root of the tree that contains this VectorNode. If this VectorNode is not attached to an ImageFile, the pathName origin root will not the root node of an ImageFile.

The element names of child elements of VectorNodes are numbers, encoded as strings, starting at "0".

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
The pathName must be defined (i.e. isDefined(pathName)).
Postcondition
No visible state is modified.
Returns
A smart Node handle referencing the child node.
Exceptions
ErrorBadPathName
ErrorPathUndefined
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
VectorNode::childCount, VectorNode::append, StructureNode::get(int64_t) const

◆ get() [2/2]

Node VectorNode::get ( int64_t  index) const

Get a child element by positional index.

Parameters
[in]indexThe index of child element to get, starting at 0.
Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
0 <= index < childCount()
Postcondition
No visible state is modified.
Returns
A smart Node handle referencing the child node.
Exceptions
ErrorChildIndexOutOfBounds
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
VectorNode::childCount, VectorNode::append, StructureNode::get(int64_t) const

◆ isAttached()

bool VectorNode::isAttached ( ) const

Has node been attached into the tree of an ImageFile.

Nodes are attached into an ImageFile tree by inserting them as children (directly or indirectly) of the ImageFile's root node. Nodes can also be attached to an ImageFile if they are used in the codecs or prototype trees of an CompressedVectorNode that is attached. Attached nodes will be saved to disk when the ImageFile is closed, and restored when the ImageFile is read back in from disk. Unattached nodes will not be saved to disk. It is not recommended to create nodes that are not eventually attached to the ImageFile.

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible object state is modified.
Returns
true if node is child of (or in codecs or prototype of a child CompressedVectorNode of) the root node of an ImageFile.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
Node::destImageFile, ImageFile::root

◆ isDefined()

bool VectorNode::isDefined ( const ustring pathName) const

Is the given pathName defined relative to this node.

Parameters
[in]pathNameThe absolute pathname, or pathname relative to this object, to check.

The pathName may be relative to this node, or absolute (starting with a "/"). The origin of the absolute path name is the root of the tree that contains this VectorNode. If this VectorNode is not attached to an ImageFile, the pathName origin root will not the root node of an ImageFile.

The element names of child elements of VectorNodes are numbers, encoded as strings, starting at "0".

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
true if pathName is currently defined.
Exceptions
ErrorBadPathName
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
StructureNode::isDefined

◆ isRoot()

bool VectorNode::isRoot ( ) const

Is this a root node.

A root node has itself as a parent (it is not a child of any node). Newly constructed nodes (before they are inserted into an ImageFile tree) start out as root nodes. It is possible to temporarily create small trees that are unattached to any ImageFile. In these temporary trees, the top-most node will be a root node. After the tree is attached to the ImageFile tree, the only root node will be the pre-created one of the ImageTree (the one returned by ImageFile::root). The concept of attachment is slightly larger than that of the parent-child relationship (see Node::isAttached and CompressedVectorNode::CompressedVectorNode for more details).

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
true if this node is a root node.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
Node::parent, Node::isAttached, CompressedVectorNode::CompressedVectorNode

◆ operator Node()

VectorNode::operator Node ( ) const

Upcast a VectorNode handle to a generic Node handle.

An upcast is always safe, and the compiler can automatically insert it for initializations of Node variables and Node function arguments.

Returns
A smart Node handle referencing the underlying object.
Exceptions
NoE57Exceptions.
See also
explanation in Node, Node::type(), VectorNode(const Node&)

◆ parent()

Node VectorNode::parent ( ) const

Return parent of node, or self if a root node.

Nodes are organized into trees (acyclic graphs) with a distinguished node (the "top-most" node) called the root node. A parent-child relationship is established between nodes to form a tree. Nodes can have zero or one parent. Nodes with zero parents are called root nodes.

In the API, if a node has zero parents it is represented by having itself as a parent. Due to the set-once design of the API, a parent-child relationship cannot be modified once established. A child node can be any of the 8 node types, but a parent node can only be one of the 3 container node types (TypeStructure, TypeVector, and TypeCompressedVector). Each parent-child link has a string name (the elementName) associated with it (See Node::elementName for more details). More than one tree can be formed at any given time. Typically small trees are temporarily constructed before attachment to an ImageFile so that they will be written to the disk.

Warning
User algorithms that use this function to walk the tree must take care to handle the case where a node is its own parent (it is a root node). Use Node::isRoot to avoid infinite loops or infinite recursion.
Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
A smart Node handle referencing the parent node or this node if is a root node.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
Node::isRoot, Node::isAttached, CompressedVectorNode::CompressedVectorNode, Node::elementName

◆ pathName()

ustring VectorNode::pathName ( ) const

Get absolute pathname of node.

Nodes are organized into trees (acyclic graphs) by a parent-child relationship between nodes. Each parent-child relationship has an associated elementName string that is unique for a given parent. Any node in a given tree can be identified by a sequence of elementNames of how to get to the node from the root of the tree. An absolute pathname string that is formed by arranging this sequence of elementNames separated by the "/" character with a leading "/" prepended.

Some example absolute pathNames: "/data3D/0/points/153/cartesianX", "/data3D/0/points", "/cameraImages/1/pose/rotation/w", and "/". These examples have probably been attached to an ImageFile. Here is an example absolute pathName of a node in a pose tree that has not yet been attached to an ImageFile: "/pose/rotation/w".

A technical aside: the elementName of a root node does not appear in absolute pathnames, since the "path" is between the staring node (the root) and the ending node. By convention, in this API, a root node has the empty string ("") as its elementName.

Precondition
The destination ImageFile must be open (i.e. destImageFile().isOpen()).
Postcondition
No visible state is modified.
Returns
The absolute path name of the node.
Exceptions
ErrorImageFileNotOpen
ErrorInternalAll objects in undocumented state
See also
Node::elementName, Node::parent, Node::isRoot

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