xref: /haiku/headers/build/os/storage/Resources.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 /*!
6 	\file Resources.h
7 	BResources interface declaration.
8 */
9 
10 #ifndef _RESOURCES_H
11 #define _RESOURCES_H
12 
13 #include <File.h>
14 
15 #ifdef USE_OPENBEOS_NAMESPACE
16 namespace OpenBeOS {
17 #endif
18 
19 namespace BPrivate {
20 	namespace Storage {
21 		class ResourcesContainer;
22 		class ResourceFile;
23 	};
24 };
25 
26 /*!
27 	\class BResources
28 	\brief Represent the resources in a file
29 
30 	Provides an interface for accessing and manipulating resources.
31 
32 	\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
33 
34 	\version 0.0.0
35 */
36 class BResources {
37 public:
38 	BResources();
39 	BResources(const BFile *file, bool clobber = false);
40 	virtual ~BResources();
41 
42 	status_t SetTo(const BFile *file, bool clobber = false);
43 	void Unset();
44 	status_t InitCheck() const;
45 
46 	const BFile &File() const;
47 
48 	const void *LoadResource(type_code type, int32 id, size_t *outSize);
49 	const void *LoadResource(type_code type, const char *name,
50 							 size_t *outSize);
51 
52 	status_t PreloadResourceType(type_code type = 0);
53 
54 	status_t Sync();
55 	status_t MergeFrom(BFile *fromFile);
56 	status_t WriteTo(BFile *file);
57 
58 	status_t AddResource(type_code type, int32 id, const void *data,
59 						 size_t length, const char *name = NULL);
60 
61 	bool HasResource(type_code type, int32 id);
62 	bool HasResource(type_code type, const char *name);
63 
64 	bool GetResourceInfo(int32 byIndex, type_code *typeFound, int32 *idFound,
65 						 const char **nameFound, size_t *lengthFound);
66 	bool GetResourceInfo(type_code byType, int32 andIndex, int32 *idFound,
67 						 const char **nameFound, size_t *lengthFound);
68 	bool GetResourceInfo(type_code byType, int32 andID,
69 						 const char **nameFound, size_t *lengthFound);
70 	bool GetResourceInfo(type_code byType, const char *andName, int32 *idFound,
71 						 size_t *lengthFound);
72 	bool GetResourceInfo(const void *byPointer, type_code *typeFound,
73 						 int32 *idFound, size_t *lengthFound,
74 						 const char **nameFound);
75 
76 	status_t RemoveResource(const void *resource);
77 	status_t RemoveResource(type_code type, int32 id);
78 
79 
80 	// deprecated
81 
82 	status_t WriteResource(type_code type, int32 id, const void *data,
83 						   off_t offset, size_t length);
84 
85 	status_t ReadResource(type_code type, int32 id, void *data, off_t offset,
86 						  size_t length);
87 
88 	void *FindResource(type_code type, int32 id, size_t *lengthFound);
89 	void *FindResource(type_code type, const char *name, size_t *lengthFound);
90 
91 private:
92 	// FBC
93 	virtual void _ReservedResources1();
94 	virtual void _ReservedResources2();
95 	virtual void _ReservedResources3();
96 	virtual void _ReservedResources4();
97 	virtual void _ReservedResources5();
98 	virtual void _ReservedResources6();
99 	virtual void _ReservedResources7();
100 	virtual void _ReservedResources8();
101 
102 private:
103 	BFile							fFile;
104 	BPrivate::Storage::ResourcesContainer	*fContainer;
105 	BPrivate::Storage::ResourceFile		*fResourceFile;
106 	bool							fReadOnly;
107 	bool							_pad[3];
108 	uint32							_reserved[3];	// FBC
109 };
110 
111 
112 #ifdef USE_OPENBEOS_NAMESPACE
113 };		// namespace OpenBeOS
114 #endif
115 
116 #endif	// _RESOURCES_H
117 
118 
119