2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef ARCHIVABLE_UTILS_H
6 #define ARCHIVABLE_UTILS_H
9 #include <Archivable.h>
12 class ArchivingUtils
{
14 template<typename ObjectType
>
15 static ObjectType
* CastOrDelete(BArchivable
* archivable
);
17 template<typename ObjectType
>
18 static ObjectType
* Unarchive(const BMessage
& archive
);
20 static status_t
ArchiveChild(BArchivable
* object
,
21 BMessage
& parentArchive
,
22 const char* fieldName
);
23 static BArchivable
* UnarchiveChild(const BMessage
& parentArchive
,
24 const char* fieldName
, int32 index
= 0);
26 template<typename ObjectType
>
27 static ObjectType
* UnarchiveChild(const BMessage
& archive
,
28 const char* fieldName
, int32 index
= 0);
32 template<typename ObjectType
>
33 /*static*/ ObjectType
*
34 ArchivingUtils::CastOrDelete(BArchivable
* archivable
)
36 if (archivable
== NULL
)
39 ObjectType
* object
= dynamic_cast<ObjectType
*>(archivable
);
47 template<typename ObjectType
>
48 /*static*/ ObjectType
*
49 ArchivingUtils::Unarchive(const BMessage
& archive
)
51 return CastOrDelete
<ObjectType
>(instantiate_object(
52 const_cast<BMessage
*>(&archive
)));
56 template<typename ObjectType
>
57 /*static*/ ObjectType
*
58 ArchivingUtils::UnarchiveChild(const BMessage
& archive
, const char* fieldName
,
61 return CastOrDelete
<ObjectType
>(UnarchiveChild(archive
, fieldName
, index
));
66 #endif // ARCHIVABLE_UTILS_H