Files
haiku-beta6/headers/private/shared/MessageBuilder.h
T
Augustin Cavalier cbfbbf6d4d Change BObjectList to take "owning" as a template parameter and adjust all consumers.
Since BObjectList is a template class, this only breaks ABI where
BObjectList was exposed in public methods, and even then it's only
a name mangling break and we should be able to add compatibility
methods if necessary.

(The old "bool owning" member variable is left intact for ABI
compatibility, for the moment, though it's otherwise unused now.)

Tracker's PoseList is the only remaining type that has a "bool owning"
switch in the constructor rather than template parameters.

This should significantly improve the output of static code analysis
tools that previously detected list operations as causing use-after-frees
and double-frees, as well as make code maintenance easier by making it
easier to determine what list owns (or does not own) an object.
It should also be a minor performance optimization, since the branches
for calls to delete/free should now be optimized out altogether.

Still boots to desktop and Tracker, Deskbar, Debugger all tested
and verified as working.

Change-Id: If2a24a6f0d22e7a506ef554fcfdd328907279ed4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8915
Reviewed-by: waddlesplash <[email protected]>
2025-02-06 00:06:32 +00:00

55 lines
1.5 KiB
C++

/*
* Copyright 2014, Augustin Cavalier (waddlesplash)
* Distributed under the terms of the MIT License.
*/
#ifndef MESSAGE_BUILDER_H
#define MESSAGE_BUILDER_H
#include <Message.h>
#include <ObjectList.h>
#include <String.h>
namespace BPrivate {
class BMessageBuilder {
public:
BMessageBuilder(BMessage& message);
status_t PushObject(const char* name);
status_t PushObject(uint32 name);
status_t PopObject();
uint32 What();
void SetWhat(uint32 what);
uint32 CountNames(type_code type = B_ANY_TYPE);
// Copied from Message.h
status_t AddString(const char* name, const char* string);
status_t AddString(const char* name,
const BString& string);
status_t AddInt8(const char* name, int8 value);
status_t AddUInt8(const char* name, uint8 value);
status_t AddInt16(const char* name, int16 value);
status_t AddUInt16(const char* name, uint16 value);
status_t AddInt32(const char* name, int32 value);
status_t AddUInt32(const char* name, uint32 value);
status_t AddInt64(const char* name, int64 value);
status_t AddUInt64(const char* name, uint64 value);
status_t AddBool(const char* name, bool value);
status_t AddFloat(const char* name, float value);
status_t AddDouble(const char* name, double value);
status_t AddPointer(const char* name,
const void* pointer);
private:
BObjectList<BMessage> fStack;
BObjectList<BString, true> fNameStack;
BMessage* fCurrentMessage;
};
} // namespace BPrivate
#endif // MESSAGE_BUILDER_H