Class FileStorage
Represents a storage associated with a file on disk.
Namespace: OpenCV.Net
Assembly: OpenCV.Net.dll
Syntax
public class FileStorage : SafeHandleZeroOrMinusOneIsInvalid
Constructors
| Improve this Doc View SourceFileStorage(String, MemStorage, StorageFlags, String)
Initializes a new instance of the FileStorage class and prepares the file storage for reading or writing data.
Declaration
public FileStorage(string fileName, MemStorage storage, StorageFlags flags, string encoding = null)
Parameters
Type | Name | Description |
---|---|---|
String | fileName | Name of the file associated with the storage. |
MemStorage | storage | Memory storage used for temporary data and for storing dynamic structures, such as Seq or Graph. If it is null, a temporary memory storage is created and used. |
StorageFlags | flags | Specifies operation flags associated with the new file storage. |
String | encoding | Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead. |
Methods
| Improve this Doc View SourceEndWriteStruct()
Ends the writing of a structure.
Declaration
public void EndWriteStruct()
GetFileNode(FileNode, StringHashNode, Boolean)
Finds a node in a map or file storage.
Declaration
public FileNode GetFileNode(FileNode map, StringHashNode key, bool createMissing = false)
Parameters
Type | Name | Description |
---|---|---|
FileNode | map | The parent map. If it is null, the function searches a top-level node. |
StringHashNode | key | Unique pointer to the node name, retrieved with GetHashedKey(String, Boolean). |
Boolean | createMissing | A value indicating whether an absent node should be added to the map. |
Returns
Type | Description |
---|---|
FileNode | The found or newly created node; null in case of failure. |
GetFileNode(FileNode, String)
Finds a node in a map or file storage.
Declaration
public FileNode GetFileNode(FileNode map, string name)
Parameters
Type | Name | Description |
---|---|---|
FileNode | map | The parent map. If it is null, the function searches a top-level node. |
String | name | The file node name. |
Returns
Type | Description |
---|---|
FileNode | The found node or null in case of failure. |
GetHashedKey(String, Boolean)
Returns a unique reference for a given name.
Declaration
public StringHashNode GetHashedKey(string name, bool createMissing = false)
Parameters
Type | Name | Description |
---|---|---|
String | name | Literal node name. |
Boolean | createMissing | A value indicating whether an absent key should be added into the hash table. |
Returns
Type | Description |
---|---|
StringHashNode | A unique reference for each particular file node name. This reference can later be passed to the GetFileNode(FileNode, StringHashNode, Boolean) method. |
GetRootFileNode(Int32)
Retrieves one of the top-level nodes of the file storage.
Declaration
public FileNode GetRootFileNode(int streamIndex = 0)
Parameters
Type | Name | Description |
---|---|---|
Int32 | streamIndex | Zero-based index of the stream. In most cases, there is only one stream in the file. |
Returns
Type | Description |
---|---|
FileNode | One of the top-level file nodes. The top-level nodes do not have a name, they correspond to the streams that are stored one after another in the file storage. If the index is out of range, the function returns null. |
Read<TElement>(FileNode)
Decodes an object and returns a reference to it.
Declaration
public TElement Read<TElement>(FileNode node)
where TElement : CVHandle
Parameters
Type | Name | Description |
---|---|---|
FileNode | node | The root object node. |
Returns
Type | Description |
---|---|
TElement | The reference to the decoded object. |
Type Parameters
Name | Description |
---|---|
TElement | The type of the object. |
Read<TElement>(FileNode, String)
Finds an object by name and decodes it.
Declaration
public TElement Read<TElement>(FileNode map, string name)
where TElement : CVHandle
Parameters
Type | Name | Description |
---|---|---|
FileNode | map | The parent map. If it is null, the function searches a top-level node. |
String | name | The node name. |
Returns
Type | Description |
---|---|
TElement | The reference to the decoded object. |
Type Parameters
Name | Description |
---|---|
TElement | The type of the object. |
ReadInt(FileNode, Int32)
Retrieves an integer value from a file node.
Declaration
public int ReadInt(FileNode node, int defaultValue = 0)
Parameters
Type | Name | Description |
---|---|---|
FileNode | node | The file node. |
Int32 | defaultValue | The value that is returned if |
Returns
Type | Description |
---|---|
Int32 | An integer that is represented by the file node. |
ReadInt(FileNode, String, Int32)
Finds a file node and returns its integer value.
Declaration
public int ReadInt(FileNode map, string name, int defaultValue = 0)
Parameters
Type | Name | Description |
---|---|---|
FileNode | map | The parent map. If it is null, the function searches a top-level node. |
String | name | The node name. |
Int32 | defaultValue | The value that is returned if the file node is not found. |
Returns
Type | Description |
---|---|
Int32 | An integer that is represented by the file node. |
ReadRawData<TElement>(FileNode, TElement[], String)
Reads multiple numbers.
Declaration
public void ReadRawData<TElement>(FileNode src, TElement[] dst, string format)
where TElement : struct
Parameters
Type | Name | Description |
---|---|---|
FileNode | src | The file node (a sequence) to read numbers from. |
TElement[] | dst | The destination array. |
String | format | Specification of each array element. |
Type Parameters
Name | Description |
---|---|
TElement | The type of the numbers to read. |
ReadReal(FileNode, Double)
Retrieves a floating-point value from a file node.
Declaration
public double ReadReal(FileNode node, double defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
FileNode | node | The file node. |
Double | defaultValue | The value that is returned if |
Returns
Type | Description |
---|---|
Double | A floating-point value that is represented by the file node. |
ReadReal(FileNode, String, Double)
Finds a file node and returns its floating-point value.
Declaration
public double ReadReal(FileNode map, string name, double defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
FileNode | map | The parent map. If it is null, the function searches a top-level node. |
String | name | The node name. |
Double | defaultValue | The value that is returned if the file node is not found. |
Returns
Type | Description |
---|---|
Double | A floating-point value that is represented by the file node. |
ReadString(FileNode, String)
Retrieves a text string from a file node.
Declaration
public string ReadString(FileNode node, string defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
FileNode | node | The file node. |
String | defaultValue | The value that is returned if |
Returns
Type | Description |
---|---|
String | A text string that is represented by the file node. |
ReadString(FileNode, String, String)
Finds a file node and returns its text string value.
Declaration
public string ReadString(FileNode map, string name, string defaultValue = null)
Parameters
Type | Name | Description |
---|---|---|
FileNode | map | The parent map. If it is null, the function searches a top-level node. |
String | name | The node name. |
String | defaultValue | The value that is returned if the file node is not found. |
Returns
Type | Description |
---|---|
String | A text string that is represented by the file node. |
ReleaseHandle()
Executes the code required to free the native FileStorage handle.
Declaration
protected override bool ReleaseHandle()
Returns
Type | Description |
---|---|
Boolean | true if the handle is released successfully; otherwise, in the event of a catastrophic failure, false. |
StartNextStream()
Starts the next stream in file storage. Both YAML and XML support multiple streams. This is useful for concatenating files or for resuming the writing process.
Declaration
public void StartNextStream()
StartWriteStruct(String, StructStorageFlags, String, AttrList)
Starts writing a new structure.
Declaration
public void StartWriteStruct(string name, StructStorageFlags structFlags, string typeName = null, AttrList attributes = default(AttrList))
Parameters
Type | Name | Description |
---|---|---|
String | name | Name of the written structure. The structure can be accessed by this name when the storage is read. |
StructStorageFlags | structFlags | Operation flags associated with the written structure. |
String | typeName | Optional parameter, the object type name. In case of XML it is written as a type_id attribute of the structure opening tag. In the case of YAML it is written after a colon following the structure name. |
AttrList | attributes | Not used in the current implementation. |
Write(String, CVHandle, AttrList)
Writes an object to file storage.
Declaration
public void Write(string name, CVHandle handle, AttrList attributes = default(AttrList))
Parameters
Type | Name | Description |
---|---|---|
String | name | Name of the written object. Should be null if and only if the parent structure is a sequence. |
CVHandle | handle | Handle to the written object. |
AttrList | attributes | The attributes of the object. They are specific for each particular type. |
WriteComment(String, Boolean)
Writes a comment.
Declaration
public void WriteComment(string comment, bool eolComment)
Parameters
Type | Name | Description |
---|---|---|
String | comment | The written comment, single-line or multi-line. |
Boolean | eolComment | If true, the method tries to put the comment at the end of current line; otherwise, 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. |
WriteFileNode(String, FileNode, Boolean)
Writes a file node from another file storage.
Declaration
public void WriteFileNode(string newNodeName, FileNode node, bool embed)
Parameters
Type | Name | Description |
---|---|---|
String | newNodeName | New name of the file node in the destination file storage. To keep the existing name, use the Name property. |
FileNode | node | The written node. |
Boolean | embed | If the written node is a collection and this parameter is true, no extra level of hierarchy is created. Instead, all the elements of node are written into the currently written structure. Of course, map elements can only be embedded into another map, and sequence elements can only be embedded into another sequence. |
WriteInt(String, Int32)
Writes an integer value.
Declaration
public void WriteInt(string name, int value)
Parameters
Type | Name | Description |
---|---|---|
String | name | Name of the written value. Should be null if and only if the parent structure is a sequence. |
Int32 | value | The written value. |
WriteRawData<TElement>(TElement[], String)
Writes multiple numbers.
Declaration
public void WriteRawData<TElement>(TElement[] source, string format)
where TElement : struct
Parameters
Type | Name | Description |
---|---|---|
TElement[] | source | The source array. |
String | format | Specification of each array element. |
Type Parameters
Name | Description |
---|---|
TElement | The type of the numbers to write. |
WriteReal(String, Double)
Writes a floating-point value.
Declaration
public void WriteReal(string name, double value)
Parameters
Type | Name | Description |
---|---|---|
String | name | Name of the written value. Should be null if and only if the parent structure is a sequence. |
Double | value | The written value. |
WriteString(String, String, Boolean)
Writes a text string.
Declaration
public void WriteString(string name, string value, bool quote = false)
Parameters
Type | Name | Description |
---|---|---|
String | name | Name of the written string. Should be null if and only if the parent structure is a sequence. |
String | value | The written string. |
Boolean | quote | If true, the written string is put in quotes, regardless of whether they are required. Otherwise, if the flag is zero, quotes are used only when they are required (e.g. when the string starts with a digit or contains spaces). |