- /**
- * Returns the singleton instance, or NULL if it could not be created.
- * Calls the instantiator with the context if the instance has not been
- * created yet. In a race condition, the duplicate may not be NULL.
- * The caller must delete the duplicate.
- * The caller need not initialize the duplicate before the call.
- */
- void *getInstance(InstantiatorFn *instantiator, const void *context,
- void *&duplicate,
- UErrorCode &errorCode);
- /**
- * Resets the fields. The caller must have deleted the singleton instance.
- * Not mutexed.
- * Call this from a cleanup function.
- */
- void reset() { fInstance=NULL; }
-};
-
-#define STATIC_SIMPLE_SINGLETON(name) static SimpleSingleton name={ NULL }
-
-/**
- * Handy wrapper for a SimpleSingleton.
- * Intended for temporary use on the stack, to make the SimpleSingleton easier to deal with.
- * Takes care of the duplicate deletion and type casting.
- */
-template<typename T>
-class SimpleSingletonWrapper {
-public:
- SimpleSingletonWrapper(SimpleSingleton &s) : singleton(s) {}
- void deleteInstance() {
- delete (T *)singleton.fInstance;
- singleton.reset();
- }
- T *getInstance(InstantiatorFn *instantiator, const void *context,
- UErrorCode &errorCode) {
- void *duplicate;
- T *instance=(T *)singleton.getInstance(instantiator, context, duplicate, errorCode);
- delete (T *)duplicate;
- return instance;
- }