EstervQrCode 1.1.1
Library for qr code manipulation
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
cv::FileStorage Class Reference

XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or reading data to/from a file. More...

#include <persistence.hpp>

Public Types

enum  Mode {
  READ = 0 , WRITE = 1 , APPEND = 2 , MEMORY = 4 ,
  FORMAT_MASK = (7<<3) , FORMAT_AUTO = 0 , FORMAT_XML = (1<<3) , FORMAT_YAML = (2<<3) ,
  FORMAT_JSON = (3<<3) , BASE64 = 64 , WRITE_BASE64 = BASE64 | WRITE
}
 file storage mode More...
 
enum  State { UNDEFINED = 0 , VALUE_EXPECTED = 1 , NAME_EXPECTED = 2 , INSIDE_MAP = 4 }
 

Public Member Functions

CV_WRAP FileStorage ()
 The constructors. More...
 
CV_WRAP FileStorage (const String &filename, int flags, const String &encoding=String())
 Opens a file. More...
 
virtual ~FileStorage ()
 the destructor. calls release() More...
 
virtual CV_WRAP bool open (const String &filename, int flags, const String &encoding=String())
 Opens a file. More...
 
virtual CV_WRAP bool isOpened () const
 Checks whether the file is opened. More...
 
virtual CV_WRAP void release ()
 Closes the file and releases all the memory buffers. More...
 
virtual CV_WRAP String releaseAndGetString ()
 Closes the file and releases all the memory buffers. More...
 
CV_WRAP FileNode getFirstTopLevelNode () const
 Returns the first element of the top-level mapping. More...
 
CV_WRAP FileNode root (int streamidx=0) const
 Returns the top-level mapping. More...
 
FileNode operator[] (const String &nodename) const
 Returns the specified element of the top-level mapping. More...
 
 CV_WRAP_AS (getNode) FileNode operator[](const char *nodename) const
 
CV_WRAP void write (const String &name, int val)
 Simplified writing API to use with bindings. More...
 
