xref: /haiku/headers/private/storage/ResourceItem.h (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
1 //----------------------------------------------------------------------
2 //  This software is part of the Haiku distribution and is covered
3 //  by the MIT License.
4 //---------------------------------------------------------------------
5 /*!
6 	\file ResourcesItem.h
7 	ResourceItem interface declaration.
8 */
9 
10 #ifndef _RESOURCE_ITEM_H
11 #define _RESOURCE_ITEM_H
12 
13 #include <DataIO.h>
14 #include <String.h>
15 
16 namespace BPrivate {
17 namespace Storage {
18 
19 /*!
20 	\class ResourceItem
21 	\brief Represents a resource loaded into memory.
22 
23 	This class represents a resource completely or partially loaded into
24 	memory. The minimal information stored in the object should be its
25 	type, ID and name and the size of its data. If the data are not loaded
26 	then additionally the offset (into a resource file) should be valid.
27 	As soon as the data are loaded as well, the offset is more or less
28 	meaningless.
29 
30 	Creating a new resource can be done by calling SetIdentity() after the
31 	default construction. The object then represents a resource with the
32 	specified type, ID and name and with empty data. Data can arbitrarily
33 	be read and written using the methods the super class BMallocIO provides.
34 
35 	The memory for the resource data is owned by the ResourceItem object and
36 	freed on destruction.
37 
38 	\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
39 
40 	\version 0.0.0
41 */
42 class ResourceItem : public BMallocIO {
43 public:
44 	ResourceItem();
45 	virtual ~ResourceItem();
46 
47 	virtual ssize_t WriteAt(off_t pos, const void *buffer, size_t size);
48 	virtual status_t SetSize(off_t size);
49 
50 	void SetLocation(int32 offset, size_t initialSize);
51 	void SetIdentity(type_code type, int32 id, const char *name);
52 
53 	void SetOffset(int32 offset);
54 	int32 Offset() const;
55 
56 	size_t InitialSize() const;
57 	size_t DataSize() const;
58 
59 	void SetType(type_code type);
60 	type_code Type() const;
61 
62 	void SetID(int32 id);
63 	int32 ID() const;
64 
65 	void SetName(const char *name);
66 	const char *Name() const;
67 
68 	void *Data() const;
69 
70 	void SetLoaded(bool loaded);
71 	bool IsLoaded() const;
72 
73 	void SetModified(bool modified);
74 	bool IsModified() const;
75 
76 private:
77 	int32		fOffset;
78 	size_t		fInitialSize;
79 	type_code	fType;
80 	int32		fID;
81 	BString		fName;
82 	bool		fIsLoaded;
83 	bool		fIsModified;
84 };
85 
86 };	// namespace Storage
87 };	// namespace BPrivate
88 
89 #endif	// _RESOURCE_ITEM_H
90 
91 
92