vfs: check userland buffers before reading them.
[haiku.git] / src / kits / debugger / util / ArchivingUtils.h
blob1f5e703b7238451fe43e3e46eaca79af66a9845a
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef ARCHIVABLE_UTILS_H
6 #define ARCHIVABLE_UTILS_H
9 #include <Archivable.h>
12 class ArchivingUtils {
13 public:
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)
37 return NULL;
39 ObjectType* object = dynamic_cast<ObjectType*>(archivable);
40 if (object == NULL)
41 delete archivable;
43 return object;
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,
59 int32 index)
61 return CastOrDelete<ObjectType>(UnarchiveChild(archive, fieldName, index));
66 #endif // ARCHIVABLE_UTILS_H