diff --git a/headers/os/app/Message.h b/headers/os/app/Message.h index 2920a1a3a2..c64fdd7fc0 100644 --- a/headers/os/app/Message.h +++ b/headers/os/app/Message.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2010, Haiku Inc. All Rights Reserved. + * Copyright 2005-2012, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -9,6 +9,8 @@ #define _MESSAGE_H +#include + #include #include #include @@ -146,6 +148,8 @@ class BMessage { const void *data, ssize_t numBytes, bool isFixedSize = true, int32 count = 1); + status_t Append(const BMessage &message); + // Removing data status_t RemoveData(const char *name, int32 index = 0); status_t RemoveName(const char *name); @@ -268,6 +272,7 @@ class BMessage { void *operator new(size_t size); void *operator new(size_t, void *pointer); + void *operator new(size_t, const std::nothrow_t &noThrow); void operator delete(void *pointer, size_t size); // Private, reserved, or obsolete diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index a4af4651c1..4b9e5dbaee 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2005-2011, Haiku Inc. All rights reserved. + * Copyright 2005-2012, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -245,8 +245,15 @@ void * BMessage::operator new(size_t size) { DEBUG_FUNCTION_ENTER2; - void *pointer = sMsgCache->Get(size); - return pointer; + return sMsgCache->Get(size); +} + + +void * +BMessage::operator new(size_t size, const std::nothrow_t &noThrow) +{ + DEBUG_FUNCTION_ENTER2; + return sMsgCache->Get(size); } @@ -2622,6 +2629,34 @@ BMessage::AddFlat(const char *name, BFlattenable *object, int32 count) } +status_t +BMessage::Append(const BMessage &other) +{ + field_header *field = other.fFields; + for (uint32 i = 0; i < other.fHeader->field_count; i++, field++) { + const char *name = (const char *)(other.fData + field->offset); + const void *data = (const void *)(other.fData + field->offset + + field->name_length); + bool isFixed = (field->flags & FIELD_FLAG_FIXED_SIZE) != 0; + size_t size = field->data_size / field->count; + + for (uint32 j = 0; j < field->count; j++) { + if (!isFixed) + size = *(uint32 *)data; + + status_t status = AddData(name, field->type, data, size, + isFixed != 0, 1); + if (status != B_OK) + return status; + + data = (const void *)((const char *)data + size + + (isFixed ? 0 : sizeof(uint32))); + } + } + return B_OK; +} + + status_t BMessage::FindAlignment(const char *name, BAlignment *alignment) const {