home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / tcoldata.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  7.2 KB  |  160 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999                    *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. */
  13. //===============================================================================
  14. //
  15. // File tcoldata.h
  16. //
  17. // Internal file.  Defines TableCollationData, an internal class which is shared
  18. // by TableCollation objects, and which contains all the invariant (and large)
  19. // pieces of data.  Once created, TableCollationData objects do not change.
  20. //
  21. // Created by: Alan Liu
  22. //
  23. // Modification History:
  24. //
  25. //  Date        Name        Description
  26. //  2/5/97      aliu        Creation.
  27. //  3/5/97      aliu        Don't stream rule table in or out.  Added data members
  28. //                          isRuleTableLoaded, desiredLocale, and realLocaleName,
  29. //                          which are required for dynamic reloading of the rule
  30. //                          string.  We still keep rules in this object so that
  31. //                          they can be held in the in-memory cache.
  32. //  3/26/97     helena      Updated with platform independent data types.
  33. //  6/20/97     helena      Java class name change.
  34. //  8/18/97     helena      Added internal API documentation.
  35. //===============================================================================
  36.  
  37. #ifndef TCOLDATA_H
  38. #define TCOLDATA_H
  39.  
  40. #include "ucmp32.h"
  41. #include "utypes.h"
  42. #include "colcache.h"
  43. #include "unistr.h"
  44. #include "locid.h"
  45. #include "filestrm.h"
  46.  
  47. //=============================================================================
  48.  
  49. class VectorOfPToContractTable;
  50. class VectorOfPToExpandTable;
  51.  
  52. //=============================================================================
  53.  
  54. /**
  55.  * TableCollationData is an internal class used by TableCollation.  It
  56.  * encapsulates most of the data associated with a TableCollation.
  57.  * This includes the large collation tables, including the contract
  58.  * order and expand order tables, and some small pieces of data that
  59.  * don't change, such as the maximum secondary order.  The general
  60.  * idea is that the TableCollation object should be a lightweight
  61.  * object.  If there are two TableCollation objects, they will each be
  62.  * very small, and users can alter the strength of each object
  63.  * independently.  However, both objects, if they are refering to the
  64.  * same underlying collation, will share pointers to the same
  65.  * TableCollationData object, which doesn't change.  <P>
  66.  * TableCollationData objects are therefore good candidates for
  67.  * caching in memory and potentially for reference counting.  */
  68. class TableCollationData
  69. {
  70. public:
  71.                                 TableCollationData();
  72.     virtual                     ~TableCollationData();
  73.  
  74.     /**
  75.      * Cache interface.  The cache uses UnicodeString objects as keys.  These
  76.      * are completely arbitrary, but are usually something uniquely associated
  77.      * with each collation, while at the same time fairly small, such as a
  78.      * locale identifier string.
  79.      * <P> Adds the collation data object to the cache list.
  80.      * @param key the unique key of the associated collation data object.
  81.      * @param data the collation data object.
  82.      */
  83.     static  void                addToCache(const UnicodeString& key, TableCollationData* data);
  84.     /**
  85.      * Finds and returns the cached collation data.
  86.      * @param key the unique key of the associated collation data object.
  87.      * @returns the found collation data object.
  88.      */
  89.     static  TableCollationData* findInCache(const UnicodeString& key);
  90.  
  91.     /**
  92.      * The streamIn and streamOut methods read and write objects of this
  93.      * class as binary, platform-dependent data in the iostream.  The stream
  94.      * must be in ios::binary mode for this to work.  These methods are not
  95.      * intended for general public use; they are used by the framework to improve
  96.      * performance by storing certain objects in binary files.
  97.      */
  98.             void                streamIn(FileStream* is);
  99.             void                streamOut(FileStream* os) const;
  100.  
  101.         /**
  102.          * Checks if this object is valid.
  103.          * @return TRUE if the object is valid, FALSE otherwise.
  104.          */
  105.             bool_t              isBogus() const;
  106. private:
  107.     /**
  108.      * The following are disallowed operations: not implemented.
  109.      */
  110.     TableCollationData(const TableCollationData&);
  111.     TableCollationData& operator=(const TableCollationData&);
  112.  
  113. private:
  114.     // Do not access the fgCache object directly; use addToCache and findInCache.
  115.     static  CollationCache      fgCache;
  116.  
  117. private:
  118.     /**
  119.      * The TableCollation class freely manipulates the data members within a
  120.      * TableCollationData object.  This is because TableCollationData is
  121.      * intended to be an internal, invisible implementation detail.  If
  122.      * TableCollationData every becomes a more public API, then this will have
  123.      * to change, although this is not really advised.
  124.      */
  125.     friend class RuleBasedCollator;
  126.  
  127.     bool_t                      isFrenchSec;
  128.     int16_t                     maxSecOrder;
  129.     int16_t                     maxTerOrder;
  130.     CompactIntArray*            mapping;
  131.     VectorOfPToContractTable*   contractTable;
  132.     VectorOfPToExpandTable*     expandTable;
  133.     bool_t                      fBogus;
  134.  
  135.     /**
  136.      * Rule string data is generated dynamically when required by the TableCollation
  137.      * object.  In particular, when a binary file is created, the rule data is
  138.      * not streamed out -- this keeps the binary file small.  However, two pieces
  139.      * of data are kept around (the desiredLocale and the realLocaleName) which
  140.      * allow later loading of the rule string efficiently.  By efficiently, we mean
  141.      * that the usual search procedure is shortened, and the final file which
  142.      * actually led to the successful loading of the collation elements is accessed
  143.      * directly.  The boolean isRuleTableLoaded allows the collation object to
  144.      * know whether rules have been loaded (an alternative is to use an empty
  145.      * ruleTable to indicate this, but this then disallows the empty string as
  146.      * a valid rule string).  Note that when a collation is constructed "from
  147.      * scratch" (not loaded from a binary file), the rule table is already in place,
  148.      * and isRuleTableLoaded is set to true.
  149.      *
  150.      * See RuleBasedCollator::getRules().
  151.      */
  152.     UnicodeString               ruleTable;
  153.     bool_t                      isRuleTableLoaded;
  154.     Locale                      desiredLocale;
  155.     UnicodeString               realLocaleName;
  156. };
  157.  
  158. #endif //_TCOLDATA
  159. //eof
  160.