OpenCV  4.0.0
Open Source Computer Vision
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cv::FileNode Class Reference

File Storage Node class. More...

#include "persistence.hpp"

Public Types

enum  {
  NONE = 0,
  INT = 1,
  REAL = 2,
  FLOAT = REAL,
  STR = 3,
  STRING = STR,
  SEQ = 4,
  MAP = 5,
  TYPE_MASK = 7,
  FLOW = 8,
  UNIFORM = 8,
  EMPTY = 16,
  NAMED = 32
}
 type of the file storage node More...
 

Public Member Functions

 FileNode ()
 The constructors. More...
 
 FileNode (const FileStorage *fs, size_t blockIdx, size_t ofs)
 
 FileNode (const FileNode &node)
 
FileNodeIterator begin () const
 returns iterator pointing to the first node element More...
 
bool empty () const
 returns true if the node is empty More...
 
FileNodeIterator end () const
 returns iterator pointing to the element following the last node element More...
 
bool isInt () const
 returns true if the node is an integer More...
 
bool isMap () const
 returns true if the node is a mapping More...
 
bool isNamed () const
 returns true if the node has a name More...
 
bool isNone () const
 returns true if the node is a "none" object More...
 
bool isReal () const
 returns true if the node is a floating-point number More...
 
bool isSeq () const
 returns true if the node is a sequence More...
 
bool isString () const
 returns true if the node is a text string More...
 
std::vector< Stringkeys () const
 Returns keys of a mapping node. More...
 
Mat mat () const
 Simplified reading API to use with bindings. More...
 
std::string name () const
 returns the node name or an empty string if the node is nameless More...
 
 operator double () const
 returns the node content as double More...
 
 operator float () const
 returns the node content as float More...
 
 operator std::string () const
 returns the node content as text string More...
 
FileNode operator[] (const String &nodename) const
 Returns element of a mapping node or a sequence node. More...
 
FileNode operator[] (const char *nodename) const
 
FileNode operator[] (int i) const
 
ucharptr ()
 
const ucharptr () const
 
size_t rawSize () const
 returns raw size of the FileNode in bytes More...
 
void readRaw (const String &fmt, void *vec, size_t len) const
 Reads node elements to the buffer with the specified format. More...
 
double real () const
 Simplified reading API to use with bindings. More...
 
void setValue (int type, const void *value, int len=-1)
 
size_t size () const
 returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise. More...
 
String string () const
 Simplified reading API to use with bindings. More...
 
int type () const
 Returns type of the node. More...
 

Static Public Member Functions

static bool isCollection (int flags)
 
static bool isEmptyCollection (int flags)
 
static bool isFlow (int flags)
 
static bool isMap (int flags)
 
static bool isSeq (int flags)
 

Public Attributes

size_t blockIdx
 
const FileStoragefs
 
size_t ofs
 

Related Functions

(Note that these are not member functions.)

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, std::string &value, const std::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, KeyPoint &value, const KeyPoint &default_value)
 
void read (const FileNode &node, DMatch &value, const DMatch &default_value)
 
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 , int m, int n>
static void read (const FileNode &node, Matx< _Tp, m, n > &value, const Matx< _Tp, m, n > &default_matx=Matx< _Tp, m, n >())
 
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 , typename std::enable_if< std::is_enum< _Tp >::value >::type * = nullptr>
static void read (const FileNode &node, _Tp &value, const _Tp &default_value=static_cast< _Tp >(0))
 
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)
 Reads data from a file storage. More...
 
template<typename _Tp >
static void operator>> (const FileNode &n, std::vector< _Tp > &vec)
 Reads data from a file storage. More...
 
static void operator>> (const FileNode &n, KeyPoint &kpt)
 Reads KeyPoint from a file storage. More...
 
static void operator>> (const FileNode &n, DMatch &m)
 Reads DMatch from a file storage. More...
 

Detailed Description

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.

Examples:
samples/cpp/filestorage.cpp.

Member Enumeration Documentation

§ anonymous enum

anonymous enum

type of the file storage node

Enumerator
NONE 

empty node

INT 

an integer

REAL 

floating-point number

FLOAT 

synonym or REAL

STR 

