Interface for objects that can be archived into a BMessage. More...
Inherited by BBitmap, BCollator, BCursor [private]
, BFormattingConventions, BGradient, BHandler, BLayoutItem, BListItem, BMenuItem, BNetAddress, BNetBuffer, BNetEndpoint, BNotification, BPicture, BShape, BTab, BToolTip, BTranslator, BTranslatorRoster, and BUrl.
Public Member Functions | |
BArchivable () | |
Constructor. Does nothing. | |
BArchivable (BMessage *from) | |
Constructor. Does important behind-the-scenes work in the unarchiving process. | |
virtual | ~BArchivable () |
Destructor. Does nothing. | |
virtual status_t | AllArchived (BMessage *archive) const |
Method relating to the use of BArchiver . | |
virtual status_t | AllUnarchived (const BMessage *archive) |
Method relating to the use of BUnarchiver . | |
virtual status_t | Archive (BMessage *into, bool deep=true) const |
Archive the object into a BMessage. | |
virtual status_t | Perform (perform_code d, void *arg) |
Perform some action (Internal method defined for binary compatibility purposes). | |
Static Public Member Functions | |
static BArchivable * | Instantiate (BMessage *archive) |
Static member to restore objects from messages. | |
Interface for objects that can be archived into a BMessage.
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 later be restored as new (but identical) objects. To illustrate this point, BArchivable objects can be restored automatically to the correct class, whereas BFlattenable objects have a data type 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.
If your class holds references to other BArchivable objects that you wish to archive, then you should consider using the BArchiver and BUnarchiver classes in your Archive() method and archive constructor, respectively. You should also consider implementing the AllArchived() and AllUnarchived() methods, which were designed to ease archiving and unarchiving in such a situation.
BArchivable::BArchivable | ( | BMessage * | from | ) |
Constructor. Does important behind-the-scenes work in the unarchiving process.
If you inherit this interface you should provide at least one constructor that takes one BMessage argument. In that constructor, you should call your parent class' archive constructor (even if your parent class is BArchivable).
BArchivable::BArchivable | ( | ) |
Constructor. Does nothing.
|
virtual |
Destructor. Does nothing.
Method relating to the use of BArchiver
.
This hook function is called once the first BArchiver that was created in an archiving session is either destroyed, or has its Finish() method called. Implementations of this method can be used, in conjunction with BArchiver::IsArchived(), to reference objects in your archive that you do not own, depending on whether or not those objects were archived by their owners. Implementations of this method should call the implementation of their parent class, the same as for the Archive() method.
Reimplemented in BAbstractLayout, BCardLayout, BLayout, BView, BGridLayout, BGroupLayout, BLayoutItem, BMenuField, BSplitView, BTextControl, and BTwoDimensionalLayout.
Method relating to the use of BUnarchiver
.
This hook function is called triggered in the BUnarchiver::Finish() method. In this method, you can rebuild references to objects that may be direct children of your object, or may be children of other objects. Implementations of this method should call the implementation of their parent class, the same as for the Archive() method.
Reimplemented in BScrollView, BView, BAbstractLayout, BCardLayout, BGridLayout, BGroupLayout, BLayout, BLayoutItem, BMenuField, BSplitView, BTabView, BTextControl, and BTwoDimensionalLayout.
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 archived as well. |
B_OK | The archive operation was successful. |
B_BAD_VALUE | NULL archive message. |
B_ERROR | The archive operation failed. |
Reimplemented in BCollator, BCursor, BNotification, BBox, BListItem, BMenu, BMenuBar, BMenuField, BMenuItem, BOutlineListView, BPictureButton, BPopUpMenu, BScrollBar, BScrollView, BShape, BStatusBar, BStringItem, BStringView, BTextControl, BTextView, BView, BWindow, BApplication, BHandler, BLooper, BDirectWindow, BAlert, BBitmap, BButton, BChannelControl, BCheckBox, BColorControl, BControl, BDragger, BListView, BPicture, BRadioButton, BSeparatorItem, BTab, BAbstractLayout, BCardLayout, BChannelSlider, BGridLayout, BGroupLayout, BLayout, BLayoutItem, BSeparatorView, BSpaceLayoutItem, BSplitView, BTabView, BTwoDimensionalLayout, BUrl, and BTranslatorRoster.
|
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() and BUnarchiver::InstantiateObject() will not choose the wrong class but manual calls to this member might be faulty. You can verify that archive
stores an object of your class with the validate_instantiation() function.
archive | The message with the data of the object to restore. |
You | should return a pointer to the object you create with archive , or NULL if the unarchival fails. |
NULL
. Even though it is possible to store plain BArchivable objects, it is impossible to restore them.
|
virtual |
Perform some action (Internal method defined for binary compatibility purposes).
Reimplemented in BPopUpMenu, BDirectWindow, BListItem, BListView, BPicture, BStringItem, BCheckBox, BDragger, BMenuBar, BOutlineListView, BPictureButton, BSeparatorView, BTextView, BView, BWindow, BApplication, BHandler, BLooper, BAbstractLayout, BAlert, BBox, BButton, BCardLayout, BCardView, BControl, BGridLayout, BGridView, BGroupLayout, BGroupView, BLayout, BLayoutItem, BMenu, BMenuField, BScrollBar, BScrollView, BSplitView, BStatusBar, BTabView, BTwoDimensionalLayout, BRadioButton, and BTab.