static ICULocaleService* getService(void) { UBool needInit; { Mutex mutex; needInit = (UBool)(gService == NULL); } if (needInit) { UErrorCode status = U_ZERO_ERROR; #ifdef U_DEBUG_CALSVC fprintf(stderr, "Spinning up Calendar Service\n"); #endif ICULocaleService * newservice = new CalendarService(); #ifdef U_DEBUG_CALSVC fprintf(stderr, "Registering classes..\n"); #endif // Register all basic instances. newservice->registerFactory(new BasicCalendarFactory("japanese"),status); newservice->registerFactory(new BasicCalendarFactory("buddhist"),status); newservice->registerFactory(new BasicCalendarFactory("gregorian"),status); #ifdef U_DEBUG_CALSVC fprintf(stderr, "Done..\n"); #endif if(U_FAILURE(status)) { #ifdef U_DEBUG_CALSVC fprintf(stderr, "err (%s) registering classes, deleting service.....\n", u_errorName(status)); #endif delete newservice; newservice = NULL; } if (newservice) { Mutex mutex; if (gService == NULL) { gService = newservice; newservice = NULL; } } if (newservice) { delete newservice; } else { // we won the contention - we can register the cleanup. ucln_i18n_registerCleanup(); } } return gService; }
URegistryKey NumberFormat::registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status) { ICULocaleService *service = getService(); if (service) { return service->registerFactory(new NFFactory(toAdopt), status); } status = U_MEMORY_ALLOCATION_ERROR; return NULL; }
URegistryKey U_EXPORT2 NumberFormat::registerFactory(NumberFormatFactory* toAdopt, UErrorCode& status) { ICULocaleService *service = getNumberFormatService(); if (service) { NFFactory *tempnnf = new NFFactory(toAdopt); if (tempnnf != NULL) { return service->registerFactory(tempnnf, status); } } status = U_MEMORY_ALLOCATION_ERROR; return NULL; }