Added a new BMessageBody and BMessageField implementation and added a version of BMessage to
use it. It is not (yet) included in the build and won't break anything. As we now only have thin wrappers around the *Data() functions, the templatized implementation does not make much sense anymore and wouldn't work either. I started this new implementation to be as clean as possible. Instead of using a std::map and BDataBuffer it uses BList and BMallocIO. It passes the unit tests and it even seems to be a bit quicker in some tests (but not as quick as the R5 one). Flattening/Unflattening does not work yet so you can't use it under Haiku right now. It's completely work in progress (I started it just 4 hours ago). Shout if you see something completely broken, reviews welcome. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13776 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2005, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz <[email protected]>
|
||||
*/
|
||||
|
||||
/* BMessageBody handles data storage and retrieval for BMessage. */
|
||||
|
||||
#ifndef _MESSAGE_BODY_H_
|
||||
#define _MESSAGE_BODY_H_
|
||||
|
||||
#include <List.h>
|
||||
#include "MessageField.h"
|
||||
|
||||
enum {
|
||||
B_FLATTENABLE_TYPE = 'FLAT'
|
||||
};
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class BMessageBody {
|
||||
public:
|
||||
BMessageBody();
|
||||
BMessageBody(const BMessageBody &other);
|
||||
~BMessageBody();
|
||||
|
||||
BMessageBody &operator=(const BMessageBody &other);
|
||||
|
||||
status_t GetInfo(type_code typeRequested, int32 which,
|
||||
char **name, type_code *typeFound,
|
||||
int32 *countFound = NULL) const;
|
||||
status_t GetInfo(const char *name, type_code *typeFound,
|
||||
int32 *countFound = NULL) const;
|
||||
status_t GetInfo(const char *name, type_code *typeFound,
|
||||
bool *fixedSize) const;
|
||||
|
||||
int32 CountNames(type_code type) const;
|
||||
bool IsEmpty() const;
|
||||
|
||||
ssize_t FlattenedSize() const;
|
||||
status_t Flatten(BDataIO *stream) const;
|
||||
|
||||
status_t AddData(const char *name, BMallocIO *buffer,
|
||||
type_code type);
|
||||
status_t RemoveData(const char *name, int32 index = 0);
|
||||
|
||||
bool HasData(const char *name, type_code t, int32 n) const;
|
||||
status_t FindData(const char *name, type_code type,
|
||||
int32 index, const void **data,
|
||||
ssize_t *numBytes) const;
|
||||
status_t ReplaceData(const char *name, int32 index,
|
||||
BMallocIO *buffer, type_code type);
|
||||
|
||||
status_t Rename(const char *oldName, const char *newName);
|
||||
status_t RemoveName(const char *name);
|
||||
status_t MakeEmpty();
|
||||
|
||||
void PrintToStream() const;
|
||||
|
||||
private:
|
||||
BMessageField *FindData(const char *name, type_code type,
|
||||
status_t &error) const;
|
||||
|
||||
BList fFields;
|
||||
};
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MESSAGE_BODY_H_
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2005, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Lotz <[email protected]>
|
||||
*/
|
||||
|
||||
/* BMessageField contains the data for indiviual named fields in BMessageBody */
|
||||
|
||||
#ifndef _MESSAGE_FIELD_H_
|
||||
#define _MESSAGE_FIELD_H_
|
||||
|
||||
#include <List.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#define MSG_FLAG_VALID 0x01
|
||||
#define MSG_FLAG_MINI_DATA 0x02
|
||||
#define MSG_FLAG_FIXED_SIZE 0x04
|
||||
#define MSG_FLAG_SINGLE_ITEM 0x08
|
||||
#define MSG_FLAG_ALL 0x0F
|
||||
|
||||
#define MSG_LAST_ENTRY 0x00
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
class BMessageField {
|
||||
public:
|
||||
BMessageField(const char *name, type_code type);
|
||||
~BMessageField();
|
||||
|
||||
uint8 Flags();
|
||||
|
||||
void SetName(const char *name);
|
||||
const char *Name() const { return fName.String(); };
|
||||
uint8 NameLength() const { return fName.Length(); };
|
||||
type_code Type() const { return fType; };
|
||||
|
||||
void AddItem(BMallocIO *item);
|
||||
void ReplaceItem(int32 index, BMallocIO *item,
|
||||
bool deleteOld = true);
|
||||
void RemoveItem(int32 index, bool deleteIt = true);
|
||||
int32 CountItems() const { return fItems.CountItems(); };
|
||||
size_t SizeAt(int32 index) const;
|
||||
const void *BufferAt(int32 index) const;
|
||||
|
||||
bool IsFixedSize() const { return fFixedSize; };
|
||||
size_t TotalSize() const { return fTotalSize; };
|
||||
|
||||
void PrintToStream() const;
|
||||
|
||||
private:
|
||||
bool IsFixedSize(type_code type);
|
||||
|
||||
BString fName;
|
||||
type_code fType;
|
||||
BList fItems;
|
||||
bool fFixedSize;
|
||||
size_t fTotalSize;
|
||||
};
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _MESSAGE_FIELD_H_
|
||||
Reference in New Issue
Block a user