//【1】OpenCv中的文件存储类FileStorage源代码的详细解读
class CV_EXPORTS_W FileStorage
{
public:
//! file storage mode
enum
{
READ =0, //! read mode //【1】读文件模式
WRITE =1, //! write mode //【2】写文件模式
APPEND=2, //! append mode
MEMORY=4,
FORMAT_MASK=(7<<3),
FORMAT_AUTO=0,
FORMAT_XML=(1<<3),
FORMAT_YAML=(2<<3)
};
enum
{
UNDEFINED=0,
VALUE_EXPECTED=1,
NAME_EXPECTED=2,
INSIDE_MAP=4
};
//! the default constructor
CV_WRAP FileStorage(); //【1】类的默认构造函数
//! the full constructor that opens file storage for reading or writing
CV_WRAP FileStorage(const string& source, int flags, const string& encoding=string());//【2】针对文件的读和写的全完全文件存储类FileStorage的构造函数
//! the constructor that takes pointer to the C FileStorage structure
FileStorage(CvFileStorage* fs); //【3】C风格OpenCv低版本的构造函数
//! the destructor. calls release()
virtual ~FileStorage();
//! opens file storage for reading or writing. The previous storage is closed with release()
CV_WRAP virtual bool open(const string& filename, int flags, const string& encoding=string()); //【1】虚函数--为了读写文件的打开函数,一般和默认构造函数搭配使用
//! returns true if the object is associated with currently opened file.
CV_WRAP virtual bool isOpened() const; //【2】如果文件打开,则返回true
//! closes the file and releases all the memory buffers
CV_WRAP virtual void release(); //【3】关掉打开的文件,并且释放掉文件所占用类存
//! closes the file, releases all the memory buffers and returns the text string
CV_WRAP string releaseAndGetString();
//! returns the first element of the top-level mapping
CV_WRAP FileNode getFirstTopLevelNode() const; //【4】返回顶层映射的第一个元素
//! returns the top-level mapping. YAML supports multiple streams
CV_WRAP FileNode root(int streamidx=0) const;
//! returns the specified element of the top-level mapping
FileNode operator[](const string& nodename) const;
//! returns the specified element of the top-level mapping
CV_WRAP FileNode operator[](const char* nodename) const;
//! returns pointer to the underlying C FileStorage structure
CvFileStorage* operator *() { return fs; }
//! returns pointer to the underlying C FileStorage structure
const CvFileStorage* operator *() const { return fs; }
//! writes one or more numbers of the specified format to the currently written structure
void writeRaw( const string& fmt, const uchar* vec, size_t len );
//! writes the registered C structure (CvMat, CvMatND, CvSeq). See cvWrite()
void writeObj( const string& name, const void* obj );
//! returns the normalized object name for the specified file name
static string getDefaultObjectName(const string& filename);
Ptr<CvFileStorage> fs; //!< the underlying C FileStorage structure
string elname; //!< the currently written element
vector<char> structs; //!< the stack of written structures
int state; //!< the writer state
};
OpenCv中,文件存储类FileStorage类源代码详解
最新推荐文章于 2024-03-18 00:05:32 发布