Files
haiku-beta6/docs/user/support/Archivable.dox
T

177 lines
6.3 KiB
Plaintext
Raw Normal View History

2007-04-16 09:28:29 +00:00
/*
* Copyright 2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
2007-05-29 15:24:25 +00:00
* Author:
2007-06-04 06:37:04 +00:00
* Niels Sascha Reedijk <[email protected]>
*
2007-05-29 15:24:25 +00:00
* Proofreader:
2007-06-04 06:37:04 +00:00
* David Weizades <[email protected]>
* Thom Holwerda <[email protected]>
*
2007-04-16 09:28:29 +00:00
* Corresponds to:
2007-06-04 06:37:04 +00:00
* /trunk/headers/os/support/Archivable.h rev 19972
* /trunk/src/kits/support/Archivable.cpp rev 19095
2007-04-16 09:28:29 +00:00
*/
2007-05-29 15:24:25 +00:00
/*!
\file Archivable.h
\brief Provides the BArchivable interface.
*/
/*!
\class BArchivable
\ingroup support
\ingroup libbe
2007-06-04 06:37:04 +00:00
\brief Interface for objects that can be archived into a BMessage.
2007-04-16 09:28:29 +00:00
2007-05-29 15:24:25 +00:00
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
2007-04-16 09:28:29 +00:00
networks.
2007-05-29 15:24:25 +00:00
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
2007-06-04 06:37:04 +00:00
you need to map to classes manually.
2007-04-16 09:28:29 +00:00
2007-05-29 15:24:25 +00:00
Archiving is done with the Archive() method. If your class supports it, the
2007-06-04 06:37:04 +00:00
caller can request it to store into a deep archive, meaning that all child
2007-05-29 15:24:25 +00:00
objects in it will be stored. Extracting the archive works with the
Instantiate() method, which is static. Since the interface is designed to
2007-06-04 06:37:04 +00:00
extract objects without the caller knowing what kind of object it actually is,
2007-05-29 15:24:25 +00:00
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.
2007-04-16 09:28:29 +00:00
2007-05-29 15:24:25 +00:00
To provide this interface in your classes you should publicly inherit this
class. You should implement Archive() and Instantiate(), and provide one
2007-06-04 06:37:04 +00:00
constructor that takes one BMessage argument.
2007-05-29 15:24:25 +00:00
*/
/*!
2007-04-16 09:28:29 +00:00
\fn BArchivable::BArchivable(BMessage* from)
\brief Constructor. Does nothing.
2007-05-29 15:24:25 +00:00
If you inherit this interface you should provide at least one constructor that
takes one BMessage argument.
*/
/*!
2007-04-16 09:28:29 +00:00
\fn BArchivable::BArchivable()
2007-05-29 15:24:25 +00:00
\brief Constructor. Does nothing.
*/
/*!
2007-04-16 09:28:29 +00:00
\fn BArchivable::~BArchivable()
2007-05-29 15:24:25 +00:00
\brief Destructor. Does nothing.
*/
/*!
2007-04-16 09:28:29 +00:00
\fn virtual status_t BArchivable::Archive(BMessage* into, bool deep = true) const
\brief Archive the object into a BMessage.
2007-05-29 15:24:25 +00:00
You should call this method from your derived implementation as it adds the
data needed to instantiate your object to the message.
2007-04-16 09:28:29 +00:00
2007-05-29 15:24:25 +00:00
\param into The message you store your object in.
\param deep If \c true, all children of this object should be stored as well.
2007-06-04 06:37:04 +00:00
Only pay attention to this parameter if you actually have child objects.
2007-04-16 09:28:29 +00:00
\retval B_OK The archiving succeeded.
2007-05-29 15:24:25 +00:00
\retval "error codes" The archiving did not succeed.
*/
/*!
2007-04-16 09:28:29 +00:00
\fn static BArchivable* BArchivable::Instantiate(BMessage* archive)
\brief Static member to restore objects from messages.
You should always check that the \a archive argument actually corresponds to
your class. The automatic functions, such as #instantiate_object() will not
2007-05-29 15:24:25 +00:00
choose the wrong class but manual calls to this member might be faulty.
2007-04-16 09:28:29 +00:00
2007-05-29 15:24:25 +00:00
\param archive The message with the data of the object to restore.
2007-04-16 09:28:29 +00:00
\retval You should return a pointer to your object, or \c NULL if you
2007-05-29 15:24:25 +00:00
fail.
2007-04-16 09:28:29 +00:00
\warning The default implementation will always return \c NULL. Even though
2007-06-04 06:37:04 +00:00
it is possible to store plain BArchive objects, it is impossible to restore
2007-04-16 09:28:29 +00:00
them.
\see instantiate_object(BMessage *from)
2007-05-29 15:24:25 +00:00
*/
/*!
2007-04-16 09:28:29 +00:00
\fn virtual status_t BArchivable::Perform(perform_code d, void* arg)
\brief Internal method.
2007-06-04 06:37:04 +00:00
\internal This method is defined in case of unforeseen binary compatibility
API issues. Currently nothing of interest is implemented.
2007-05-29 15:24:25 +00:00
*/
///// Global methods /////
/*!
\addtogroup support_globals
@{
*/
/*!
2007-04-16 09:28:29 +00:00
\typedef typedef BArchivable* (*instantiation_func)(BMessage*)
\brief Internal definition of a function that can instantiate objects that
2007-05-29 15:24:25 +00:00
have been created with the BArchivable API.
*/
/*!
2007-04-16 09:28:29 +00:00
\fn BArchivable* instantiate_object(BMessage *from, image_id *id)
\brief Instantiate an archived object with the object being defined in a
different application or library.
This function is similar to instantiate_object(BMessage *from), except that
2007-06-04 06:37:04 +00:00
it takes the \a id argument referring to an image where the object might be
2007-05-29 15:24:25 +00:00
stored.
2007-04-16 09:28:29 +00:00
2007-05-29 15:24:25 +00:00
\note Images are names for executable files. Image id's refer to these
2007-04-16 09:28:29 +00:00
executable files that have been loaded by your application. Have a look
2007-06-04 06:37:04 +00:00
at the kernel API for further information.
2007-05-29 15:24:25 +00:00
*/
/*!
2007-04-16 09:28:29 +00:00
\fn BArchivable* instantiate_object(BMessage *from)
\brief Instantiate an archived object.
2007-06-04 06:37:04 +00:00
This global function will determine the base class, based on the \a from
2007-04-16 09:28:29 +00:00
argument, and it will call the Instantiate() function of that object to
restore it.
\param from The archived object.
\return The object returns a pointer to the instantiated object, or \c NULL
if the instantiation failed. The global \c errno variable will contain the
2007-05-29 15:24:25 +00:00
reason why it failed.
\see instantiate_object(BMessage *from, image_id *id)
*/
/*!
2007-04-16 09:28:29 +00:00
\fn bool validate_instantiation(BMessage* from, const char* className)
\brief Internal function that checks if the \a className is the same as the
2007-05-29 15:24:25 +00:00
one stored in the \a from message.
*/
/*!
\fn instantiation_func find_instantiation_func(const char* className, const char* signature)
2007-04-16 09:28:29 +00:00
\brief Internal function that searches for the instantiation func with a
specific signature. Use instantiate_object() instead.
2007-05-29 15:24:25 +00:00
*/
/*!
2007-04-16 09:28:29 +00:00
\fn instantiation_func find_instantiation_func(const char* className)
2007-06-04 06:37:04 +00:00
\brief Internal function that searches for the instantiation func of a
2007-05-29 15:24:25 +00:00
specific class. Use instantiate_object() instead.
*/
/*!
2007-04-16 09:28:29 +00:00
\fn instantiation_func find_instantiation_func(BMessage* archive)
\brief Internal function that searches for the instantiation func that
2007-05-29 15:24:25 +00:00
works on the specified \a archive. Use instantiate_object() instead.
*/
//! @}