Added BMessage::Append(), and new(std::nothrow_t).
* Append() copies all fields from the specified message. * The nothrow operator new allows you to add BMessages to a BObjectList.
This commit is contained in:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -9,6 +9,8 @@
|
|||||||
#define _MESSAGE_H
|
#define _MESSAGE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#include <BeBuild.h>
|
#include <BeBuild.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Flattenable.h>
|
#include <Flattenable.h>
|
||||||
@@ -146,6 +148,8 @@ class BMessage {
|
|||||||
const void *data, ssize_t numBytes,
|
const void *data, ssize_t numBytes,
|
||||||
bool isFixedSize = true, int32 count = 1);
|
bool isFixedSize = true, int32 count = 1);
|
||||||
|
|
||||||
|
status_t Append(const BMessage &message);
|
||||||
|
|
||||||
// Removing data
|
// Removing data
|
||||||
status_t RemoveData(const char *name, int32 index = 0);
|
status_t RemoveData(const char *name, int32 index = 0);
|
||||||
status_t RemoveName(const char *name);
|
status_t RemoveName(const char *name);
|
||||||
@@ -268,6 +272,7 @@ class BMessage {
|
|||||||
|
|
||||||
void *operator new(size_t size);
|
void *operator new(size_t size);
|
||||||
void *operator new(size_t, void *pointer);
|
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);
|
void operator delete(void *pointer, size_t size);
|
||||||
|
|
||||||
// Private, reserved, or obsolete
|
// Private, reserved, or obsolete
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -245,8 +245,15 @@ void *
|
|||||||
BMessage::operator new(size_t size)
|
BMessage::operator new(size_t size)
|
||||||
{
|
{
|
||||||
DEBUG_FUNCTION_ENTER2;
|
DEBUG_FUNCTION_ENTER2;
|
||||||
void *pointer = sMsgCache->Get(size);
|
return sMsgCache->Get(size);
|
||||||
return pointer;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
status_t
|
||||||
BMessage::FindAlignment(const char *name, BAlignment *alignment) const
|
BMessage::FindAlignment(const char *name, BAlignment *alignment) const
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user