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

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1998                    *
  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.cpp
  16. //
  17. // Internal file.  Implements 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.
  28. //===============================================================================
  29.  
  30. #include "ucmp32.h"
  31. #include "tcoldata.h"
  32. #include "tables.h"
  33. #include "mutex.h"
  34. #include "tblcoll.h"
  35.  
  36. //===============================================================================
  37.  
  38. CollationCache TableCollationData::fgCache;
  39.  
  40. //===============================================================================
  41.  
  42. TableCollationData::TableCollationData() 
  43.     : isFrenchSec(FALSE),
  44.       maxSecOrder(0),
  45.       maxTerOrder(0),
  46.       isRuleTableLoaded(FALSE),
  47.       fBogus(FALSE)
  48. {
  49.     mapping = 0;
  50.     contractTable = 0;
  51.     expandTable = 0;
  52. }
  53.  
  54. TableCollationData::~TableCollationData()
  55. {
  56.     ucmp32_close(mapping);
  57.     delete contractTable;
  58.     delete expandTable;
  59. }
  60.  
  61. bool_t
  62. TableCollationData::isBogus() const
  63. {
  64.     return fBogus;
  65. }
  66.  
  67. void TableCollationData::streamIn(FileStream* is)
  68. {
  69.     if (!T_FileStream_error(is))
  70.     {
  71.         // Stream in large objects
  72.         char isNull;
  73.         T_FileStream_read(is, &isNull, sizeof(isNull));
  74.         if (isNull)
  75.         {
  76.             ucmp32_close(mapping);
  77.             mapping = 0;
  78.         }
  79.         else
  80.         {
  81.             // Slight ugliness: We are a friend of TableCollation solely so
  82.             // we can access the constant UNMAPPED here.  In fact, this code
  83.             // path shouldn't really happen, because mapping should always != 0.
  84.             if (mapping == 0) mapping = ucmp32_open(RuleBasedCollator::UNMAPPED);
  85.             if (mapping->fBogus ){
  86.                 fBogus = TRUE;
  87.                 return;
  88.             }
  89.             ucmp32_streamIn(mapping, is);
  90.             if (mapping->fBogus) {
  91.                 fBogus = TRUE;
  92.                 ucmp32_close(mapping);
  93.                 mapping = 0;
  94.                 return;
  95.             }
  96.         }
  97.  
  98.         T_FileStream_read(is, &isNull, sizeof(isNull));
  99.         if (isNull)
  100.         {
  101.             delete contractTable;
  102.             contractTable = 0;
  103.         }
  104.         else
  105.         {
  106.             if (contractTable == 0) contractTable = new VectorOfPToContractTable;
  107.             if (contractTable->isBogus()) {
  108.                 fBogus = TRUE;
  109.                 return;
  110.             }
  111.             contractTable->streamIn(is);
  112.             if (contractTable->isBogus()) {
  113.                 fBogus = TRUE;
  114.                 ucmp32_close(mapping);
  115.                 mapping = 0;
  116.                 delete contractTable;
  117.                 contractTable = 0;
  118.                 return;
  119.             }
  120.         }
  121.  
  122.         T_FileStream_read(is, &isNull, sizeof(isNull));
  123.         if (isNull)
  124.         {
  125.             delete expandTable;
  126.             expandTable = 0;
  127.         }
  128.         else
  129.         {
  130.             if (expandTable == 0) expandTable = new VectorOfPToExpandTable;
  131.             if (expandTable->isBogus()) {
  132.                 fBogus = TRUE;
  133.                 return;
  134.             }
  135.             expandTable->streamIn(is);
  136.             if (expandTable->isBogus()) {
  137.                 fBogus = TRUE;
  138.                 ucmp32_close(mapping);
  139.                 mapping = 0;
  140.                 delete contractTable;
  141.                 contractTable = 0;
  142.                 delete expandTable;
  143.                 expandTable = 0;
  144.                 return;
  145.             }
  146.         }
  147.  
  148.         // We don't stream in or out the rule table, in order to keep
  149.         // binary files small.  We reconstruct rules on the fly.
  150.         ruleTable.remove();
  151.         isRuleTableLoaded = FALSE;
  152.  
  153.         // Stream in the small objects
  154.         T_FileStream_read(is, &isFrenchSec, sizeof(isFrenchSec));
  155.         T_FileStream_read(is, &maxSecOrder, sizeof(maxSecOrder));
  156.         T_FileStream_read(is, &maxTerOrder, sizeof(maxTerOrder));
  157.     }
  158. }
  159.  
  160. void TableCollationData::streamOut(FileStream* os) const
  161. {
  162.     if (!T_FileStream_error(os))
  163.     {
  164.         // Stream out the large objects
  165.         char isNull;
  166.         isNull = (mapping == 0);
  167.         T_FileStream_write(os, &isNull, sizeof(isNull));
  168.         if (!isNull) ucmp32_streamOut(mapping, os);
  169.  
  170.         isNull = (contractTable == 0);
  171.         T_FileStream_write(os, &isNull, sizeof(isNull));
  172.         if (!isNull) contractTable->streamOut(os);
  173.  
  174.         isNull = (expandTable == 0);
  175.         T_FileStream_write(os, &isNull, sizeof(isNull));
  176.         if (!isNull) expandTable->streamOut(os);
  177.  
  178.         // We don't stream out the rule table, in order to keep
  179.         // binary files small.  We reconstruct rules on the fly.
  180.  
  181.         // Stream out the small objects
  182.         T_FileStream_write(os, &isFrenchSec, sizeof(isFrenchSec));
  183.         T_FileStream_write(os, &maxSecOrder, sizeof(maxSecOrder));
  184.         T_FileStream_write(os, &maxTerOrder, sizeof(maxTerOrder));
  185.     }
  186. }
  187.  
  188. void TableCollationData::addToCache(const UnicodeString& key, TableCollationData* collation)
  189. {
  190.     Mutex lock;
  191.     fgCache.Add(key, collation);
  192. }
  193.  
  194. TableCollationData* TableCollationData::findInCache(const UnicodeString& key)
  195. {
  196.     Mutex lock;
  197.     return fgCache.Find(key);
  198. }
  199.  
  200. //eof
  201.