XML/YAML file storage class that incapsulates all the information necessary for writing or reading data to/from file.
XML/YAML file storage class that incapsulates all the information necessary for writing or reading data to/from a file.
FileStorage::FileStorage
------------------------
The constructors.
..ocv:function:: FileStorage::FileStorage()
..ocv:function:: FileStorage::FileStorage(const string& filename, int flags, const string& encoding=string())
:param filename:Name of the file to open. Extension of the file (``.xml`` or ``.yml``/``.yaml``) determines its format (XML or YAML respectively). Also you can append ``.gz`` to work with compressed files, for example ``myHugeMatrix.xml.gz``.
:param flags:Mode of operation. Possible values are:
* **FileStorage::READ** Open the file for reading.
* **FileStorage::WRITE** Open the file for writing.
* **FileStorage::APPEND** Open the file for appending.
:param encoding:Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.
The full constructor opens the file. Alternatively you can use the default constructor and then call :ocv:func:`FileStorage::open`.
FileStorage::open
-----------------
Opens a file.
..ocv:function:: bool FileStorage::open(const string& filename, int flags, const string& encoding=string())
See description of parameters in :ocv:func:`FileStorage::FileStorage`. The method calls :ocv:func:`FileStorage::release` before openning the file.
:param streamidx:Zero-based index of the stream. In most cases there is only one stream in the file. However, YAML supports multiple streams and so there can be several.
:returns:The top-level mapping.
FileStorage::operator[]
-----------------------
Returns the specified element of the top-level mapping.
:param fmt:Specification of each array element that has the following format ``([count]{'u'|'c'|'w'|'s'|'i'|'f'|'d'})...`` where the characters correspond to fundamental C++ types:
* **u** 8-bit unsigned number
* **c** 8-bit signed number
* **w** 16-bit unsigned number
* **s** 16-bit signed number
* **i** 32-bit signed number
* **f** single precision floating-point number
* **d** double precision floating-point number
* **r** pointer, 32 lower bits of which are written as a signed integer. The type can be used to store structures with links between the elements.
``count`` is the optional counter of values of a given type. For example, ``2if`` means that each array element is a structure of 2 integers, followed by a single-precision floating-point number. The equivalent notations of the above specification are ' ``iif`` ', ' ``2i1f`` ' and so forth. Other examples: ``u`` means that the array consists of bytes, and ``2d`` means the array consists of pairs of doubles.
:param vec:Pointer to the written array.
:param len:Number of the ``uchar`` elements to write.
Writes one or more numbers of the specified format to the currently written structure. Usually it is more convenient to use :ocv:func:`operator <<` instead of this method.
FileStorage::writeObj
---------------------
Writes the registered C structure (CvMat, CvMatND, CvSeq).
:param value:Value to be read from the file storage.
:param vec:Vector of values to be read from the file storage.
It is the main function to read data from a file storage. See an example of its usage at the beginning of the section.
FileNode
--------
..ocv:class:: FileNode
The class ``FileNode`` represents each element of the file storage, be it a matrix, a matrix element or a top-level node, containing all the file content. That is, a file node may contain either a singe value (integer, floating-point value or a text string), or it can be a sequence of other file nodes, or it can be a mapping. Type of the file node can be determined using :ocv:func:`FileNode::type` method.
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 :ocv:func:`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.
:param fmt:Specification of each array element. It has the same format as in :ocv:func:`FileStorage::writeRaw`.
:param vec:Pointer to the destination array.
:param len:Number of elements to read. If it is greater than number of remaning elements then all of them will be read.
Usually it is more convenient to use :ocv:func:`operator >>` instead of this method.
FileNode::readObj
-----------------
Reads the registered object.
..ocv:function:: void* FileNode::readObj() const
:returns:Pointer to the read object.
See :ocv:cfunc:`Read` for details.
FileNodeIterator
----------------
..ocv:class:: FileNodeIterator
The class ``FileNodeIterator`` is used to iterate through sequences and mappings. A standard STL notation, with ``node.begin()``, ``node.end()`` denoting the beginning and the end of a sequence, stored in ``node``. See the data reading sample in the beginning of the section.