1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 #ifndef _T_RESOURCE_SET_H 35 #define _T_RESOURCE_SET_H 36 37 #include <List.h> 38 #include <Locker.h> 39 #include <SupportDefs.h> 40 41 class BBitmap; 42 class BResources; 43 class BDataIO; 44 class BString; 45 46 namespace TResourcePrivate { 47 class TypeItem; 48 class TypeList; 49 } 50 51 using namespace TResourcePrivate; 52 53 const uint32 B_STRING_BLOCK_TYPE = 'SBLK'; 54 55 class TStringBlock { 56 public: 57 TStringBlock(BDataIO* data); 58 TStringBlock(const void* block, size_t size); 59 virtual ~TStringBlock(); 60 61 const char* String(size_t index) const; 62 63 private: 64 size_t PreIndex(char* strings, ssize_t len); 65 void MakeIndex(const char* strings, ssize_t len, 66 size_t indexLen, size_t* outIndex); 67 68 size_t fNumEntries; 69 size_t* fIndex; 70 char* fStrings; 71 bool fOwnData; 72 }; 73 74 class TResourceSet { 75 public: 76 TResourceSet(); 77 virtual ~TResourceSet(); 78 79 status_t AddResources(BResources* resources); 80 status_t AddDirectory(const char* fullPath); 81 status_t AddEnvDirectory(const char* envPath, 82 const char* defaultValue = NULL); 83 84 const void* FindResource(type_code type, int32 id, 85 size_t* outSize); 86 const void* FindResource(type_code type, const char* name, 87 size_t* outSize); 88 89 const BBitmap* FindBitmap(type_code type, int32 id); 90 const BBitmap* FindBitmap(type_code type, const char* name); 91 92 const TStringBlock* FindStringBlock(type_code type, int32 id); 93 const TStringBlock* FindStringBlock(type_code type, const char* name); 94 95 const char* FindString(type_code type, int32 id, uint32 index); 96 const char* FindString(type_code type, const char* name, uint32 index); 97 98 private: 99 status_t ExpandString(BString* out, const char* in); 100 TypeList* FindTypeList(type_code type); 101 102 TypeItem* FindItemID(type_code type, int32 id); 103 TypeItem* FindItemName(type_code type, const char* name); 104 105 TypeItem* LoadResource(type_code type, int32 id, const char* name, 106 TypeList** inoutList = NULL); 107 108 BBitmap* ReturnBitmapItem(type_code type, TypeItem* from); 109 TStringBlock* ReturnStringBlockItem(TypeItem* from); 110 111 BLocker fLock; // access control. 112 BList fResources; // containing BResources objects. 113 BList fDirectories; // containing BPath objects. 114 BList fTypes; // containing TypeList objects. 115 }; 116 117 TResourceSet* AppResSet(); 118 119 #endif 120 121