BMessage: Add {Add,Find}Strings()
They add a BStringList to/extract it from a B_STRING_TYPE field.
This commit is contained in:
parent
3c6784e95c
commit
cf0a957ff6
@ -24,6 +24,7 @@ class BBlockCache;
|
||||
class BMessenger;
|
||||
class BHandler;
|
||||
class BString;
|
||||
class BStringList;
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
@ -125,6 +126,7 @@ class BMessage {
|
||||
status_t AddSize(const char* name, BSize aSize);
|
||||
status_t AddString(const char *name, const char *aString);
|
||||
status_t AddString(const char *name, const BString &aString);
|
||||
status_t AddStrings(const char *name, const BStringList &list);
|
||||
status_t AddInt8(const char *name, int8 value);
|
||||
status_t AddUInt8(const char *name, uint8 value);
|
||||
status_t AddInt16(const char *name, int16 value);
|
||||
@ -170,6 +172,7 @@ class BMessage {
|
||||
status_t FindString(const char *name, int32 index, const char **string) const;
|
||||
status_t FindString(const char *name, BString *string) const;
|
||||
status_t FindString(const char *name, int32 index, BString *string) const;
|
||||
status_t FindStrings(const char *name, BStringList *list) const;
|
||||
status_t FindInt8(const char *name, int8 *value) const;
|
||||
status_t FindInt8(const char *name, int32 index, int8 *value) const;
|
||||
status_t FindUInt8(const char *name, uint8 *value) const;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <Point.h>
|
||||
#include <Rect.h>
|
||||
#include <String.h>
|
||||
#include <StringList.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
@ -2531,6 +2532,20 @@ BMessage::AddString(const char *name, const BString &string)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::AddStrings(const char *name, const BStringList &list)
|
||||
{
|
||||
int32 count = list.CountStrings();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
status_t error = AddString(name, list.StringAt(i));
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::AddPointer(const char *name, const void *pointer)
|
||||
{
|
||||
@ -2691,6 +2706,36 @@ BMessage::FindString(const char *name, int32 index, BString *string) const
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::FindStrings(const char *name, BStringList *list) const
|
||||
{
|
||||
if (list == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
list->MakeEmpty();
|
||||
|
||||
// get the number of items
|
||||
type_code type;
|
||||
int32 count;
|
||||
if (GetInfo(name, &type, &count) != B_OK)
|
||||
return B_NAME_NOT_FOUND;
|
||||
|
||||
if (type != B_STRING_TYPE)
|
||||
return B_BAD_DATA;
|
||||
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
BString string;
|
||||
status_t error = FindString(name, i, &string);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
if (!list->Add(string))
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::FindPointer(const char *name, void **pointer) const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user