1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 1997-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*
|
|
|
|
* File rbcache.h
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 03/20/97 aliu Creation.
|
|
|
|
* 04/29/97 aliu Convert to use new Hashtable protocol.
|
|
|
|
* 04/15/99 damiba plugged in new C hashtable
|
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
|
2000-03-29 18:47:02 +00:00
|
|
|
#include "hash.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/unistr.h"
|
2000-03-30 04:17:27 +00:00
|
|
|
|
|
|
|
/* Disable these warnings:
|
|
|
|
d:\icu\source\common\rbcache.h(31) : warning C4251: 'hash' : class 'Hashtable' needs to have dll-interface to be used by clients of class 'ResourceBundleCache'
|
|
|
|
d:\icu\source\common\rbcache.h(57) : warning C4251: 'hash' : class 'Hashtable' needs to have dll-interface to be used by clients of class 'VisitedFileCache'
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning( disable : 4251 )
|
|
|
|
#endif
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/**
|
2000-03-29 18:47:02 +00:00
|
|
|
* A class that maps UnicodeString keys to UHashtable objects. It
|
|
|
|
* owns the UHashtable objects passed to put() and will eventually
|
|
|
|
* close and delete them.
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2000-03-29 18:47:02 +00:00
|
|
|
class U_COMMON_API ResourceBundleCache { // Not really external; just making the compiler happy
|
|
|
|
private:
|
2000-03-30 04:17:27 +00:00
|
|
|
Hashtable hash;
|
2000-03-29 18:47:02 +00:00
|
|
|
static void U_CALLCONV deleteUHashtable(void* value);
|
|
|
|
public:
|
|
|
|
ResourceBundleCache();
|
2000-03-30 04:17:27 +00:00
|
|
|
inline ~ResourceBundleCache() {}
|
2000-03-29 18:47:02 +00:00
|
|
|
inline void put(const UnicodeString& key, UHashtable* adoptedValue);
|
|
|
|
inline const UHashtable* get(const UnicodeString& key) const;
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2000-03-29 18:47:02 +00:00
|
|
|
inline void ResourceBundleCache::put(const UnicodeString& key, UHashtable* adoptedValue) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-03-30 04:17:27 +00:00
|
|
|
hash.put(key, adoptedValue, status);
|
2000-03-29 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const UHashtable* ResourceBundleCache::get(const UnicodeString& key) const {
|
2000-03-30 04:17:27 +00:00
|
|
|
return (const UHashtable*) hash.get(key);
|
2000-03-29 18:47:02 +00:00
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
2000-03-29 18:47:02 +00:00
|
|
|
* A class that records whether a filename has been seen before or
|
|
|
|
* not. Call markAsVisited() to mark a filename as seen. Call
|
|
|
|
* wasVisited() to see if markAsVisited() has been called with that
|
|
|
|
* filename or not.
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2000-03-29 18:47:02 +00:00
|
|
|
class U_COMMON_API VisitedFileCache { // Not really external; just making the compiler happy
|
|
|
|
private:
|
2000-03-30 04:17:27 +00:00
|
|
|
Hashtable hash;
|
2000-03-29 18:47:02 +00:00
|
|
|
public:
|
2000-03-30 04:17:27 +00:00
|
|
|
inline VisitedFileCache() {}
|
|
|
|
inline ~VisitedFileCache() {}
|
2000-03-29 18:47:02 +00:00
|
|
|
inline bool_t wasVisited(const UnicodeString& filename) const;
|
|
|
|
inline void markAsVisited(const UnicodeString& filename);
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2000-03-29 18:47:02 +00:00
|
|
|
inline bool_t VisitedFileCache::wasVisited(const UnicodeString& filename) const {
|
2000-03-30 04:17:27 +00:00
|
|
|
return (hash.get(filename) != 0);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-03-29 18:47:02 +00:00
|
|
|
inline void VisitedFileCache::markAsVisited(const UnicodeString& filename) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-03-30 04:17:27 +00:00
|
|
|
hash.put(filename, (void*)1, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//eof
|