1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
1999-11-23 01:30:04 +00:00
|
|
|
* Copyright (C) 1997-1999, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
1999-08-16 21:50:52 +00:00
|
|
|
*****************************************************************************************
|
|
|
|
*/
|
|
|
|
//===============================================================================
|
|
|
|
//
|
|
|
|
// File colcache.h
|
|
|
|
//
|
|
|
|
// CollationCache implements a persistent in-memory cache for
|
|
|
|
// TableCollationData objects. The goal of CollationCache is to improve
|
|
|
|
// the memory footprint of a process which may have multiple threads
|
|
|
|
// loading up the same TableCollation object. Performance improvement is
|
|
|
|
// strictly a secondary goal.
|
|
|
|
//
|
|
|
|
// Created by: Alan Liu
|
|
|
|
//
|
|
|
|
// Modification History:
|
|
|
|
//
|
|
|
|
// Date Name Description
|
|
|
|
// 2/11/97 aliu Creation.
|
|
|
|
// 2/12/97 aliu Modified to work with TableCollationData.
|
|
|
|
// 8/18/97 helena Added internal API documentation.
|
|
|
|
//
|
|
|
|
//===============================================================================
|
|
|
|
|
|
|
|
#ifndef COLCACHE_H
|
|
|
|
#define COLCACHE_H
|
|
|
|
|
2000-03-30 04:30:20 +00:00
|
|
|
#include "hash.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/unistr.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-03-28 22:12:14 +00:00
|
|
|
class Hashtable;
|
1999-08-16 21:50:52 +00:00
|
|
|
class TableCollationData;
|
|
|
|
|
2000-10-04 22:32:34 +00:00
|
|
|
/* Tell the VC++ compiler not to warn about DLL interface */
|
|
|
|
/*
|
1999-08-16 21:50:52 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning( disable : 4251 )
|
|
|
|
#endif
|
2000-10-04 22:32:34 +00:00
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* CollationCache implements a simple cache for TableCollationData objects.
|
|
|
|
* TableCollationData objects may be added to the cache, and looked up in the
|
|
|
|
* cache. When the cache is destroyed, all the TableCollationData objects are
|
|
|
|
* deleted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CollationCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
CollationCache();
|
2000-03-30 04:30:20 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2000-03-30 04:30:20 +00:00
|
|
|
inline ~CollationCache() {}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ::Add and ::Find use a UnicodeString as the key to Collation objects in the
|
|
|
|
* cache. If Add is called twice with equivalent keys, but different
|
|
|
|
* collation objects, the first collation object will be deleted when the
|
|
|
|
* second one is added. In general, this is undesirable; objects in the
|
|
|
|
* cache are usually pointed to by various clients in the system. For this
|
|
|
|
* reason, clients should call Find to ensure a Collation object does not
|
|
|
|
* already exist in the cache for the given key before calling Add.
|
|
|
|
* @param key the unique key.
|
|
|
|
* @param data the collation data object.
|
|
|
|
* @return the found collation data object
|
|
|
|
*/
|
2000-03-30 04:30:20 +00:00
|
|
|
void Add(const UnicodeString& key, TableCollationData* adoptedData);
|
1999-08-16 21:50:52 +00:00
|
|
|
TableCollationData* Find(const UnicodeString& key);
|
|
|
|
|
|
|
|
private:
|
2000-03-30 04:30:20 +00:00
|
|
|
Hashtable fHashtable;
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2000-03-30 04:30:20 +00:00
|
|
|
inline void CollationCache::Add(const UnicodeString& key, TableCollationData* adoptedValue) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
fHashtable.put(key, adoptedValue, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline TableCollationData* CollationCache::Find(const UnicodeString& keyString) {
|
|
|
|
return (TableCollationData*) fHashtable.get(keyString);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#endif
|
|
|
|
//eof
|