1 //------------------------------------------------------------------------------
2 // MessageStringItemTest.h
4 //------------------------------------------------------------------------------
6 #ifndef MESSAGESTRINGITEMTEST_H
7 #define MESSAGESTRINGITEMTEST_H
9 // Standard Includes -----------------------------------------------------------
11 // System Includes -------------------------------------------------------------
15 // Project Includes ------------------------------------------------------------
17 // Local Includes --------------------------------------------------------------
18 #include "MessageItemTest.h"
20 // Local Defines ---------------------------------------------------------------
22 // Globals ---------------------------------------------------------------------
24 struct TBStringFuncPolicy
26 static status_t
Add(BMessage
& msg
, const char* name
, BString
& data
);
27 static status_t
Find(BMessage
& msg
, const char* name
, int32 index
,
29 static status_t
ShortFind(BMessage
& msg
, const char* name
, BString
* data
);
30 static BString
QuickFind(BMessage
& msg
, const char* name
, int32 index
);
31 static bool Has(BMessage
& msg
, const char* name
, int32 index
);
32 static status_t
Replace(BMessage
& msg
, const char* name
, int32 index
,
34 static status_t
AddData(BMessage
& msg
, const char* name
, type_code type
,
35 const BString
* data
, ssize_t size
, bool);
36 static status_t
FindData(BMessage
& msg
, const char* name
, type_code type
,
37 int32 index
, const void** data
, ssize_t
* size
);
42 BString
TBStringFuncPolicy::sStr
;
43 //------------------------------------------------------------------------------
44 status_t
TBStringFuncPolicy::Add(BMessage
& msg
, const char* name
,
47 return msg
.AddString(name
, data
);
49 //------------------------------------------------------------------------------
50 status_t
TBStringFuncPolicy::Find(BMessage
& msg
, const char* name
,
51 int32 index
, BString
* data
)
53 return msg
.FindString(name
, index
, data
);
55 //------------------------------------------------------------------------------
56 inline status_t
TBStringFuncPolicy::ShortFind(BMessage
& msg
, const char* name
,
59 return msg
.FindString(name
, data
);
61 //------------------------------------------------------------------------------
62 BString
TBStringFuncPolicy::QuickFind(BMessage
& msg
, const char* name
,
66 msg
.FindString(name
, index
, &data
);
69 //------------------------------------------------------------------------------
70 bool TBStringFuncPolicy::Has(BMessage
& msg
, const char* name
,
73 return msg
.HasString(name
, index
);
75 //------------------------------------------------------------------------------
76 status_t
TBStringFuncPolicy::Replace(BMessage
& msg
, const char* name
,
77 int32 index
, BString
& data
)
79 return msg
.ReplaceString(name
, index
, data
);
81 //------------------------------------------------------------------------------
82 status_t
TBStringFuncPolicy::AddData(BMessage
& msg
, const char* name
,
83 type_code type
, const BString
* data
,
86 return msg
.AddData(name
, type
, (const void*)data
->String(), size
,
89 //------------------------------------------------------------------------------
90 status_t
TBStringFuncPolicy::FindData(BMessage
& msg
, const char* name
,
91 type_code type
, int32 index
,
92 const void** data
, ssize_t
* size
)
96 status_t err
= msg
.FindData(name
, type
, index
, (const void**)&ptr
, size
);
100 *(BString
**)data
= &sStr
;
105 //------------------------------------------------------------------------------
108 struct TBStringInitPolicy
: public ArrayTypeBase
<BString
>
110 inline static BString
Zero() { return BString(); }
111 inline static BString
Test1() { return "Test1"; }
112 inline static BString
Test2() { return "Supercalafragilistricexpialadocious"; }
113 inline static size_t SizeOf(const BString
& s
) { return s
.Length() + 1; }
114 inline static ArrayType
Array()
117 array
.push_back(Zero());
118 array
.push_back(Test1());
119 array
.push_back(Test2());
123 //------------------------------------------------------------------------------
124 struct TBStringAssertPolicy
126 inline static BString
Zero() { return BString(); }
127 inline static BString
Invalid() { return BString(); }
128 static bool Size(size_t size
, BString
& msg
)
129 ;//{ return size == msg.FlattenedSize(); }
131 bool TBStringAssertPolicy::Size(size_t size
, BString
& data
)
133 return size
== (size_t)data
.Length() + 1;
135 //------------------------------------------------------------------------------
136 typedef TMessageItemTest
144 TMessageBStringItemTest
;
146 #endif // MESSAGESTRINGITEMTEST_H