Storage
* Set of related streams
* Used to realize Object Persistence
* Generally, storage is a file.
-Although it also provides memory storage
-Storage can also be embedded into other storage streams.
* For various considerations, replace the direct use of the file and File Server Client APIs
-Although it is related to other features of the file server
* It is of great significance to the application framework because it provides support for embedded documents.
* Storage is also the basis of the database provided by DBMS.
Storage stream
* Stream is suitable for storage.
* Circulation is often created in the storage Context
* The stored stream is encapsulated by one of the following two classes:
-Rstorewritestream indicates the write stream.
· Supports the creation and operation of storage streaming
-Rstorreadstream indicates reading a stream.
· Allows you to open an existing stream in the storage.
Stream ID
* The unique identifier of a stream in storage
-Encapsulated by the tstreamid class
* Used for the given storage context and opening the stream
-For example, rstorereadstream: openlc (cfilestore & store, tstreamid streamid );
* Tstreamid provides externalizel () and internalizel () functions.
-The Stream ID can be externalized to other streams, which is the basis of the stream network.
* Save in storage
-If there is only one stream, the stream ID is saved in the storage root.
-If the storage contains more than one stream, the stream ID is saved in the stream dictionary.
Use storage stream
* Rstorewritestream
-Createl () or createlc () can create a new stream in the storage.
-Openl () or openlc () can open an existing stream in the storage for write operations.
· Note that not all storage types support modification of existing streams
-Commitl () executes the external operations of the stream.
· As a simple criterion, createl () or createlc () can be matched by calling commitl ().
* Rstorereadstream
-Openl () or openlc () open an existing stream in the storage for read Operations
Use storage stream-Example
* Use the createl () or createlc () member function of rstorewritestream to create a new stream in the storage and return the ID of the stream.
Rstorewritestream outstream;
Tstreamid id = outstream. createlc (* store );
...
Cleanupstack: popanddestory ();
...
* Use the openl () or openlc () member function of rstorereadstream to open a stream and use it for read operations.
Rstorereadstream instream;
Tstream ID;
...
Instream. openlc (* store, ID );
...
Storage Type
* Cstreamstore defines an interface for adding and deleting streams in storage.
-It also provides an execution/recovery mechanism, as well as space compression and recovery.
* Stream-based storage example
-Persistent Storage
-Embedded storage
-Dictionary storage
-Memory storage
Persistent Storage
* The storage persistence is provided beyond the lifecycle of the stored application.
-For example, file storage
* In particular
-Root stream, which can be used to find all other streams stored
-Open and Close stored Functions
* Cpersistentstore, inherited from cstreamstore
File Storage
* File storage is a persistent storage that can be used to implement data files of applications.
* There are two types of cfilestore-derived file storage:
-Direct file storage, encapsulated by cdirectfilestore
· Direct file storage is suitable for applications that use the data memory copy as the primary copy, such as a text processor, which implements a classic loading/saving example.
-Persistent file storage, which is encapsulated by cpermanetfilestore.
· In general, persistent file storage applies to database applications. Such applications store all data in files, but occasionally edit some entries in the database.
Use File Storage
* Createlc () creates a storage
* Replace existing storage with repalcelc ()
* Open () or openlc () open an existing storage
* File () obtains a copy of The rfile object from the storage.
* Detach () separates the storage from the file. In fact, the ownership of the file is abandoned.
* Reattach () re-establishes the association between the file and the file storage. In fact, it obtains the ownership of the file.
Use nas-Example
* In the following code snippet
-Files associated with file storage are separated and closed
-The file is re-opened and re-associated with the file storage.
Local_c void dousel (const tdesc & aname)
{
Tparse filestorename;
...
Fssession. parse (aname, filestorename );
Cfilestore * store = cpermanentfilestore: openlc (fssession, filestorename, fullname (), efileread | efilewrite );
Rfile thefile = store-> file ();
Store-> detach ();
Thefile. Close ();
...
Thefile. Open (fssession, filestorename. fullname (), efileread | efilewrite );
Store-> reattach (thefile );
...
}
Embedded storage
* It can be saved as a stream in another storage.
* Used to represent a part of the object Network
-By copying (or deleting) the main stream from the contained storage, you can perform network operations on some objects more easily.
* Similar to direct file storage
-Once written, the stored stream cannot be modified.
* Objects used to embed the application framework
-Only embedded files directly represent the Document Type
* Cembeddedstore, inherited from cpersistentstore
Dictionary storage
* The stream is generally included, but the difference is that the root stream is a stream dictionary.
-Access through uid instead of Stream ID
-It is mainly used by the application framework to process. ini files.
* The interface is provided by the cdictionarystore abstract class.
-Cdictionaryfilestore is an example of a specific class, which is implemented using file storage.
* It does not inherit from cstreamstore, but has its own persistent storage cpersistentstore and stream dictionary cstreamdictionary
* Special stream types: rdictionarywritestream and rdictionaryreadstream are mainly used for dictionary storage.
Stream dictionary
* Maintain a list to maintain the correspondence between UID and stream ID
-The UID identifies the stream for a specific purpose.
* Each tuid and tstreamid pair constitute an entry of the array.
* Type cstreamdictionary
-Provides member functions to manage array entries. For example, you can add new entries or change the stream ID associated with the UID.
* The system initialization file uses a stream dictionary.