CV_WRAP void write (const String &name, double val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
CV_WRAP void write (const String &name, const String &val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
CV_WRAP void write (const String &name, const Mat &val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
CV_WRAP void write (const String &name, const std::vector< String > &val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void writeRaw (const String &fmt, const void *vec, size_t len)
 Writes multiple numbers. More...
 
CV_WRAP void writeComment (const String &comment, bool append=false)
 Writes a comment. More...
 
CV_WRAP void startWriteStruct (const String &name, int flags, const String &typeName=String())
 Starts to write a nested structure (sequence or a mapping). More...
 
CV_WRAP void endWriteStruct ()
 Finishes writing nested structure (should pair startWriteStruct()) More...
 
CV_WRAP int getFormat () const
 Returns the current format. More...
 

Static Public Member Functions

static String getDefaultObjectName (const String &filename)
 Returns the normalized object name for the specified name of a file. More...
 

Public Attributes

int state
 
std::string elname
 
Ptr< Impl > p
 

Detailed Description

XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or reading data to/from a file.

Member Enumeration Documentation

◆ Mode

file storage mode

Enumerator
READ 

value, open the file for reading

WRITE 

value, open the file for writing

APPEND 

value, open the file for appending

MEMORY 

flag, read data from source or write data to the internal buffer (which is returned by FileStorage::release)

FORMAT_MASK 

mask for format flags

FORMAT_AUTO 

flag, auto format

FORMAT_XML 

flag, XML format

FORMAT_YAML 

flag, YAML format

FORMAT_JSON 

flag, JSON format

BASE64 

flag, write rawdata in Base64 by default. (consider using WRITE_BASE64)

WRITE_BASE64 

flag, enable both WRITE and BASE64

◆ State

Enumerator
UNDEFINED 
VALUE_EXPECTED 
NAME_EXPECTED 
INSIDE_MAP 

Constructor & Destructor Documentation

◆ FileStorage() [1/2]

CV_WRAP cv::FileStorage::FileStorage ( )

The constructors.

The full constructor opens the file. Alternatively you can use the default constructor and then call FileStorage::open.

◆ FileStorage() [2/2]

CV_WRAP cv::FileStorage::FileStorage ( const String filename,
int  flags,
const String encoding = String() 
)

Opens a file.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release before opening the file.

Parameters
filenameName of the file to open or the text string to read the data from. Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to FileStorage::BASE64 flag.
flagsMode of operation. One of FileStorage::Mode
encodingEncoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.

◆ ~FileStorage()

virtual cv::FileStorage::~FileStorage ( )
virtual

the destructor. calls release()

Member Function Documentation

◆ CV_WRAP_AS()

cv::FileStorage::CV_WRAP_AS ( getNode  ) const

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

◆ endWriteStruct()

CV_WRAP void cv::FileStorage::endWriteStruct ( )

Finishes writing nested structure (should pair startWriteStruct())

◆ getDefaultObjectName()

static String cv::FileStorage::getDefaultObjectName ( const String filename)
static

Returns the normalized object name for the specified name of a file.

Parameters
filenameName of a file
Returns
The normalized object name.

◆ getFirstTopLevelNode()

CV_WRAP FileNode cv::FileStorage::getFirstTopLevelNode ( ) const

Returns the first element of the top-level mapping.

Returns
The first element of the top-level mapping.

◆ getFormat()

CV_WRAP int cv::FileStorage::getFormat ( ) const

Returns the current format.

Returns
The current format, see FileStorage::Mode

◆ isOpened()

virtual CV_WRAP bool cv::FileStorage::isOpened ( ) const
virtual

Checks whether the file is opened.

Returns
true if the object is associated with the current file and false otherwise. It is a good practice to call this method after you tried to open a file.

◆ open()

virtual CV_WRAP bool cv::FileStorage::open ( const String filename,
int  flags,
const String encoding = String() 
)
virtual

Opens a file.

See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release before opening the file.

Parameters
filenameName of the file to open or the text string to read the data from. Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to FileStorage::BASE64 flag.
flagsMode of operation. One of FileStorage::Mode
encodingEncoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.

◆ operator[]()

FileNode cv::FileStorage::operator[] ( const String nodename) const

Returns the specified element of the top-level mapping.

Parameters
nodenameName of the file node.
Returns
Node with the given name.

◆ release()

virtual CV_WRAP void cv::FileStorage::release ( )
virtual

Closes the file and releases all the memory buffers.

Call this method after all I/O operations with the storage are finished.

◆ releaseAndGetString()

virtual CV_WRAP String cv::FileStorage::releaseAndGetString ( )
virtual

Closes the file and releases all the memory buffers.

Call this method after all I/O operations with the storage are finished. If the storage was opened for writing data and FileStorage::WRITE was specified

◆ root()

CV_WRAP FileNode cv::FileStorage::root ( int  streamidx = 0) const

Returns the top-level mapping.

Parameters
streamidxZero-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.

◆ startWriteStruct()

CV_WRAP void cv::FileStorage::startWriteStruct ( const String name,
int  flags,
const String typeName = String() 
)

Starts to write a nested structure (sequence or a mapping).

Parameters
namename of the structure. When writing to sequences (a.k.a. "arrays"), pass an empty string.
flagstype of the structure (FileNode::MAP or FileNode::SEQ (both with optional FileNode::FLOW)).
typeNameoptional name of the type you store. The effect of setting this depends on the storage format. I.e. if the format has a specification for storing type information, this parameter is used.

◆ write() [1/5]

CV_WRAP void cv::FileStorage::write ( const String name,
const Mat val 
)

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

◆ write() [2/5]

CV_WRAP void cv::FileStorage::write ( const String name,
const std::vector< String > &  val 
)

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

◆ write() [3/5]

CV_WRAP void cv::FileStorage::write ( const String name,
const String val 
)

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

◆ write() [4/5]

CV_WRAP void cv::FileStorage::write ( const String name,
double  val 
)

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

◆ write() [5/5]

CV_WRAP void cv::FileStorage::write ( const String name,
int  val 
)

Simplified writing API to use with bindings.

Parameters
nameName of the written object. When writing to sequences (a.k.a. "arrays"), pass an empty string.
valValue of the written object.

◆ writeComment()

CV_WRAP void cv::FileStorage::writeComment ( const String comment,
bool  append = false 
)

Writes a comment.

The function writes a comment into file storage. The comments are skipped when the storage is read.

Parameters
commentThe written comment, single-line or multi-line
appendIf true, the function tries to put the comment at the end of current line. Else if the comment is multi-line, or if it does not fit at the end of the current line, the comment starts a new line.

◆ writeRaw()

void cv::FileStorage::writeRaw ( const String fmt,
const void *  vec,
size_t  len 
)

Writes multiple numbers.

Writes one or more numbers of the specified format to the currently written structure. Usually it is more convenient to use operator << instead of this method.

Parameters
fmtSpecification of each array element, see format specification
vecPointer to the written array.
lenNumber of the uchar elements to write.

Member Data Documentation

◆ elname

std::string cv::FileStorage::elname

◆ p

Ptr<Impl> cv::FileStorage::p

◆ state

int cv::FileStorage::state

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