ICULocaleBackend.h revision 3f9e3b0a
1/*
2 * Copyright 2010-2011, Oliver Tappe, zooey@hirschkaefer.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _ICU_LOCALE_BACKEND_H
6#define _ICU_LOCALE_BACKEND_H
7
8
9#include "LocaleBackend.h"
10
11#include <locale.h>
12#include <pthread.h>
13#include <timelocal.h>
14
15#include "ICUCollateData.h"
16#include "ICUCtypeData.h"
17#include "ICUMessagesData.h"
18#include "ICUMonetaryData.h"
19#include "ICUNumericData.h"
20#include "ICUTimeConversion.h"
21#include "ICUTimeData.h"
22
23
24namespace BPrivate {
25namespace Libroot {
26
27
28class ICULocaleBackend : public LocaleBackend {
29public:
30								ICULocaleBackend();
31	virtual						~ICULocaleBackend();
32
33	virtual void				Initialize(LocaleDataBridge* dataBridge);
34
35	virtual	const char*			SetLocale(int category,
36									const char* posixLocaleName);
37	virtual	const struct lconv*	LocaleConv();
38	virtual	const struct lc_time_t*	LCTimeInfo();
39
40	virtual	int					IsWCType(wint_t wc, wctype_t charClass);
41	virtual	status_t			ToWCTrans(wint_t wc, wctrans_t transition,
42									wint_t& result);
43
44	virtual status_t			MultibyteToWchar(wchar_t* wcOut, const char* mb,
45									size_t mbLength, mbstate_t* mbState,
46									size_t& lengthOut);
47	virtual status_t			MultibyteStringToWchar(wchar_t* wcDest,
48									size_t wcDestLength, const char** mbSource,
49									size_t mbSourceLength, mbstate_t* mbState,
50									size_t& lengthOut);
51	virtual status_t			WcharToMultibyte(char* mbOut, wchar_t wc,
52									mbstate_t* mbState, size_t& lengthOut);
53	virtual status_t			WcharStringToMultibyte(char* mbDest,
54									size_t mbDestLength,
55									const wchar_t** wcSource,
56									size_t wcSourceLength, mbstate_t* mbState,
57									size_t& lengthOut);
58
59	virtual	const char*			GetLanginfo(int index);
60
61	virtual	status_t			Strcoll(const char* a, const char* b, int& out);
62	virtual status_t			Strxfrm(char* out, const char* in, size_t size,
63									size_t& outSize);
64	virtual	status_t			Wcscoll(const wchar_t* a, const wchar_t* b,
65									int& out);
66	virtual status_t			Wcsxfrm(wchar_t* out, const wchar_t* in,
67									size_t size, size_t& outSize);
68
69	virtual status_t			TZSet(const char* timeZoneID, const char* tz);
70	virtual	status_t			Localtime(const time_t* inTime,
71									struct tm* tmOut);
72	virtual status_t			Gmtime(const time_t* inTime, struct tm* tmOut);
73
74	virtual status_t			Mktime(struct tm* inOutTm, time_t& timeOut);
75
76private:
77			const char*			_QueryLocale(int category);
78			const char*			_SetPosixLocale(int category);
79
80	static	pthread_key_t		_CreateThreadLocalStorageKey();
81	static	void 				_DestroyThreadLocalStorageValue(void* value);
82
83			// buffer for locale names (up to one per category)
84			char				fLocaleDescription[1024];
85
86			// data containers
87			struct lconv 	 	fLocaleConv;
88			struct lc_time_t 	fLCTimeInfo;
89
90			//
91			pthread_key_t		fThreadLocalStorageKey;
92
93			// these work on the data containers above
94			ICUCollateData		fCollateData;
95			ICUCtypeData		fCtypeData;
96			ICUMessagesData		fMessagesData;
97			ICUMonetaryData		fMonetaryData;
98			ICUNumericData		fNumericData;
99			ICUTimeData			fTimeData;
100			ICUTimeConversion	fTimeConversion;
101
102			// static posix langinfo data
103			const char**		fPosixLanginfo;
104};
105
106
107}	// namespace Libroot
108}	// namespace BPrivate
109
110
111#endif	// _ICU_LOCALE_BACKEND_H
112