Class File

Inheritance Relationships

Base Type

Class Documentation

class File : public nix::base::ImplContainer<base::IFile>

Public Functions

inline File()

Constructor that creates an uninitialized File.

Calling any method on an uninitialized file will throw a nix::UninitializedEntity exception. The following code illustrates how to check if a file is initialized:

File e = ...;
if (e) {
    // e is initialised
} else {
    // e is uninitialized
}

inline File(const File &other)

Copy constructor.

Copying of all NIX front facing objects like File is a rather cheap operation. Semantically this is equivalent to the creation of another reference to the original object.

Parameters

other – The file to copy.

inline File(const std::shared_ptr<base::IFile> &p_impl)

Constructor that creates a new file from a shared pointer to an implementation instance.

This constructor should only be used in the back-end.

inline File(std::shared_ptr<base::IFile> &&ptr)

Constructor with move semantics that creates a new entity from a shared pointer to an implementation instance.

This constructor should only be used in the back-end.

bool flush()

Persists all cached changes to the backend.

inline ndsize_t blockCount() const

Get the number of blocks in in the file.

Returns

The number of blocks.

inline bool hasBlock(const std::string &name_or_id) const

Check if a block exists in the file.

Parameters

name_or_id – Name or ID of the block.

Returns

True if the block exists, false otherwise.

bool hasBlock(const Block &block) const

Check if a block exists in the file.

Parameters

block – The block to check.

Returns

True if the block exists, false otherwise.

inline Block getBlock(const std::string &name_or_id) const

Read an existing block from the file.

Parameters

name_or_id – Name or ID of the block.

Returns

The block with the given name or id.

inline Block getBlock(ndsize_t index) const

Read an existing with block from the file, addressed by index.

Parameters

index – The index of the block to read.

Returns

The block at the given index.

Block createBlock(const std::string &name, const std::string &type)

Create an new block, that is immediately persisted in the file.

Parameters
  • name – The name of the block.

  • type – The type of the block.

Returns

The created block.

inline bool deleteBlock(const std::string &name_or_id)

Deletes a block from the file.

Parameters

name_or_id – Name or id of the block to delete.

Returns

True if the block has been removed, false otherwise.

bool deleteBlock(const Block &block)

Deletes a block from the file.

Parameters

block – The block to delete.

Returns

True if the block has been removed, false otherwise.

std::vector<Block> blocks(const util::Filter<Block>::type &filter) const

Get all blocks within this file.

The parameter filter can be used to filter block by various criteria.

Parameters

filter – A filter function.

Returns

A vector of filtered Block entities.

inline std::vector<Block> blocks() const

Get all blocks within this file.

The parameter filter can be used to filter block by various criteria. By default a filter is used that accepts all blocks.

Returns

A vector of filtered Block entities.

inline bool hasSection(const std::string &name_or_id) const

Check if a specific root section exists in the file.

Parameters

name_or_id – Name or ID of the section.

Returns

True if the section exists, false otherwise.

bool hasSection(const Section &section) const

Check if a specific root section exists in the file.

Parameters

section – The section to check.

Returns

True if the section exists, false otherwise.

inline Section getSection(const std::string &name_or_id) const

Get a root section with the given name/id.

Parameters

name_or_id – Name or id of the section.

Returns

The section with the specified name/id.

inline Section getSection(ndsize_t index) const

Get root section with a given index/position.

Parameters

index – The index of the section.

Returns

The section with the specified index.

inline ndsize_t sectionCount() const

Returns the number of root sections stored in the File.

Returns

size_t The number of sections.

std::vector<Section> sections(const util::Filter<Section>::type &filter) const

Get all root sections within this file.

The parameter filter can be used to filter sections by various criteria.

Parameters

filter – A filter function.

Returns

A vector of filtered Section entities.

inline std::vector<Section> sections() const

Get all root sections within this file.

The parameter filter can be used to filter sections by various criteria. By default a filter is used that accepts all sections.

Returns

A vector of filtered Section entities.

std::vector<Section> findSections(const util::Filter<Section>::type &filter, size_t max_depth = std::numeric_limits<size_t>::max()) const

Get all sections in this file recursively.

This method traverses the trees of all section in the file. The traversal is accomplished via breadth first and can be limited in depth. On each node or section a filter is applied. If the filter returns true the respective section will be added to the result list.

Parameters
  • filter – A filter function.

  • max_depth – The maximum depth of traversal.

Returns

A vector containing the matching sections.

inline std::vector<Section> findSections(size_t max_depth = std::numeric_limits<size_t>::max()) const

Get all sections in this file recursively.

This method traverses the trees of all section in the file. The traversal is accomplished via breadth first and can be limited in depth. On each node or section a filter is applied. If the filter returns true the respective section will be added to the result list. By default a filter is used that accepts all sections.

Parameters

max_depth – The maximum depth of traversal.

Returns

A vector containing the matching sections.

Section createSection(const std::string &name, const std::string &type)

Creates a new Section with a given name and type. Both must not be empty.

Parameters
  • name – The name of the section.

  • type – The type of the section.

Returns

The created Section.

inline bool deleteSection(const std::string &name_or_id)

Deletes the Section that is specified with the id.

Parameters

name_or_id – Name or id of the section to delete.

Returns

True if the section was deleted, false otherwise.

bool deleteSection(const Section &section)

Deletes the Section.

Parameters

section – The section to delete.

Returns

True if the section was deleted, false otherwise.

inline std::vector<int> version() const

Read the NIX format version from the file.

The version consist of three integers standing for the major, minor and patch version of the nix format.

Returns

The format version of the NIX file.

inline std::string format() const

Read the format hint from the file.

Returns

The format hint.

inline std::string location() const

Return the location / uri.

Returns

The uri string.

inline std::string id() const

Return the file’s id.

Returns

The file’s id.

inline void forceId()

Forces resetting the file’s id. WARNING! A unique file id is automatically assigned during file creation and should under normal circumstances not be changed afterwards. Use this function only for assigning an id when, for some reason, there has not bee any or you created a copy and want to force a new id.

inline time_t createdAt() const

Get the creation date of the file.

Returns

The creation date of the file.

inline time_t updatedAt() const

Get the date of the last update.

Returns

The date of the last update.

inline void setUpdatedAt()

Sets the time of the last update to the current time if the field is not set.

inline void forceUpdatedAt()

Sets the time of the last update to the current time.

inline void setCreatedAt()

Sets the creation time to the current time if the field is not set.

inline void forceCreatedAt(time_t t)

Sets the creation time to the provided value even if the attribute is set.

Parameters

t – The creation time to set.

void close()

Close the file.

inline bool isOpen() const

Check if the file is currently open.

Returns

True if the file is open, false otherwise.

inline FileMode fileMode()
inline Compression compression() const
inline File &operator=(const none_t &t)

Assignment operator for none.

inline File &operator=(const File &other)

Copy-assignment operator.

valid::Result validate() const

Public Static Functions

static File open(const std::string &name, FileMode mode = FileMode::ReadWrite, const std::string &impl = "hdf5", Compression compression = Compression::Auto, OpenFlags flags = OpenFlags::None)

Opens a file.

Parameters
  • name – The name/path of the file.

  • mode – The open mode.

  • impl – The back-end implementation to be used to open the file. (currently only hdf5)

  • compression – The compression mode, defaults to Compression::None (can be overridden upon DataArray creation)

  • flags – Control aspects of the file opening process

Returns

The opened file.