#include <core.hpp>
Public Types | |
| enum | { READ =0, WRITE =1, APPEND =2, MEMORY =4, FORMAT_MASK =(7<<3), FORMAT_AUTO =0, FORMAT_XML =(1<<3), FORMAT_YAML =(2<<3) } |
| file storage mode More... | |
| enum | { UNDEFINED =0, VALUE_EXPECTED =1, NAME_EXPECTED =2, INSIDE_MAP =4 } |
Public Member Functions | |
| FileStorage () | |
| the default constructor More... | |
| FileStorage (const string &source, int flags, const string &encoding=string()) | |
| the full constructor that opens file storage for reading or writing More... | |
| FileStorage (CvFileStorage *fs) | |
| the constructor that takes pointer to the C FileStorage structure More... | |
| virtual | ~FileStorage () |
| the destructor. calls release() More... | |
| virtual bool | open (const string &filename, int flags, const string &encoding=string()) |
| opens file storage for reading or writing. The previous storage is closed with release() More... | |
| virtual bool | isOpened () const |
| returns true if the object is associated with currently opened file. More... | |
| virtual void | release () |
| closes the file and releases all the memory buffers More... | |
| string | releaseAndGetString () |
| closes the file, releases all the memory buffers and returns the text string More... | |
| FileNode | getFirstTopLevelNode () const |
| returns the first element of the top-level mapping More... | |
| FileNode | root (int streamidx=0) const |
| returns the top-level mapping. YAML supports multiple streams More... | |
| FileNode | operator[] (const string &nodename) const |
| returns the specified element of the top-level mapping More... | |
| FileNode | operator[] (const char *nodename) const |
| returns the specified element of the top-level mapping More... | |
| CvFileStorage * | operator* () |
| returns pointer to the underlying C FileStorage structure More... | |
| const CvFileStorage * | operator* () const |
| returns pointer to the underlying C FileStorage structure More... | |
| void | writeRaw (const string &fmt, const uchar *vec, size_t len) |
| writes one or more numbers of the specified format to the currently written structure More... | |
| void | writeObj (const string &name, const void *obj) |
| writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite() More... | |
Static Public Member Functions | |
| static string | getDefaultObjectName (const string &filename) |
| returns the normalized object name for the specified file name More... | |
Public Attributes | |
| Ptr< CvFileStorage > | fs |
| the underlying C FileStorage structure More... | |
| string | elname |
| the currently written element More... | |
| vector< char > | structs |
| the stack of written structures More... | |
| int | state |
| the writer state More... | |
XML/YAML File Storage Class.
The class describes an object associated with XML or YAML file. It can be used to store data to such a file or read and decode the data.
The storage is organized as a tree of nested sequences (or lists) and mappings. Sequence is a heterogenious array, which elements are accessed by indices or sequentially using an iterator. Mapping is analogue of std::map or C structure, which elements are accessed by names. The most top level structure is a mapping. Leaves of the file storage tree are integers, floating-point numbers and text strings.
For example, the following code:
will produce the following file:
%YAML:1.0
test_int: 5
test_real: 3.1000000000000001e+00
test_string: ABCDEFGH
test_mat: !!opencv-matrix
rows: 3
cols: 3
dt: f
data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ]
test_list:
- 1.0000000000000000e-13
- 2
- 3.1415926535897931e+00
- -3435345
- "2-502 2-029 3egegeg"
- { month:12, day:31, year:1969 }
test_map:
x: 1
y: 2
width: 100
height: 200
lbp: [ 0, 1, 1, 0, 1, 1, 0, 1 ]
and to read the file above, the following code can be used:
| anonymous enum |
| cv::FileStorage::FileStorage | ( | ) |
the default constructor
| cv::FileStorage::FileStorage | ( | const string & | source, |
| int | flags, | ||
| const string & | encoding = string() |
||
| ) |
the full constructor that opens file storage for reading or writing
| cv::FileStorage::FileStorage | ( | CvFileStorage * | fs | ) |
the constructor that takes pointer to the C FileStorage structure
|
virtual |
the destructor. calls release()
|
static |
returns the normalized object name for the specified file name
|
inline |
returns the first element of the top-level mapping
|
virtual |
returns true if the object is associated with currently opened file.
|
virtual |
opens file storage for reading or writing. The previous storage is closed with release()
|
inline |
returns pointer to the underlying C FileStorage structure
|
inline |
returns pointer to the underlying C FileStorage structure
| FileNode cv::FileStorage::operator[] | ( | const string & | nodename | ) | const |
returns the specified element of the top-level mapping
| FileNode cv::FileStorage::operator[] | ( | const char * | nodename | ) | const |
returns the specified element of the top-level mapping
|
virtual |
closes the file and releases all the memory buffers
| string cv::FileStorage::releaseAndGetString | ( | ) |
closes the file, releases all the memory buffers and returns the text string
returns the top-level mapping. YAML supports multiple streams
writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
writes one or more numbers of the specified format to the currently written structure
| string cv::FileStorage::elname |
the currently written element
| Ptr<CvFileStorage> cv::FileStorage::fs |
the underlying C FileStorage structure
| int cv::FileStorage::state |
the writer state
| vector<char> cv::FileStorage::structs |
the stack of written structures