Google Custom Search

BArchivable Class Reference
[Support Kit(libbe.so)]

Interface for objects that can be archived into a BMessage. More...

Inheritance diagram for BArchivable:

BHandler List of all members.

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 BArchivableInstantiate (BMessage *archive)
 Static member to restore objects from messages.

Detailed Description

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 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.


Constructor & Destructor Documentation

BArchivable::BArchivable ( BMessage from  ) 

Constructor. Does nothing.

If you inherit this interface you should provide at least one constructor that takes one BMessage argument.


Member Function Documentation

status_t BArchivable::Archive ( BMessage into,
bool  deep = true 
) const [virtual]

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.

Parameters:
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.
Return values:
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.

Parameters:
archive The message with the data of the object to restore.
Return values:
You should return a pointer to your object, or NULL if you fail.
Warning:
The default implementation will always return NULL. Even though it is possible to store plain BArchive objects, it is impossible to restore them.
See also:
instantiate_object(BMessage *from)

Reimplemented in BHandler.


The Haiku Book pre-R1 - BArchivable Class Reference
Generated on 14 Feb 2008