text string in UTF-8 encoding

STRING 

synonym for STR

SEQ 

sequence

MAP 

mapping

TYPE_MASK 
FLOW 

compact representation of a sequence or mapping. Used only by YAML writer

UNIFORM 

UNIFORM is used only when reading FileStorage; FLOW is used only when writing. So they share the same bit.

if set, means that all the collection elements are numbers of the same type (real's or int's).

EMPTY 

empty structure (sequence or mapping)

NAMED 

the node has a name (i.e. it is element of a mapping).

Constructor & Destructor Documentation

§ FileNode() [1/3]

cv::FileNode::FileNode ( )
Python:
<FileNode object>=cv.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() [2/3]

cv::FileNode::FileNode ( const FileStorage fs,
size_t  blockIdx,
size_t  ofs 
)
Python:
<FileNode object>=cv.FileNode()

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

Parameters
fsPointer to the file storage structure.
blockIdxIndex of the memory block where the file node is stored
ofsOffset in bytes from the beginning of the serialized storage

§ FileNode() [3/3]

cv::FileNode::FileNode ( const FileNode node)
Python:
<FileNode object>=cv.FileNode()

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

Parameters
nodeFile node to be used as initialization for the created file node.

Member Function Documentation

§ begin()

FileNodeIterator cv::FileNode::begin ( ) const

returns iterator pointing to the first node element

Examples:
samples/cpp/filestorage.cpp.

§ empty()

bool cv::FileNode::empty ( ) const
Python:
retval=cv.FileNode.empty()

returns true if the node is empty

Examples:
samples/cpp/filestorage.cpp.

§ end()

FileNodeIterator cv::FileNode::end ( ) const

returns iterator pointing to the element following the last node element

Examples:
samples/cpp/filestorage.cpp.

§ isCollection()

static bool cv::FileNode::isCollection ( int  flags)
static

§ isEmptyCollection()

static bool cv::FileNode::isEmptyCollection ( int  flags)
static

§ isFlow()

static bool cv::FileNode::isFlow ( int  flags)
static

§ isInt()

bool cv::FileNode::isInt ( ) const
Python:
retval=cv.FileNode.isInt()

returns true if the node is an integer

§ isMap() [1/2]

bool cv::FileNode::isMap ( ) const
Python:
retval=cv.FileNode.isMap()

returns true if the node is a mapping

§ isMap() [2/2]

static bool cv::FileNode::isMap ( int  flags)
static
Python:
retval=cv.FileNode.isMap()

§ isNamed()

bool cv::FileNode::isNamed ( ) const
Python:
retval=cv.FileNode.isNamed()

returns true if the node has a name

§ isNone()

bool cv::FileNode::isNone ( ) const
Python:
retval=cv.FileNode.isNone()

returns true if the node is a "none" object

§ isReal()

bool cv::FileNode::isReal ( ) const
Python:
retval=cv.FileNode.isReal()

returns true if the node is a floating-point number

§ isSeq() [1/2]

bool cv::FileNode::isSeq ( ) const
Python:
retval=cv.FileNode.isSeq()

returns true if the node is a sequence

§ isSeq() [2/2]

static bool cv::FileNode::isSeq ( int  flags)
static
Python:
retval=cv.FileNode.isSeq()

§ isString()

bool cv::FileNode::isString ( ) const
Python:
retval=cv.FileNode.isString()

returns true if the node is a text string

§ keys()

std::vector<String> cv::FileNode::keys ( ) const
Python:
retval=cv.FileNode.keys()

Returns keys of a mapping node.

Returns
Keys of a mapping node.

§ mat()

Mat cv::FileNode::mat ( ) const
Python:
retval=cv.FileNode.mat()

Simplified reading API to use with bindings.

§ name()

std::string cv::FileNode::name ( ) const
Python:
retval=cv.FileNode.name()

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

§ operator double()

cv::FileNode::operator double ( ) const

returns the node content as double

§ operator float()

cv::FileNode::operator float ( ) const

returns the node content as float

§ operator std::string()

cv::FileNode::operator std::string ( ) const

returns the node content as text string

§ operator[]() [1/3]

