1/* 2 * Copyright 2007 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Niels Sascha Reedijk, niels.reedijk@gmail.com 7 * Alex Wilson, yourpalal2@gmail.com 8 * John Scipione, jscipione@gmail.com 9 * 10 * Proofreader: 11 * David Weizades, ddewbofh@hotmail.com 12 * Thom Holwerda, slakje@quicknet.nl 13 * 14 * Corresponds to: 15 * headers/os/support/Archivable.h rev 37751 16 * src/kits/support/Archivable.cpp rev 44303 17 */ 18 19 20/*! 21 \file Archivable.h 22 \ingroup support 23 \ingroup libbe 24 \brief Provides the BArchivable interface and declares the BArchiver and 25 BUnarchiver classes. 26*/ 27 28 29/*! 30 \class BArchivable 31 \ingroup support 32 \ingroup libbe 33 \brief Interface for objects that can be archived into a BMessage. 34 35 BArchivable provides an interface for objects that can be put into message 36 archives and extracted into objects in another location. Using this you are 37 able to send objects between applications, or even between computers across 38 networks. 39 40 BArchivable differs from BFlattenable in that BFlattenable is designed to 41 store objects into flat streams of data, the main objective being storage to 42 disk. The objective of this interface, however, is to store objects that 43 will later be restored as new (but identical) objects. To illustrate this 44 point, BArchivable objects can be restored automatically to the correct 45 class, whereas BFlattenable objects have a data type which you need to map 46 to classes manually. 47 48 Archiving is done with the Archive() method. If your class supports it, the 49 caller can request it to store into a deep archive, meaning that all child 50 objects in it will be stored. Extracting the archive works with the 51 Instantiate() method, which is static. Since the interface is designed to 52 extract objects without the caller knowing what kind of object it actually 53 is, the global function #instantiate_object() instantiates a message without 54 you manually having to determine the class the message is from. This adds 55 considerable flexibility and allows BArchivable to be used in combination 56 with other add-ons. 57 58 To provide this interface in your classes you should publicly inherit this 59 class. You should implement Archive() and Instantiate(), and provide one 60 constructor that takes one BMessage argument. 61 62 If your class holds references to other BArchivable objects that you wish 63 to archive, then you should consider using the BArchiver and BUnarchiver 64 classes in your Archive() method and archive constructor, respectively. 65 You should also consider implementing the AllArchived() and AllUnarchived() 66 methods, which were designed to ease archiving and unarchiving in such 67 a situation. 68 69 \since BeOS R3 70*/ 71 72 73/*! 74 \fn BArchivable::BArchivable(BMessage* from) 75 \brief Constructor. Does important behind-the-scenes work in the 76 unarchiving process. 77 78 If you inherit this interface you should provide at least one constructor 79 that takes one BMessage argument. In that constructor, you should call 80 your parent class' archive constructor (even if your parent class is 81 BArchivable). 82 83 \since BeOS R3 84*/ 85 86 87/*! 88 \fn BArchivable::BArchivable() 89 \brief Constructor. Does nothing. 90 91 \since BeOS R3 92*/ 93 94 95/*! 96 \fn BArchivable::~BArchivable() 97 \brief Destructor. Does nothing. 98 99 \since BeOS R3 100*/ 101 102 103/*! 104 \fn virtual status_t BArchivable::Archive(BMessage* into, bool deep) const 105 \brief Archive the object into a BMessage. 106 107 You should call this method from your derived implementation as it adds the 108 data needed to instantiate your object to the message. 109 110 \param into The message you store your object in. 111 \param deep If \c true, all children of this object should be archived as 112 well. 113 114 \retval B_OK The archive operation was successful. 115 \retval B_BAD_VALUE \c NULL \a archive message. 116 \retval B_ERROR The archive operation failed. 117 118 \since BeOS R3 119*/ 120 121 122/*! 123 \fn static BArchivable* BArchivable::Instantiate(BMessage* archive) 124 \brief Static member to restore objects from messages. 125 126 You should always check that the \a archive argument actually corresponds to 127 your class. The automatic functions, such as #instantiate_object() and 128 BUnarchiver::InstantiateObject() will not choose the wrong class but manual 129 calls to this member might be faulty. You can verify that \c archive 130 stores an object of your class with the validate_instantiation() function. 131 132 \param archive The message with the data of the object to restore. 133 134 \return A pointer to a BArchivable object. 135 \retval You should return a pointer to the object you create with 136 \c archive, or \c NULL if the unarchival fails. 137 138 \warning The default implementation will always return \c NULL. Even though 139 it is possible to store plain BArchivable objects, it is impossible to 140 restore them. 141 142 \see instantiate_object(BMessage*) 143 \see BUnarchiver::InstantiateObject() 144 145 \since BeOS R3 146*/ 147 148 149/*! 150 \fn virtual status_t BArchivable::Perform(perform_code d, void* arg) 151 \brief Perform some action (Internal method defined for binary 152 compatibility purposes). 153 154 \internal This method is defined for binary compatibility purposes, it is 155 used to ensure that the correct AllUnarchived() and AllArchived() 156 methods are called for objects, as those methods are new to 157 Haiku. 158 159 \param d The perform code. 160 \param arg A pointer to store some data. 161 162 \returns A status code. 163 164 \since Haiku R1 165*/ 166 167 168/*! 169 \fn virtual status_t BArchivable::AllUnarchived(const BMessage* archive) 170 \brief Method relating to the use of \c BUnarchiver. 171 172 This hook function is called triggered in the BUnarchiver::Finish() method. 173 In this method, you can rebuild references to objects that may be direct 174 children of your object, or may be children of other objects. 175 Implementations of this method should call the implementation of 176 their parent class, the same as for the Archive() method. 177 178 \warning To guarantee that your AllUnarchived() method will be called 179 during unarchival, you must create a BUnarchiver object in your 180 archive constructor. 181 182 \see BUnarchiver, BUnarchiver::Finish() 183 184 \since Haiku R1 185*/ 186 187 188/*! \fn virtual status_t BArchivable::AllArchived(BMessage* into) const 189 \brief Method relating to the use of \c BArchiver. 190 191 This hook function is called once the first BArchiver that was created in 192 an archiving session is either destroyed, or has its Finish() method 193 called. Implementations of this method can be used, in conjunction with 194 BArchiver::IsArchived(), to reference objects in your archive that you 195 do not own, depending on whether or not those objects were archived by their 196 owners. Implementations of this method should call the implementation of 197 their parent class, the same as for the Archive() method. 198 199 \warning To guarantee that your AllArchived() method will be called 200 during archival, you must create a BArchiver object in your 201 Archive() implementation. 202 203 \warning You should archive any objects you own in your Archive() 204 method implementation, and \b NOT your AllArchived() method. 205 206 \see BArchiver BArchiver::Finish() 207 208 \since Haiku R1 209*/ 210 211 212///// BArchiver ///// 213 214 215/*! 216 \class BArchiver 217 \ingroup support 218 \ingroup libbe 219 \brief A class that simplifies the archiving of complicated BArchivable 220 hierarchies. 221 222 The BArchiver class is a small class that is used for archiving of 223 complicated BArchivable hierarchies. Such a hierarchy may include 224 multiple BArchivable objects, each of which might be referenced by 225 many BArchivable objects. With the BArchiver class, you can be certain 226 that each BArchivable object is archived only once with very little work. 227 When used in conjuction with the BArchivable::AllArchived() and 228 BArchivable::AllUnarchived() methods, it is simple to rebuild your system of 229 references upon unarchival so that they are equivalent to those that were 230 present in your original hierarchy. 231 232 The objects you archive can be retrieved using a BUnarchiver object. 233 234 \since Haiku R1 235*/ 236 237 238/*! 239 \fn BArchiver::BArchiver(BMessage* archive) 240 \brief Constructs a BArchiver object that manages \c archive. 241 242 \since Haiku R1 243*/ 244 245 246/*! 247 \fn BArchiver::~BArchiver() 248 \brief Destroys a BArchiver object. If the BArchiver object has not had its 249 Finish() method called, this will be done now. 250 251 \since Haiku R1 252*/ 253 254 255/*! 256 \fn status_t BArchiver::AddArchivable(const char* name, 257 BArchivable* archivable, bool deep = true) 258 \brief Adds a reference to \c archivable to the archive used to 259 construct this BArchiver. May call \c archivable's Archive() method. 260 261 \param name Where this reference will be stored in the archive. 262 \param archivable The BArchivable* object that to reference. 263 \param deep Passed to \c archivable->Archive() if \c archivable must 264 be archived. 265 266 Adds a reference to \c archivable to your archive. If \c archivable has 267 not yet been archived, then its Archive() method is called. BArchiver 268 can only track BArchivable objects that have been archived through this 269 method or the GetTokenForArchivable() methods. 270 271 \warning If you manually archive an object, and then pass it to 272 AddArchivable() or GetTokenForArchivable(), it will be archived 273 again, and when unarchived you will end up with two different 274 BArchivable objects. 275 276 \since Haiku R1 277*/ 278 279 280/*! 281 \fn status_t BArchiver::GetTokenForArchivable(BArchivable* archivable, 282 bool deep, int32& _token); 283 \brief Get a token representing a BArchivable object for this archiving 284 session. 285 286 \param archivable The BArchivable object for which you wish to get a 287 token. 288 \param deep Controls how \c archivable will be archived, if it has not yet 289 been archived in this session. 290 \param[out] _token The token representing \c archivable is stored here. 291 292 Retrieves or creates a token to represent \c archivable in this archiving 293 session. If \c archivable has not yet been archived, it will be now. If 294 \c archivable gets archived, the \c deep parameter will be passed to its 295 Archive() method. 296 297 \warning If you manually archive an object, and then pass it to 298 GetTokenForArchivable(), it will be archived again, and when 299 unarchived you will end up with two different BArchivable objects. 300 301 \since Haiku R1 302*/ 303 304 305/*! 306 \fn status_t BArchiver::GetTokenForArchivable(BArchivable* archivable, 307 int32 &_token) 308 \brief Equivalent to calling the expanded GetTokenForArchivable( 309 BArchivable*, bool, int32&), with the deep parameter equal to 310 \c true. 311 312 \see GetTokenForArchivable(BArchivable*, bool, int32&) 313 314 \since Haiku R1 315*/ 316 317 318/*! 319 \fn bool BArchiver::IsArchived(BArchivable* archivable); 320 \brief Returns whether \c archivable has already been archived in this 321 session. 322 323 \return Whether or not the object has already been archived. 324 \retval true \c archivable has been archived in this archiving session. 325 \retval false \c archivable has not been archived in this archiving session. 326 327 \since Haiku R1 328*/ 329 330 331/*! 332 \fn status_t BArchiver::Finish(status_t err = B_OK); 333 \brief Report any archiving errors and possibly complete the archiving 334 session. 335 336 This method may finish an archiving session (triggering the call of all 337 archived objects' AllArchived() methods) if the following conditions 338 are true: 339 - No errors have been reported to this or any other BArchiver object 340 within this session. 341 - This is the last remaining BArchiver that has not had its Finish() 342 method invoked. 343 344 If you call this method with an error code not equal to B_OK, then this 345 archiving session has failed, archived objects will not have their 346 AllArchived() methods called, and any subsequent calls to this method 347 on any BArchiver objects in this session will return your error code. 348 349 \return The first error reported in this archiving session, or \c B_OK. 350 351 \since Haiku R1 352*/ 353 354 355/*! 356 \fn const BMessage* BArchiver::ArchiveMessage() const 357 \brief Returns the BMessage* used to construct this BArchiver. This is 358 the archive that AddArchivable() modifies. 359 360 \since Haiku R1 361*/ 362 363 364///// BUnarchiver ///// 365 366 367/*! 368 \class BUnarchiver 369 \ingroup support 370 \ingroup libbe 371 \brief A class that simplifies the unarchiving of complicated BArchivable 372 hierarchies. 373 374 The BUnarchiver class is a small class used to recover BArchivable objects 375 that have been archived with the BArchiver class. It also provides ownership 376 semantics, so that memory leaks can be avoided during the unarchival 377 process. When retrieving an object (either via GetObject() or FindObject()), 378 you can specify a BUnarchiver::ownership_policy. If you specify 379 BUnarchiver::B_ASSUME_OWNERSHIP, you will become responsible for deleting 380 the retrieved item. If you specify BUnarchiver::B_DONT_ASSUME_OWNERSHIP, 381 you will not become responsible. You cannot take ownership of the same 382 object twice. After the unarchival process finishes, any unclaimed objects, 383 excluding the root object (the object being instantiated via 384 instantiate_object() or BUnarchiver::InstantiateObject()), will be deleted. 385 386 If you are updating a class that previously did not use the BArchiver and 387 BUnarchiver helper classes, and want to maintain backwards compatibility 388 with old archive, this can be done using the IsArchiveManaged() method. 389 390 \warning Calling methods on your BUnarchiver with a legacy archive (one 391 that was not managed by a BArchiver during archival) will result 392 in a call to debugger(). 393 394 \since Haiku R1 395*/ 396 397 398/*! 399 \enum BUnarchiver::ownership_policy 400 \brief Options for the ownership policy of objects retrieved from 401 BUnarchiver 402 403 \since Haiku R1 404*/ 405 406 407/*! 408 \var ownership_policy BUnarchiver::B_ASSUME_OWNERSHIP 409 \brief Ownership of unarchived objects will be transferred to the caller. 410 411 \since Haiku R1 412*/ 413 414 415/*! 416 \var ownership_policy BUnarchiver::B_DONT_ASSUME_OWNERSHIP 417 \brief The unarchived objects will be borrowed to the caller. 418 419 \since Haiku R1 420*/ 421 422 423/*! 424 \fn BUnarchiver::BUnarchiver(const BMessage* archive) 425 \brief Constructs a BUnarchiver object to manage \c archive. 426 427 \note To guarantee that your AllUnarchived() method will be called during 428 archival, you must create a BUnarchiver object in your archive 429 constructor. It is necessary to do this even if you won't use the 430 BUnarchiver object in your archive constructor. 431 432 \warning Do not construct a BUnarchiver object without first calling 433 BUnarchiver::PrepareArchive() on \c archive. It is only safe to 434 build a BUnarchiver without this call in your AllUnarchived() 435 implementation. 436 437 \see BUnarchiver::PrepareArchive() 438 439 \since Haiku R1 440*/ 441 442 443/*! 444 \fn BUnarchiver::~BUnarchiver() 445 \brief Destroys a BUnarchiver object. 446 447 Calls this objects Finish() method, if it has not yet been called. 448 449 \since Haiku R1 450*/ 451 452 453/*! 454 \fn status_t BUnarchiver::EnsureUnarchived(int32 token) 455 \brief Ensure the object represented by \a token is unarchived and 456 instantiated. 457 458 \param token the object \a token 459 460 \returns A status code. 461 462 \since Haiku R1 463*/ 464 465 466/*! 467 \fn status_t BUnarchiver::EnsureUnarchived(const char* name, 468 int32 index = 0) 469 \brief Ensure the object archived under \a name at \a index is unarchived 470 and instantiated. 471 472 \param name The archive \a name. 473 \param index The archive \a index. 474 475 \returns A status code. 476 477 \since Haiku R1 478*/ 479 480 481/*! 482 \fn bool BUnarchiver::IsInstantiated(int32 token) 483 \brief Checks whether the object represented by \c token has been 484 instantiated in this session. 485 486 \param token The object \a token. 487 488 \returns \c true if instantiated, \c false otherwise 489 490 \since Haiku R1 491*/ 492 493 494/*! 495 \fn bool BUnarchiver::IsInstantiated(const char* name, int32 index = 0) 496 \brief Checks whether the object archived under \a name at \a index has been 497 instantiated in this session. 498 499 \param name The archive \a name. 500 \param index The arcive \a token. 501 502 \returns \c true if instantiated, \c false otherwise. 503 504 \since Haiku R1 505*/ 506 507 508/*! 509 \fn template<class T> status_t BUnarchiver::GetObject(int32 token, 510 ownership_policy owning, T*& object) 511 \brief Recover an object by token that was archived by a BArchiver object. 512 If the object has not yet been instantiated, and this request is not coming 513 from an AllUnarchived() implementation, the object will be instantiated now. 514 515 If the retrieved object is not of the type T, then this method will fail. 516 If this method fails, you will not receive ownership of the object, no 517 matter what you specified in \c owning. 518 519 \tparam T The type of \a object you wish to find. 520 521 \param token The \a token you got for this object from 522 BArchiver::GetTokenForArchivable() during archival. 523 \param owning Whether or not you wish to take ownership of the 524 retrieved object. 525 \param object Return parameter for the retrieved object of type T. 526 527 \returns A status code. 528 \retval B_OK The object retrieved was of type T. 529 \retval B_BAD_TYPE The object retrieved was not of type T. 530 531 \since Haiku R1 532*/ 533 534 535/*! 536 \fn template<class T> status_t BUnarchiver::GetObject(int32 token, 537 T*& object) 538 \brief Recover and take ownership of an object represented by \a token. 539 540 Equivalent to calling GetObject(token, \c B_ASSUME_OWNERSHIP, object) 541 542 \tparam T The type of \a object you wish to find. 543 544 \param token The \a token you got for this object from 545 BArchiver::GetTokenForArchivable() during archival. 546 \param object The return parameter for the retrieved object of type T. 547 548 \returns A status code. 549 \retval B_OK The object retrieved was of type T. 550 \retval B_BAD_TYPE The object retrieved was not of type T. 551 552 \since Haiku R1 553*/ 554 555 556/*! 557 \fn template<class T> status_t BUnarchiver::FindObject(const char* name, 558 int32 index, ownership_policy owning, T*& object) 559 \brief Recover an object that had previously been archived using 560 the BArchiver::AddArchivable() method. 561 562 If the object has not yet been instantiated, and this request is not 563 coming from an AllUnarchived() implementation, the object will be 564 instantiated now. 565 566 If the retrieved object is not of the type T, then this method will fail. 567 If this method fails, you will not receive ownership of the object, no 568 matter what you specified in \c owning. 569 570 \tparam T The type of object you wish to find. 571 572 \param name The name that was passed to BArchiver::AddArchivable() when 573 adding this object. 574 \param index The index of the object you wish to recover (\c 0-based, 575 like BMessage::FindData(). 576 \param owning Dictates whether or not you wish to take ownership of the 577 retrieved object. 578 \param object Return parameter for the retrieved object of type T. 579 580 \returns A status code. 581 \retval B_OK The object retrieved was of type T. 582 \retval B_BAD_TYPE The object retrieved was not of type T. 583 584 \since Haiku R1 585*/ 586 587 588/*! 589 \fn template<class T> status_t BUnarchiver::FindObject(const char* name, 590 int32 index, T*& object) 591 \brief Recover and take ownership of an object that had previously been 592 archived using the BArchiver::AddArchivable() method. 593 594 \tparam T The type of object you wish to find. 595 596 \param name The name that was passed to BArchiver::AddArchivable() when 597 adding this object. 598 \param index The index of the object you wish to recover (\c 0-based, 599 like #BMessage::FindData(). 600 \param object Return parameter for the retrieved object of type T. 601 602 \returns A status code. 603 \retval B_OK The object retrieved was of type T. 604 \retval B_BAD_TYPE The object retrieved was not of type T. 605 606 \since Haiku R1 607*/ 608 609 610/*! 611 \fn template<class T> status_t BUnarchiver::FindObject(const char* name, 612 ownership_policy owning, T*& object) 613 \brief Recover an object at index \c 0 that had previously been 614 archived using the BArchiver::AddArchivable() method. 615 616 Equivalent to calling FindObject(name, \c 0, owning, object). 617 618 \tparam T The type of \a object you wish to find. 619 620 \param name The name that was passed to BArchiver::AddArchivable() when 621 adding this object. 622 \param owning Dictates whether or not you wish to take ownership of the 623 retrieved object. 624 \param object Return parameter for the retrieved object of type T. 625 626 \returns A status code. 627 \retval B_OK The object retrieved was of type T. 628 \retval B_BAD_TYPE The object retrieved was not of type T. 629 630 \since Haiku R1 631*/ 632 633 634/*! 635 \fn template<class T> status_t BUnarchiver::FindObject(const char* name, 636 T*& object) 637 \brief Recover and take ownership of an object at index \c 0 that had 638 previously been archived using the BArchiver::AddArchivable() method. 639 640 Equivalent to calling FindObject(name, \c 0, 641 BUnarchiver::B_ASSUME_OWNERSHIP, object). 642 643 \tparam T The type of \a object you wish to find. 644 645 \param name The name that was passed to BArchiver::AddArchivable() when 646 adding this object. 647 \param object Return parameter for the retrieved \a object of type T. 648 649 \returns A status code. 650 \retval B_OK The \a object retrieved was of type T. 651 \retval B_BAD_TYPE The \a object retrieved was not of type T. 652 653 \since Haiku R1 654*/ 655 656 657/*! 658 \fn status_t BUnarchiver::Finish(status_t err = B_OK); 659 \brief Report any unarchiving errors and possibly complete the archiving 660 session. 661 662 This method may finish an unarchiving session (triggering the call of all 663 instantiated objects' AllUnarchived() methods) if the following conditions 664 are true: 665 666 - No errors have been reported to this or any other BUnarchiver 667 object within this session. 668 - This is the last remaining BUnarchiver that has not had its 669 Finish() method invoked. 670 671 If you call this method with an error code not equal to B_OK, then this 672 unarchiving session has failed, instantiated objects will not have their 673 AllUnarchived() methods called, and any subsequent calls to this method 674 on any BUnarchiver objects in this session will return your error code. 675 Furthermore, any objects that have been instantiated, but have not had 676 their ownership assumed by another object will now be deleted (excluding 677 the root object). 678 679 \return The first error reported in this unarchiving session, or \c B_OK. 680 681 \since Haiku R1 682*/ 683 684 685/*! 686 \fn const BMessage* BUnarchiver::ArchiveMessage() const 687 \brief Returns the BMessage* used to construct this BUnarchiver. 688 689 This is the archive that FindObject() uses. 690*/ 691 692 693/*! 694 \fn static bool BUnarchiver::IsArchiveManaged(const BMessage* archive) 695 \brief Checks whether \a archive was managed by a BArchiver object. 696 697 This method can be used to maintain archive backwards-compatibility for a 698 class that has been updated to use the BArchiver class. If there is a 699 possibility that you are may dealing with a legacy archive, you can use 700 this method to find out before calling any methods on your BUnarchiver 701 object. 702 703 Here is an example of how you might use this method. Note that you 704 must still call PrepareArchive(archive) either way. 705 706\code 707MyArchivableClas::MyArchivableClass(BMessage* archive) 708 : 709 BArchivable(BUnarchiver::PrepareArchive(archive)) 710{ 711 BUnarchiver unarchiver(archive); 712 713 if (BUnarchiver::IsArchiveManaged(archive)) { 714 // ... calls to FindObject() or GetObject() here ... 715 } else { 716 // ... calls to BMessage::FindMessage() here ... 717 } 718} 719\endcode 720 721 \returns Whether \a archive was managed by a BArchiver object. 722 \retval true if \a archive was managed by a BArchiver object. 723 \retval false otherwise. 724 725 \since Haiku R1 726*/ 727 728 729/*! 730 \fn static BMessage* BUnarchiver::PrepareArchive(BMessage* &archive) 731 \brief Prepares \c archive for use by a BUnarchiver. 732 733 This method must be called if you plan to use a BUnarchiver on an archive. 734 It must be called once for each class an object inherits from that 735 will use a BUnarchiver. 736 737 \warning This method \b must be called \b before a call to the 738 archive constructor of your parent class. 739 740 Notice the use of this method in the example provided below. 741\code 742MyArchivableClas::MyArchivableClas(BMessage* archive) 743 : 744 BArchivable(BUnarchiver::PrepareArchive(archive)) 745{ 746 // ... 747} 748\endcode 749 750 \param archive The archive you wish to have prepared. 751 752 \return The same #BMessage as is passed in. 753 754 \since Haiku R1 755*/ 756 757 758/*! 759 \fn void BUnarchiver::AssumeOwnership(BArchivable* archivable) 760 \brief Become the owner of \a archivable. 761 762 After calling this method you are responsible for deleting the 763 \a archivable. 764 765 \param archivable The \a archivable object. 766 767 \since Haiku R1 768*/ 769 770 771/*! 772 \fn void BUnarchiver::RelinquishOwnership(BArchivable* archivable) 773 \brief Relinquish ownership of \a archivable. If \a archivable remains 774 unclaimed at the end of the unarchiving session, it will be deleted 775 (unless it is the root object). 776 777 \param archivable The \a archivable object. 778 779 \since Haiku R1 780*/ 781 782 783/*! 784 \fn template<class T> status_t BUnarchiver::InstantiateObject( 785 BMessage* from, T*& object) 786 \brief Attempt to instantiate an object of type T from BMessage* 787 \a from. 788 789 If the instantiated object is not of type T, then it will be deleted, 790 and this method will return \c B_BAD_TYPE. This method is similar to 791 the instantiate_object() function, but provides error reporting and 792 protection from memory leaks. 793 794 \param from The #BMessage to instantiate from. 795 \param object Return parameter for the retrieved object of type T. 796 797 \returns A status code. 798 \retval B_OK The object retrieved was of type T. 799 \retval B_BAD_TYPE The object retrieved was not of type T. 800 801 \since Haiku R1 802*/ 803 804 805///// Global methods ///// 806 807 808/*! 809 \addtogroup support_globals 810*/ 811 812 813//! @{ 814 815 816/*! 817 \typedef typedef BArchivable* (*instantiation_func)(BMessage*) 818 \brief Internal definition of a function that can instantiate objects that 819 have been created with the BArchivable API. 820 821 \since BeOS R3 822*/ 823 824 825/*! 826 \fn BArchivable* instantiate_object(BMessage *from, image_id *id) 827 \brief Instantiate an archived object with the object being defined in a 828 different application or library. 829 830 This function is similar to instantiate_object(BMessage *from), except that 831 it takes the \a id argument referring to an image where the object might be 832 stored. 833 834 \note Images are names for executable files. Image id's refer to these 835 executable files that have been loaded by your application. Have a 836 look at the kernel API for further information. 837 838 \since BeOS R3 839*/ 840 841 842/*! 843 \fn BArchivable* instantiate_object(BMessage *from) 844 \brief Instantiate an archived object. 845 846 This global function will determine the base class, based on the \a from 847 argument, and it will call the Instantiate() function of that object to 848 restore it. 849 850 \param from The archived object. 851 852 \return The object returns a pointer to the instantiated object, or \c NULL 853 if the instantiation failed. The global \c errno variable will 854 contain the reason why it failed. 855 856 \see instantiate_object(BMessage *from, image_id *id) 857 858 \since BeOS R3 859*/ 860 861 862/*! 863 \fn bool validate_instantiation(BMessage* from, const char* className) 864 \brief Internal function that checks if the \a className is the same as the 865 one stored in the \a from message. 866 867 \since BeOS R3 868*/ 869 870 871/*! 872 \fn instantiation_func find_instantiation_func(const char* className, 873 const char* signature) 874 \brief Internal function that searches for the instantiation func with a 875 specific signature. Use instantiate_object() instead. 876 877 \since Haiku R1 878*/ 879 880 881/*! 882 \fn instantiation_func find_instantiation_func(const char* className) 883 \brief Internal function that searches for the instantiation func of a 884 specific class. Use instantiate_object() instead. 885 886 \since BeOS R3 887*/ 888 889 890/*! 891 \fn instantiation_func find_instantiation_func(BMessage* archive) 892 \brief Internal function that searches for the instantiation func that 893 works on the specified \a archive. Use instantiate_object() instead. 894 895 \since BeOS R3 896*/ 897 898 899//! @} 900