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 30 trademarks of Be Incorporated in the United States and other countries. Other 31 brand product names are registered trademarks or trademarks of their respective 32 holders. 33 All rights reserved. 34 */ 35 #ifndef _T_RESOURCE_SET_H 36 #define _T_RESOURCE_SET_H 37 38 #include <List.h> 39 #include <Locker.h> 40 #include <SupportDefs.h> 41 42 class BBitmap; 43 class BResources; 44 class BDataIO; 45 class BString; 46 47 namespace TResourcePrivate { 48 class TypeItem; 49 class TypeList; 50 } 51 52 using namespace TResourcePrivate; 53 54 const uint32 B_STRING_BLOCK_TYPE = 'SBLK'; 55 56 class TStringBlock { 57 public: 58 TStringBlock(BDataIO* data); 59 TStringBlock(const void* block, size_t size); 60 virtual ~TStringBlock(); 61 62 const char* String(size_t index) const; 63 64 private: 65 size_t PreIndex(char* strings, ssize_t len); 66 void MakeIndex(const char* strings, ssize_t len, size_t indexLen, 67 size_t* outIndex); 68 69 size_t fNumEntries; 70 size_t* fIndex; 71 char* fStrings; 72 bool fOwnData; 73 }; 74 75 class TResourceSet { 76 public: 77 TResourceSet(); 78 virtual ~TResourceSet(); 79 80 status_t AddResources(BResources* resources); 81 status_t AddDirectory(const char* fullPath); 82 status_t AddEnvDirectory(const char* envPath, 83 const char* defaultValue = NULL); 84 85 const void* FindResource(type_code type, int32 id, size_t* outSize); 86 const void* FindResource(type_code type, const char* name, size_t* outSize); 87 88 const BBitmap* FindBitmap(type_code type, int32 id); 89 const BBitmap* FindBitmap(type_code type, const char* name); 90 91 const TStringBlock* FindStringBlock(type_code type, int32 id); 92 const TStringBlock* FindStringBlock(type_code type, const char* name); 93 94 const char* FindString(type_code type, int32 id, uint32 index); 95 const char* FindString(type_code type, const char* name, uint32 index); 96 97 private: 98 status_t ExpandString(BString* out, const char* in); 99 TypeList* FindTypeList(type_code type); 100 101 TypeItem* FindItemID(type_code type, int32 id); 102 TypeItem* FindItemName(type_code type, const char* name); 103 104 TypeItem* LoadResource(type_code type, int32 id, const char* name, 105 TypeList** inoutList = NULL); 106 107 BBitmap* ReturnBitmapItem(type_code type, TypeItem* from); 108 TStringBlock* ReturnStringBlockItem(TypeItem* from); 109 110 BLocker fLock; // access control. 111 BList fResources; // containing BResources objects. 112 BList fDirectories; // containing BPath objects. 113 BList fTypes; // containing TypeList objects. 114 }; 115 116 TResourceSet* AppResSet(); 117 118 #endif 119 120