class cv::FileNode

Overview

File Storage Node class. More…

#include <persistence.hpp>

class FileNode
{
public:
    // enums

    enum Type;

    // fields

    const CvFileStorage* fs;
    const CvFileNode* node;

    // construction

    FileNode();

    FileNode(
        const CvFileStorage* fs,
        const CvFileNode* node
        );

    FileNode(const FileNode& node);

    // methods

    void
    read(
        const FileNode& node,
        int& value,
        int default_value
        );

    void
    read(
        const FileNode& node,
        float& value,
        float default_value
        );

    void
    read(
        const FileNode& node,
        double& value,
        double default_value
        );

    void
    read(
        const FileNode& node,
        String& value,
        const String& default_value
        );

    void
    read(
        const FileNode& node,
        Mat& mat,
        const Mat& default_mat = Mat()
        );

    void
    read(
        const FileNode& node,
        SparseMat& mat,
        const SparseMat& default_mat = SparseMat()
        );

    void
    read(
        const FileNode& node,
        std::vector<KeyPoint>& keypoints
        );

    void
    read(
        const FileNode& node,
        std::vector<DMatch>& matches
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        Point_<_Tp>& value,
        const Point_<_Tp>& default_value
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        Point3_<_Tp>& value,
        const Point3_<_Tp>& default_value
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        Size_<_Tp>& value,
        const Size_<_Tp>& default_value
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        Complex<_Tp>& value,
        const Complex<_Tp>& default_value
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        Rect_<_Tp>& value,
        const Rect_<_Tp>& default_value
        );

    template <
        typename _Tp,
        int cn
        >
    static
    void
    read(
        const FileNode& node,
        Vec<_Tp, cn>& value,
        const Vec<_Tp, cn>& default_value
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        Scalar_<_Tp>& value,
        const Scalar_<_Tp>& default_value
        );

    static
    void
    read(
        const FileNode& node,
        Range& value,
        const Range& default_value
        );

    static
    void
    read(
        const FileNode& node,
        bool& value,
        bool default_value
        );

    static
    void
    read(
        const FileNode& node,
        uchar& value,
        uchar default_value
        );

    static
    void
    read(
        const FileNode& node,
        schar& value,
        schar default_value
        );

    static
    void
    read(
        const FileNode& node,
        ushort& value,
        ushort default_value
        );

    static
    void
    read(
        const FileNode& node,
        short& value,
        short default_value
        );

    template <typename _Tp>
    static
    void
    read(
        FileNodeIterator& it,
        std::vector<_Tp>& vec,
        size_t maxCount = (size_t) INT_MAX
        );

    template <typename _Tp>
    static
    void
    read(
        const FileNode& node,
        std::vector<_Tp>& vec,
        const std::vector<_Tp>& default_value = std::vector<_Tp>()
        );

    static
    void
    read(
        const FileNode& node,
        std::vector<KeyPoint>& vec,
        const std::vector<KeyPoint>& default_value
        );

    static
    void
    read(
        const FileNode& node,
        std::vector<DMatch>& vec,
        const std::vector<DMatch>& default_value
        );

    template <typename _Tp>
    static
    void
    operator>>(
        const FileNode& n,
        _Tp& value
        );

    template <typename _Tp>
    static
    void
    operator>>(
        const FileNode& n,
        std::vector<_Tp>& vec
        );

    static
    void
    operator>>(
        const FileNode& n,
        std::vector<KeyPoint>& vec
        );

    static
    void
    operator>>(
        const FileNode& n,
        KeyPoint& kpt
        );

    static
    void
    operator>>(
        const FileNode& n,
        std::vector<DMatch>& vec
        );

    static
    void
    operator>>(
        const FileNode& n,
        DMatch& m
        );

    FileNodeIterator
    begin() const;

    bool
    empty() const;

    FileNodeIterator
    end() const;

    bool
    isInt() const;

    bool
    isMap() const;

    bool
    isNamed() const;

    bool
    isNone() const;

    bool
    isReal() const;

    bool
    isSeq() const;

    bool
    isString() const;

