1/*
2 * Copyright 2001-2010, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _RESOURCE_STRINGS_H
6#define _RESOURCE_STRINGS_H
7
8
9#include <Entry.h>
10#include <Locker.h>
11
12
13class BResources;
14class BString;
15
16
17/*!	\brief Simple class to access the string resources in a file.
18
19	A BResourceStrings object reads the string type resources from a given
20	resource file and provides fast read only access to them.
21*/
22class BResourceStrings {
23public:
24								BResourceStrings();
25								BResourceStrings(const entry_ref& ref);
26	virtual						~BResourceStrings();
27
28			status_t			InitCheck();
29	virtual BString*			NewString(int32 id);
30	virtual const char*			FindString(int32 id);
31
32	virtual status_t			SetStringFile(const entry_ref* ref);
33			status_t			GetStringFile(entry_ref* outRef);
34
35			enum {
36				RESOURCE_TYPE = 'CSTR'
37			};
38
39protected:
40			struct _string_id_hash {
41				_string_id_hash();
42				~_string_id_hash();
43
44				void			assign_string(const char* str, bool makeCopy);
45
46				_string_id_hash* next;
47				int32			id;
48				char*			data;
49				bool 			data_alloced;
50				bool			_reserved1[3];
51				uint32			_reserved2;
52			};
53
54private:
55			void				_Cleanup();
56			void				_MakeEmpty();
57			status_t			_Rehash(int32 newSize);
58			_string_id_hash*	_AddString(char* str, int32 id,
59									bool wasMalloced);
60
61	virtual _string_id_hash*	_FindString(int32 id);
62
63	virtual	status_t			_Reserved_ResourceStrings_0(void*);
64	virtual	status_t			_Reserved_ResourceStrings_1(void*);
65	virtual	status_t			_Reserved_ResourceStrings_2(void*);
66	virtual	status_t			_Reserved_ResourceStrings_3(void*);
67	virtual	status_t			_Reserved_ResourceStrings_4(void*);
68	virtual	status_t			_Reserved_ResourceStrings_5(void*);
69
70protected:
71			BLocker				_string_lock;
72			status_t			_init_error;
73
74private:
75			entry_ref		fFileRef;
76			BResources		*fResources;
77			_string_id_hash	**fHashTable;
78			int32			fHashTableSize;
79			int32			fStringCount;
80			uint32			_reserved[16];	// FBC
81};
82
83
84#endif	// _RESOURCE_STRINGS_H
85
86
87