Class FileStorage
XML/YAML file storage class that encapsulates all the information necessary for writing or reading data to/from a file.
public class FileStorage : UnmanagedObject, IDisposable
- Inheritance
-
FileStorage
- Implements
- Inherited Members
Constructors
FileStorage(string, Mode, string)
Initializes a new instance of the FileStorage class.
public FileStorage(string source, FileStorage.Mode flags, string encoding = null)
Parameters
source
stringName of the file to open or the text string to read the data from. 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. 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.).
flags
FileStorage.ModeMode of operation.
encoding
stringEncoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.
Properties
IsOpened
Gets a value indicating whether this instance is opened.
public bool IsOpened { get; }
Property Value
- bool
true
if the object is associated with the current file; otherwise,false
.
this[string]
Gets the FileNode with the specified node name.
public FileNode this[string nodeName] { get; }
Parameters
nodeName
stringName of the node.
Property Value
Methods
DisposeObject()
Release the unmanaged resources
protected override void DisposeObject()
GetFirstTopLevelNode()
Gets the first element of the top-level mapping.
public FileNode GetFirstTopLevelNode()
Returns
- FileNode
The first element of the top-level mapping.
GetNode(string)
Gets the specified element of the top-level mapping.
public FileNode GetNode(string nodeName)
Parameters
nodeName
stringName of the node.
Returns
- FileNode
The specified element of the top-level mapping.
GetRoot(int)
Gets the top-level mapping.
public FileNode GetRoot(int streamIdx = 0)
Parameters
streamIdx
intZero-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
- FileNode
The top-level mapping
Insert(string)
Similar to the << operator in C++, we cannot have the operator overload to << in C# where the second parameter is not an int. Therefore we use this function instead.
public void Insert(string value)
Parameters
value
stringThe string value to insert.
ReleaseAndGetString()
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.Mode.Write was specified
public string ReleaseAndGetString()
Returns
- string
The string that represent the text in the FileStorage
Write(Mat, string)
Writes the specified Mat to the node with the specific name.
public void Write(Mat m, string nodeName = null)
Parameters
Write(double, string)
Writes the specified Mat to the node with the specific name
public void Write(double value, string nodeName = null)
Parameters
Write(int, string)
Writes the specified Mat to the node with the specific name
public void Write(int value, string nodeName = null)
Parameters
Write(float, string)
Writes the specified Mat to the node with the specific name
public void Write(float value, string nodeName = null)
Parameters
Write(string, string)
Writes the specified Mat to the node with the specific name
public void Write(string value, string nodeName = null)