1//----------------------------------------------------------------------
2//  This software is part of the Haiku distribution and is covered
3//  by the MIT License.
4//---------------------------------------------------------------------
5/*!
6	\file ResourcesContainer.h
7	ResourcesContainer interface declaration.
8*/
9
10#ifndef _RESOURCES_CONTAINER_H
11#define _RESOURCES_CONTAINER_H
12
13#include <List.h>
14
15namespace BPrivate {
16namespace Storage {
17
18class ResourceItem;
19
20/*!
21	\class ResourcesContainer
22	\brief Represents a collection of resources.
23
24	This class can be used to manage a collection of resources represented
25	by ResourceItem's. Usually it does never contain two resources with the
26	same type \em and ID, since AddResource() replaces an old item with the
27	new one, unless explicitly told not to do so. This should only be done
28	by ResourceFile, when type and ID of the items are not yet known.
29	Asside from the basic vector features like Add/RemoveResource()/
30	ResourceAt() and MakeEmpty() a bunch of IndexOf() methods are provided
31	and AssimilateResources() which incorporates all resources of another
32	container into this one (replacing old resources, if necessary), emptying
33	the other one.
34
35	The ResourceItem's in a container are deleted on destruction, unless
36	removed before via RemoveResource(). MakeEmpty() deletes the items as
37	well.
38
39	\author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a>
40
41	\version 0.0.0
42*/
43class ResourcesContainer {
44public:
45	ResourcesContainer();
46	virtual ~ResourcesContainer();
47
48	bool AddResource(ResourceItem *item, int32 index = -1,
49					 bool replace = true);
50
51	ResourceItem *RemoveResource(int32 index);
52	bool RemoveResource(ResourceItem *item);
53
54	void MakeEmpty();
55
56	void AssimilateResources(ResourcesContainer &container);
57
58	int32 IndexOf(ResourceItem *item) const;
59	int32 IndexOf(const void *data) const;
60	int32 IndexOf(type_code type, int32 id) const;
61	int32 IndexOf(type_code type, const char *name) const;
62	int32 IndexOfType(type_code type, int32 index) const;
63	ResourceItem *ResourceAt(int32 index) const;
64	int32 CountResources() const;
65
66	void SetModified(bool modified);
67	bool IsModified() const;
68
69private:
70	BList	fResources;
71	bool	fIsModified;
72};
73
74};	// namespace Storage
75};	// namespace BPrivate
76
77#endif	// _RESOURCES_CONTAINER_H
78
79
80