    Mat
    mat() const;

    String
    name() const;

    operator double() const;
    operator float() const;
    operator std::string() const;
    operator String() const;

    CvFileNode*
    operator*();

    const CvFileNode*
    operator*() const;

    FileNode
    operator[](const String& nodename) const;

    FileNode
    operator[](const char* nodename) const;

    FileNode
    operator[](int i) const;

    void*
    readObj() const;

    void
    readRaw(
        const String& fmt,
        uchar* vec,
        size_t len
        ) const;

    double
    real() const;

    size_t
    size() const;

    String
    string() const;

    int
    type() const;
};

Detailed Documentation

File Storage Node class.

The node is used to store each and every element of the file storage opened for reading. When XML/YAML file is read, it is first parsed and stored in the memory as a hierarchical collection of nodes. Each node can be a “leaf” that is contain a single number or a string, or be a collection of other nodes. There can be named collections (mappings) where each element has a name and it is accessed by a name, and ordered collections (sequences) where elements do not have names but rather accessed by index. Type of the file node can be determined using FileNode::type method.

Note that file nodes are only used for navigating file storages opened for reading. When a file storage is opened for writing, no data is stored in memory after it is written.

Construction

FileNode()

The constructors.

These constructors are used to create a default file node, construct it from obsolete structures or from the another file node.

FileNode(
    const CvFileStorage* fs,
    const CvFileNode* node
    )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

fs Pointer to the obsolete file storage structure.
node File node to be used as initialization for the created file node.
FileNode(const FileNode& node)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

node File node to be used as initialization for the created file node.

Methods

template <typename _Tp>
static
void
operator>>(
    const FileNode& n,
    _Tp& value
    )

Reads data from a file storage.

template <typename _Tp>
static
void
operator>>(
    const FileNode& n,
    std::vector<_Tp>& vec
    )

Reads data from a file storage.

static
void
operator>>(
    const FileNode& n,
    std::vector<KeyPoint>& vec
    )

Reads KeyPoint from a file storage.

static
void
operator>>(
    const FileNode& n,
    std::vector<DMatch>& vec
    )

Reads DMatch from a file storage.

FileNodeIterator
begin() const

returns iterator pointing to the first node element

bool
empty() const

returns true if the node is empty

FileNodeIterator
end() const

returns iterator pointing to the element following the last node element

bool
isInt() const

returns true if the node is an integer

bool
isMap() const

returns true if the node is a mapping

bool
isNamed() const

returns true if the node has a name

bool
isNone() const

returns true if the node is a “none” object

bool
isReal() const

returns true if the node is a floating-point number

bool
isSeq() const

returns true if the node is a sequence

bool
isString() const

returns true if the node is a text string

Mat
mat() const

Simplified reading API to use with bindings.

String
name() const

returns the node name or an empty string if the node is nameless

operator double() const

returns the node content as double

operator float() const

returns the node content as float

operator String() const

returns the node content as text string

CvFileNode*
operator*()

returns pointer to the underlying file node

const CvFileNode*
operator*() const

returns pointer to the underlying file node

FileNode
operator[](const String& nodename) const

Returns element of a mapping node or a sequence node.

Parameters:

nodename Name of an element in the mapping node.

Returns:

Returns the element with the given identifier.

FileNode
operator[](const char* nodename) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

nodename Name of an element in the mapping node.
FileNode
operator[](int i) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

i Index of an element in the sequence node.
void*
readObj() const

reads the registered object and returns pointer to it

void
readRaw(
    const String& fmt,
    uchar* vec,
    size_t len
    ) const

Reads node elements to the buffer with the specified format.

Usually it is more convenient to use operator >> instead of this method.

Parameters:

fmt Specification of each array element. See format specification
vec Pointer to the destination array.
len Number of elements to read. If it is greater than number of remaining elements then all of them will be read.
double
real() const

Simplified reading API to use with bindings.

size_t
size() const

returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise.

String
string() const

Simplified reading API to use with bindings.

int
type() const

Returns type of the node.

Returns:

Type of the node. See FileNode::Type