Data Access Library (DAL)
 All Classes Functions Variables Typedefs Friends
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends
dal::Node Class Reference

#include <Node.h>

Inheritance diagram for dal::Node:
dal::AttributeBase dal::Group dal::Attribute< T > dal::Attribute< std::vector< T > > dal::BF_BeamGroup dal::BF_ProcessingHistory dal::BF_SubArrayPointing dal::BF_SysLog dal::Coordinate dal::CoordinatesGroup dal::Dataset< T > dal::File dal::TBB_Station dal::TBB_Trigger dal::Dataset< float > dal::Dataset< short >

List of all members.

Public Types

typedef int FileMode

Public Member Functions

 Node (Group &parent, const std::string &name)
Nodeoperator= (Node rhs)
std::string name () const
virtual bool exists () const
bool supported ()
const std::string & filename () const
FileMode fileMode () const
 Returns the mode the file was opened with.
bool canWrite () const
const std::string & versionAttrName () const
 Returns name of the version attribute.

Static Public Attributes

static const FileMode READ = 1
static const FileMode READWRITE = 2
static const FileMode CREATE = 3
static const FileMode CREATE_EXCL = 4

Protected Member Functions

 Node (const hid_gc &parent, const std::string &name, FileInfo fileInfo)
 Constructor for Node of root group (in File) only.
int fileDirfd () const
VersionTypefileInfoVersion () const
void setFileInfoVersion (const VersionType &newVersion)

Protected Attributes

hid_gc parent
std::string _name
VersionType minVersion
FileInfo fileInfo

Friends

void swap (Node &first, Node &second)

Detailed Description

Represents a node in the HDF5 hierarchy (an attribute, group, or dataset).


Member Typedef Documentation

typedef int dal::Node::FileMode

File open/create mode. If the filename already exists, CREATE will truncate it, while CREATE_EXCL will throw. None means not opened. It is used internally; not for DAL users.

For why this needs to be here, see the FileInfo class description.


Member Function Documentation

bool dal::Node::canWrite ( ) const

Whether the file was opened for writing. Derived from fileMode().

Python example:

    # Create a new HDF5 file called "example.h5"
    >>> f = File("example.h5", File.CREATE)
    >>> f.canWrite()
    True

    # Can also query other nodes
    >>> a = AttributeString(f, "EXAMPLE_ATTR")
    >>> a.canWrite()
    True

    # Reopen the same file read-only
    >>> del a
    >>> del f
    >>> f = File("example.h5", File.READ)
    >>> f.canWrite()
    False

    # Clean up
    >>> import os
    >>> os.remove("example.h5")
virtual bool dal::Node::exists ( ) const [inline, virtual]

Returns whether this Node exists in the HDF5 file.

Python example:

    # Create a new HDF5 file called "example.h5"
    >>> f = File("example.h5", File.CREATE)

    # An open file always exists
    >>> f.exists()
    True

    # Reference an attribute in the file
    >>> a = AttributeString(f, "EXAMPLE_ATTRIBUTE")

    # Initially, the attribute does not exist
    >>> a.exists()
    False

    # If we create it, it does exist
    >>> a.create()
    <...>
    >>> a.exists()
    True

    # Clean up
    >>> import os
    >>> os.remove("example.h5")

Reimplemented in dal::File, dal::Group, and dal::AttributeBase.

int dal::Node::fileDirfd ( ) const [protected]

The file descriptor of the name of the dir in the file as it was opened, or -1 if "." or failed to open. Needed for a HDF5 issue workaround.

VersionType & dal::Node::fileInfoVersion ( ) const [protected]

Returns the in-memory stored file version.

const string & dal::Node::filename ( ) const

The name of the file as it was opened.

Python example:

    # Create a new HDF5 file called "example.h5"
    >>> f = File("example.h5", File.CREATE)

    # Query the file name
    >>> f.fileName()
    'example.h5'

    # Clean up
    >>> import os
    >>> os.remove("example.h5")
std::string dal::Node::name ( ) const [inline]

Returns the HDF5 name of this node.

void dal::Node::setFileInfoVersion ( const VersionType newVersion) [protected]

Set the in-memory stored file version. HDF5 file remains unchanged. Use only after changing the version attribute in the HDF5 file (or for init).

bool dal::Node::supported ( ) [inline]

Returns whether this node is supported by the current version.

Python example:

    # Create a new HDF5 file called "example.h5"
    >>> f = File("example.h5", File.CREATE)

    # Set the file's version number to 2.6.0.
    # Pass three integers or pass a string.
    >>> f.fileVersion(VersionType("2.6.0"))

    # Create some attribute to play with
    >>> a = AttributeString(f, "EXAMPLE_ATTR")
    >>> a.value = "hello world"

    # Request the file version (any node in the file will do)
    >>> f.fileVersion()
    VersionType('2.6.0')
    >>> a.fileVersion()
    VersionType('2.6.0')

    # If an attribute is older than the file,
    # it is supported and should be present.
    >>> a.minVersion = VersionType('2.5.0')
    >>> a.supported()
    True

    # If an attribute is newer than the file,
    # it is possibly not present and therefor
    # not supported.
    >>> a.minVersion = VersionType('2.7.0')
    >>> a.supported()
    False

    # Clean up
    >>> import os
    >>> os.remove("example.h5")

Member Data Documentation

The minimal version required for this node to be supported. Version numbers are user-defined, and matched against a fixed field in the HDF5 file (see fileVersion()).

Python example:

    # Create a new HDF5 file called "example.h5"
    >>> f = File("example.h5", File.CREATE)
    >>> a = AttributeString(f, "EXAMPLE_ATTRIBUTE")

    # The minimal required version of any node is 0.0.0 by default
    >>> a.minVersion
    VersionType('0.0.0')

    # Setting the minimal version.
    >>> a.minVersion = VersionType('1.2.3')

    # Requesting the minimal version.
    >>> str(a.minVersion)
    '1.2.3'

    # Clean up
    >>> import os
    >>> os.remove("example.h5")

The documentation for this class was generated from the following files:
 All Classes Functions Variables Typedefs Friends