FileNode cv::FileNode::operator[] ( const String nodename) const
Python:
retval=cv.FileNode.at(i)
retval=cv.FileNode.getNode(nodename)

Returns element of a mapping node or a sequence node.

Parameters
nodenameName of an element in the mapping node.
Returns
Returns the element with the given identifier.

§ operator[]() [2/3]

FileNode cv::FileNode::operator[] ( const char *  nodename) const
Python:
retval=cv.FileNode.at(i)
retval=cv.FileNode.getNode(nodename)

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

Parameters
nodenameName of an element in the mapping node.

§ operator[]() [3/3]

FileNode cv::FileNode::operator[] ( int  i) const
Python:
retval=cv.FileNode.at(i)
retval=cv.FileNode.getNode(nodename)

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

Parameters
iIndex of an element in the sequence node.

§ ptr() [1/2]

uchar* cv::FileNode::ptr ( )

§ ptr() [2/2]

const uchar* cv::FileNode::ptr ( ) const

§ rawSize()

size_t cv::FileNode::rawSize ( ) const
Python:
retval=cv.FileNode.rawSize()

returns raw size of the FileNode in bytes

§ readRaw()

void cv::FileNode::readRaw ( const String fmt,
void *  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
fmtSpecification of each array element. See format specification
vecPointer to the destination array.
lenNumber of elements to read. If it is greater than number of remaining elements then all of them will be read.

§ real()

double cv::FileNode::real ( ) const
Python:
retval=cv.FileNode.real()

Simplified reading API to use with bindings.

§ setValue()

void cv::FileNode::setValue ( int  type,
const void *  value,
int  len = -1 
)

Internal method used when reading FileStorage. Sets the type (int, real or string) and value of the previously created node.

§ size()

size_t cv::FileNode::size ( ) const
Python:
retval=cv.FileNode.size()

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

§ string()

String cv::FileNode::string ( ) const
Python:
retval=cv.FileNode.string()

Simplified reading API to use with bindings.

§ type()

int cv::FileNode::type ( ) const
Python:
retval=cv.FileNode.type()

Returns type of the node.

Returns
Type of the node. See FileNode::Type
Examples:
samples/cpp/filestorage.cpp.

Friends And Related Function Documentation

§ operator>>() [1/4]

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

Reads data from a file storage.

§ operator>>() [2/4]

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

Reads data from a file storage.

§ operator>>() [3/4]

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

Reads KeyPoint from a file storage.

§ operator>>() [4/4]

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

Reads DMatch from a file storage.

§ read() [1/27]

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

§ read() [2/27]

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

§ read() [3/27]

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

§ read() [4/27]

void read ( const FileNode node,
std::string &  value,
const std::string &  default_value 
)
related

§ read() [5/27]

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

§ read() [6/27]

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

§ read() [7/27]

void read ( const FileNode node,
KeyPoint value,
const KeyPoint default_value 
)
related

§ read() [8/27]

void read ( const FileNode node,
DMatch value,
const DMatch default_value 
)
related

§ read() [9/27]

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

§ read() [10/27]

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

§ read() [11/27]

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

§ read() [12/27]

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

§ read() [13/27]

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

§ read() [14/27]

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

§ read() [15/27]

template<typename _Tp , int m, int n>
static void read ( const FileNode node,
Matx< _Tp, m, n > &  value,
const Matx< _Tp, m, n > &  default_matx = Matx<_Tp, m, n>() 
)
related

§ read() [16/27]

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

§ read() [17/27]

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

§ read() [18/27]

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

§ read() [19/27]

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

§ read() [20/27]

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

§ read() [21/27]

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

§ read() [22/27]

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

§ read() [23/27]

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

§ read() [24/27]

template<typename _Tp , typename std::enable_if< std::is_enum< _Tp >::value >::type * = nullptr>
static void read ( const FileNode node,
_Tp &  value,
const _Tp &  default_value = static_cast<_Tp>(0) 
)
related

§ read() [25/27]

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

§ read() [26/27]

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

§ read() [27/27]

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

Member Data Documentation

§ blockIdx

size_t cv::FileNode::blockIdx

§ fs

const FileStorage* cv::FileNode::fs

§ ofs

size_t cv::FileNode::ofs

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