Inheritance diagram for BArchivable:

Public Member Functions | |
| virtual status_t | Archive (BMessage *into, bool deep=true) const |
| Archive the object into a BMessage. | |
| BArchivable () | |
| Constructor. Does nothing. | |
| BArchivable (BMessage *from) | |
| Constructor. Does nothing. | |
| virtual status_t | Perform (perform_code d, void *arg) |
| Internal method. | |
| virtual | ~BArchivable () |
| Destructor. Does nothing. | |
Static Public Member Functions | |
| static BArchivable * | Instantiate (BMessage *archive) |
| Static member to restore objects from messages. | |
BArchivable provides an interface for objects that can be put into message archives and extracted into objects in another location. Using this you are able to send objects between applications, or even between computers across networks.
BArchivable differs from BFlattenable in that BFlattenable is designed to store objects into flat streams of data, the main objective being storage to disk. The objective of this interface, however, is to store objects that will be restored to other objects. To illustrate this point, BArchivable messages know how to restore themselves whereas BFlattenables have a datatype which you need to map to classes manually.
Archiving is done with the Archive() method. If your class supports it, the caller can request it to store into a deep archive, meaning that all child objects in it will be stored. Extracting the archive works with the Instantiate() method, which is static. Since the interface is designed to extract objects without the caller knowing what kind of object it actually is, the global function instantiate_object() instantiates a message without you manually having to determine the class the message is from. This adds considerable flexibility and allows BArchivable to be used in combination with other add-ons.
To provide this interface in your classes you should publicly inherit this class. You should implement Archive() and Instantiate(), and provide one constructor that takes one BMessage argument.
| BArchivable::BArchivable | ( | BMessage * | from | ) |
Constructor. Does nothing.
If you inherit this interface you should provide at least one constructor that takes one BMessage argument.
Archive the object into a BMessage.
You should call this method from your derived implementation as it adds the data needed to instantiate your object to the message.
| into | The message you store your object in. | |
| deep | If true, all children of this object should be stored as well. Only pay attention to this parameter if you actually have child objects. |
| B_OK | The archiving succeeded. | |
| error codes | The archiving did not succeed. |
Reimplemented in BHandler.
| static BArchivable * BArchivable::Instantiate | ( | BMessage * | archive | ) | [static] |
Static member to restore objects from messages.
You should always check that the archive argument actually corresponds to your class. The automatic functions, such as instantiate_object() will not choose the wrong class but manual calls to this member might be faulty.
| archive | The message with the data of the object to restore. |
| You | should return a pointer to your object, or NULL if you fail. |
NULL. Even though it is possible to store plain BArchive objects, it is impossible to restore them. Reimplemented in BHandler.