xref: /haiku/docs/user/support/Archivable.dox (revision c4b9309a9964a8bf18a834cf41aa97f1172bab0d)
181071f5eSNiels Sascha Reedijk/*
2820dca4dSJohn Scipione * Copyright 2007 Haiku, Inc. All rights reserved.
381071f5eSNiels Sascha Reedijk * Distributed under the terms of the MIT License.
481071f5eSNiels Sascha Reedijk *
5886c23bfSAlex Wilson * Authors:
655f7db1bSNiels Sascha Reedijk *		Niels Sascha Reedijk, niels.reedijk@gmail.com
7886c23bfSAlex Wilson *		Alex Wilson, yourpalal2@gmail.com
8*c4b9309aSJohn Scipione *		John Scipione, jscipione@gmail.com
9e3c5ca85SNiels Sascha Reedijk *
1037503f54SNiels Sascha Reedijk * Proofreader:
1155f7db1bSNiels Sascha Reedijk *		David Weizades, ddewbofh@hotmail.com
1255f7db1bSNiels Sascha Reedijk *		Thom Holwerda, slakje@quicknet.nl
13e3c5ca85SNiels Sascha Reedijk *
1481071f5eSNiels Sascha Reedijk * Corresponds to:
15820dca4dSJohn Scipione *		headers/os/support/Archivable.h rev 37751
16b7235efcSNiels Sascha Reedijk *		src/kits/support/Archivable.cpp rev 44303
1781071f5eSNiels Sascha Reedijk */
1881071f5eSNiels Sascha Reedijk
1955f7db1bSNiels Sascha Reedijk
20820dca4dSJohn Scipione/*!
21820dca4dSJohn Scipione	\file Archivable.h
22820dca4dSJohn Scipione	\ingroup support
2341611c9cSJohn Scipione	\ingroup libbe
24886c23bfSAlex Wilson	\brief Provides the BArchivable interface and declares the BArchiver and
25886c23bfSAlex Wilson	       BUnarchiver classes.
2681071f5eSNiels Sascha Reedijk*/
2781071f5eSNiels Sascha Reedijk
2855f7db1bSNiels Sascha Reedijk
29820dca4dSJohn Scipione/*!
30820dca4dSJohn Scipione	\class BArchivable
3181071f5eSNiels Sascha Reedijk	\ingroup support
3241611c9cSJohn Scipione	\ingroup libbe
33e3c5ca85SNiels Sascha Reedijk	\brief Interface for objects that can be archived into a BMessage.
3481071f5eSNiels Sascha Reedijk
3537503f54SNiels Sascha Reedijk	BArchivable provides an interface for objects that can be put into message
3637503f54SNiels Sascha Reedijk	archives and extracted into objects in another location. Using this you are
3737503f54SNiels Sascha Reedijk	able to send objects between applications, or even between computers across
3881071f5eSNiels Sascha Reedijk	networks.
3981071f5eSNiels Sascha Reedijk
4037503f54SNiels Sascha Reedijk	BArchivable differs from BFlattenable in that BFlattenable is designed to
4137503f54SNiels Sascha Reedijk	store objects into flat streams of data, the main objective being storage to
4255f7db1bSNiels Sascha Reedijk	disk. The objective of this interface, however, is to store objects that
43886c23bfSAlex Wilson	will later be restored as new (but identical) objects. To illustrate this
44886c23bfSAlex Wilson	point, BArchivable objects can be restored automatically to the correct
45820dca4dSJohn Scipione	class, whereas BFlattenable objects have a data type which you need to map
46820dca4dSJohn Scipione	to classes manually.
4781071f5eSNiels Sascha Reedijk
4837503f54SNiels Sascha Reedijk	Archiving is done with the Archive() method. If your class supports it, the
4937503f54SNiels Sascha Reedijk	caller can request it to store into a deep archive, meaning that all child
5037503f54SNiels Sascha Reedijk	objects in it will be stored. Extracting the archive works with the
5137503f54SNiels Sascha Reedijk	Instantiate() method, which is static. Since the interface is designed to
5255f7db1bSNiels Sascha Reedijk	extract objects without the caller knowing what kind of object it actually
5355f7db1bSNiels Sascha Reedijk	is, the global function #instantiate_object() instantiates a message without
5455f7db1bSNiels Sascha Reedijk	you manually having to determine the class the message is from. This adds
5555f7db1bSNiels Sascha Reedijk	considerable flexibility and allows BArchivable to be used in combination
5655f7db1bSNiels Sascha Reedijk	with other add-ons.
5781071f5eSNiels Sascha Reedijk
5837503f54SNiels Sascha Reedijk	To provide this interface in your classes you should publicly inherit this
5937503f54SNiels Sascha Reedijk	class. You should implement Archive() and Instantiate(), and provide one
6081071f5eSNiels Sascha Reedijk	constructor that takes one BMessage argument.
61886c23bfSAlex Wilson
62886c23bfSAlex Wilson	If your class holds references to other BArchivable objects that you wish
63886c23bfSAlex Wilson	to archive, then you should consider using the BArchiver and BUnarchiver
64886c23bfSAlex Wilson	classes in your Archive() method and archive constructor, respectively.
65886c23bfSAlex Wilson	You should also consider implementing the AllArchived() and AllUnarchived()
66886c23bfSAlex Wilson	methods, which were designed to ease archiving and unarchiving in such
67886c23bfSAlex Wilson	a situation.
68*c4b9309aSJohn Scipione
69*c4b9309aSJohn Scipione	\since BeOS R3
7081071f5eSNiels Sascha Reedijk*/
7181071f5eSNiels Sascha Reedijk
7255f7db1bSNiels Sascha Reedijk
736ac7032dSJohn Scipione/*!
746ac7032dSJohn Scipione	\fn BArchivable::BArchivable(BMessage* from)
75820dca4dSJohn Scipione	\brief Constructor. Does important behind-the-scenes work in the
76820dca4dSJohn Scipione		   unarchiving process.
7781071f5eSNiels Sascha Reedijk
7855f7db1bSNiels Sascha Reedijk	If you inherit this interface you should provide at least one constructor
79820dca4dSJohn Scipione	that takes one BMessage argument. In that constructor, you should call
80820dca4dSJohn Scipione	your parent class' archive constructor (even if your parent class is
81886c23bfSAlex Wilson	BArchivable).
82*c4b9309aSJohn Scipione
83*c4b9309aSJohn Scipione	\since BeOS R3
8481071f5eSNiels Sascha Reedijk*/
8581071f5eSNiels Sascha Reedijk
8655f7db1bSNiels Sascha Reedijk
876ac7032dSJohn Scipione/*!
886ac7032dSJohn Scipione	\fn BArchivable::BArchivable()
8981071f5eSNiels Sascha Reedijk	\brief Constructor. Does nothing.
90*c4b9309aSJohn Scipione
91*c4b9309aSJohn Scipione	\since BeOS R3
9281071f5eSNiels Sascha Reedijk*/
9381071f5eSNiels Sascha Reedijk
9455f7db1bSNiels Sascha Reedijk
956ac7032dSJohn Scipione/*!
966ac7032dSJohn Scipione	\fn BArchivable::~BArchivable()
9781071f5eSNiels Sascha Reedijk	\brief Destructor. Does nothing.
98*c4b9309aSJohn Scipione
99*c4b9309aSJohn Scipione	\since BeOS R3
10081071f5eSNiels Sascha Reedijk*/
10181071f5eSNiels Sascha Reedijk
10255f7db1bSNiels Sascha Reedijk
1036ac7032dSJohn Scipione/*!
104*c4b9309aSJohn Scipione	\fn virtual status_t BArchivable::Archive(BMessage* into, bool deep) const
10581071f5eSNiels Sascha Reedijk	\brief Archive the object into a BMessage.
10681071f5eSNiels Sascha Reedijk
10737503f54SNiels Sascha Reedijk	You should call this method from your derived implementation as it adds the
10837503f54SNiels Sascha Reedijk	data needed to instantiate your object to the message.
10981071f5eSNiels Sascha Reedijk
11037503f54SNiels Sascha Reedijk	\param into The message you store your object in.
111886c23bfSAlex Wilson	\param deep If \c true, all children of this object should be archived as
112886c23bfSAlex Wilson	       well.
1136ac7032dSJohn Scipione
1146ac7032dSJohn Scipione	\retval B_OK The archive operation was successful.
1156ac7032dSJohn Scipione	\retval B_BAD_VALUE \c NULL \a archive message.
1166ac7032dSJohn Scipione	\retval B_ERROR The archive operation failed.
117*c4b9309aSJohn Scipione
118*c4b9309aSJohn Scipione	\since BeOS R3
11981071f5eSNiels Sascha Reedijk*/
12081071f5eSNiels Sascha Reedijk
12155f7db1bSNiels Sascha Reedijk
1226ac7032dSJohn Scipione/*!
1236ac7032dSJohn Scipione	\fn static BArchivable* BArchivable::Instantiate(BMessage* archive)
12481071f5eSNiels Sascha Reedijk	\brief Static member to restore objects from messages.
12581071f5eSNiels Sascha Reedijk
12681071f5eSNiels Sascha Reedijk	You should always check that the \a archive argument actually corresponds to
127886c23bfSAlex Wilson	your class. The automatic functions, such as #instantiate_object() and
128886c23bfSAlex Wilson	BUnarchiver::InstantiateObject() will not choose the wrong class but manual
129886c23bfSAlex Wilson	calls to this member might be faulty. You can verify that \c archive
130*c4b9309aSJohn Scipione	stores an object of your class with the validate_instantiation() function.
13181071f5eSNiels Sascha Reedijk
13237503f54SNiels Sascha Reedijk	\param archive The message with the data of the object to restore.
133*c4b9309aSJohn Scipione
134*c4b9309aSJohn Scipione	\return A pointer to a BArchivable object.
135886c23bfSAlex Wilson	\retval You should return a pointer to the object you create with
136*c4b9309aSJohn Scipione	        \c archive, or \c NULL if the unarchival fails.
137*c4b9309aSJohn Scipione
13881071f5eSNiels Sascha Reedijk	\warning The default implementation will always return \c NULL. Even though
139a46d62a2SAlex Wilson		it is possible to store plain BArchivable objects, it is impossible to
14055f7db1bSNiels Sascha Reedijk		restore them.
141886c23bfSAlex Wilson
142*c4b9309aSJohn Scipione	\see instantiate_object(BMessage*)
143886c23bfSAlex Wilson	\see BUnarchiver::InstantiateObject()
144*c4b9309aSJohn Scipione
145*c4b9309aSJohn Scipione	\since BeOS R3
14681071f5eSNiels Sascha Reedijk*/
14781071f5eSNiels Sascha Reedijk
14855f7db1bSNiels Sascha Reedijk
1496ac7032dSJohn Scipione/*!
1506ac7032dSJohn Scipione	\fn virtual status_t BArchivable::Perform(perform_code d, void* arg)
1516ac7032dSJohn Scipione	\brief Perform some action (Internal method defined for binary
1526ac7032dSJohn Scipione		   compatibility purposes).
1536ac7032dSJohn Scipione
154886c23bfSAlex Wilson	\internal This method is defined for binary compatibility purposes, it is
155886c23bfSAlex Wilson	          used to ensure that the correct AllUnarchived() and AllArchived()
156*c4b9309aSJohn Scipione	          methods are called for objects, as those methods are new to
157*c4b9309aSJohn Scipione	          Haiku.
1586ac7032dSJohn Scipione
1596ac7032dSJohn Scipione	\param d The perform code.
1606ac7032dSJohn Scipione	\param arg A pointer to store some data.
1616ac7032dSJohn Scipione
1626ac7032dSJohn Scipione	\returns A status code.
163*c4b9309aSJohn Scipione
164*c4b9309aSJohn Scipione	\since Haiku R1
165886c23bfSAlex Wilson*/
166886c23bfSAlex Wilson
167886c23bfSAlex Wilson
1686ac7032dSJohn Scipione/*!
1696ac7032dSJohn Scipione	\fn virtual status_t BArchivable::AllUnarchived(const BMessage* archive)
170886c23bfSAlex Wilson	\brief Method relating to the use of \c BUnarchiver.
171886c23bfSAlex Wilson
172886c23bfSAlex Wilson	This hook function is called triggered in the BUnarchiver::Finish() method.
173886c23bfSAlex Wilson	In this method, you can rebuild references to objects that may be direct
174886c23bfSAlex Wilson	children of your object, or may be children of other objects.
175886c23bfSAlex Wilson	Implementations of this method should call the implementation of
176886c23bfSAlex Wilson	their parent class, the same as for the Archive() method.
177886c23bfSAlex Wilson
178a33f8fbdSAdrien Destugues	\warning To guarantee that your AllUnarchived() method will be called
179a33f8fbdSAdrien Destugues	         during unarchival, you must create a BUnarchiver object in your
180a33f8fbdSAdrien Destugues	         archive constructor.
181886c23bfSAlex Wilson
182886c23bfSAlex Wilson	\see BUnarchiver, BUnarchiver::Finish()
183*c4b9309aSJohn Scipione
184*c4b9309aSJohn Scipione	\since Haiku R1
185886c23bfSAlex Wilson*/
186886c23bfSAlex Wilson
187886c23bfSAlex Wilson
188a33f8fbdSAdrien Destugues/*! \fn virtual status_t BArchivable::AllArchived(BMessage* into) const
189886c23bfSAlex Wilson	\brief Method relating to the use of \c BArchiver.
190886c23bfSAlex Wilson
191886c23bfSAlex Wilson	This hook function is called once the first BArchiver that was created in
192a33f8fbdSAdrien Destugues	an archiving session is either destroyed, or has its Finish() method
193886c23bfSAlex Wilson	called. Implementations of this method can be used, in conjunction with
194886c23bfSAlex Wilson	BArchiver::IsArchived(), to reference objects in your archive that you
195886c23bfSAlex Wilson	do not own, depending on whether or not those objects were archived by their
196886c23bfSAlex Wilson	owners. Implementations of this method should call the implementation of
197886c23bfSAlex Wilson	their parent class, the same as for the Archive() method.
198886c23bfSAlex Wilson
199a33f8fbdSAdrien Destugues	\warning To guarantee that your AllArchived() method will be called
200a33f8fbdSAdrien Destugues		during archival, you must create a BArchiver object in your
201a33f8fbdSAdrien Destugues		Archive() implementation.
202886c23bfSAlex Wilson
203a33f8fbdSAdrien Destugues	\warning You should archive any objects you own in your Archive()
204a33f8fbdSAdrien Destugues		method implementation, and \b NOT your AllArchived() method.
205886c23bfSAlex Wilson
206886c23bfSAlex Wilson	\see BArchiver BArchiver::Finish()
207*c4b9309aSJohn Scipione
208*c4b9309aSJohn Scipione	\since Haiku R1
20981071f5eSNiels Sascha Reedijk*/
21081071f5eSNiels Sascha Reedijk
21155f7db1bSNiels Sascha Reedijk
2120e1ec24aSNiels Sascha Reedijk///// BArchiver /////
2130e1ec24aSNiels Sascha Reedijk
2140e1ec24aSNiels Sascha Reedijk
2150e1ec24aSNiels Sascha Reedijk/*!
2160e1ec24aSNiels Sascha Reedijk	\class BArchiver
2170e1ec24aSNiels Sascha Reedijk	\ingroup support
2180e1ec24aSNiels Sascha Reedijk	\ingroup libbe
2190e1ec24aSNiels Sascha Reedijk	\brief A class that simplifies the archiving of complicated BArchivable
2200e1ec24aSNiels Sascha Reedijk	       hierarchies.
2210e1ec24aSNiels Sascha Reedijk
2220e1ec24aSNiels Sascha Reedijk	The BArchiver class is a small class that is used for archiving of
2230e1ec24aSNiels Sascha Reedijk	complicated BArchivable hierarchies. Such a hierarchy may include
2240e1ec24aSNiels Sascha Reedijk	multiple BArchivable objects, each of which might be referenced by
2250e1ec24aSNiels Sascha Reedijk	many BArchivable objects. With the BArchiver class, you can be certain
2260e1ec24aSNiels Sascha Reedijk	that each BArchivable object is archived only once with very little work.
2270e1ec24aSNiels Sascha Reedijk	When used in conjuction with the BArchivable::AllArchived() and
2280e1ec24aSNiels Sascha Reedijk	BArchivable::AllUnarchived() methods, it is simple to rebuild your system of
2290e1ec24aSNiels Sascha Reedijk	references upon unarchival so that they are equivalent to those that were
2300e1ec24aSNiels Sascha Reedijk	present in your original hierarchy.
2310e1ec24aSNiels Sascha Reedijk
2320e1ec24aSNiels Sascha Reedijk	The objects you archive can be retrieved using a BUnarchiver object.
233*c4b9309aSJohn Scipione
234*c4b9309aSJohn Scipione	\since Haiku R1
2350e1ec24aSNiels Sascha Reedijk*/
2360e1ec24aSNiels Sascha Reedijk
2370e1ec24aSNiels Sascha Reedijk
2380e1ec24aSNiels Sascha Reedijk/*!
2390e1ec24aSNiels Sascha Reedijk	\fn BArchiver::BArchiver(BMessage* archive)
2400e1ec24aSNiels Sascha Reedijk	\brief Constructs a BArchiver object that manages \c archive.
241*c4b9309aSJohn Scipione
242*c4b9309aSJohn Scipione	\since Haiku R1
2430e1ec24aSNiels Sascha Reedijk*/
2440e1ec24aSNiels Sascha Reedijk
2450e1ec24aSNiels Sascha Reedijk
2460e1ec24aSNiels Sascha Reedijk/*!
2470e1ec24aSNiels Sascha Reedijk	\fn BArchiver::~BArchiver()
2480e1ec24aSNiels Sascha Reedijk	\brief Destroys a BArchiver object. If the BArchiver object has not had its
2490e1ec24aSNiels Sascha Reedijk	       Finish() method called, this will be done now.
250*c4b9309aSJohn Scipione
251*c4b9309aSJohn Scipione	\since Haiku R1
2520e1ec24aSNiels Sascha Reedijk*/
2530e1ec24aSNiels Sascha Reedijk
2540e1ec24aSNiels Sascha Reedijk
2550e1ec24aSNiels Sascha Reedijk/*!
2560e1ec24aSNiels Sascha Reedijk	\fn status_t BArchiver::AddArchivable(const char* name,
2570e1ec24aSNiels Sascha Reedijk			BArchivable* archivable, bool deep = true)
2580e1ec24aSNiels Sascha Reedijk	\brief Adds a reference to \c archivable to the archive used to
2590e1ec24aSNiels Sascha Reedijk	       construct this BArchiver. May call \c archivable's Archive() method.
2600e1ec24aSNiels Sascha Reedijk
2610e1ec24aSNiels Sascha Reedijk	\param name Where this reference will be stored in the archive.
2620e1ec24aSNiels Sascha Reedijk	\param archivable The BArchivable* object that to reference.
2630e1ec24aSNiels Sascha Reedijk	\param deep Passed to \c archivable->Archive() if \c archivable must
2640e1ec24aSNiels Sascha Reedijk	       be archived.
2650e1ec24aSNiels Sascha Reedijk
2660e1ec24aSNiels Sascha Reedijk	Adds a reference to \c archivable to your archive. If \c archivable has
2670e1ec24aSNiels Sascha Reedijk	not yet been archived, then its Archive() method is called. BArchiver
2680e1ec24aSNiels Sascha Reedijk	can only track BArchivable objects that have been archived through this
2690e1ec24aSNiels Sascha Reedijk	method or the GetTokenForArchivable() methods.
2700e1ec24aSNiels Sascha Reedijk
2710e1ec24aSNiels Sascha Reedijk	\warning If you manually archive an object, and then pass it to
272*c4b9309aSJohn Scipione	         AddArchivable() or GetTokenForArchivable(), it will be archived
273*c4b9309aSJohn Scipione	         again, and when unarchived you will end up with two different
274*c4b9309aSJohn Scipione	         BArchivable objects.
275*c4b9309aSJohn Scipione
276*c4b9309aSJohn Scipione	\since Haiku R1
2770e1ec24aSNiels Sascha Reedijk*/
2780e1ec24aSNiels Sascha Reedijk
2790e1ec24aSNiels Sascha Reedijk
2800e1ec24aSNiels Sascha Reedijk/*!
2810e1ec24aSNiels Sascha Reedijk	\fn status_t BArchiver::GetTokenForArchivable(BArchivable* archivable,
2820e1ec24aSNiels Sascha Reedijk		bool deep, int32& _token);
2830e1ec24aSNiels Sascha Reedijk	\brief Get a token representing a BArchivable object for this archiving
2840e1ec24aSNiels Sascha Reedijk	       session.
2850e1ec24aSNiels Sascha Reedijk
2860e1ec24aSNiels Sascha Reedijk	\param archivable The BArchivable object for which you wish to get a
2870e1ec24aSNiels Sascha Reedijk	       token.
2880e1ec24aSNiels Sascha Reedijk	\param deep Controls how \c archivable will be archived, if it has not yet
2890e1ec24aSNiels Sascha Reedijk	       been archived in this session.
2900e1ec24aSNiels Sascha Reedijk	\param[out] _token The token representing \c archivable is stored here.
2910e1ec24aSNiels Sascha Reedijk
2920e1ec24aSNiels Sascha Reedijk	Retrieves or creates a token to represent \c archivable in this archiving
2930e1ec24aSNiels Sascha Reedijk	session. If \c archivable has not yet been archived, it will be now. If
2940e1ec24aSNiels Sascha Reedijk	\c archivable gets archived, the \c deep parameter will be passed to its
2950e1ec24aSNiels Sascha Reedijk	Archive() method.
2960e1ec24aSNiels Sascha Reedijk
2970e1ec24aSNiels Sascha Reedijk	\warning If you manually archive an object, and then pass it to
298*c4b9309aSJohn Scipione	         GetTokenForArchivable(), it will be archived again, and when
299*c4b9309aSJohn Scipione	         unarchived you will end up with two different BArchivable objects.
300*c4b9309aSJohn Scipione
301*c4b9309aSJohn Scipione	\since Haiku R1
3020e1ec24aSNiels Sascha Reedijk*/
3030e1ec24aSNiels Sascha Reedijk
3040e1ec24aSNiels Sascha Reedijk
3050e1ec24aSNiels Sascha Reedijk/*!
3060e1ec24aSNiels Sascha Reedijk	\fn status_t BArchiver::GetTokenForArchivable(BArchivable* archivable,
3070e1ec24aSNiels Sascha Reedijk		int32 &_token)
3080e1ec24aSNiels Sascha Reedijk	\brief Equivalent to calling the expanded GetTokenForArchivable(
309*c4b9309aSJohn Scipione	       BArchivable*, bool, int32&), with the deep parameter equal to
310*c4b9309aSJohn Scipione	       \c true.
3110e1ec24aSNiels Sascha Reedijk
3120e1ec24aSNiels Sascha Reedijk	\see GetTokenForArchivable(BArchivable*, bool, int32&)
313*c4b9309aSJohn Scipione
314*c4b9309aSJohn Scipione	\since Haiku R1
3150e1ec24aSNiels Sascha Reedijk*/
3160e1ec24aSNiels Sascha Reedijk
3170e1ec24aSNiels Sascha Reedijk
3180e1ec24aSNiels Sascha Reedijk/*!
3190e1ec24aSNiels Sascha Reedijk	\fn bool BArchiver::IsArchived(BArchivable* archivable);
3200e1ec24aSNiels Sascha Reedijk	\brief Returns whether \c archivable has already been archived in this
3210e1ec24aSNiels Sascha Reedijk	       session.
3220e1ec24aSNiels Sascha Reedijk
323*c4b9309aSJohn Scipione	\return Whether or not the object has already been archived.
3240e1ec24aSNiels Sascha Reedijk	\retval true \c archivable has been archived in this archiving session.
3250e1ec24aSNiels Sascha Reedijk	\retval false \c archivable has not been archived in this archiving session.
326*c4b9309aSJohn Scipione
327*c4b9309aSJohn Scipione	\since Haiku R1
3280e1ec24aSNiels Sascha Reedijk*/
3290e1ec24aSNiels Sascha Reedijk
3300e1ec24aSNiels Sascha Reedijk
3310e1ec24aSNiels Sascha Reedijk/*!
3320e1ec24aSNiels Sascha Reedijk	\fn status_t BArchiver::Finish(status_t err = B_OK);
3330e1ec24aSNiels Sascha Reedijk	\brief Report any archiving errors and possibly complete the archiving
3340e1ec24aSNiels Sascha Reedijk	       session.
3350e1ec24aSNiels Sascha Reedijk
3360e1ec24aSNiels Sascha Reedijk	This method may finish an archiving session (triggering the call of all
3370e1ec24aSNiels Sascha Reedijk	archived objects' AllArchived() methods) if the following conditions
3380e1ec24aSNiels Sascha Reedijk	are true:
339*c4b9309aSJohn Scipione	- No errors have been reported to this or any other BArchiver object
3400e1ec24aSNiels Sascha Reedijk	  within this session.
341*c4b9309aSJohn Scipione	- This is the last remaining BArchiver that has not had its Finish()
3420e1ec24aSNiels Sascha Reedijk	  method invoked.
343*c4b9309aSJohn Scipione
3440e1ec24aSNiels Sascha Reedijk	If you call this method with an error code not equal to B_OK, then this
3450e1ec24aSNiels Sascha Reedijk	archiving session has failed, archived objects will not have their
3460e1ec24aSNiels Sascha Reedijk	AllArchived() methods called, and any subsequent calls to this method
3470e1ec24aSNiels Sascha Reedijk	on any BArchiver objects in this session will return your error code.
348*c4b9309aSJohn Scipione
349*c4b9309aSJohn Scipione	\return The first error reported in this archiving session, or \c B_OK.
350*c4b9309aSJohn Scipione
351*c4b9309aSJohn Scipione	\since Haiku R1
3520e1ec24aSNiels Sascha Reedijk*/
3530e1ec24aSNiels Sascha Reedijk
3540e1ec24aSNiels Sascha Reedijk
3550e1ec24aSNiels Sascha Reedijk/*!
3560e1ec24aSNiels Sascha Reedijk	\fn const BMessage*	BArchiver::ArchiveMessage() const
3570e1ec24aSNiels Sascha Reedijk	\brief Returns the BMessage* used to construct this BArchiver. This is
3580e1ec24aSNiels Sascha Reedijk	       the archive that AddArchivable() modifies.
359*c4b9309aSJohn Scipione
360*c4b9309aSJohn Scipione	\since Haiku R1
3610e1ec24aSNiels Sascha Reedijk*/
3620e1ec24aSNiels Sascha Reedijk
3630e1ec24aSNiels Sascha Reedijk
3640e1ec24aSNiels Sascha Reedijk///// BUnarchiver /////
3650e1ec24aSNiels Sascha Reedijk
3660e1ec24aSNiels Sascha Reedijk
3670e1ec24aSNiels Sascha Reedijk/*!
3680e1ec24aSNiels Sascha Reedijk	\class BUnarchiver
3690e1ec24aSNiels Sascha Reedijk	\ingroup support
3700e1ec24aSNiels Sascha Reedijk	\ingroup libbe
3710e1ec24aSNiels Sascha Reedijk	\brief A class that simplifies the unarchiving of complicated BArchivable
3720e1ec24aSNiels Sascha Reedijk	       hierarchies.
3730e1ec24aSNiels Sascha Reedijk
3740e1ec24aSNiels Sascha Reedijk	The BUnarchiver class is a small class used to recover BArchivable objects
3750e1ec24aSNiels Sascha Reedijk	that have been archived with the BArchiver class. It also provides ownership
3760e1ec24aSNiels Sascha Reedijk	semantics, so that memory leaks can be avoided during the unarchival
3770e1ec24aSNiels Sascha Reedijk	process. When retrieving an object (either via GetObject() or FindObject()),
3780e1ec24aSNiels Sascha Reedijk	you can specify a BUnarchiver::ownership_policy. If you specify
3790e1ec24aSNiels Sascha Reedijk	BUnarchiver::B_ASSUME_OWNERSHIP, you will become responsible for deleting
3800e1ec24aSNiels Sascha Reedijk	the retrieved item. If you specify BUnarchiver::B_DONT_ASSUME_OWNERSHIP,
3810e1ec24aSNiels Sascha Reedijk	you will not become responsible. You cannot take ownership of the same
3820e1ec24aSNiels Sascha Reedijk	object twice. After the unarchival process finishes, any unclaimed objects,
3830e1ec24aSNiels Sascha Reedijk	excluding the root object (the object being instantiated via
3840e1ec24aSNiels Sascha Reedijk	instantiate_object() or BUnarchiver::InstantiateObject()), will be deleted.
3850e1ec24aSNiels Sascha Reedijk
3860e1ec24aSNiels Sascha Reedijk	If you are updating a class that previously did not use the BArchiver and
3870e1ec24aSNiels Sascha Reedijk	BUnarchiver helper classes, and want to maintain backwards compatibility
3880e1ec24aSNiels Sascha Reedijk	with old archive, this can be done using the IsArchiveManaged() method.
3890e1ec24aSNiels Sascha Reedijk
390*c4b9309aSJohn Scipione	\warning Calling methods on your BUnarchiver with a legacy archive (one
391*c4b9309aSJohn Scipione	         that was not managed by a BArchiver during archival) will result
392*c4b9309aSJohn Scipione	         in a call to debugger().
393*c4b9309aSJohn Scipione
394*c4b9309aSJohn Scipione	\since Haiku R1
3950e1ec24aSNiels Sascha Reedijk*/
3960e1ec24aSNiels Sascha Reedijk
3970e1ec24aSNiels Sascha Reedijk
3980e1ec24aSNiels Sascha Reedijk/*!
3990e1ec24aSNiels Sascha Reedijk	\fn BUnarchiver::BUnarchiver(const BMessage* archive)
4000e1ec24aSNiels Sascha Reedijk	\brief Constructs a BUnarchiver object to manage \c archive.
4010e1ec24aSNiels Sascha Reedijk
4020e1ec24aSNiels Sascha Reedijk	\note To guarantee that your AllUnarchived() method will be called during
4030e1ec24aSNiels Sascha Reedijk	      archival, you must create a BUnarchiver object in your archive
4040e1ec24aSNiels Sascha Reedijk	      constructor. It is necessary to do this even if you won't use the
4050e1ec24aSNiels Sascha Reedijk	      BUnarchiver object in your archive constructor.
4060e1ec24aSNiels Sascha Reedijk
4070e1ec24aSNiels Sascha Reedijk	\warning Do not construct a BUnarchiver object without first calling
408*c4b9309aSJohn Scipione	         BUnarchiver::PrepareArchive() on \c archive. It is only safe to
409*c4b9309aSJohn Scipione	         build a BUnarchiver without this call in your AllUnarchived()
410*c4b9309aSJohn Scipione	         implementation.
4110e1ec24aSNiels Sascha Reedijk
4120e1ec24aSNiels Sascha Reedijk	\see BUnarchiver::PrepareArchive()
413*c4b9309aSJohn Scipione
414*c4b9309aSJohn Scipione	\since Haiku R1
4150e1ec24aSNiels Sascha Reedijk*/
4160e1ec24aSNiels Sascha Reedijk
4170e1ec24aSNiels Sascha Reedijk
4180e1ec24aSNiels Sascha Reedijk/*!
4190e1ec24aSNiels Sascha Reedijk	\fn BUnarchiver::~BUnarchiver()
4200e1ec24aSNiels Sascha Reedijk	\brief Destroys a BUnarchiver object.
4210e1ec24aSNiels Sascha Reedijk
4220e1ec24aSNiels Sascha Reedijk	Calls this objects Finish() method, if it has not yet been called.
423*c4b9309aSJohn Scipione
424*c4b9309aSJohn Scipione	\since Haiku R1
4250e1ec24aSNiels Sascha Reedijk*/
4260e1ec24aSNiels Sascha Reedijk
4270e1ec24aSNiels Sascha Reedijk
4280e1ec24aSNiels Sascha Reedijk/*!
4290e1ec24aSNiels Sascha Reedijk	\fn status_t BUnarchiver::EnsureUnarchived(int32 token)
4300e1ec24aSNiels Sascha Reedijk	\brief Ensure the object represented by \a token is unarchived and
4310e1ec24aSNiels Sascha Reedijk	       instantiated.
4320e1ec24aSNiels Sascha Reedijk
4330e1ec24aSNiels Sascha Reedijk	\param token the object \a token
4340e1ec24aSNiels Sascha Reedijk
4350e1ec24aSNiels Sascha Reedijk	\returns A status code.
436*c4b9309aSJohn Scipione
437*c4b9309aSJohn Scipione	\since Haiku R1
4380e1ec24aSNiels Sascha Reedijk*/
4390e1ec24aSNiels Sascha Reedijk
4400e1ec24aSNiels Sascha Reedijk
4410e1ec24aSNiels Sascha Reedijk/*!
4420e1ec24aSNiels Sascha Reedijk	\fn status_t BUnarchiver::EnsureUnarchived(const char* name,
4430e1ec24aSNiels Sascha Reedijk		int32 index = 0)
4440e1ec24aSNiels Sascha Reedijk	\brief Ensure the object archived under \a name at \a index is unarchived
4450e1ec24aSNiels Sascha Reedijk	       and instantiated.
4460e1ec24aSNiels Sascha Reedijk
4470e1ec24aSNiels Sascha Reedijk	\param name The archive \a name.
4480e1ec24aSNiels Sascha Reedijk	\param index The archive \a index.
4490e1ec24aSNiels Sascha Reedijk
4500e1ec24aSNiels Sascha Reedijk	\returns A status code.
451*c4b9309aSJohn Scipione
452*c4b9309aSJohn Scipione	\since Haiku R1
4530e1ec24aSNiels Sascha Reedijk*/
4540e1ec24aSNiels Sascha Reedijk
4550e1ec24aSNiels Sascha Reedijk
4560e1ec24aSNiels Sascha Reedijk/*!
4570e1ec24aSNiels Sascha Reedijk	\fn bool BUnarchiver::IsInstantiated(int32 token)
4580e1ec24aSNiels Sascha Reedijk	\brief Checks whether the object represented by \c token has been
4590e1ec24aSNiels Sascha Reedijk	       instantiated in this session.
4600e1ec24aSNiels Sascha Reedijk
4610e1ec24aSNiels Sascha Reedijk	\param token The object \a token.
4620e1ec24aSNiels Sascha Reedijk
4630e1ec24aSNiels Sascha Reedijk	\returns \c true if instantiated, \c false otherwise
464*c4b9309aSJohn Scipione
465*c4b9309aSJohn Scipione	\since Haiku R1
4660e1ec24aSNiels Sascha Reedijk*/
4670e1ec24aSNiels Sascha Reedijk
4680e1ec24aSNiels Sascha Reedijk
4690e1ec24aSNiels Sascha Reedijk/*!
4700e1ec24aSNiels Sascha Reedijk	\fn bool BUnarchiver::IsInstantiated(const char* name, int32 index = 0)
4710e1ec24aSNiels Sascha Reedijk	\brief Checks whether the object archived under \a name at \a index has been
4720e1ec24aSNiels Sascha Reedijk	       instantiated in this session.
4730e1ec24aSNiels Sascha Reedijk
4740e1ec24aSNiels Sascha Reedijk	\param name The archive \a name.
4750e1ec24aSNiels Sascha Reedijk	\param index The arcive \a token.
4760e1ec24aSNiels Sascha Reedijk
4770e1ec24aSNiels Sascha Reedijk	\returns \c true if instantiated, \c false otherwise.
478*c4b9309aSJohn Scipione
479*c4b9309aSJohn Scipione	\since Haiku R1
4800e1ec24aSNiels Sascha Reedijk*/
4810e1ec24aSNiels Sascha Reedijk
4820e1ec24aSNiels Sascha Reedijk
4830e1ec24aSNiels Sascha Reedijk/*!
4840e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::GetObject(int32 token,
4850e1ec24aSNiels Sascha Reedijk		ownership_policy owning, T*& object)
4860e1ec24aSNiels Sascha Reedijk	\brief Recover an object by token that was archived by a BArchiver object.
4870e1ec24aSNiels Sascha Reedijk	If the object has not yet been instantiated, and this request is not coming
4880e1ec24aSNiels Sascha Reedijk	from an AllUnarchived() implementation, the object will be instantiated now.
4890e1ec24aSNiels Sascha Reedijk
4900e1ec24aSNiels Sascha Reedijk	If the retrieved object is not of the type T, then this method will fail.
4910e1ec24aSNiels Sascha Reedijk	If this method fails, you will not receive ownership of the object, no
4920e1ec24aSNiels Sascha Reedijk	matter what you specified in \c owning.
4930e1ec24aSNiels Sascha Reedijk
4940e1ec24aSNiels Sascha Reedijk	\tparam T The type of \a object you wish to find.
4950e1ec24aSNiels Sascha Reedijk
4960e1ec24aSNiels Sascha Reedijk	\param token The \a token you got for this object from
4970e1ec24aSNiels Sascha Reedijk	       BArchiver::GetTokenForArchivable() during archival.
4980e1ec24aSNiels Sascha Reedijk	\param owning Whether or not you wish to take ownership of the
4990e1ec24aSNiels Sascha Reedijk	       retrieved object.
5000e1ec24aSNiels Sascha Reedijk	\param object Return parameter for the retrieved object of type T.
5010e1ec24aSNiels Sascha Reedijk
5020e1ec24aSNiels Sascha Reedijk	\returns A status code.
5030e1ec24aSNiels Sascha Reedijk	\retval B_OK The object retrieved was of type T.
5040e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The object retrieved was not of type T.
505*c4b9309aSJohn Scipione
506*c4b9309aSJohn Scipione	\since Haiku R1
5070e1ec24aSNiels Sascha Reedijk*/
5080e1ec24aSNiels Sascha Reedijk
5090e1ec24aSNiels Sascha Reedijk
5100e1ec24aSNiels Sascha Reedijk/*!
5110e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::GetObject(int32 token,
5120e1ec24aSNiels Sascha Reedijk		T*& object)
5130e1ec24aSNiels Sascha Reedijk	\brief Recover and take ownership of an object represented by \a token.
5140e1ec24aSNiels Sascha Reedijk
5150e1ec24aSNiels Sascha Reedijk	Equivalent to calling GetObject(token, \c B_ASSUME_OWNERSHIP, object)
5160e1ec24aSNiels Sascha Reedijk
5170e1ec24aSNiels Sascha Reedijk	\tparam T The type of \a object you wish to find.
5180e1ec24aSNiels Sascha Reedijk
5190e1ec24aSNiels Sascha Reedijk	\param token The \a token you got for this object from
5200e1ec24aSNiels Sascha Reedijk	       BArchiver::GetTokenForArchivable() during archival.
5210e1ec24aSNiels Sascha Reedijk	\param object The return parameter for the retrieved object of type T.
5220e1ec24aSNiels Sascha Reedijk
5230e1ec24aSNiels Sascha Reedijk	\returns A status code.
5240e1ec24aSNiels Sascha Reedijk	\retval B_OK The object retrieved was of type T.
5250e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The object retrieved was not of type T.
526*c4b9309aSJohn Scipione
527*c4b9309aSJohn Scipione	\since Haiku R1
5280e1ec24aSNiels Sascha Reedijk*/
5290e1ec24aSNiels Sascha Reedijk
5300e1ec24aSNiels Sascha Reedijk
5310e1ec24aSNiels Sascha Reedijk/*!
5320e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::FindObject(const char* name,
5330e1ec24aSNiels Sascha Reedijk		int32 index, ownership_policy owning, T*& object)
5340e1ec24aSNiels Sascha Reedijk	\brief Recover an object that had previously been archived using
5350e1ec24aSNiels Sascha Reedijk	       the BArchiver::AddArchivable() method.
5360e1ec24aSNiels Sascha Reedijk
5370e1ec24aSNiels Sascha Reedijk	If the object has not yet been instantiated, and this request is not
5380e1ec24aSNiels Sascha Reedijk	coming from an AllUnarchived() implementation, the object will be
5390e1ec24aSNiels Sascha Reedijk	instantiated now.
5400e1ec24aSNiels Sascha Reedijk
5410e1ec24aSNiels Sascha Reedijk	If the retrieved object is not of the type T, then this method will fail.
5420e1ec24aSNiels Sascha Reedijk	If this method fails, you will not receive ownership of the object, no
5430e1ec24aSNiels Sascha Reedijk	matter what you specified in \c owning.
5440e1ec24aSNiels Sascha Reedijk
5450e1ec24aSNiels Sascha Reedijk	\tparam T The type of object you wish to find.
5460e1ec24aSNiels Sascha Reedijk
5470e1ec24aSNiels Sascha Reedijk	\param name The name that was passed to BArchiver::AddArchivable() when
5480e1ec24aSNiels Sascha Reedijk	       adding this object.
5490e1ec24aSNiels Sascha Reedijk	\param index The index of the object you wish to recover (\c 0-based,
5500e1ec24aSNiels Sascha Reedijk	       like BMessage::FindData().
5510e1ec24aSNiels Sascha Reedijk	\param owning Dictates whether or not you wish to take ownership of the
5520e1ec24aSNiels Sascha Reedijk	       retrieved object.
5530e1ec24aSNiels Sascha Reedijk	\param object Return parameter for the retrieved object of type T.
5540e1ec24aSNiels Sascha Reedijk
5550e1ec24aSNiels Sascha Reedijk	\returns A status code.
5560e1ec24aSNiels Sascha Reedijk	\retval B_OK The object retrieved was of type T.
5570e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The object retrieved was not of type T.
558*c4b9309aSJohn Scipione
559*c4b9309aSJohn Scipione	\since Haiku R1
5600e1ec24aSNiels Sascha Reedijk*/
5610e1ec24aSNiels Sascha Reedijk
5620e1ec24aSNiels Sascha Reedijk
5630e1ec24aSNiels Sascha Reedijk/*!
5640e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::FindObject(const char* name,
5650e1ec24aSNiels Sascha Reedijk		int32 index, T*& object)
5660e1ec24aSNiels Sascha Reedijk	\brief Recover and take ownership of an object that had previously been
5670e1ec24aSNiels Sascha Reedijk	       archived using the BArchiver::AddArchivable() method.
5680e1ec24aSNiels Sascha Reedijk
5690e1ec24aSNiels Sascha Reedijk	\tparam T The type of object you wish to find.
5700e1ec24aSNiels Sascha Reedijk
5710e1ec24aSNiels Sascha Reedijk	\param name The name that was passed to BArchiver::AddArchivable() when
5720e1ec24aSNiels Sascha Reedijk	       adding this object.
5730e1ec24aSNiels Sascha Reedijk	\param index The index of the object you wish to recover (\c 0-based,
5740e1ec24aSNiels Sascha Reedijk	       like #BMessage::FindData().
5750e1ec24aSNiels Sascha Reedijk	\param object Return parameter for the retrieved object of type T.
5760e1ec24aSNiels Sascha Reedijk
5770e1ec24aSNiels Sascha Reedijk	\returns A status code.
5780e1ec24aSNiels Sascha Reedijk	\retval B_OK The object retrieved was of type T.
5790e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The object retrieved was not of type T.
580*c4b9309aSJohn Scipione
581*c4b9309aSJohn Scipione	\since Haiku R1
5820e1ec24aSNiels Sascha Reedijk*/
5830e1ec24aSNiels Sascha Reedijk
5840e1ec24aSNiels Sascha Reedijk
5850e1ec24aSNiels Sascha Reedijk/*!
5860e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::FindObject(const char* name,
5870e1ec24aSNiels Sascha Reedijk		ownership_policy owning, T*& object)
5880e1ec24aSNiels Sascha Reedijk	\brief Recover an object at index \c 0 that had previously been
5890e1ec24aSNiels Sascha Reedijk	       archived using the BArchiver::AddArchivable() method.
5900e1ec24aSNiels Sascha Reedijk
5910e1ec24aSNiels Sascha Reedijk	Equivalent to calling FindObject(name, \c 0, owning, object).
5920e1ec24aSNiels Sascha Reedijk
5930e1ec24aSNiels Sascha Reedijk	\tparam T The type of \a object you wish to find.
5940e1ec24aSNiels Sascha Reedijk
5950e1ec24aSNiels Sascha Reedijk	\param name The name that was passed to BArchiver::AddArchivable() when
5960e1ec24aSNiels Sascha Reedijk	       adding this object.
5970e1ec24aSNiels Sascha Reedijk	\param owning Dictates whether or not you wish to take ownership of the
5980e1ec24aSNiels Sascha Reedijk	       retrieved object.
5990e1ec24aSNiels Sascha Reedijk	\param object Return parameter for the retrieved object of type T.
6000e1ec24aSNiels Sascha Reedijk
6010e1ec24aSNiels Sascha Reedijk	\returns A status code.
6020e1ec24aSNiels Sascha Reedijk	\retval B_OK The object retrieved was of type T.
6030e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The object retrieved was not of type T.
604*c4b9309aSJohn Scipione
605*c4b9309aSJohn Scipione	\since Haiku R1
6060e1ec24aSNiels Sascha Reedijk*/
6070e1ec24aSNiels Sascha Reedijk
6080e1ec24aSNiels Sascha Reedijk
6090e1ec24aSNiels Sascha Reedijk/*!
6100e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::FindObject(const char* name,
6110e1ec24aSNiels Sascha Reedijk		T*& object)
6120e1ec24aSNiels Sascha Reedijk	\brief Recover and take ownership of an object at index \c 0 that had
6130e1ec24aSNiels Sascha Reedijk		previously been archived using the BArchiver::AddArchivable() method.
6140e1ec24aSNiels Sascha Reedijk
6150e1ec24aSNiels Sascha Reedijk	Equivalent to calling FindObject(name, \c 0,
6160e1ec24aSNiels Sascha Reedijk	BUnarchiver::B_ASSUME_OWNERSHIP, object).
6170e1ec24aSNiels Sascha Reedijk
6180e1ec24aSNiels Sascha Reedijk	\tparam T The type of \a object you wish to find.
6190e1ec24aSNiels Sascha Reedijk
6200e1ec24aSNiels Sascha Reedijk	\param name The name that was passed to BArchiver::AddArchivable() when
6210e1ec24aSNiels Sascha Reedijk	       adding this object.
6220e1ec24aSNiels Sascha Reedijk	\param object Return parameter for the retrieved \a object of type T.
6230e1ec24aSNiels Sascha Reedijk
6240e1ec24aSNiels Sascha Reedijk	\returns A status code.
6250e1ec24aSNiels Sascha Reedijk	\retval B_OK The \a object retrieved was of type T.
6260e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The \a object retrieved was not of type T.
627*c4b9309aSJohn Scipione
628*c4b9309aSJohn Scipione	\since Haiku R1
6290e1ec24aSNiels Sascha Reedijk*/
6300e1ec24aSNiels Sascha Reedijk
6310e1ec24aSNiels Sascha Reedijk
6320e1ec24aSNiels Sascha Reedijk/*!
6330e1ec24aSNiels Sascha Reedijk	\fn status_t BUnarchiver::Finish(status_t err = B_OK);
6340e1ec24aSNiels Sascha Reedijk	\brief Report any unarchiving errors and possibly complete the archiving
6350e1ec24aSNiels Sascha Reedijk	       session.
6360e1ec24aSNiels Sascha Reedijk
6370e1ec24aSNiels Sascha Reedijk	This method may finish an unarchiving session (triggering the call of all
6380e1ec24aSNiels Sascha Reedijk	instantiated objects' AllUnarchived() methods) if the following conditions
6390e1ec24aSNiels Sascha Reedijk	are true:
6400e1ec24aSNiels Sascha Reedijk
641*c4b9309aSJohn Scipione	- No errors have been reported to this or any other BUnarchiver
6420e1ec24aSNiels Sascha Reedijk	  object within this session.
643*c4b9309aSJohn Scipione	- This is the last remaining BUnarchiver that has not had its
6440e1ec24aSNiels Sascha Reedijk	  Finish() method invoked.
6450e1ec24aSNiels Sascha Reedijk
6460e1ec24aSNiels Sascha Reedijk	If you call this method with an error code not equal to B_OK, then this
6470e1ec24aSNiels Sascha Reedijk	unarchiving session has failed, instantiated objects will not have their
6480e1ec24aSNiels Sascha Reedijk	AllUnarchived() methods called, and any subsequent calls to this method
6490e1ec24aSNiels Sascha Reedijk	on any BUnarchiver objects in this session will return your error code.
6500e1ec24aSNiels Sascha Reedijk	Furthermore, any objects that have been instantiated, but have not had
6510e1ec24aSNiels Sascha Reedijk	their ownership assumed by another object will now be deleted (excluding
6520e1ec24aSNiels Sascha Reedijk	the root object).
6530e1ec24aSNiels Sascha Reedijk
6540e1ec24aSNiels Sascha Reedijk	\return The first error reported in this unarchiving session, or \c B_OK.
655*c4b9309aSJohn Scipione
656*c4b9309aSJohn Scipione	\since Haiku R1
6570e1ec24aSNiels Sascha Reedijk*/
6580e1ec24aSNiels Sascha Reedijk
6590e1ec24aSNiels Sascha Reedijk
6600e1ec24aSNiels Sascha Reedijk/*!
6610e1ec24aSNiels Sascha Reedijk	\fn const BMessage* BUnarchiver::ArchiveMessage() const
6620e1ec24aSNiels Sascha Reedijk	\brief Returns the BMessage* used to construct this BUnarchiver.
6630e1ec24aSNiels Sascha Reedijk
6640e1ec24aSNiels Sascha Reedijk	This is the archive that FindObject() uses.
6650e1ec24aSNiels Sascha Reedijk*/
6660e1ec24aSNiels Sascha Reedijk
6670e1ec24aSNiels Sascha Reedijk
6680e1ec24aSNiels Sascha Reedijk/*!
6690e1ec24aSNiels Sascha Reedijk	\fn static bool BUnarchiver::IsArchiveManaged(const BMessage* archive)
6700e1ec24aSNiels Sascha Reedijk	\brief Checks whether \a archive was managed by a BArchiver object.
6710e1ec24aSNiels Sascha Reedijk
6720e1ec24aSNiels Sascha Reedijk	This method can be used to maintain archive backwards-compatibility for a
6730e1ec24aSNiels Sascha Reedijk	class that has been updated to use the BArchiver class. If there is a
6740e1ec24aSNiels Sascha Reedijk	possibility that you are may dealing with a legacy archive, you can use
6750e1ec24aSNiels Sascha Reedijk	this method to find out before calling any methods on your BUnarchiver
6760e1ec24aSNiels Sascha Reedijk	object.
6770e1ec24aSNiels Sascha Reedijk
6780e1ec24aSNiels Sascha Reedijk	Here is an example of how you might use this method. Note that you
6790e1ec24aSNiels Sascha Reedijk	must still call PrepareArchive(archive) either way.
6800e1ec24aSNiels Sascha Reedijk
6810e1ec24aSNiels Sascha Reedijk\code
6820e1ec24aSNiels Sascha ReedijkMyArchivableClas::MyArchivableClass(BMessage* archive)
6830e1ec24aSNiels Sascha Reedijk    :
6840e1ec24aSNiels Sascha Reedijk    BArchivable(BUnarchiver::PrepareArchive(archive))
6850e1ec24aSNiels Sascha Reedijk{
6860e1ec24aSNiels Sascha Reedijk    BUnarchiver unarchiver(archive);
6870e1ec24aSNiels Sascha Reedijk
6880e1ec24aSNiels Sascha Reedijk    if (BUnarchiver::IsArchiveManaged(archive)) {
6890e1ec24aSNiels Sascha Reedijk        // ... calls to FindObject() or GetObject() here ...
6900e1ec24aSNiels Sascha Reedijk    } else {
6910e1ec24aSNiels Sascha Reedijk        // ... calls to BMessage::FindMessage() here ...
6920e1ec24aSNiels Sascha Reedijk    }
6930e1ec24aSNiels Sascha Reedijk}
6940e1ec24aSNiels Sascha Reedijk\endcode
6950e1ec24aSNiels Sascha Reedijk
6960e1ec24aSNiels Sascha Reedijk	\returns Whether \a archive was managed by a BArchiver object.
6970e1ec24aSNiels Sascha Reedijk	\retval true if \a archive was managed by a BArchiver object.
6980e1ec24aSNiels Sascha Reedijk	\retval false otherwise.
699*c4b9309aSJohn Scipione
700*c4b9309aSJohn Scipione	\since Haiku R1
7010e1ec24aSNiels Sascha Reedijk*/
7020e1ec24aSNiels Sascha Reedijk
7030e1ec24aSNiels Sascha Reedijk
7040e1ec24aSNiels Sascha Reedijk/*!
7050e1ec24aSNiels Sascha Reedijk	\fn static BMessage* BUnarchiver::PrepareArchive(BMessage* &archive)
7060e1ec24aSNiels Sascha Reedijk	\brief Prepares \c archive for use by a BUnarchiver.
7070e1ec24aSNiels Sascha Reedijk
7080e1ec24aSNiels Sascha Reedijk	This method must be called if you plan to use a BUnarchiver on an archive.
7090e1ec24aSNiels Sascha Reedijk	It must be called once for each class an object inherits from that
7100e1ec24aSNiels Sascha Reedijk	will use a BUnarchiver.
7110e1ec24aSNiels Sascha Reedijk
7120e1ec24aSNiels Sascha Reedijk	\warning This method \b must be called \b before a call to the
7130e1ec24aSNiels Sascha Reedijk		archive constructor of your parent class.
7140e1ec24aSNiels Sascha Reedijk
7150e1ec24aSNiels Sascha Reedijk	Notice the use of this method in the example provided below.
7160e1ec24aSNiels Sascha Reedijk\code
7170e1ec24aSNiels Sascha ReedijkMyArchivableClas::MyArchivableClas(BMessage* archive)
7180e1ec24aSNiels Sascha Reedijk    :
7190e1ec24aSNiels Sascha Reedijk    BArchivable(BUnarchiver::PrepareArchive(archive))
7200e1ec24aSNiels Sascha Reedijk{
7210e1ec24aSNiels Sascha Reedijk    // ...
7220e1ec24aSNiels Sascha Reedijk}
7230e1ec24aSNiels Sascha Reedijk\endcode
7240e1ec24aSNiels Sascha Reedijk
7250e1ec24aSNiels Sascha Reedijk	\param archive The archive you wish to have prepared.
7260e1ec24aSNiels Sascha Reedijk
7270e1ec24aSNiels Sascha Reedijk	\return The same #BMessage as is passed in.
728*c4b9309aSJohn Scipione
729*c4b9309aSJohn Scipione	\since Haiku R1
7300e1ec24aSNiels Sascha Reedijk*/
7310e1ec24aSNiels Sascha Reedijk
7320e1ec24aSNiels Sascha Reedijk
7330e1ec24aSNiels Sascha Reedijk/*!
7340e1ec24aSNiels Sascha Reedijk	\fn void BUnarchiver::AssumeOwnership(BArchivable* archivable)
7350e1ec24aSNiels Sascha Reedijk	\brief Become the owner of \a archivable.
7360e1ec24aSNiels Sascha Reedijk
7370e1ec24aSNiels Sascha Reedijk	After calling this method you are responsible for deleting the
7380e1ec24aSNiels Sascha Reedijk	\a archivable.
7390e1ec24aSNiels Sascha Reedijk
7400e1ec24aSNiels Sascha Reedijk	\param archivable The \a archivable object.
741*c4b9309aSJohn Scipione
742*c4b9309aSJohn Scipione	\since Haiku R1
7430e1ec24aSNiels Sascha Reedijk*/
7440e1ec24aSNiels Sascha Reedijk
7450e1ec24aSNiels Sascha Reedijk
7460e1ec24aSNiels Sascha Reedijk/*!
7470e1ec24aSNiels Sascha Reedijk	\fn void BUnarchiver::RelinquishOwnership(BArchivable* archivable)
7480e1ec24aSNiels Sascha Reedijk	\brief Relinquish ownership of \a archivable. If \a archivable remains
7490e1ec24aSNiels Sascha Reedijk	       unclaimed at the end of the unarchiving session, it will be deleted
7500e1ec24aSNiels Sascha Reedijk	       (unless it is the root object).
7510e1ec24aSNiels Sascha Reedijk
7520e1ec24aSNiels Sascha Reedijk	\param archivable The \a archivable object.
753*c4b9309aSJohn Scipione
754*c4b9309aSJohn Scipione	\since Haiku R1
7550e1ec24aSNiels Sascha Reedijk*/
7560e1ec24aSNiels Sascha Reedijk
7570e1ec24aSNiels Sascha Reedijk
7580e1ec24aSNiels Sascha Reedijk/*!
7590e1ec24aSNiels Sascha Reedijk	\fn template<class T> status_t BUnarchiver::InstantiateObject(
7600e1ec24aSNiels Sascha Reedijk		BMessage* from, T*& object)
7610e1ec24aSNiels Sascha Reedijk	\brief Attempt to instantiate an object of type T from BMessage*
7620e1ec24aSNiels Sascha Reedijk	       \a from.
7630e1ec24aSNiels Sascha Reedijk
7640e1ec24aSNiels Sascha Reedijk	If the instantiated object is not of type T, then it will be deleted,
7650e1ec24aSNiels Sascha Reedijk	and this method will return \c B_BAD_TYPE. This method is similar to
7660e1ec24aSNiels Sascha Reedijk	the instantiate_object() function, but provides error reporting and
7670e1ec24aSNiels Sascha Reedijk	protection from memory leaks.
7680e1ec24aSNiels Sascha Reedijk
7690e1ec24aSNiels Sascha Reedijk	\param from The #BMessage to instantiate from.
7700e1ec24aSNiels Sascha Reedijk	\param object Return parameter for the retrieved object of type T.
7710e1ec24aSNiels Sascha Reedijk
7720e1ec24aSNiels Sascha Reedijk	\returns A status code.
7730e1ec24aSNiels Sascha Reedijk	\retval B_OK The object retrieved was of type T.
7740e1ec24aSNiels Sascha Reedijk	\retval B_BAD_TYPE The object retrieved was not of type T.
775*c4b9309aSJohn Scipione
776*c4b9309aSJohn Scipione	\since Haiku R1
7770e1ec24aSNiels Sascha Reedijk*/
7780e1ec24aSNiels Sascha Reedijk
7790e1ec24aSNiels Sascha Reedijk
78037503f54SNiels Sascha Reedijk///// Global methods /////
781820dca4dSJohn Scipione
782820dca4dSJohn Scipione
78381071f5eSNiels Sascha Reedijk/*!
78481071f5eSNiels Sascha Reedijk	\addtogroup support_globals
78581071f5eSNiels Sascha Reedijk*/
78681071f5eSNiels Sascha Reedijk
78755f7db1bSNiels Sascha Reedijk
788820dca4dSJohn Scipione//! @{
789820dca4dSJohn Scipione
790820dca4dSJohn Scipione
791820dca4dSJohn Scipione/*!
792820dca4dSJohn Scipione	\typedef typedef BArchivable* (*instantiation_func)(BMessage*)
79381071f5eSNiels Sascha Reedijk	\brief Internal definition of a function that can instantiate objects that
79481071f5eSNiels Sascha Reedijk	       have been created with the BArchivable API.
795*c4b9309aSJohn Scipione
796*c4b9309aSJohn Scipione	\since BeOS R3
79781071f5eSNiels Sascha Reedijk*/
79881071f5eSNiels Sascha Reedijk
79955f7db1bSNiels Sascha Reedijk
8006ac7032dSJohn Scipione/*!
8016ac7032dSJohn Scipione	\fn BArchivable* instantiate_object(BMessage *from, image_id *id)
80281071f5eSNiels Sascha Reedijk	\brief Instantiate an archived object with the object being defined in a
80381071f5eSNiels Sascha Reedijk	       different application or library.
80481071f5eSNiels Sascha Reedijk
80581071f5eSNiels Sascha Reedijk	This function is similar to instantiate_object(BMessage *from), except that
806e3c5ca85SNiels Sascha Reedijk	it takes the \a id argument referring to an image where the object might be
80737503f54SNiels Sascha Reedijk	stored.
80881071f5eSNiels Sascha Reedijk
80937503f54SNiels Sascha Reedijk	\note Images are names for executable files. Image id's refer to these
810*c4b9309aSJohn Scipione	      executable files that have been loaded by your application. Have a
811*c4b9309aSJohn Scipione	      look at the kernel API for further information.
812*c4b9309aSJohn Scipione
813*c4b9309aSJohn Scipione	\since BeOS R3
81481071f5eSNiels Sascha Reedijk*/
81581071f5eSNiels Sascha Reedijk
81655f7db1bSNiels Sascha Reedijk
8176ac7032dSJohn Scipione/*!
8186ac7032dSJohn Scipione	\fn BArchivable* instantiate_object(BMessage *from)
81981071f5eSNiels Sascha Reedijk	\brief Instantiate an archived object.
82081071f5eSNiels Sascha Reedijk
82137503f54SNiels Sascha Reedijk	This global function will determine the base class, based on the \a from
82281071f5eSNiels Sascha Reedijk	argument, and it will call the Instantiate() function of that object to
82381071f5eSNiels Sascha Reedijk	restore it.
82481071f5eSNiels Sascha Reedijk
82581071f5eSNiels Sascha Reedijk	\param from The archived object.
826*c4b9309aSJohn Scipione
82781071f5eSNiels Sascha Reedijk	\return The object returns a pointer to the instantiated object, or \c NULL
828*c4b9309aSJohn Scipione	        if the instantiation failed. The global \c errno variable will
829*c4b9309aSJohn Scipione	        contain the reason why it failed.
830*c4b9309aSJohn Scipione
83181071f5eSNiels Sascha Reedijk	\see instantiate_object(BMessage *from, image_id *id)
832*c4b9309aSJohn Scipione
833*c4b9309aSJohn Scipione	\since BeOS R3
83481071f5eSNiels Sascha Reedijk*/
83581071f5eSNiels Sascha Reedijk
83655f7db1bSNiels Sascha Reedijk
8376ac7032dSJohn Scipione/*!
8386ac7032dSJohn Scipione	\fn bool validate_instantiation(BMessage* from, const char* className)
83981071f5eSNiels Sascha Reedijk	\brief Internal function that checks if the \a className is the same as the
84081071f5eSNiels Sascha Reedijk	       one stored in the \a from message.
841*c4b9309aSJohn Scipione
842*c4b9309aSJohn Scipione	\since BeOS R3
84381071f5eSNiels Sascha Reedijk*/
84481071f5eSNiels Sascha Reedijk
84555f7db1bSNiels Sascha Reedijk
8466ac7032dSJohn Scipione/*!
8476ac7032dSJohn Scipione	\fn instantiation_func find_instantiation_func(const char* className,
84855f7db1bSNiels Sascha Reedijk		const char* signature)
84981071f5eSNiels Sascha Reedijk	\brief Internal function that searches for the instantiation func with a
85081071f5eSNiels Sascha Reedijk	       specific signature. Use instantiate_object() instead.
851*c4b9309aSJohn Scipione
852*c4b9309aSJohn Scipione	\since Haiku R1
85381071f5eSNiels Sascha Reedijk*/
85481071f5eSNiels Sascha Reedijk
85555f7db1bSNiels Sascha Reedijk
8566ac7032dSJohn Scipione/*!
8576ac7032dSJohn Scipione	\fn instantiation_func find_instantiation_func(const char* className)
85881071f5eSNiels Sascha Reedijk	\brief Internal function that searches for the instantiation func of a
85981071f5eSNiels Sascha Reedijk	       specific class. Use instantiate_object() instead.
860*c4b9309aSJohn Scipione
861*c4b9309aSJohn Scipione	\since BeOS R3
86281071f5eSNiels Sascha Reedijk*/
86381071f5eSNiels Sascha Reedijk
86455f7db1bSNiels Sascha Reedijk
8656ac7032dSJohn Scipione/*!
8666ac7032dSJohn Scipione	\fn instantiation_func find_instantiation_func(BMessage* archive)
86781071f5eSNiels Sascha Reedijk	\brief Internal function that searches for the instantiation func that
86881071f5eSNiels Sascha Reedijk	       works on the specified \a archive. Use instantiate_object() instead.
869*c4b9309aSJohn Scipione
870*c4b9309aSJohn Scipione	\since BeOS R3
87181071f5eSNiels Sascha Reedijk*/
87281071f5eSNiels Sascha Reedijk
87355f7db1bSNiels Sascha Reedijk
87481071f5eSNiels Sascha Reedijk//! @}
875