152a38012Sejakowatz //---------------------------------------------------------------------- 2*2ca13760SColdfirex // This software is part of the Haiku distribution and is covered 3b6f76ebeSAugustin Cavalier // by the MIT License. 452a38012Sejakowatz //--------------------------------------------------------------------- 552a38012Sejakowatz /*! 652a38012Sejakowatz \file ResourcesContainer.h 752a38012Sejakowatz ResourcesContainer interface declaration. 852a38012Sejakowatz */ 952a38012Sejakowatz 1082b75665STyler Dauwalder #ifndef _RESOURCES_CONTAINER_H 1182b75665STyler Dauwalder #define _RESOURCES_CONTAINER_H 1252a38012Sejakowatz 1352a38012Sejakowatz #include <List.h> 1452a38012Sejakowatz 1509d84e61STyler Dauwalder namespace BPrivate { 1609d84e61STyler Dauwalder namespace Storage { 1752a38012Sejakowatz 1852a38012Sejakowatz class ResourceItem; 1952a38012Sejakowatz 2052a38012Sejakowatz /*! 2152a38012Sejakowatz \class ResourcesContainer 2252a38012Sejakowatz \brief Represents a collection of resources. 2352a38012Sejakowatz 2452a38012Sejakowatz This class can be used to manage a collection of resources represented 2552a38012Sejakowatz by ResourceItem's. Usually it does never contain two resources with the 2652a38012Sejakowatz same type \em and ID, since AddResource() replaces an old item with the 2752a38012Sejakowatz new one, unless explicitly told not to do so. This should only be done 2852a38012Sejakowatz by ResourceFile, when type and ID of the items are not yet known. 2952a38012Sejakowatz Asside from the basic vector features like Add/RemoveResource()/ 3052a38012Sejakowatz ResourceAt() and MakeEmpty() a bunch of IndexOf() methods are provided 3152a38012Sejakowatz and AssimilateResources() which incorporates all resources of another 3252a38012Sejakowatz container into this one (replacing old resources, if necessary), emptying 3352a38012Sejakowatz the other one. 3452a38012Sejakowatz 3552a38012Sejakowatz The ResourceItem's in a container are deleted on destruction, unless 3652a38012Sejakowatz removed before via RemoveResource(). MakeEmpty() deletes the items as 3752a38012Sejakowatz well. 3852a38012Sejakowatz 3952a38012Sejakowatz \author <a href='mailto:bonefish@users.sf.net'>Ingo Weinhold</a> 4052a38012Sejakowatz 4152a38012Sejakowatz \version 0.0.0 4252a38012Sejakowatz */ 4352a38012Sejakowatz class ResourcesContainer { 4452a38012Sejakowatz public: 4552a38012Sejakowatz ResourcesContainer(); 4652a38012Sejakowatz virtual ~ResourcesContainer(); 4752a38012Sejakowatz 4852a38012Sejakowatz bool AddResource(ResourceItem *item, int32 index = -1, 4952a38012Sejakowatz bool replace = true); 5052a38012Sejakowatz 5152a38012Sejakowatz ResourceItem *RemoveResource(int32 index); 5252a38012Sejakowatz bool RemoveResource(ResourceItem *item); 5352a38012Sejakowatz 5452a38012Sejakowatz void MakeEmpty(); 5552a38012Sejakowatz 5652a38012Sejakowatz void AssimilateResources(ResourcesContainer &container); 5752a38012Sejakowatz 5852a38012Sejakowatz int32 IndexOf(ResourceItem *item) const; 5952a38012Sejakowatz int32 IndexOf(const void *data) const; 6052a38012Sejakowatz int32 IndexOf(type_code type, int32 id) const; 6152a38012Sejakowatz int32 IndexOf(type_code type, const char *name) const; 6252a38012Sejakowatz int32 IndexOfType(type_code type, int32 index) const; 6352a38012Sejakowatz ResourceItem *ResourceAt(int32 index) const; 6452a38012Sejakowatz int32 CountResources() const; 6552a38012Sejakowatz 6652a38012Sejakowatz void SetModified(bool modified); 6752a38012Sejakowatz bool IsModified() const; 6852a38012Sejakowatz 6952a38012Sejakowatz private: 7052a38012Sejakowatz BList fResources; 7152a38012Sejakowatz bool fIsModified; 7252a38012Sejakowatz }; 7352a38012Sejakowatz 7409d84e61STyler Dauwalder }; // namespace Storage 7509d84e61STyler Dauwalder }; // namespace BPrivate 7652a38012Sejakowatz 7782b75665STyler Dauwalder #endif // _RESOURCES_CONTAINER_H 7809d84e61STyler Dauwalder 7909d84e61STyler Dauwalder 80