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 * 8 * Corresponds to: 9 * /trunk/headers/os/app/Message.h rev 21562 10 * /trunk/src/kits/app/Message.cpp rev 22240 11 */ 12 13 14/*! 15 \file Message.h 16 \brief Provides the BMessage class. 17*/ 18 19///// Name lengths and Scripting specifiers ///// 20 21/*! 22 \def B_FIELD_NAME_LENGTH 23 \brief Undocumented... 24*/ 25 26 27/*! 28 \def B_PROPERTY_NAME_LENGTH 29 \brief Undocumented... 30*/ 31 32 33/*! 34 \var B_NO_SPECIFIER 35 \brief Undocumented... 36*/ 37 38 39/*! 40 \var B_DIRECT_SPECIFIER 41 \brief Undocumented... 42*/ 43 44 45/*! 46 \var B_INDEX_SPECIFIER 47 \brief Undocumented... 48*/ 49 50 51/*! 52 \var B_REVERSE_INDEX_SPECIFIER, 53 \brief Undocumented... 54*/ 55 56 57/*! 58 \var B_RANGE_SPECIFIER 59 \brief Undocumented... 60*/ 61 62 63/*! 64 \var B_REVERSE_RANGE_SPECIFIER 65 \brief Undocumented... 66*/ 67 68 69/*! 70 \var B_NAME_SPECIFIER 71 \brief Undocumented... 72*/ 73 74 75/*! 76 \var B_ID_SPECIFIER 77 \brief Undocumented... 78*/ 79 80 81/*! 82 \var B_SPECIFIERS_END 83 \brief Undocumented... 84*/ 85 86 87///// Class BMessage ///// 88 89 90/*! 91 \class BMessage 92 \ingroup app 93 \brief A container that can be send and received using the Haiku messaging 94 subsystem. 95 96 This class is at the center of the web of messaging classes, in the sense 97 that it defines the actual structure of the messages. Messages have two 98 <b>important elements</b>: the #what identifier, and the data members. The 99 first can be directly manipulated, the latter can be manipulated through 100 AddData(), FindData() and ReplaceData() and their derivatives. Neither of 101 these elements are mandatory. 102 103 The second important role of BMessage is that it stores <b>meta data</b>: 104 who sent the message and with what intention? The methods of BMessage will 105 disclose if the message was a reply (IsReply()), where it came from 106 (IsSourceRemote()), whether a reply is expected (IsSourceWaiting()), and in 107 case the message is a reply, what it's a reply to (Previous()). 108 109 Mostly, messages are used to pass information between the the objects in 110 your application, but because messages are such flexible data containers, 111 they are also often used for other <b>data storage purposes</b>. Many 112 applications store their settings as messages. Because messages can be 113 flattened to data streams (such as files), they provide an easy but 114 powerful tool for data storage. 115 116 All methods can be classified in these areas: 117 - Adding, Finding, Replacing and Removing Data. 118 - Statistics and Miscellaneous information. 119 - Delivery information. 120 - Utilities to reply to messages. 121 122 To see how messages fit in with the greater picture, have a look at the 123 \ref app_messaging "Messaging Introduction". 124*/ 125 126 127/*! 128 \var BMessage::what 129 \brief A 4-byte constant that determines the type of message. 130 131 You can directly manipulate this data member. 132*/ 133 134 135/*! 136 \fn BMessage::BMessage() 137 \brief Construct an empty message, without any data members and with a 138 \a what constant set to \c 0. 139 140 \see BMessage(uint32 what) 141 \see BMessage(const BMessage &other) 142*/ 143 144 145/*! 146 \fn BMessage::BMessage(uint32 what) 147 \brief Construct an empty message with the \a what member set to the 148 specified value. 149 150 \see BMessage::BMessage() 151 \see BMessage::BMessage(const BMessage &other) 152*/ 153 154 155/*! 156 \fn BMessage::BMessage(const BMessage &other) 157 \brief Construct a new message that is a copy of another message. 158 159 The \a what member and the data values are copied. The metadata, such as 160 whether or not the message is a drop message or reply information, is 161 not copied. So if the original message is a reply to a previous message, 162 which will make IsReply() return \c true, calling the same method on a copy 163 of the message will return \c false. 164 165 \remarks BeOS R5 did keep the metadata of the message. Haiku deviates from 166 this behavior. Please use the Haiku implementation of message copying as 167 the default behavior. This will keep your applications backwards 168 compatible. 169 170 \see BMessage::BMessage() 171 \see BMessage(uint32 what) 172*/ 173 174 175/*! 176 \fn BMessage::~BMessage() 177 \brief Free the data members associated with the message. 178 179 If there still is a sender waiting for a reply, the \c B_NO_REPLY message 180 will be sent to inform them that there won't be a reply. 181*/ 182 183 184/*! 185 \fn BMessage &BMessage::operator=(const BMessage &other) 186 \brief Copy one message into another. 187 188 See the copy constructor, BMessage(const BMessage &other), for details on 189 what is copied, and what isn't. 190*/ 191 192 193/*! 194 \name Statistics and Miscellaneous Information 195*/ 196 197 198//! @{ 199 200 201/*! 202 \fn status_t BMessage::GetInfo(type_code typeRequested, int32 index, 203 char **nameFound, type_code *typeFound, int32 *countFound) const 204 \brief Retrieve the name, the type and the number of items in a message by 205 an \a index. 206 207 \param[in] typeRequested If you want to limit the search to only one type, 208 pass that type code here. If you don't care which type the data has, 209 you can pass \c B_ANY_TYPE. 210 \param[in] index The index of the data you want to investigate. 211 \param[out] nameFound The name of the item if it is found. Haiku will fill 212 in a pointer to the internal name buffer in the message. This means 213 that you should not manipulate this name. If you are not interested in 214 the name, you can safely pass \c NULL. 215 \param[out] typeFound The type of the item at \a index. If you are 216 not interested in the type (because you specifically asked for a type), 217 you can safely pass \c NULL. 218 \param[out] countFound The number of items at \a index. If data 219 items have the same name, they will be placed under the same index. 220 221 \return If the \a index is found, and matches the requested type, 222 then the other parameters will be filled in. If this is not the case, 223 the method will return with an error. 224 225 \retval B_OK An match was found. The values have been filled in. 226 \retval B_BAD_INDEX The \a index was out of range. None of the 227 passed variables have been altered. 228 \retval B_BAD_TYPE The data field at \a index does not have the 229 requested type. 230*/ 231 232 233/*! 234 \fn status_t BMessage::GetInfo(const char *name, type_code *typeFound, 235 int32 *countFound) const 236 \brief Retrieve the type and the number of data items in this message that 237 are associated with a \a name. 238 239 \param[in] name The name of the data member that you are looking for. 240 \param[out] typeFound In case of a match, the name of the data member will 241 be put in this parameter. In case you are not interested, you can pass 242 \c NULL. 243 \param[out] countFound In case of a match, the number of items at this 244 label will be in this parameter. In case you are not interested, you 245 can safely pass \c NULL. 246 247 \return If the message has data associated with the given \a name, 248 the other parameters will contain information associated with the data, 249 else, the method will return with an error. 250 251 \retval B_OK A match was found. The other parameters have been filled in. 252 \retval B_BAD_VALUE You passed \c NULL as argument to \a name. 253 \retval B_NAME_NOT_FOUND There is no data with the label \a name. 254*/ 255 256 257/*! 258 \fn status_t BMessage::GetInfo(const char *name, type_code *typeFound, 259 bool *fixedSize) const 260 \brief Retrieve the type and whether or not the size of the data is fixed 261 associated with a \a name. 262 263 This method is the same as GetInfo(const char *,type_code *, int32 *) const, 264 with the difference that you can find out whether or not the size of the 265 data associated with the \a name is fixed. You will get this value 266 in the variable you passed as \a fixedSize parameter. 267*/ 268 269 270/*! 271 \fn int32 BMessage::CountNames(type_code type) const 272 \brief Count the number of names of a certain \a type. 273 274 This method can be used to count the number of items of a certain type. 275 It's practical use is limited to debugging purposes. 276 277 \param type The type you want to find. If you pass \c B_ANY_TYPE, this 278 method will return the total number of data items. 279 280 \return The number of data items in this message with the specified 281 \a type, or \c 0 in case no items match the type. 282*/ 283 284 285/*! 286 \fn bool BMessage::IsEmpty() const 287 \brief Check if the message has data members. 288 289 \return If this message contains data members, this method will return 290 \c true, else it will return \c false. 291 \see MakeEmpty() 292*/ 293 294 295/*! 296 \fn bool BMessage::IsSystem() const 297 \brief Check if the message is a system message. 298 299 \return If this message is a system message, the method will return 300 \c true. 301*/ 302 303 304/*! 305 \fn bool BMessage::IsReply() const 306 \brief Check if the message is a reply to a (previous) message. 307 308 \return If this message is a reply, this method will return \c true. 309*/ 310 311 312/*! 313 \fn void BMessage::PrintToStream() const 314 \brief Print the message to the standard output. 315 316 This method can be used to debug your application. It can be used to check 317 if it creates the messages properly, by checking if all the required fields 318 are present, and it can be used to debug your message handling routines, 319 especially the handling of those that are sent by external applications, to 320 see if you understand the semantics correctly. 321*/ 322 323 324/*! 325 \fn status_t BMessage::Rename(const char *oldEntry, const char *newEntry) 326 \brief Rename a data label. 327 328 \param oldEntry The name of the label you want to rename. 329 \param newEntry The new name of the data entry. 330 331 \retval B_OK Renaming succeeded. 332 \retval B_BAD_VALUE Either the \a oldEntry or the 333 \a newEntry pointers are \c NULL. 334 \retval B_NAME_NOT_FOUND There is no data associated with the label 335 \a oldEntry. 336*/ 337 338 339//! @} 340 341/*! 342 \name Delivery Info 343*/ 344 345//! @{ 346 347 348/*! 349 \fn bool BMessage::WasDelivered() const 350 \brief Check if this message was delivered through the delivery methods. 351 352 If this message is passed via a BMessenger or BLooper::PostMessage(), this 353 method will return \c true. 354 355 \warning This method should not be abused by a thread that sends a message 356 to track whether or not a message was delivered. This is because the 357 ownership of the message goes to the receiving looper, which will 358 delete the message as soon as it is done with it. 359 360 \warning If you need to check whether a message is delivered, you should 361 either ask for a reply, or use one of the synchronous 362 BMessenger::SendMessage() methods. 363*/ 364 365 366/*! 367 \fn bool BMessage::IsSourceWaiting() const 368 \brief Check if the sender expects a reply. 369 370 This method will return \c true, if the sender flagged that it is waiting 371 for a reply, and such a reply has not yet been sent. 372*/ 373 374 375/*! 376 \fn bool BMessage::IsSourceRemote() const 377 \brief Check if the message is sent by another application. 378*/ 379 380 381/*! 382 \fn BMessenger BMessage::ReturnAddress() const 383 \brief Get a messenger that points to the sender of the message. 384 385 Using this method, you can fetch a BMessenger that can be used to deliver 386 replies to this message. This method works both for local and remote 387 deliveries. 388 389 For remote deliveries, this approach is preferred over sending the reply 390 using a standard BMessenger that is created with the signature of the 391 application. A standard BMessenger sends the messages to the main BLooper 392 of the application, the BApplication object. With the delivery data stored 393 in the messages, the reply using this messenger will be directed at a 394 specific looper that is able to handle the replies. 395 396 If this method is called on a message that has not been delivered (yet), 397 it will return an empty BMessenger object. 398*/ 399 400 401/*! 402 \fn const BMessage *BMessage::Previous() const 403 \brief Get the message to which this message is a reply. 404 405 \return Returns a new BMessage with the same data stuctures as the message 406 to which this message is a reply. You get the ownership of this 407 message, so free it when you're done. If this message isn't a reply to 408 another message, this method will return \c NULL. 409*/ 410 411 412/*! 413 \fn bool BMessage::WasDropped() const 414 \brief Check if the message was delivered through 'drag and drop'. 415 416 \return This method returns \c true if the message has been delivered 417 through drag and drop. It returns \c false if it has been delivered 418 through the regular messaging functions, or if the message has not 419 been delivered at all. 420 \see DropPoint() 421*/ 422 423 424/*! 425 \fn BPoint BMessage::DropPoint(BPoint *offset) const 426 \brief Get the coordinates of the drop point of the message. 427 428 If the message has been delivered because of drag and drop, which can be 429 verified with the WasDropped() method, this method will return a BPoint to 430 where exactly the drop off was made. 431 432 Because drop messages are delivered to the BWindow in which they were 433 dropped, and BWindow is a subclass of BLooper, you can use BWindow to 434 determine based on the location, how you should react to it. 435 436 If this message was not delivered through drag and drop, it will return 437 a \c NULL pointer. 438 439 \see WasDropped() 440*/ 441 442 443//! @} 444 445 446/*! 447 \name Replying 448*/ 449 450 451//! @{ 452 453 454/*! 455 \fn status_t BMessage::SendReply(uint32 command, BHandler *replyTo) 456 \brief Asynchronously send a reply to this message. 457 458 This is an overloaded member of SendReply(BMessage *, BMessenger, bigtime_t). 459 Use this variant if you want to send a message without data members. 460*/ 461 462 463/*! 464 \fn status_t BMessage::SendReply(BMessage *reply, BHandler *replyTo, 465 bigtime_t timeout) 466 \brief Asynchronously send a reply to this message. 467 468 This is an overloaded member of SendReply(BMessage *, BMessenger, bigtime_t). 469 Use this variant if you want to send the message to a specific handler 470 (instead of a complete messenger). 471*/ 472 473 474/*! 475 \fn status_t BMessage::SendReply(BMessage *reply, BMessenger replyTo, 476 bigtime_t timeout) 477 \brief Asynchronously send a reply to this message. 478 479 This method sends a reply to this message to the sender. On your turn, 480 you specify a messenger that handles a reply back to the message you 481 specify as the \a reply argument. You can set a timeout for the 482 message to be delivered. This method blocks until the message has been 483 received, or the \a timeout has been reached. 484 485 \param reply The message that is in reply to this message. 486 \param replyTo In case the receiver needs to reply to the message you are 487 sending, you can specify the return address with this argument. 488 \param timeout The maximum time in microseconds this delivery may take. The 489 \a timeout is a relative timeout. You can also use 490 \c B_INFINITE_TIMEOUT if you want to wait infinitely for the message 491 to be delivered. 492 493 \retval B_OK The message has been delivered. 494 \retval B_DUPLICATE_REPLY There already has been a reply to this message. 495 \retval B_BAD_PORT_ID The reply address is not valid (anymore). 496 \retval B_WOULD_BLOCK The delivery \a timeout was 497 \c B_INFINITE_TIMEOUT (\c 0) and the target port was full when trying 498 to deliver the message. 499 \retval B_TIMED_OUT The timeout expired while trying to deliver the 500 message. 501 \see SendReply(uint32 command, BHandler *replyTo) 502*/ 503 504 505/*! 506 \fn status_t BMessage::SendReply(uint32 command, BMessage *replyToReply) 507 \brief Synchronously send a reply to this message, and wait for a reply 508 back. 509 510 This is an overloaded member of SendReply(BMessage *, BMessage *, 511 bigtime_t, bigtime_t) Use this variant if you want to send a message 512 without data members. 513*/ 514 515 516/*! 517 \fn status_t BMessage::SendReply(BMessage *reply, BMessage *replyToReply, 518 bigtime_t sendTimeout, bigtime_t replyTimeout) 519 \brief Synchronously send a reply to this message, and wait for a reply 520 back. 521 522 This method sends a reply to this message to the sender. The 523 \a reply is delivered, and then the method waits for a reply from 524 the receiver. If a reply is received, that reply is copied into the 525 \a replyToReply argument. 526 If the message was delivered properly, but the receiver did not reply 527 within the specified \a replyTimeout, the \a what member of 528 \a replyToReply will be set to \c B_NO_REPLY. 529 530 \param reply The message that is in reply to this message. 531 \param[out] replyToReply The reply is copied into this argument. 532 \param sendTimeout The maximum time in microseconds this delivery may take. 533 The \a timeout is a relative timeout. You can also use 534 \c B_INFINITE_TIMEOUT if you want to wait infinitely for the message 535 to be delivered. 536 \param replyTimeout The maximum time in microseconds you want to wait for a 537 reply. Note that the timer starts when the message has been delivered. 538 539 \retval B_OK The message has been delivered. 540 \retval B_DUPLICATE_REPLY There already has been a reply to this message. 541 \retval B_BAD_VALUE Either \a reply or \a replyToReply is 542 \c NULL. 543 \retval B_BAD_PORT_ID The reply address is not valid (anymore). 544 \retval B_WOULD_BLOCK The delivery \a timeout was 545 \c B_INFINITE_TIMEOUT (\c 0) and the target port was full when trying 546 to deliver the message. 547 \retval B_TIMED_OUT The timeout expired while trying to deliver the 548 message. 549 \retval B_NO_MORE_PORTS All reply ports are in use. 550 \see SendReply(uint32 command, BMessage *replyToReply) 551*/ 552 553 554//! @} 555 556 557/*! 558 \name Flattening methods 559 560 Because of historical reasons and for binary compatibility, this class 561 provides a flattening API without inheriting the BFlattenable class. The 562 API is more or less the same, but you are inconvenienced when you want to 563 use messages in methods that handle BFlattenable objects. 564*/ 565 566 567//! @{ 568 569 570/*! 571 \fn ssize_t BMessage::FlattenedSize() const 572 \brief Return the size in bytes required when you want to flatten this 573 message to a stream of bytes. 574*/ 575 576 577/*! 578 \fn status_t BMessage::Flatten(char *buffer, ssize_t size) const 579 \brief Flatten the message to a \a buffer. 580 581 \param buffer The buffer to write the data to. 582 \param size The size of the buffer. 583 584 \return \c B_OK in case of success, or an error code in case something went 585 awry. 586 587 \warning Make sure the buffer is large enough to hold the message. This 588 method does not double-check for you! 589 \see FlattenedSize() 590 \see Flatten(BDataIO *stream, ssize_t *size) const 591*/ 592 593 594/*! 595 \fn status_t BMessage::Flatten(BDataIO *stream, ssize_t *size) const 596 \brief Flatten the message to a \a stream. 597 598 \param[in] stream The stream to flatten the message to. 599 \param[out] size The method writes the number of bytes actually written to 600 this argument. 601 \return \c B_OK in case of success, or an error code in case something went 602 awry. 603 604 \warning Make sure the subclass of the BDataIO interface either protects 605 against buffer overwrites, or check if the number of bytes that is 606 going to be written isn't larger than it can handle. 607 \see FlattenedSize() 608 \see Flatten(char *buffer, ssize_t size) const 609*/ 610 611 612/*! 613 \fn status_t BMessage::Unflatten(const char *flatBuffer) 614 \brief Unflatten a message from a buffer and put it into the current 615 object. 616 617 This action clears the current contents of the message. 618 619 \param flatBuffer The buffer that contains the message. 620 621 \retval B_OK The buffer has been unflattened. 622 \retval B_BAD_VALUE The buffer does not contain a valid message. 623 \retval B_NO_MEMORY An error occured whilst allocating memory for the data 624 members. 625 \see Flatten(char *buffer, ssize_t size) const 626 \see Unflatten(BDataIO *stream) 627*/ 628 629 630/*! 631 \fn status_t BMessage::Unflatten(BDataIO *stream) 632 \brief Unflatten a message from a stream and put it into the current 633 object. 634 635 This action clears the current contents of the message. 636 637 \param stream The stream that contains the message. 638 639 \retval B_OK The message has been unflattened. 640 \retval B_BAD_VALUE The stream does not contain a valid message. 641 \retval B_NO_MEMORY An error occured whilst allocating memory for the data 642 members. 643 \see Flatten(BDataIO *stream, ssize_t *size) const 644 \see Unflatten(const char *flatBuffer) 645*/ 646 647 648//! @} 649 650/*! 651 \name Specifiers (Scripting) 652*/ 653 654//! @{ 655 656 657/*! 658 \fn status_t BMessage::AddSpecifier(const char *property) 659 \brief Undocumented. 660*/ 661 662 663/*! 664 \fn status_t BMessage::AddSpecifier(const char *property, int32 index) 665 \brief Undocumented. 666*/ 667 668 669/*! 670 \fn status_t BMessage::AddSpecifier(const char *property, int32 index, 671 int32 range) 672 \brief Undocumented. 673*/ 674 675 676/*! 677 \fn status_t BMessage::AddSpecifier(const char *property, const char *name) 678 \brief Undocumented. 679*/ 680 681 682/*! 683 \fn status_t BMessage::AddSpecifier(const BMessage *specifier) 684 \brief Undocumented. 685*/ 686 687 688/*! 689 \fn status_t BMessage::SetCurrentSpecifier(int32 index) 690 \brief Undocumented. 691*/ 692 693 694/*! 695 \fn status_t BMessage::GetCurrentSpecifier(int32 *index, 696 BMessage *specifier, int32 *what, const char **property) const 697 \brief Undocumented. 698*/ 699 700 701/*! 702 \fn bool BMessage::HasSpecifiers() const 703 \brief Undocumented. 704*/ 705 706 707/*! 708 \fn status_t BMessage::PopSpecifier() 709 \brief Undocumented. 710*/ 711 712 713//! @} 714 715 716/*! 717 \name Adding Data 718*/ 719 720 721//! @{ 722 723 724/*! 725 \fn status_t BMessage::AddData(const char *name, type_code type, 726 const void *data, ssize_t numBytes, bool isFixedSize, int32 count) 727 \brief Add \a data of a certain \a type to the message. 728 729 The amount of \a numBytes is copied into the message. The data is 730 stored at the label specified in \a name. You are responsible for 731 specifying the correct \a type. The Haiku API already specifies 732 many constants, such as \c B_FLOAT_TYPE or \c B_RECT_TYPE. See 733 TypeConstants.h for more information on the system-wide defined types. 734 735 If the field with the \a name already exists, the data is added in 736 an array-like form. If you are adding a certain \a name for the 737 first time, you are able to specify some properties of this array. You can 738 fix the size of each data entry, and you can also instruct BMessage to 739 allocate a \a count of items. The latter does not mean that the 740 number of items is fixed; the array will grow nonetheless. Also, note that 741 every \a name can only be associated with one \a type of 742 data. 743 744 If consecutive method calls specify a different \a type than the 745 initial, these calls will fail. 746 747 There is no limit to the number of labels, or the amount of data, but 748 note that searching of data members is linear, as well as that some 749 messages will be copied whilst being passed around, so if the amount of 750 data you need to pass is too big, find another way to pass it. 751 752 \param name The label to which this data needs to be associated. If the 753 \a name already exists, the new data will be added in an 754 array-like style. 755 \param type The type of data. If you are adding data to the same 756 \a name, make sure it is the same type. 757 \param data The data buffer to copy the bytes from. 758 \param numBytes The number of bytes to be copied. If this is the first call 759 to this method for this type of data, and you set 760 \a isFixedSize to \c true, this will specify the size of all 761 consecutive calls to this 762 method. 763 \param isFixedSize If this is the first call to this method with this 764 \a name, you can specify the whether or not all items in this 765 array should have the same fixed size. 766 \param count If this is the first call to this method with this 767 \a name, you can instruct this message to allocate a number of 768 items in advance. This does not limit the amount of items though. The 769 array will grow if needed. 770 771 \retval B_OK The \a data is succesfully added. 772 \retval B_BAD_VALUE The \a numBytes is less than, or equal to \c 0, 773 or the size of this item is larger than the \a name allows, 774 since it has been specified to have a fixed size. 775 \retval B_ERROR There was an error whilst creating the label with your 776 \a name. 777 \retval B_BAD_TYPE The \a type you specified is different than the 778 one already associated with \a name. 779*/ 780 781 782/*! 783 \fn status_t BMessage::AddRect(const char *name, BRect aRect) 784 \brief Convenience method to add a BRect to the label \a name. 785 786 This method calls AddData() with the \c B_RECT_TYPE \a type. 787 788 \param name The label to associate the data with. 789 \param aRect The rectangle to store in the message. 790 \see AddData() for a more detailed overview of the inner workings. 791 \see FindRect() 792 \see ReplaceRect() 793*/ 794 795 796/*! 797 \fn status_t BMessage::AddPoint(const char *name, BPoint aPoint) 798 \brief Convenience method to add a BPoint to the label \a name. 799 800 This method calls AddData() with the \c B_POINT_TYPE \a type. 801 802 \param name The label to associate the data with. 803 \param aPoint The point to store in the message. 804 \see AddData() for a more detailed overview of the inner workings. 805 \see FindPoint() 806 \see ReplacePoint() 807*/ 808 809 810/*! 811 \fn status_t BMessage::AddString(const char *name, const char *aString) 812 \brief Convenience method to add a C-string to the label \a name. 813 814 This method calls AddData() with the \c B_STRING_TYPE \a type. 815 816 \param name The label to associate the data with. 817 \param aString The string to copy to the message. 818 \see AddData() for a more detailed overview of the inner workings. 819 \see FindString() 820 \see ReplaceString() 821*/ 822 823 824/*! 825 \fn status_t BMessage::AddString(const char *name, const BString &aString) 826 \brief Convenience method to add a BString to the label \a name. 827 828 This method calls AddData() with the \c B_STRING_TYPE \a type. 829 830 \param name The label to associate the data with. 831 \param aString The string to copy to the message. 832 \see AddData() for a more detailed overview of the inner workings. 833 \see FindString() 834 \see ReplaceString() 835*/ 836 837 838/*! 839 \fn status_t BMessage::AddInt8(const char *name, int8 value) 840 \brief Convenience method to add an \c int8 to the label \a name. 841 842 This method calls AddData() with the \c B_INT8_TYPE \a type. 843 844 \param name The label to associate the data with. 845 \param value The value to store in the message. 846 \see AddData() for a more detailed overview of the inner workings. 847 \see FindInt8() 848 \see ReplaceInt8() 849*/ 850 851 852/*! 853 \fn status_t BMessage::AddInt16(const char *name, int16 value) 854 \brief Convenience method to add an \c int16 to the label \a name. 855 856 This method calls AddData() with the \c B_INT16_TYPE \a type. 857 858 \param name The label to associate the data with. 859 \param value The value to store in the message. 860 \see AddData() for a more detailed overview of the inner workings. 861 \see FindInt16() 862 \see ReplaceInt16() 863*/ 864 865 866/*! 867 \fn status_t BMessage::AddInt32(const char *name, int32 value) 868 \brief Convenience method to add an \c int32 to the label \a name. 869 870 This method calls AddData() with the \c B_INT32_TYPE \a type. 871 872 \param name The label to associate the data with. 873 \param value The value to store in the message. 874 \see AddData() for a more detailed overview of the inner workings. 875 \see FindInt32() 876 \see ReplaceInt32() 877*/ 878 879 880/*! 881 \fn status_t BMessage::AddInt64(const char *name, int64 value) 882 \brief Convenience method to add an \c int64 to the label \a name. 883 884 This method calls AddData() with the \c B_INT64_TYPE \a type. 885 886 \param name The label to associate the data with. 887 \param value The value to store in the message. 888 \see AddData() for a more detailed overview of the inner workings. 889 \see FindInt64() 890 \see ReplaceInt64() 891*/ 892 893 894/*! 895 \fn status_t BMessage::AddBool(const char *name, bool aBoolean) 896 \brief Convenience method to add a \c bool to the label \a name. 897 898 This method calls AddData() with the \c B_BOOL_TYPE \a type. 899 900 \param name The label to associate the data with. 901 \param aBoolean The value to store in the message. 902 \see AddData() for a more detailed overview of the inner workings. 903 \see FindBool() 904 \see ReplaceBool() 905*/ 906 907/*! 908 \fn status_t BMessage::AddFloat(const char *name, float aFloat) 909 \brief Convenience method to add a \c float to the label \a name. 910 911 This method calls AddData() with the \c B_FLOAT_TYPE \a type. 912 913 \param name The label to associate the data with. 914 \param aFloat The value to store in the message. 915 \see AddData() for a more detailed overview of the inner workings. 916 \see FindFloat() 917 \see ReplaceFloat() 918*/ 919 920 921/*! 922 \fn status_t BMessage::AddDouble(const char *name, double aDouble) 923 \brief Convenience method to add a \c double to the label \a name. 924 925 This method calls AddData() with the \c B_DOUBLE_TYPE \a type. 926 927 \param name The label to associate the data with. 928 \param aDouble The value to store in the message. 929 \see AddData() for a more detailed overview of the inner workings. 930 \see FindDouble() 931 \see ReplaceDouble() 932*/ 933 934 935/*! 936 \fn status_t BMessage::AddPointer(const char *name, const void *aPointer) 937 \brief Convenience method to add a \c pointer to the label \a name. 938 939 This method calls AddData() with the \c B_POINTER_TYPE \a type. 940 941 \warning If you want to share objects between applications, please remember 942 that each application has its own address space, and that it therefore 943 is useless to try to pass around objects by sending pointers in 944 messages. You should think about copying the entire object in the 945 message, or you should consider using shared memory. 946 947 \param name The label to associate the data with. 948 \param aPointer The value to store in the message. 949 \see AddData() for a more detailed overview of the inner workings. 950 \see FindPointer() 951 \see ReplacePointer() 952*/ 953 954 955/*! 956 \fn status_t BMessage::AddMessenger(const char *name, BMessenger messenger) 957 \brief Convenience method to add a messenger to the label \a name. 958 959 This method calls AddData() with the \c B_MESSENGER_TYPE \a type. 960 961 \param name The label to associate the data with. 962 \param messenger The messenger to store in the message. 963 \see AddData() for a more detailed overview of the inner workings. 964 \see FindMessenger() 965 \see ReplaceMessenger() 966*/ 967 968 969/*! 970 \fn status_t BMessage::AddRef(const char *name, const entry_ref *ref) 971 \brief Convenience method to add an \c entry_ref to the label 972 \a name. 973 974 This method calls AddData() with the \c B_REF_TYPE \a type. 975 976 \param name The label to associate the data with. 977 \param ref The reference to store in the message. 978 \see AddData() for a more detailed overview of the inner workings. 979 \see FindRef() 980 \see ReplaceRef() 981*/ 982 983 984/*! 985 \fn status_t BMessage::AddMessage(const char *name, const BMessage *message) 986 \brief Convenience method to add a message to the label \a name. 987 988 This method calls AddData() with the \c B_MESSAGE_TYPE \a type. 989 990 \param name The label to associate the data with. 991 \param message The message to store in this message. 992 \see AddData() for a more detailed overview of the inner workings. 993 \see FindMessage() 994 \see ReplaceMessage() 995*/ 996 997 998/*! 999 \fn status_t BMessage::AddFlat(const char *name, BFlattenable *object, 1000 int32 count = 1) 1001 \brief Convenience method to add a flattenable to the label \a name. 1002 1003 This method uses BFlattenable::TypeCode() to determine the type. It also 1004 uses BFlattenable::IsFixedSize() to determine whether or not the size of 1005 the object is supposedly always the same. You can specify a 1006 \a count, to pre-allocate more entries if you are going to add 1007 more than one of this type. 1008 1009 \param name The label to associate the data with. 1010 \param object The object to flatten into the message. 1011 \param count The number of items to pre-allocate associated with this 1012 \a name. 1013 \see AddData() for a more detailed overview of the inner workings. 1014 \see FindFlat() 1015 \see ReplaceFlat() 1016*/ 1017 1018 1019//! @} 1020 1021 1022/*! 1023 \name Removing Data 1024*/ 1025 1026 1027//! @{ 1028 1029 1030/*! 1031 \fn status_t BMessage::RemoveData(const char *name, int32 index) 1032 \brief Remove data associated with \a name at a specified 1033 \a index. 1034 1035 If this is the only instance of the data, then the entire label will be 1036 removed. This means you can recreate it with another type. 1037 1038 \param name The \a name of which the associated data should be cleared. 1039 \param index The \a index of the item that should be cleared. 1040 \retval B_OK The data has been removed. 1041 \retval B_BAD_VALUE The \a index is less than \c 0. 1042 \retval B_BAD_INDEX The \a index is out of bounds. 1043 \retval B_NAME_NOT_FOUND The \a name does not hava any data 1044 associated with it. 1045 \see RemoveName() 1046 \see MakeEmpty() 1047*/ 1048 1049 1050/*! 1051 \fn status_t BMessage::RemoveName(const char *name) 1052 \brief Remove all data associated with a \a name. 1053 1054 This also removes the label, so that you can recreate it with another type, 1055 if you want to. 1056 1057 \param name The \a name that refers to the data you want to clear 1058 out. 1059 \retval B_OK All the data is removed. 1060 \retval B_BAD_VALUE The \a name pointer points to \c NULL. 1061 \retval B_NAME_NOT_FOUND The \a name does not exist in this message. 1062 \see RemoveData() 1063 \see MakeEmpty() 1064*/ 1065 1066 1067/*! 1068 \fn status_t BMessage::MakeEmpty() 1069 \brief Clear all data and metadata in this message. 1070 1071 Everything is cleared out, all labels and all associated data, as well 1072 as metadata such as reply info. 1073 1074 \return This method always returns \c B_OK. 1075 \see RemoveData() 1076 \see RemoveName() 1077*/ 1078 1079 1080//! @} 1081 1082 1083/*! 1084 \name Finding Data 1085 1086 Look at FindData() for a general introduction to finding data. 1087*/ 1088 1089/* TODO: 1090 Quick overview: 1091 1092 <table> 1093 <tr><th>Type of data</th><th>Type code</th><th>Method</td></tr> 1094 <tr><td>BRect</td><td>\c B_RECT_TYPE</td><td>FindRect()</td></tr> 1095 </table> 1096*/ 1097 1098 1099//! @{ 1100 1101 1102/*! 1103 \fn status_t BMessage::FindData(const char *name, type_code type, 1104 int32 index, const void **data, ssize_t *numBytes) const 1105 \brief Find \a data that is stored in this message at an 1106 \a index. 1107 1108 This method matches the label \a name with the \a type you 1109 are asking for, and it looks for the data that is stored at a certain 1110 \a index number. If all these things match, you will get a pointer 1111 to the internal buffer, and the method will put the size of the item in 1112 \a numBytes. 1113 1114 Note that only this method, and FindString(const char *, const char **), 1115 pass a pointer to the internal buffer. The other more specific methods, 1116 such as FindBool() and FindRect() copy the data into a buffer you specify. 1117 This means that the data retrieved with this method is valid until the 1118 message is deleted. 1119 1120 \param name The label the data should be associated with. 1121 \param type The type of data you want to retrieve. You can pass 1122 \c B_ANY_TYPE if you don't mind which type the data is. 1123 \param index The index in the array of the data that you want to retrieve. 1124 Note that the array is zero-based. 1125 \param[out] data A pointer to a pointer where the data can point to. 1126 \param[out] numBytes The size of the data will be put in this parameter. 1127 \retval B_OK The \a name was found, matches the type, and the data 1128 at \a index has been put in \a data. 1129 \retval B_BAD_VALUE One of the output arguments were \c NULL. 1130 \retval B_BAD_INDEX The \a index does not exist. 1131 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1132 \see status_t FindData(const char *, type_code, int32, 1133 const void **, ssize_t *) const 1134*/ 1135 1136 1137/*! 1138 \fn status_t BMessage::FindData(const char *name, type_code type, 1139 const void **data, ssize_t *numBytes) const 1140 \brief Find \a data that is stored in this message. 1141 1142 This is an overloaded method of 1143 FindData(const char *, type_code, int32, const void **, ssize_t *) const 1144 where data is sought at \a index \c 0. 1145*/ 1146 1147 1148/*! 1149 \fn status_t BMessage::FindRect(const char *name, BRect *rect) const 1150 \brief Find a rectangle at the label \a name. 1151 1152 This is an overloaded method of 1153 FindRect(const char *, int32, BRect *) const 1154 where the data is sought at \a index \c 0. 1155*/ 1156 1157 1158/*! 1159 \fn status_t BMessage::FindRect(const char *name, int32 index, BRect *rect) const 1160 \brief Find a rectangle at the label \a name at an \a index. 1161 1162 This method looks for the data with the \c B_RECT_TYPE, and copies it into 1163 a provided buffer. 1164 1165 \param name The label to which the data is associated. 1166 \param index The index from which the data should be copied. 1167 \param rect The object in which the data should be copied. 1168 \retval B_OK The object now contains the requested data. 1169 \retval B_BAD_INDEX The \a index does not exist. 1170 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1171 \see FindRect(const char *, BRect *) const 1172*/ 1173 1174 1175/*! 1176 \fn status_t BMessage::FindPoint(const char *name, BPoint *point) const 1177 \brief Find a point at the label \a name. 1178 1179 This is an overloaded method of 1180 FindPoint(const char *, int32, BPoint *) const 1181 where the data is sought at \a index \c 0. 1182*/ 1183 1184 1185/*! 1186 \fn status_t BMessage::FindPoint(const char *name, int32 index, BPoint *point) const 1187 \brief Find a point at the label \a name at an \a index. 1188 1189 This method looks for the data with the \c B_POINT_TYPE, and copies it into 1190 a provided buffer. 1191 1192 \param name The label to which the data is associated. 1193 \param index The index from which the data should be copied. 1194 \param point The object in which the data should be copied. 1195 \retval B_OK The object now contains the requested data. 1196 \retval B_BAD_INDEX The \a index does not exist. 1197 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1198 \see FindPoint(const char *, BPoint *) const 1199*/ 1200 1201 1202/*! 1203 \fn status_t BMessage::FindString(const char *name, const char **string) const 1204 \brief Find a string at the label \a name. 1205 1206 This is an overloaded method of 1207 FindString(const char *, int32, const char **) const 1208 where the data is sought at \a index \c 0. 1209*/ 1210 1211 1212/*! 1213 \fn status_t BMessage::FindString(const char *name, int32 index, 1214 const char ** string) const 1215 \brief Find a string at the label \a name at an \a index. 1216 1217 This method looks for the data with the \c B_STRING_TYPE, and returns a 1218 pointer to the internal buffer of the message. Note that this pointer is 1219 valid, until the message is deleted. 1220 1221 \param name The label to which the data is associated. 1222 \param index The index from which the data should be copied. 1223 \param string The object in which the data should be copied. 1224 \retval B_OK The object now contains the requested data. 1225 \retval B_BAD_INDEX The \a index does not exist. 1226 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1227 \see FindString(const char *, const char **) const 1228 \see FindString(const char *, int32, BString *) const 1229*/ 1230 1231 1232/*! 1233 \fn status_t BMessage::FindString(const char *name, BString *string) const 1234 \brief Find a string at the label \a name. 1235 1236 This is an overloaded method of 1237 FindString(const char *, int32, BString *) const 1238 where the data is sought at \a index \c 0. 1239*/ 1240 1241 1242/*! 1243 \fn status_t BMessage::FindString(const char *name, int32 index, BString *string) const 1244 \brief Find a string at the label \a name at an \a index. 1245 1246 This method looks for the data with the \c B_STRING_TYPE, and copies it 1247 into the \a string object. 1248 1249 \param name The label to which the data is associated. 1250 \param index The index from which the data should be copied. 1251 \param string The object in which the data should be copied. 1252 \retval B_OK The object now contains the requested data. 1253 \retval B_BAD_INDEX The \a index does not exist. 1254 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1255 \see FindString(const char *, BString *) const 1256 \see FindString(const char *, int32, const char **) const 1257*/ 1258 1259 1260/*! 1261 \fn status_t BMessage::FindInt8(const char *name, int8 *value) const 1262 \brief Find an integer at the label \a name. 1263 1264 This is an overloaded method of FindInt8(const char *, int32, int8 *) const 1265 where the data is sought at \a index \c 0. 1266*/ 1267 1268 1269/*! 1270 \fn status_t BMessage::FindInt8(const char *name, int32 index, int8 *value) const 1271 \brief Find an integer at the label \a name at an \a index. 1272 1273 This method looks for the data with the \c B_INT8_TYPE, and copies it into 1274 a provided buffer. 1275 1276 \param name The label to which the data is associated. 1277 \param index The index from which the data should be copied. 1278 \param value The object in which the data should be copied. 1279 \retval B_OK The object now contains the requested data. 1280 \retval B_BAD_INDEX The \a index does not exist. 1281 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1282 \see FindInt8(const char *, int8 *) const 1283*/ 1284 1285 1286/*! 1287 \fn status_t BMessage::FindInt16(const char *name, int16 *value) const 1288 \brief Find an integer at the label \a name. 1289 1290 This is an overloaded method of FindInt8(const char *, int32, int16 *) const 1291 where the data is sought at \a index \c 0. 1292*/ 1293 1294 1295/*! 1296 \fn status_t BMessage::FindInt16(const char *name, int32 index, int16 *value) const 1297 \brief Find an integer at the label \a name at an \a index. 1298 1299 This method looks for the data with the \c B_INT16_TYPE, and copies it into 1300 a provided buffer. 1301 1302 \param name The label to which the data is associated. 1303 \param index The index from which the data should be copied. 1304 \param value The object in which the data should be copied. 1305 \retval B_OK The object now contains the requested data. 1306 \retval B_BAD_INDEX The \a index does not exist. 1307 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1308 \see FindInt16(const char *, int16 *) const 1309*/ 1310 1311 1312/*! 1313 \fn status_t BMessage::FindInt32(const char *name, int32 *value) const 1314 \brief Find an integer at the label \a name. 1315 1316 This is an overloaded method of 1317 FindInt32(const char *, int32, int32 *) const 1318 where the data is sought at \a index \c 0. 1319*/ 1320 1321 1322/*! 1323 \fn status_t BMessage::FindInt32(const char *name, int32 index, int32 *value) const 1324 \brief Find an integer at the label \a name at an \a index. 1325 1326 This method looks for the data with the \c B_INT32_TYPE, and copies it into 1327 a provided buffer. 1328 1329 \param name The label to which the data is associated. 1330 \param index The index from which the data should be copied. 1331 \param value The object in which the data should be copied. 1332 \retval B_OK The object now contains the requested data. 1333 \retval B_BAD_INDEX The \a index does not exist. 1334 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1335 \see FindInt32(const char *, int32 *) const 1336*/ 1337 1338 1339/*! 1340 \fn status_t BMessage::FindInt64(const char *name, int64 *value) const 1341 \brief Find an integer at the label \a name. 1342 1343 This is an overloaded method of 1344 FindInt64(const char *, int32, int64 *) const 1345 where the data is sought at \a index \c 0. 1346*/ 1347 1348 1349/*! 1350 \fn status_t BMessage::FindInt64(const char *name, int32 index, int64 *value) const 1351 \brief Find an integer at the label \a name at an \a index. 1352 1353 This method looks for the data with the \c B_INT64_TYPE, and copies it into 1354 a provided buffer. 1355 1356 \param name The label to which the data is associated. 1357 \param index The index from which the data should be copied. 1358 \param value The object in which the data should be copied. 1359 \retval B_OK The object now contains the requested data. 1360 \retval B_BAD_INDEX The \a index does not exist. 1361 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1362 \see FindInt64(const char *, int64 *) const 1363*/ 1364 1365 1366/*! 1367 \fn status_t BMessage::FindBool(const char *name, bool *value) const 1368 \brief Find a boolean at the label \a name. 1369 1370 This is an overloaded method of 1371 FindBool(const char *, int32, bool *) const 1372 where the data is sought at \a index \c 0. 1373*/ 1374 1375 1376/*! 1377 \fn status_t BMessage::FindBool(const char *name, int32 index, bool *value) const 1378 \brief Find a boolean at the label \a name at an \a index. 1379 1380 This method looks for the data with the \c B_BOOL_TYPE, and copies it into 1381 a provided buffer. 1382 1383 \param name The label to which the data is associated. 1384 \param index The index from which the data should be copied. 1385 \param value The object in which the data should be copied. 1386 \retval B_OK The object now contains the requested data. 1387 \retval B_BAD_INDEX The \a index does not exist. 1388 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1389 \see FindBool(const char *, bool *) const 1390*/ 1391 1392 1393/*! 1394 \fn status_t BMessage::FindFloat(const char *name, float *value) const 1395 \brief Find a float at the label \a name. 1396 1397 This is an overloaded method of 1398 FindFloat(const char *, int32, float *) const 1399 where the data is sought at \a index \c 0. 1400*/ 1401 1402 1403/*! 1404 \fn status_t BMessage::FindFloat(const char *name, int32 index, float *value) const 1405 \brief Find a float at the label \a name at an \a index. 1406 1407 This method looks for the data with the \c B_FLOAT_TYPE, and copies it into 1408 a provided buffer. 1409 1410 \param name The label to which the data is associated. 1411 \param index The index from which the data should be copied. 1412 \param value The object in which the data should be copied. 1413 \retval B_OK The object now contains the requested data. 1414 \retval B_BAD_INDEX The \a index does not exist. 1415 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1416 \see FindFloat(const char *, float *) const 1417*/ 1418 1419 1420/*! 1421 \fn status_t BMessage::FindDouble(const char *name, double *value) const 1422 \brief Find a double at the label \a name. 1423 1424 This is an overloaded method of 1425 FindDouble(const char *, int32, double *) const 1426 where the data is sought at \a index \c 0. 1427*/ 1428 1429 1430/*! 1431 \fn status_t BMessage::FindDouble(const char *name, int32 index, double *value) const 1432 \brief Find a double at the label \a name at an \a index. 1433 1434 This method looks for the data with the \c B_DOUBLE_TYPE, and copies it into 1435 a provided buffer. 1436 1437 \param name The label to which the data is associated. 1438 \param index The index from which the data should be copied. 1439 \param value The object in which the data should be copied. 1440 \retval B_OK The object now contains the requested data. 1441 \retval B_BAD_INDEX The \a index does not exist. 1442 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1443 \see FindDouble(const char *, double *) const 1444*/ 1445 1446 1447/*! 1448 \fn status_t BMessage::FindPointer(const char *name, void **pointer) const 1449 \brief Find a pointer at the label \a name. 1450 1451 This is an overloaded method of 1452 FindPointer(const char *, int32, void *) const 1453 where the data is sought at \a index \c 0. 1454*/ 1455 1456 1457/*! 1458 \fn status_t BMessage::FindPointer(const char *name, int32 index, void **pointer) const 1459 \brief Find a pointer at the label \a name at an \a index. 1460 1461 This method looks for the data with the \c B_POINTER_TYPE, and copies it into 1462 a provided buffer. 1463 1464 \warning If you want to share objects between applications, please remember 1465 that each application has its own address space, and that it therefore 1466 is useless to try to pass around objects by sending pointers in 1467 messages. You should think about copying the entire object in the 1468 message, or you should consider using shared memory. 1469 1470 \param name The label to which the data is associated. 1471 \param index The index from which the data should be copied. 1472 \param pointer The object in which the data should be copied. 1473 \retval B_OK The object now contains the requested data. 1474 \retval B_BAD_INDEX The \a index does not exist. 1475 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1476 \see FindPointer(const char *, double *) const 1477*/ 1478 1479 1480/*! 1481 \fn status_t BMessage::FindMessenger(const char *name, BMessenger *messenger) const 1482 \brief Find a messenger at the label \a name. 1483 1484 This is an overloaded method of 1485 FindMessenger(const char *, int32, BMessenger *) const 1486 where the data is sought at \a index \c 0. 1487*/ 1488 1489 1490/*! 1491 \fn status_t BMessage::FindMessenger(const char *name, int32 index, BMessenger *messenger) const 1492 \brief Find a messenger at the label \a name at an \a index. 1493 1494 This method looks for the data with the \c B_MESSENGER_TYPE, and copies it 1495 into a provided buffer. 1496 1497 \param name The label to which the data is associated. 1498 \param index The index from which the data should be copied. 1499 \param messenger The object in which the data should be copied. 1500 \retval B_OK The object now contains the requested data. 1501 \retval B_BAD_INDEX The \a index does not exist. 1502 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1503 \see FindMessenger(const char *, BMessenger *) const 1504*/ 1505 1506 1507/*! 1508 \fn status_t BMessage::FindRef(const char *name, entry_ref *ref) const 1509 \brief Find a reference to a file at the label \a name. 1510 1511 This is an overloaded method of 1512 FindRef(const char *, int32, entry_ref *) const 1513 where the data is sought at \a index \c 0. 1514*/ 1515 1516 1517/*! 1518 \fn status_t BMessage::FindRef(const char *name, int32 index, entry_ref *ref) const 1519 \brief Find a reference to a file at the label \a name at an 1520 \a index. 1521 1522 This method looks for the data with the \c B_REF_TYPE, and copies it into 1523 a provided buffer. 1524 1525 \param name The label to which the data is associated. 1526 \param index The index from which the data should be copied. 1527 \param ref The object in which the data should be copied. 1528 \retval B_OK The object now contains the requested data. 1529 \retval B_BAD_INDEX The \a index does not exist. 1530 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1531 \see FindRef(const char *, entry_ref *) const 1532*/ 1533 1534 1535/*! 1536 \fn status_t BMessage::FindMessage(const char *name, BMessage *message) const 1537 \brief Find a message at the label \a name. 1538 1539 This is an overloaded method of 1540 FindMessage(const char *, int32, BMessage *) const 1541 where the data is sought at \a index \c 0. 1542*/ 1543 1544 1545/*! 1546 \fn status_t BMessage::FindMessage(const char *name, int32 index, BMessage *message) const 1547 \brief Find a message at the label \a name at an \a index. 1548 1549 This method looks for the data with the \c B_MESSAGE_TYPE, and copies it 1550 into a provided buffer. 1551 1552 \param name The label to which the data is associated. 1553 \param index The index from which the data should be copied. 1554 \param message The object in which the data should be copied. 1555 \retval B_OK The object now contains the requested data. 1556 \retval B_BAD_INDEX The \a index does not exist. 1557 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1558 \see FindMessage(const char *, BMessage *) const 1559*/ 1560 1561 1562/*! 1563 \fn status_t BMessage::FindFlat(const char *name, BFlattenable *object) const 1564 \brief Find a flattened object at the label \a name. 1565 1566 This is an overloaded method of 1567 FindFlat(const char *, int32, BFlattenable *) const 1568 where the data is sought at \a index \c 0. 1569*/ 1570 1571 1572/*! 1573 \fn status_t BMessage::FindFlat(const char *name, int32 index, 1574 BFlattenable *object) const 1575 \brief Find a flattened object at the label \a name at an 1576 \a index. 1577 1578 The type is determined by the type of the passed object. If that type is 1579 available at the specified label, then the Unflatten() method of that 1580 object will be called. 1581 1582 \param name The label to which the data is associated. 1583 \param index The index from which the data should be unflattened. 1584 \param object The object in which the data should be unflattened. 1585 \retval B_OK The object now contains the requested data. 1586 \retval B_BAD_INDEX The \a index does not exist. 1587 \retval B_NAME_NOT_FOUND There is no field with this \a name. 1588 \see FindFlat(const char *, BFlattenable *) const 1589*/ 1590 1591 1592//! @} 1593 1594 1595/*! 1596 \name Replacing Data 1597 1598 Look at ReplaceData() for a general introduction to replacing data. 1599*/ 1600 1601 1602//! @{ 1603 1604 1605/*! 1606 \fn status_t BMessage::ReplaceData(const char *name, type_code type, 1607 const void *data, ssize_t numBytes) 1608 \brief Replace the data at label \a name. 1609 1610 This method is an overloaded method that replaces the data at 1611 \a index \c 0. See 1612 ReplaceData(const char *, type_code, int32, const void *, ssize_t). 1613*/ 1614 1615 1616/*! 1617 \fn status_t BMessage::ReplaceData(const char *name, type_code type, 1618 int32 index, const void *data, ssize_t numBytes) 1619 \brief Replace the data at label \a name at a specified 1620 \a index. 1621 1622 The conditions for replacing data are that the\a name is correct, 1623 the \a type matches and the data entry at \a index 1624 exists. 1625 1626 There is also a collection of convenience methods, that allow you to 1627 efficiently replace rectanges (ReplaceRect()), booleans (ReplaceBool()), 1628 and so on. 1629 1630 \param name The name associated with the data to replace. 1631 \param type The type of the data. 1632 \param index The index in the array to replace. 1633 \param data A pointer to the new data that needs to be copied into the 1634 message. 1635 \param numBytes The size of the new data. 1636 1637 \retval B_OK The operation succeeded. 1638 \retval B_BAD_VALUE One of the input parameters are invalid. Check that 1639 you did not pass \c NULL, and in case the field has fixed sized data, 1640 check that \a numBytes is the same as the specified fixed size. 1641 \retval B_BAD_INDEX The \a index is out of range. 1642*/ 1643 1644 1645/*! 1646 \fn status_t BMessage::ReplaceRect(const char *name, BRect aRect) 1647 \brief Replace a rectangle at the label \a name. 1648 1649 This method is an overloaded method of 1650 ReplaceRect(const char *, int32, BRect). 1651 It replaces the data at \a index \c 0. 1652*/ 1653 1654 1655/*! 1656 \fn status_t BMessage::ReplaceRect(const char *name, int32 index, BRect aRect) 1657 \brief Replace a rectangle at the label \a name at a specified 1658 \a index. 1659 1660 The data at the specified \a name and \a index will be 1661 replaced, if it matches the \c B_RECT_TYPE. 1662 \param name The name associated with the data to replace. 1663 \param index The index in the array to replace. 1664 \param aRect The object to store in the message. 1665 \retval B_OK The operation succeeded. 1666 \retval B_BAD_INDEX The index was out of range. 1667 \see ReplaceRect(const char*, BRect) 1668*/ 1669 1670 1671/*! 1672 \fn status_t BMessage::ReplacePoint(const char *name, BPoint aPoint) 1673 \brief Replace a point at the label \a name. 1674 1675 This method is an overloaded method of 1676 ReplacePoint(const char *, int32, BPoint). 1677 It replaces the data at \a index \c 0. 1678*/ 1679 1680 1681/*! 1682 \fn status_t BMessage::ReplacePoint(const char *name, int32 index, BPoint aPoint) 1683 \brief Replace a point at the label \a name at a specified 1684 \a index. 1685 1686 The data at the specified \a name and \a index will be 1687 replaced, if it matches the \c B_POINT_TYPE. 1688 \param name The name associated with the data to replace. 1689 \param index The index in the array to replace. 1690 \param aPoint The object to store in the message. 1691 \retval B_OK The operation succeeded. 1692 \retval B_BAD_INDEX The index was out of range. 1693 \see ReplacePoint(const char*, aPoint) 1694*/ 1695 1696 1697/*! 1698 \fn status_t BMessage::ReplaceString(const char *name, const char *aString) 1699 \brief Replace a string at the label \a name. 1700 1701 This method is an overloaded method of 1702 ReplaceString(const char *, int32, const char *). 1703 It replaces the data at \a index \c 0. 1704*/ 1705 1706 1707/*! 1708 \fn status_t BMessage::ReplaceString(const char *name, int32 index, const char *aString) 1709 \brief Replace a string at the label \a name at a specified 1710 \a index. 1711 1712 The data at the specified \a name and \a index will be 1713 replaced, if it matches the \c B_STRING_TYPE. 1714 \param name The name associated with the data to replace. 1715 \param index The index in the array to replace. 1716 \param aString The object to store in the message. 1717 \retval B_OK The operation succeeded. 1718 \retval B_BAD_INDEX The index was out of range. 1719 \see ReplaceString(const char*, const char *) 1720*/ 1721 1722 1723/*! 1724 \fn status_t BMessage::ReplaceString(const char *name, const BString &aString) 1725 \brief Replace a string at the label \a name. 1726 1727 This method is an overloaded method of 1728 ReplaceString(const char *, int32, BString &). 1729 It replaces the data at \a index \c 0. 1730*/ 1731 1732 1733/*! 1734 \fn status_t BMessage::ReplaceString(const char *name, int32 index, const BString &aString) 1735 \brief Replace a string at the label \a name at a specified 1736 \a index. 1737 1738 The data at the specified \a name and \a index will be 1739 replaced, if it matches the \c B_STRING_TYPE. 1740 \param name The name associated with the data to replace. 1741 \param index The index in the array to replace. 1742 \param aString The object to store in the message. 1743 \retval B_OK The operation succeeded. 1744 \retval B_BAD_INDEX The index was out of range. 1745 \see ReplaceString(const char*, BString &) 1746*/ 1747 1748 1749/*! 1750 \fn status_t BMessage::ReplaceInt8(const char *name, int8 value) 1751 \brief Replace an integer at the label \a name. 1752 1753 This method is an overloaded method of 1754 ReplaceInt8(const char *, int32, int8). 1755 It replaces the data at \a index \c 0. 1756*/ 1757 1758 1759/*! 1760 \fn status_t BMessage::ReplaceInt8(const char *name, int32 index, int8 value) 1761 \brief Replace an integer at the label \a name at a specified 1762 \a index. 1763 1764 The data at the specified \a name and \a index will be 1765 replaced, if it matches the \c B_INT8_TYPE. 1766 \param name The name associated with the data to replace. 1767 \param index The index in the array to replace. 1768 \param value The object to store in the message. 1769 \retval B_OK The operation succeeded. 1770 \retval B_BAD_INDEX The index was out of range. 1771 \see ReplaceInt8(const char*, int8) 1772*/ 1773 1774 1775/*! 1776 \fn status_t BMessage::ReplaceInt16(const char *name, int16 value) 1777 \brief Replace an integer at the label \a name. 1778 1779 This method is an overloaded method of 1780 ReplaceInt16(const char *, int32, int16). 1781 It replaces the data at \a index \c 0. 1782*/ 1783 1784 1785/*! 1786 \fn status_t BMessage::ReplaceInt16(const char *name, int32 index, int16 value) 1787 \brief Replace an integer at the label \a name at a specified 1788 \a index. 1789 1790 The data at the specified \a name and \a index will be 1791 replaced, if it matches the \c B_INT16_TYPE. 1792 \param name The name associated with the data to replace. 1793 \param index The index in the array to replace. 1794 \param value The object to store in the message. 1795 \retval B_OK The operation succeeded. 1796 \retval B_BAD_INDEX The index was out of range. 1797 \see ReplaceInt16(const char*, int16) 1798*/ 1799 1800 1801/*! 1802 \fn status_t BMessage::ReplaceInt32(const char *name, int32 value) 1803 \brief Replace an integer at the label \a name. 1804 1805 This method is an overloaded method of 1806 ReplaceInt8(const char *, int32, int32). 1807 It replaces the data at \a index \c 0. 1808*/ 1809 1810 1811/*! 1812 \fn status_t BMessage::ReplaceInt32(const char *name, int32 index, int32 value) 1813 \brief Replace an integer at the label \a name at a specified 1814 \a index. 1815 1816 The data at the specified \a name and \a index will be 1817 replaced, if it matches the \c B_INT32_TYPE. 1818 \param name The name associated with the data to replace. 1819 \param index The index in the array to replace. 1820 \param value The object to store in the message. 1821 \retval B_OK The operation succeeded. 1822 \retval B_BAD_INDEX The index was out of range. 1823 \see ReplaceInt32(const char*, int32) 1824*/ 1825 1826 1827/*! 1828 \fn status_t BMessage::ReplaceInt64(const char *name, int64 value) 1829 \brief Replace an integer at the label \a name. 1830 1831 This method is an overloaded method of 1832 ReplaceInt8(const char *, int32, int64). 1833 It replaces the data at \a index \c 0. 1834*/ 1835 1836 1837/*! 1838 \fn status_t BMessage::ReplaceInt64(const char *name, int32 index, int64 value) 1839 \brief Replace an integer at the label \a name at a specified 1840 \a index. 1841 1842 The data at the specified \a name and \a index will be 1843 replaced, if it matches the \c B_INT64_TYPE. 1844 \param name The name associated with the data to replace. 1845 \param index The index in the array to replace. 1846 \param value The object to store in the message. 1847 \retval B_OK The operation succeeded. 1848 \retval B_BAD_INDEX The index was out of range. 1849 \see ReplaceInt64(const char*, int64) 1850*/ 1851 1852 1853/*! 1854 \fn status_t BMessage::ReplaceBool(const char *name, bool aBoolean) 1855 \brief Replace a boolean at the label \a name. 1856 1857 This method is an overloaded method of 1858 ReplaceBool(const char *, int32, bool). 1859 It replaces the data at \a index \c 0. 1860*/ 1861 1862 1863/*! 1864 \fn status_t BMessage::ReplaceBool(const char *name, int32 index, bool aBoolean) 1865 \brief Replace a boolean at the label \a name at a specified 1866 \a index. 1867 1868 The data at the specified \a name and \a index will be 1869 replaced, if it matches the \c B_BOOL_TYPE. 1870 1871 \param name The name associated with the data to replace. 1872 \param index The index in the array to replace. 1873 \param aBoolean The object to store in the message. 1874 \retval B_OK The operation succeeded. 1875 \retval B_BAD_INDEX The index was out of range. 1876 \see ReplaceBool(const char*, bool) 1877*/ 1878 1879 1880/*! 1881 \fn status_t BMessage::ReplaceFloat(const char *name, float aFloat) 1882 \brief Replace a float at the label \a name. 1883 1884 This method is an overloaded method of 1885 ReplaceFloat(const char *, int32, float). 1886 It replaces the data at \a index \c 0. 1887*/ 1888 1889 1890/*! 1891 \fn status_t BMessage::ReplaceFloat(const char *name, int32 index, float aFloat) 1892 \brief Replace a float at the label \a name at a specified 1893 \a index. 1894 1895 The data at the specified \a name and \a index will be 1896 replaced, if it matches the \c B_FLOAT_TYPE. 1897 1898 \param name The name associated with the data to replace. 1899 \param index The index in the array to replace. 1900 \param aFloat The object to store in the message. 1901 \retval B_OK The operation succeeded. 1902 \retval B_BAD_INDEX The index was out of range. 1903 \see ReplaceFloat(const char*, float) 1904*/ 1905 1906 1907/*! 1908 \fn status_t BMessage::ReplaceDouble(const char *name, double aDouble) 1909 \brief Replace a double at the label \a name. 1910 1911 This method is an overloaded method of 1912 ReplaceDouble(const char *, int32, double). 1913 It replaces the data at \a index \c 0. 1914*/ 1915 1916 1917/*! 1918 \fn status_t BMessage::ReplaceDouble(const char *name, int32 index, double aDouble) 1919 \brief Replace a double at the label \a name at a specified 1920 \a index. 1921 1922 The data at the specified \a name and \a index will be 1923 replaced, if it matches the \c B_DOUBLE_TYPE. 1924 1925 \param name The name associated with the data to replace. 1926 \param index The index in the array to replace. 1927 \param aDouble The object to store in the message. 1928 \retval B_OK The operation succeeded. 1929 \retval B_BAD_INDEX The index was out of range. 1930 \see ReplaceDouble(const char*, double) 1931*/ 1932 1933 1934/*! 1935 \fn status_t BMessage::ReplacePointer(const char *name, const void *pointer) 1936 \brief Replace a pointer at the label \a name. 1937 1938 This method is an overloaded method of 1939 ReplacePointer(const char *, int32, const void *). 1940 It replaces the data at \a index \c 0. 1941*/ 1942 1943 1944/*! 1945 \fn status_t BMessage::ReplacePointer(const char *name,int32 index, const void *pointer) 1946 \brief Replace a pointer at the label \a name at a specified \a index. 1947 1948 The data at the specified \a name and \a index will be 1949 replaced, if it matches the \c B_POINTER_TYPE. 1950 1951 \param name The name associated with the data to replace. 1952 \param index The index in the array to replace. 1953 \param pointer The object to store in the message. 1954 \retval B_OK The operation succeeded. 1955 \retval B_BAD_INDEX The index was out of range. 1956 \see ReplacePointer(const char*, const void *) 1957*/ 1958 1959 1960/*! 1961 \fn status_t BMessage::ReplaceMessenger(const char *name, BMessenger messenger) 1962 \brief Replace a messenger at the label \a name. 1963 1964 This method is an overloaded method of 1965 ReplaceMessenger(const char *, int32, BMessenger). 1966 It replaces the data at \a index \c 0. 1967*/ 1968 1969 1970/*! 1971 \fn status_t BMessage::ReplaceMessenger(const char *name, int32 index, BMessenger messenger) 1972 \brief Replace a messenger at the label \a name at a specified 1973 \a index. 1974 1975 The data at the specified \a name and \a index will be 1976 replaced, if it matches the \c B_MESSENGER_TYPE. 1977 1978 \param name The name associated with the data to replace. 1979 \param index The index in the array to replace. 1980 \param messenger The object to store in the message. 1981 \retval B_OK The operation succeeded. 1982 \retval B_BAD_INDEX The index was out of range. 1983 \see ReplaceMessenger(const char*, BMessenger) 1984*/ 1985 1986 1987/*! 1988 \fn status_t BMessage::ReplaceRef(const char *name,const entry_ref *ref) 1989 \brief Replace a reference to a file at the label \a name. 1990 1991 This method is an overloaded method of 1992 ReplaceRef(const char *, int32, entry_ref *). 1993 It replaces the data at \a index \c 0. 1994*/ 1995 1996 1997/*! 1998 \fn status_t BMessage::ReplaceRef( const char *name, int32 index, const entry_ref *ref) 1999 \brief Replace a reference to a file at the label \a name at a 2000 specified \a index. 2001 2002 The data at the specified \a name and \a index will be 2003 replaced, if it matches the \c B_REF_TYPE. 2004 2005 \param name The name associated with the data to replace. 2006 \param index The index in the array to replace. 2007 \param ref The object to store in the message. 2008 \retval B_OK The operation succeeded. 2009 \retval B_BAD_INDEX The index was out of range. 2010 \see ReplaceRef(const char*, entry_ref *) 2011*/ 2012 2013 2014/*! 2015 \fn status_t BMessage::ReplaceMessage(const char *name, const BMessage *message) 2016 \brief Replace a message at the label \a name. 2017 2018 This method is an overloaded method of 2019 ReplaceMessage(const char *, int32, BMessage *). 2020 It replaces the data at \a index \c 0. 2021*/ 2022 2023 2024/*! 2025 \fn status_t BMessage::ReplaceMessage(const char *name, int32 index, const BMessage *message) 2026 \brief Replace a message at the label \a name at a specified 2027 \a index. 2028 2029 The data at the specified \a name and \a index will be 2030 replaced, if it matches the \c B_MESSAGE_TYPE. 2031 2032 \param name The name associated with the data to replace. 2033 \param index The index in the array to replace. 2034 \param message The object to store in the message. 2035 \retval B_OK The operation succeeded. 2036 \retval B_BAD_INDEX The index was out of range. 2037 \see ReplaceMessage(const char*, BMessage *) 2038*/ 2039 2040 2041/*! 2042 \fn status_t BMessage::ReplaceFlat(const char *name, BFlattenable *object) 2043 \brief Replace a flattened object at the label \a name. 2044 2045 This method is an overloaded method of 2046 ReplaceFlat(const char *, int32, BFlattenable *). 2047 2048 It replaces the data at \a index \c 0. 2049*/ 2050 2051 2052/*! 2053 \fn status_t BMessage::ReplaceFlat(const char *name, int32 index, BFlattenable *object) 2054 \brief Replace a flattened object at the label \a name at a 2055 specified \a index. 2056 2057 The data at the specified \a name and \a index will be 2058 replaced, if it matches the type returned by your object. This method uses 2059 BFlattenable::TypeCode() to determine the type of the object. 2060 2061 \param name The name associated with the data to replace. 2062 \param index The index in the array to replace. 2063 \param object The object to store in the message. 2064 2065 \retval B_OK The operation succeeded. 2066 \retval B_BAD_INDEX The index was out of range. 2067 2068 \see ReplaceFlat(const char*, BFlattenable *) 2069*/ 2070 2071 2072//! @} 2073 2074 2075/*! 2076 \name Deprecated methods 2077 2078 These methods are \e very likely to disappear, and they have been replaced 2079 by safer and more powerful methods. These methods are still implemented 2080 for binary compatibility, but they are not documented. 2081*/ 2082 2083 2084//! @{ 2085 2086 2087/*! 2088 \fn void *BMessage::operator new(size_t size) 2089 \brief Internal operator. 2090*/ 2091 2092 2093/*! 2094 \fn void *BMessage::operator new(size_t, void *pointer) 2095 \brief Internal operator. 2096*/ 2097 2098 2099/*! 2100 \fn void BMessage::operator delete(void *pointer, size_t size) 2101 \brief Internal operator. 2102*/ 2103 2104 2105/*! 2106 \fn bool BMessage::HasRect(const char *, int32) const 2107 \brief Deprecated. 2108*/ 2109 2110 2111/*! 2112 \fn bool BMessage::HasPoint(const char *, int32) const 2113 \brief Deprecated. 2114*/ 2115 2116 2117/*! 2118 \fn bool BMessage::HasString(const char *, int32) const 2119 \brief Deprecated. 2120*/ 2121 2122 2123/*! 2124 \fn bool BMessage::HasInt8(const char *, int32) const 2125 \brief Deprecated. 2126*/ 2127 2128 2129/*! 2130 \fn bool BMessage::HasInt16(const char *, int32) const 2131 \brief Deprecated. 2132*/ 2133 2134 2135/*! 2136 \fn bool BMessage::HasInt32(const char *, int32) const 2137 \brief Deprecated. 2138*/ 2139 2140 2141/*! 2142 \fn bool BMessage::HasInt64(const char *, int32) const 2143 \brief Deprecated. 2144*/ 2145 2146 2147/*! 2148 \fn bool BMessage::HasBool(const char *, int32) const 2149 \brief Deprecated. 2150*/ 2151 2152 2153/*! 2154 \fn bool BMessage::HasFloat(const char *, int32) const 2155 \brief Deprecated. 2156*/ 2157 2158 2159/*! 2160 \fn bool BMessage::HasDouble(const char *, int32) const 2161 \brief Deprecated. 2162*/ 2163 2164 2165/*! 2166 \fn bool BMessage::HasPointer(const char *, int32) const 2167 \brief Deprecated. 2168*/ 2169 2170 2171/*! 2172 \fn bool BMessage::HasMessenger(const char *, int32) const 2173 \brief Deprecated. 2174*/ 2175 2176 2177/*! 2178 \fn bool BMessage::HasRef(const char *, int32) const 2179 \brief Deprecated. 2180*/ 2181 2182 2183/*! 2184 \fn bool BMessage::HasMessage(const char *, int32) const 2185 \brief Deprecated. 2186*/ 2187 2188 2189/*! 2190 \fn bool BMessage::HasFlat(const char *, const BFlattenable *) const 2191 \brief Deprecated. 2192*/ 2193 2194 2195/*! 2196 \fn bool BMessage::HasFlat(const char *, int32, const BFlattenable *) const 2197 \brief Deprecated. 2198*/ 2199 2200 2201/*! 2202 \fn bool BMessage::HasData(const char *, type_code , int32) const 2203 \brief Deprecated. 2204*/ 2205 2206 2207/*! 2208 \fn BRect BMessage::FindRect(const char *, int32) const 2209 \brief Deprecated. 2210*/ 2211 2212 2213/*! 2214 \fn BPoint BMessage::FindPoint(const char *, int32) const 2215 \brief Deprecated. 2216*/ 2217 2218 2219/*! 2220 \fn const char *BMessage::FindString(const char *, int32) const 2221 \brief Deprecated. 2222*/ 2223 2224 2225/*! 2226 \fn int8 BMessage::FindInt8(const char *, int32) const 2227 \brief Deprecated. 2228*/ 2229 2230 2231/*! 2232 \fn int16 BMessage::FindInt16(const char *, int32) const 2233 \brief Deprecated. 2234*/ 2235 2236 2237/*! 2238 \fn int32 BMessage::FindInt32(const char *, int32) const 2239 \brief Deprecated. 2240*/ 2241 2242 2243/*! 2244 \fn int64 BMessage::FindInt64(const char *, int32) const 2245 \brief Deprecated. 2246*/ 2247 2248 2249/*! 2250 \fn bool BMessage::FindBool(const char *, int32) const 2251 \brief Deprecated. 2252*/ 2253 2254 2255/*! 2256 \fn float BMessage::FindFloat(const char *, int32) const 2257 \brief Deprecated. 2258*/ 2259 2260 2261/*! 2262 \fn double BMessage::FindDouble(const char *, int32) const 2263 \brief Deprecated. 2264*/ 2265 2266 2267//! @} 2268