1 /* 2 * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _LOCALE_BACKEND_H 6 #define _LOCALE_BACKEND_H 7 8 9 #include <SupportDefs.h> 10 11 #include <time.h> 12 #include <wctype.h> 13 14 15 struct lconv; 16 struct lc_time_t; 17 18 19 namespace BPrivate { 20 21 22 struct LocaleCtypeDataBridge { 23 const unsigned short** addrOfClassInfoTable; 24 const int** addrOfToLowerTable; 25 const int** addrOfToUpperTable; 26 27 const unsigned short* posixClassInfo; 28 const int* posixToLowerMap; 29 const int* posixToUpperMap; 30 31 LocaleCtypeDataBridge(); 32 }; 33 34 35 struct LocaleMessagesDataBridge { 36 const char** posixLanginfo; 37 38 LocaleMessagesDataBridge(); 39 }; 40 41 42 struct LocaleMonetaryDataBridge { 43 const struct lconv* posixLocaleConv; 44 45 LocaleMonetaryDataBridge(); 46 }; 47 48 49 struct LocaleNumericDataBridge { 50 const char** addrOfGlibcDecimalPoint; 51 const char** addrOfGlibcThousandsSep; 52 const char** addrOfGlibcGrouping; 53 uint32_t* addrOfGlibcWCDecimalPoint; 54 uint32_t* addrOfGlibcWCThousandsSep; 55 const struct lconv* posixLocaleConv; 56 57 LocaleNumericDataBridge(); 58 }; 59 60 61 struct LocaleTimeDataBridge { 62 const struct lc_time_t* posixLCTimeInfo; 63 64 LocaleTimeDataBridge(); 65 }; 66 67 68 struct TimeConversionDataBridge { 69 int* addrOfDaylight; 70 long* addrOfTimezone; 71 char** addrOfTZName; 72 73 TimeConversionDataBridge(); 74 }; 75 76 77 struct LocaleDataBridge { 78 LocaleCtypeDataBridge ctypeDataBridge; 79 LocaleMessagesDataBridge messagesDataBridge; 80 LocaleMonetaryDataBridge monetaryDataBridge; 81 LocaleNumericDataBridge numericDataBridge; 82 LocaleTimeDataBridge timeDataBridge; 83 TimeConversionDataBridge timeConversionDataBridge; 84 const char** posixLanginfo; 85 86 LocaleDataBridge(); 87 }; 88 89 90 class LocaleBackend { 91 public: 92 LocaleBackend(); 93 virtual ~LocaleBackend(); 94 95 virtual const char* SetLocale(int category, const char* locale) = 0; 96 virtual const struct lconv* LocaleConv() = 0; 97 virtual const struct lc_time_t* LCTimeInfo() = 0; 98 99 virtual int IsWCType(wint_t wc, wctype_t charClass) = 0; 100 virtual status_t ToWCTrans(wint_t wc, wctrans_t transition, 101 wint_t& result) = 0; 102 103 virtual const char* GetLanginfo(int index) = 0; 104 105 virtual status_t Strcoll(const char* a, const char* b, 106 int& out) = 0; 107 virtual status_t Strxfrm(char* out, const char* in, size_t size, 108 size_t& outSize) = 0; 109 110 virtual status_t TZSet(const char* timeZoneID) = 0; 111 virtual status_t Localtime(const time_t* inTime, 112 struct tm* tmOut) = 0; 113 virtual status_t Gmtime(const time_t* inTime, 114 struct tm* tmOut) = 0; 115 virtual status_t Mktime(struct tm* inOutTm, time_t& timeOut) = 0; 116 117 virtual void Initialize(LocaleDataBridge* dataBridge) = 0; 118 119 static status_t LoadBackend(); 120 }; 121 122 123 extern LocaleBackend* gLocaleBackend; 124 125 126 } // namespace BPrivate 127 128 129 #endif // _LOCALE_BACKEND_H 130