1 //------------------------------------------------------------------------------
2 // MessageRefItemTest.h
4 //------------------------------------------------------------------------------
6 #ifndef MESSAGEREFITEMTEST_H
7 #define MESSAGEREFITEMTEST_H
9 // Standard Includes -----------------------------------------------------------
11 // System Includes -------------------------------------------------------------
15 // Project Includes ------------------------------------------------------------
17 // Local Includes --------------------------------------------------------------
19 // Local Defines ---------------------------------------------------------------
21 // Globals ---------------------------------------------------------------------
25 static status_t
Add(BMessage
& msg
, const char* name
, entry_ref
& val
)
27 return msg
.AddRef(name
, &val
);
29 static status_t
AddData(BMessage
& msg
, const char* name
, type_code type
,
30 entry_ref
* data
, ssize_t size
, bool);
31 static status_t
Find(BMessage
& msg
, const char* name
, int32 index
,
34 return msg
.FindRef(name
, index
, val
);
36 static status_t
ShortFind(BMessage
& msg
, const char* name
, entry_ref
* val
)
38 return msg
.FindRef(name
, val
);
40 static entry_ref
QuickFind(BMessage
& msg
, const char* name
, int32 index
);
41 static bool Has(BMessage
& msg
, const char* name
, int32 index
)
43 return msg
.HasRef(name
, index
);
45 static status_t
Replace(BMessage
& msg
, const char* name
, int32 index
,
48 return msg
.ReplaceRef(name
, index
, &val
);
50 static status_t
FindData(BMessage
& msg
, const char* name
, type_code type
,
51 int32 index
, const void** data
, ssize_t
* size
);
54 static entry_ref sRef
;
56 status_t
TRefFuncPolicy::AddData(BMessage
& msg
, const char* name
, type_code type
,
57 entry_ref
* data
, ssize_t size
, bool)
60 status_t err
= Path
.InitCheck();
65 err
= Path
.Flatten(buf
, size
);
70 err
= msg
.AddData(name
, type
, buf
, size
, false);
76 entry_ref
TRefFuncPolicy::QuickFind(BMessage
&msg
, const char *name
, int32 index
)
79 // There must be some 1337 template voodoo way of making the inclusion
80 // of this function conditional. In the meantime, we offer this
83 msg
.FindRef(name
, index
, &ref
);
87 status_t
TRefFuncPolicy::FindData(BMessage
& msg
, const char* name
,
88 type_code type
, int32 index
,
89 const void** data
, ssize_t
* size
)
93 status_t err
= msg
.FindData(name
, type
, index
, (const void**)&ptr
, size
);
97 err
= Path
.Unflatten(type
, ptr
, *size
);
102 err
= get_ref_for_path(Path
.Path(), &sRef
);
105 *(entry_ref
**)data
= &sRef
;
111 *(entry_ref
**)data
= &sRef
;
117 entry_ref
TRefFuncPolicy::sRef
;
118 //------------------------------------------------------------------------------
119 struct TRefInitPolicy
: public ArrayTypeBase
<entry_ref
>
121 inline static entry_ref
Zero() { return entry_ref(); }
122 static entry_ref
Test1()
125 get_ref_for_path("/boot/beos/apps/camera", &ref
);
128 static entry_ref
Test2()
131 get_ref_for_path("/boot/develop/headers/be/Be.h", &ref
);
134 static size_t SizeOf(const entry_ref
& data
)
137 return Path
.FlattenedSize();
139 inline static ArrayType
Array()
142 array
.push_back(Zero());
143 array
.push_back(Test1());
144 array
.push_back(Test2());
148 //------------------------------------------------------------------------------
149 struct TRefAssertPolicy
151 inline static entry_ref
Zero() { return TRefInitPolicy::Zero(); }
152 inline static entry_ref
Invalid() { return TRefInitPolicy::Zero();}
154 static bool Size(size_t size
, entry_ref
& ref
)
156 return size
== TRefInitPolicy::SizeOf(ref
);
159 //------------------------------------------------------------------------------
160 typedef TMessageItemTest
170 #endif // MESSAGEREFITEMTEST_H