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

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1996                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1996-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 tables.h
  16. //
  17. // 
  18. //
  19. // Created by: Helena Shih
  20. //
  21. // Modification History:
  22. //
  23. //  Date        Name        Description
  24. //  2/5/97      aliu        Added streamIn and streamOut methods to EntryPair,
  25. //                          VectorOfInt, VectorOfPToExpandTable, VectorOfPToContractElement,
  26. //                          VectorOfPToContractTable.  These are used by TableCollation
  27. //                          streamIn and streamOut methods.
  28. //  3/5/97      aliu        Made VectorOfPointersToPatternEntry::at() inline.
  29. //  5/07/97     helena      Added isBogus().
  30. //  6/18/97     helena      Added VectorOfPointer for queue-up extension list in
  31. //                          MergeCollation.
  32. //  8/18/97     helena      Added internal API documentation.  Note. All the VectorOfXXX
  33. //                          interface is about the same.  The internal API docs will be
  34. //                          added to only the first version and additional description
  35. //                          will be added where necessary.
  36. //  8/04/98        erm            Added fwd member to EntryPair.
  37. //===============================================================================
  38.  
  39. #ifndef TABLES_H
  40. #define TABLES_H
  41.  
  42.  
  43. #include "filestrm.h"
  44. #include "unistr.h"
  45.  
  46.  
  47. /**
  48.  * EntryPair is used for contracting characters.  Each entry pair contains the contracting 
  49.  * character string and its collation order.
  50.  */
  51. class EntryPair
  52. {
  53. public :
  54.     /**
  55.      * Constructor
  56.      */
  57.     EntryPair();
  58.     EntryPair(const UnicodeString &name, int32_t aValue, bool_t aFwd = TRUE);
  59.  
  60.     UnicodeString entryName;        // Contracting characters
  61.     int32_t value;                  // Collation order
  62.     bool_t fwd;                        // true if this pair is for the forward direction
  63.  
  64.     /**
  65.      * The streamIn and streamOut methods read and write objects of this
  66.      * class as binary, platform-dependent data in the iostream.  The stream
  67.      * must be in ios::binary mode for this to work.  These methods are not
  68.      * intended for general public use; they are used by the framework to improve
  69.      * performance by storing certain objects in binary files.
  70.      */
  71.     void streamOut(FileStream* os) const;
  72.     void streamIn(FileStream* is);
  73. };
  74.  
  75.  
  76. /**
  77.  * VectorOfInt is a dynamic array of 32-bit integers.  
  78.  * Ideally we would use templates for this, but they're not supported
  79.  * on all of the platforms we need to support.
  80.  */
  81. class VectorOfInt {
  82.  
  83.     public:
  84.         /**
  85.          * The chunk size by which the array is grown.
  86.          * This probably shouldn't be in the API
  87.          */
  88.         enum EGrowthRate { GROWTH_RATE = 4 };
  89.         /**
  90.          * Creates a vector that contains elements of integers.
  91.          * @param initialSize the initial size of the vector object.
  92.          */
  93.                                 VectorOfInt(int32_t initialSize = 0);
  94.         /**
  95.          * Copy constructor.
  96.          */
  97.                                 VectorOfInt(const VectorOfInt&  that);
  98.         /**
  99.          * Destructor.
  100.          */
  101.                                 ~VectorOfInt();
  102.  
  103.         /**
  104.          * Assignment operator.
  105.          */
  106.         const VectorOfInt&      operator=(const VectorOfInt&    that);
  107.         
  108.  
  109.         /**
  110.          * Equality operators.
  111.          */
  112.         bool_t                  operator==(const VectorOfInt& that);
  113.         bool_t                  operator!=(const VectorOfInt& that);
  114.  
  115.         /**
  116.          * Gets a read-only reference to the element at the specified index.
  117.          * This does not do range-checking; an invalid index may cause a crash.
  118.          * @return the accessed element.
  119.          */
  120.         int32_t                 operator[](int32_t  index) const;
  121.         int32_t                 at(int32_t  index) const;
  122.  
  123.         /**
  124.          * Gets a non-const reference to the element at the specified index.
  125.          * This does range-checking; access to elements beyond the end of the
  126.          * array will cause the array to grow.
  127.          */
  128.         int32_t&                operator[](int32_t  index);
  129.         int32_t&                at(int32_t  index);
  130.  
  131.         /**
  132.          * Sets the element at the specified index to a different value.
  133.          * @param index the specified index.
  134.          * @param value the new value.
  135.          */
  136.         void                    atPut(  int32_t     index,
  137.                                         const int32_t&  value);
  138.         /**
  139.          * Inserts a value at the specified index, sliding the rest of
  140.          * the elements in the array over to make room.
  141.          * @param index the specified index.
  142.          * @param value the value.
  143.          */
  144.         void                    atInsert(   int32_t     index,
  145.                                         const int32_t&  value);
  146.  
  147.         /**
  148.          * Returns the number of elements in the vector.
  149.          * @return the size of vector.
  150.          */
  151.         int32_t                 size(void) const;
  152.  
  153.         /**
  154.          * Checks if this vector object is valid.
  155.          * @return TRUE if the vector object is valid, FALSE otherwise.
  156.          */
  157.         bool_t                  isBogus(void) const;
  158.  
  159.         /**
  160.          * The streamIn and streamOut methods read and write objects of this
  161.          * class as binary, platform-dependent data in the iostream.  The stream
  162.          * must be in ios::binary mode for this to work.  These methods are not
  163.          * intended for general public use; they are used by the framework to improve
  164.          * performance by storing certain objects in binary files.
  165.          */
  166.         void                    streamOut(FileStream* os) const;
  167.         void                    streamIn(FileStream* is);
  168.  
  169.     private:
  170.         /**
  171.          * Resizes the vector if necessary when compared to a new size.
  172.          * @param newSize the new size.
  173.          */
  174.         void                        resize(int32_t  newSize);
  175.     
  176.         int32_t                     fSize;
  177.         int32_t                     fCapacity;
  178.         int32_t*                    fElements;
  179.         bool_t                      fBogus;
  180. };
  181.  
  182. /**
  183.  * VectorOfPointer is a dynamic array of void* pointers.  
  184.  *  <P>
  185.  *  This is a vector class that is designed to be used with pointer types and which implements
  186.  *  owning semantics.  That is, once a value is placed an element of the vector, the vector is
  187.  *  considered to own it and is responsible for disposing it.  This will happen both when the
  188.  *  element is changed using atPut() or through an PointerTo****, and when the vector itself is
  189.  *  disposed.  
  190.  *  <P>
  191.  *  WARNING:  The caller must be careful to avoid holding onto any dangling references
  192.  *  after the vector is disposed, and the caller must also be careful not to put the same
  193.  *  value into more than one element in the vector (unless the value is NULL).
  194.  *  <P>
  195.  *  As with VectorOf***>, the vector grows as necessary to accommodate all elements, the
  196.  *  size is one plus the index of the highest element that's been set, and any elements below
  197.  *  the highest element that aren't explicitly initialized are initialized to NULL.
  198.  */
  199. class VectorOfPointer {
  200.     public:
  201.         /**
  202.          * The chunk size by which the array is grown.
  203.          * This probably shouldn't be in the API
  204.          */
  205.         enum EGrowthRate { GROWTH_RATE = 4 };
  206.         /**
  207.          * Creates a vector that contains elements of pointers to objects.
  208.          * @param initialSize the initial size of the vector object.
  209.          */
  210.                                     VectorOfPointer(int32_t initialSize = 0);
  211.         /**
  212.          * Copy constructor.
  213.          */
  214.                                     VectorOfPointer(const VectorOfPointer&  that);
  215.         /**
  216.          * Destructor.
  217.          */
  218.                                     ~VectorOfPointer();
  219.         /**
  220.          * Assignment operator.
  221.          */
  222.         const VectorOfPointer&      operator=(const VectorOfPointer&    that);
  223.  
  224.         /**
  225.          * Equality operators.
  226.          */
  227.         bool_t                      operator==(const VectorOfPointer& that);
  228.         bool_t                      operator!=(const VectorOfPointer& that);
  229.  
  230.         /**
  231.          * Gets a read-only reference to the element at the specified index.
  232.          * This does not do range-checking; an invalid index may cause a crash.
  233.          * @return the accessed element.
  234.          */
  235.         void*                       operator[](int32_t  index) const;
  236.         void*                       at(int32_t  index) const;
  237.  
  238.         /**
  239.          * Gets a non-const reference to the element at the specified index.
  240.          * This does range-checking; access to elements beyond the end of the
  241.          * array will cause the array to grow.
  242.          */
  243.         void*&                      operator[](int32_t  index);
  244.         void*&                      at(int32_t  index);
  245.  
  246.         /**
  247.          * Sets the element at the specified index to a different value.
  248.          * @param index the specified index.
  249.          * @param value the new value.
  250.          */
  251.         void                        atPut(  int32_t         index,
  252.                                             const void*&    value);
  253.  
  254.         /**
  255.          * Inserts a value at the specified index, sliding the rest of
  256.          * the elements in the array over to make room.
  257.          * @param index the specified index.
  258.          * @param value the value.
  259.          */
  260.         void                        atInsert(   int32_t     index,
  261.                                                 const void*&    value);
  262.         /**
  263.          * Returns the number of elements in the vector.
  264.          * @return the size of vector.
  265.          */
  266.         int32_t                     size(void) const;
  267.  
  268.         /**
  269.          * Checks if this vector object is valid.
  270.          * @return TRUE if the vector object is valid, FALSE otherwise.
  271.          */
  272.         bool_t                      isBogus(void) const;
  273.  
  274.     private:
  275.         /**
  276.          * Resizes the vector if necessary when compared to a new size.
  277.          * @param newSize the new size.
  278.          */
  279.         void                        resize(int32_t  newSize);
  280.     
  281.         int32_t                     fSize;
  282.         int32_t                     fCapacity;
  283.         void**                      fElements;
  284.         bool_t                      fBogus;
  285. };
  286.  
  287. //=================================================================================================
  288. //  The following diagram shows the data structure of the RuleBasedCollator object.
  289. //  Suppose we have the rule, where 'o-umlaut' is the unicode char 0x00F6.
  290. //  "a, A < b, B < c, C, ch, cH, Ch, CH < d, D ... < o, O; 'o-umlaut'/E, 'O-umlaut'/E ...".
  291. //  What the rule says is, sorts 'ch'ligatures and 'c' only with tertiary difference and
  292. //  sorts 'o-umlaut' as if it's always expanded with 'e'.
  293. //
  294. //                                     (VectorOfPToContractTable)         (VectorOfPToExpandTable)
  295. // mapping table                           contracting list                  expanding list
  296. // (contains all unicode char
  297. //  entries)
  298. //                   (VectorOfPToContractElement) *(PToContractElement)      (PToExpandTable)
  299. //                                      ___        _____________         _________________________
  300. //   ________                   |=====>|_*_|----->|'c'  |v('c') |   |==>|v('o')|v('umlaut')|v('e')|
  301. //  |_\u0001_|--> v('\u0001')   |      |_:_|      |-------------|   |   |-------------------------|
  302. //  |_\u0002_|--> v('\u0002')   |      |_:_|      |'ch' |v('ch')|   |   |             :           |
  303. //  |____:___|                  |      |_:_|      |-------------|   |   |-------------------------|
  304. //  |____:___|                  |                 |'cH' |v('cH')|   |   |             :           |
  305. //  |__'a'___|--> v('a')        |                 |-------------|   |   |-------------------------|
  306. //  |__'b'___|--> v('b')        |                 |'Ch' |v('Ch')|   |   |             :           |
  307. //  |____:___|                  |                 |-------------|   |   |-------------------------|
  308. //  |____:___|                  |                 |'CH' |v('CH')|   |   |             :           |
  309. //  |__'ch'__|-------------------                  -------------    |   |-------------------------|
  310. //  |____:___|                                                      |   |             :           |
  311. //  |o-umlaut|------------------------------------------------------    |_________________________|
  312. //  |____:___|
  313. //
  314. //
  315. // Noted by Helena Shih on 6/23/97 with pending design changes (slimming collation).
  316. //=================================================================================================
  317.  
  318. /** 
  319.  * PToExpandTable is a smart-pointer to a VectorOfInt that is used to store
  320.  * the collation orders that are the result of an expansion.
  321.  * <P>
  322.  * You can use this object as if it were a pointer to a VectorOfInt, e.g.
  323.  * <pre>
  324.  * PToExpandTable foo = ....;
  325.  * foo->atInsert(....);
  326.  * </pre>
  327.  */
  328. class PToExpandTable {
  329.     public:
  330.         
  331.         /**
  332.          * Destructor.
  333.          */
  334.                                             ~PToExpandTable();
  335.         
  336.         /**
  337.          * Assignment operators
  338.          * The expand table that this object already points to (if any) is deleted.
  339.          */
  340.         const PToExpandTable&               operator=(VectorOfInt*  newValue);
  341.         const PToExpandTable&               operator=(const PToExpandTable& pointerToNewValue);
  342.  
  343.         /**
  344.          * Pointer operator override
  345.          */
  346.                                             operator VectorOfInt*() const;
  347.  
  348.     private:
  349.         /**
  350.          * Constructor
  351.          */
  352.                                             PToExpandTable(VectorOfInt*&    value);
  353.         /**
  354.          * Copy constructor.
  355.          */
  356.                                             PToExpandTable(const PToExpandTable&    that);
  357.  
  358.         VectorOfInt*&                       fValue;
  359.  
  360.         friend class VectorOfPToExpandTable;
  361. };
  362.  
  363. /**
  364.  *  VectorOfPointer is a dynamic array of PToExpandTable objects
  365.  *  which in turn point to the array of collation orders for each expanding character.
  366.  *  <P>
  367.  *  This is a vector class that is designed to be used with pointer types and which implements
  368.  *  owning semantics.  That is, once a value is placed an element of the vector, the vector is
  369.  *  considered to own it and is responsible for disposing it.  This will happen both when the
  370.  *  element is changed using atPut() or through an PointerTo****, and when the vector itself is
  371.  *  disposed.  
  372.  *  <P>
  373.  *  WARNING:  The caller must be careful to avoid holding onto any dangling references
  374.  *  after the vector is disposed, and the caller must also be careful not to put the same
  375.  *  value into more than one element in the vector (unless the value is NULL).
  376.  *  <P>
  377.  *  As with VectorOf***>, the vector grows as necessary to accommodate all elements, the
  378.  *  size is one plus the index of the highest element that's been set, and any elements below
  379.  *  the highest element that aren't explicitly initialized are initialized to NULL.
  380.  */
  381. class VectorOfPToExpandTable {
  382.     public:
  383.  
  384.         /**
  385.          * The chunk size by which the array is grown.
  386.          * This probably shouldn't be in the API
  387.          */
  388.         enum EGrowthRate { GROWTH_RATE = 4 };
  389.         /**
  390.          * Creates a vector that contains elements of PToExpandTable.
  391.          * @param initialSize the initial size of the vector object.
  392.          */
  393.                             VectorOfPToExpandTable(int32_t  initialSize = 0);
  394.         /**
  395.          * Copy constructor.
  396.          */
  397.                             VectorOfPToExpandTable(const VectorOfPToExpandTable&    that);
  398.  
  399.         /**
  400.          * Destructor.
  401.          */
  402.                             ~VectorOfPToExpandTable();
  403.  
  404.         /**
  405.          * Assignment operator.
  406.          */
  407.         const VectorOfPToExpandTable&   
  408.                             operator=(const VectorOfPToExpandTable& that);
  409.  
  410.         /**
  411.          * Return a modifiable smart-pointer to the expansion table
  412.          * at the given index.  Assigning to this smart pointer will work, e.g.
  413.          *  VectorOfPToExpandTable foo = ....;
  414.          *  foo[5] = new VectorOfInt ...;
  415.          * This does range-checking; access to elements beyond the end of the
  416.          * array will cause the array to grow.
  417.          */
  418.         PToExpandTable      at(int32_t  index);
  419.         PToExpandTable      operator[](int32_t  index);
  420.  
  421.         /**
  422.          * Return a pointer to the table at the given index.
  423.          * The pointer itself cannot be modified, but the elements it points to may:
  424.          * <pre>
  425.          *  const VectorOfPToExpandTable foo = ....;
  426.          *  foo[5] = ....;      // NOT ALLOWED
  427.          *  foo[5][0] = 12345;  // ok
  428.          * </pre>
  429.          * This does not do range-checking; an invalid index may cause a crash.
  430.          * @return the accessed element.
  431.          */
  432.         VectorOfInt*        at(int32_t  index) const;
  433.         VectorOfInt*        operator[](int32_t  index) const;
  434.  
  435.         /**
  436.          * Sets the element at the specified index to a different value.
  437.          * If there was aready an object stored at this index, it is deleted.
  438.          * @param index the specified index.
  439.          * @param value the new value.
  440.          */
  441.         void                atPut(  int32_t         index,
  442.                                     VectorOfInt*    value);
  443.  
  444.         /**
  445.          * "Orphan" the pointer at the specified index.  The array will no
  446.          * longer contain a reference to the object, and the caller is
  447.          * now responsible for deleting its storage.
  448.          */
  449.         VectorOfInt*        orphanAt(int32_t    index);
  450.  
  451.         /**
  452.          * Returns the number of elements in the vector.
  453.          * @return the size of vector.
  454.          */
  455.         int32_t             size(void) const;
  456.  
  457.         /**
  458.          * Checks if this vector object is valid.
  459.          * @return TRUE if the vector object is valid, FALSE otherwise.
  460.          */
  461.         bool_t              isBogus(void) const;
  462.  
  463.     /**
  464.      * The streamIn and streamOut methods read and write objects of this
  465.      * class as binary, platform-dependent data in the iostream.  The stream
  466.      * must be in ios::binary mode for this to work.  These methods are not
  467.      * intended for general public use; they are used by the framework to improve
  468.      * performance by storing certain objects in binary files.
  469.      */
  470.         void                streamOut(FileStream* os) const;
  471.         void                streamIn(FileStream* is);
  472.  
  473.     private:
  474.         /**
  475.          * Resizes the vector if necessary when compared to a new size.
  476.          * @param newSize the new size.
  477.          */
  478.         void                resize(int32_t      newSize);
  479.  
  480.         int32_t             fSize;
  481.         int32_t             fCapacity;
  482.         VectorOfInt**       fElements;
  483.         bool_t              fBogus;
  484. };
  485.  
  486. /** 
  487.  * PToContractElement is a smart-pointer to an array that is used to store
  488.  * the contracting-character strings that are associated with a given Unicode character.
  489.  * <P>
  490.  * You can use this object as if it were a pointer to an EntryPair array, e.g.
  491.  * <pre>
  492.  * PToContractElement foo = ....;
  493.  * foo->entryName = ....;
  494.  * </pre>
  495.  */
  496. class PToContractElement {
  497.     public:
  498.         /**
  499.          * Destructor.
  500.          */
  501.                                             ~PToContractElement();
  502.         
  503.         /**
  504.          * Assignment operators
  505.          * The EntryPair that this object already points to (if any) is deleted.
  506.          */
  507.         const PToContractElement&               operator=(EntryPair*    newValue);
  508.         const PToContractElement&               operator=(const PToContractElement& pointerToNewValue);
  509.  
  510.         /**
  511.          * Pointer operator override
  512.          */
  513.                                             operator EntryPair*() const;
  514.  
  515.     private:
  516.         /**
  517.          * Constructor
  518.          */
  519.                                             PToContractElement(EntryPair*&  value);
  520.         /**
  521.          * Copy constructor.
  522.          */
  523.                                             PToContractElement(const PToContractElement&    that);
  524.  
  525.         EntryPair*&                     fValue;
  526.  
  527.         friend class VectorOfPToContractElement;
  528. };
  529.  
  530. /**
  531.  *  The table that contains the list of contracting character entries.
  532.  *  <P>
  533.  *  This is a vector class that is designed to be used with pointer types and which implements
  534.  *  owning semantics.  That is, once a value is placed an element of the vector, the vector is
  535.  *  considered to own it and is responsible for disposing it.  This will happen both when the
  536.  *  element is changed using atPut() or through an PointerTo****, and when the vector itself is
  537.  *  disposed.  
  538.  *  <P>
  539.  *  WARNING:  The caller must be careful to avoid holding onto any dangling references
  540.  *  after the vector is disposed, and the caller must also be careful not to put the same
  541.  *  value into more than one element in the vector (unless the value is NULL).
  542.  *  <P>
  543.  *  As with VectorOf***>, the vector grows as necessary to accommodate all elements, the
  544.  *  size is one plus the index of the highest element that's been set, and any elements below
  545.  *  the highest element that aren't explicitly initialized are initialized to NULL.
  546.  */
  547. class VectorOfPToContractElement {
  548.     public:
  549.         /**
  550.          * The chunk size by which the array is grown.
  551.          * This probably shouldn't be in the API
  552.          */
  553.         enum EGrowthRate { GROWTH_RATE = 4 };
  554.         /**
  555.          * Creates a vector that contains elements of PToContractElement.
  556.          * @param initialSize the initial size of the vector object.
  557.          */
  558.                             VectorOfPToContractElement(int32_t  initialSize = 0);
  559.         /**
  560.          * Copy constructor.
  561.          */
  562.                             VectorOfPToContractElement(const VectorOfPToContractElement&    that);
  563.  
  564.         /**
  565.          * Destructor.
  566.          */
  567.                             ~VectorOfPToContractElement();
  568.  
  569.         /**
  570.          * Assignment operator.
  571.          */
  572.         const VectorOfPToContractElement&   
  573.                             operator=(const VectorOfPToContractElement& that);
  574.  
  575.         /**
  576.          * Return a modifiable smart-pointer to the EntryPair
  577.          * at the given index.  Assigning to this smart pointer will work, e.g.
  578.          * <pre>
  579.          *  PToContractElement foo = ....;
  580.          *  foo[5] = ...;
  581.          * </pre>
  582.          * This does range-checking; access to elements beyond the end of the
  583.          * array will cause the array to grow.
  584.          */
  585.         PToContractElement  operator[](int32_t  index);
  586.         PToContractElement  at(int32_t  index);
  587.  
  588.         /**
  589.          * Return a pointer to the EntryPair at the given index.
  590.          * The pointer itself cannot be modified, but the elements it points to may:
  591.          * <pre>
  592.          *  const VectorOfPToExpandTable foo = ....;
  593.          *  foo[5] = ....;              // NOT ALLOWED
  594.          *  foo[5]->entryName = ....;   // ok
  595.          * </pre>
  596.          * This does not do range-checking; an invalid index may cause a crash.
  597.          * @return the accessed element.
  598.          */
  599.         EntryPair*          operator[](int32_t  index) const;
  600.         EntryPair*          at(int32_t  index) const;
  601.  
  602.         /**
  603.          * Sets the element at the specified index to a different value.
  604.          * If there was aready an object stored at this index, it is deleted.
  605.          * @param index the specified index.
  606.          * @param value the new value.
  607.          */
  608.         void                atPut(  int32_t         index,
  609.                                     EntryPair*      value);
  610.         /**
  611.          * Inserts a value at the specified index, sliding the rest of
  612.          * the elements in the array over to make room.
  613.          * @param index the specified index.
  614.          * @param value the value.
  615.          */
  616.         void                atInsert(   int32_t     index,
  617.                                         EntryPair*  value);
  618.         /**
  619.          * "Orphan" the pointer at the specified index.  The array will no
  620.          * longer contain a reference to the object, and the caller is
  621.          * now responsible for deleting its storage.
  622.          */
  623.         EntryPair*          orphanAt(int32_t    index);
  624.  
  625.         /**
  626.          * Returns the number of elements in the vector.
  627.          * @return the size of vector.
  628.          */
  629.         int32_t             size(void) const;
  630.  
  631.         /**
  632.          * Checks if this vector object is valid.
  633.          * @return TRUE if the vector object is valid, FALSE otherwise.
  634.          */
  635.         bool_t              isBogus(void) const;
  636.  
  637.         /**
  638.          * The streamIn and streamOut methods read and write objects of this
  639.          * class as binary, platform-dependent data in the iostream.  The stream
  640.          * must be in ios::binary mode for this to work.  These methods are not
  641.          * intended for general public use; they are used by the framework to improve
  642.          * performance by storing certain objects in binary files.
  643.          */
  644.         void                streamOut(FileStream* os) const;
  645.         void                streamIn(FileStream* is);
  646.  
  647.     private:
  648.         /**
  649.          * Resizes the vector if necessary when compared to a new size.
  650.          * @param newSize the new size.
  651.          */
  652.         void                resize(int32_t      newSize);
  653.  
  654.         int32_t             fSize;
  655.         int32_t             fCapacity;
  656.         EntryPair**         fElements;
  657.         bool_t              fBogus;
  658. };
  659.  
  660. /**
  661.  * Pointer to each contracing element list.
  662.  */
  663. class PToContractTable {
  664.     public:
  665.         /**
  666.          * Destructor.
  667.          */
  668.                                             ~PToContractTable();
  669.         
  670.         /**
  671.          * Assignment operators.
  672.          * <P>
  673.          * The contracting element list (if any) that this object already points to
  674.          * is deleted.
  675.          */
  676.         const PToContractTable&             operator=(VectorOfPToContractElement*   newValue);
  677.         const PToContractTable&             operator=(const PToContractTable&   pointerToNewValue);
  678.  
  679.         /**
  680.          * Pointer operator override
  681.          */
  682.                                             operator VectorOfPToContractElement*() const;
  683.  
  684.     private:
  685.         /**
  686.          * Constructor
  687.          */
  688.                                             PToContractTable(VectorOfPToContractElement*&   value);
  689.         /**
  690.          * Copy constructor.
  691.          */
  692.                                             PToContractTable(const PToContractTable&    that);
  693.  
  694.         VectorOfPToContractElement*&                        fValue;
  695.  
  696.         friend class VectorOfPToContractTable;
  697. };
  698.  
  699. /**
  700.  * The vector that contains all contracting list tables.
  701.  *  <P>
  702.  *  This is a vector class that is designed to be used with pointer types and which implements
  703.  *  owning semantics.  That is, once a value is placed an element of the vector, the vector is
  704.  *  considered to own it and is responsible for disposing it.  This will happen both when the
  705.  *  element is changed using atPut() or through an PointerTo****, and when the vector itself is
  706.  *  disposed.  
  707.  *  <P>
  708.  *  WARNING:  The caller must be careful to avoid holding onto any dangling references
  709.  *  after the vector is disposed, and the caller must also be careful not to put the same
  710.  *  value into more than one element in the vector (unless the value is NULL).
  711.  *  <P>
  712.  *  As with VectorOf***>, the vector grows as necessary to accommodate all elements, the
  713.  *  size is one plus the index of the highest element that's been set, and any elements below
  714.  *  the highest element that aren't explicitly initialized are initialized to NULL.
  715.  */
  716. class VectorOfPToContractTable {
  717.     public:
  718.         /**
  719.          * The chunk size by which the array is grown.
  720.          * This probably shouldn't be in the API
  721.          */
  722.         enum EGrowthRate { GROWTH_RATE = 4 };
  723.         /**
  724.          * Creates a vector that contains elements of PToContractTable.
  725.          * @param initialSize the initial size of the vector object.
  726.          */
  727.                             VectorOfPToContractTable(int32_t    initialSize = 0);
  728.         /**
  729.          * Copy constructor.
  730.          */
  731.                             VectorOfPToContractTable(const VectorOfPToContractTable&    that);
  732.  
  733.                             ~VectorOfPToContractTable();
  734.  
  735.         /**
  736.          * Assignment operator.
  737.          */
  738.         const VectorOfPToContractTable& 
  739.                             operator=(const VectorOfPToContractTable&   that);
  740.  
  741.         /**
  742.          * Return a modifiable smart-pointer to the contraction table
  743.          * at the given index.  Assigning to this smart pointer will work, e.g.
  744.          * <pre>
  745.          *  VectorOfPToContractTable foo = ....;
  746.          *  foo[5] = ...;
  747.          * </pre>
  748.          * This does range-checking; access to elements beyond the end of the
  749.          * array will cause the array to grow.
  750.          */
  751.         PToContractTable        operator[](int32_t  index);
  752.         PToContractTable        at(int32_t  index);
  753.  
  754.         /**
  755.          * Return a pointer to the contraction table at the given index.
  756.          * The pointer itself cannot be modified, but the elements it points to may:
  757.          * <pre>
  758.          *  const VectorOfPToExpandTable foo = ....;
  759.          *  foo[5] = ....;              // NOT ALLOWED
  760.          *  foo[5][0] = ....;           // ok
  761.          * </pre>
  762.          * This does not do range-checking; an invalid index may cause a crash.
  763.          * @return the accessed element.
  764.          */
  765.         VectorOfPToContractElement*     operator[](int32_t  index) const;
  766.         VectorOfPToContractElement*     at(int32_t  index) const;
  767.  
  768.         /**
  769.          * Sets the element at the specified index to a different value.
  770.          * If there was aready an object stored at this index, it is deleted.
  771.          * @param index the specified index.
  772.          * @param value the new value.
  773.          */
  774.         void                atPut(  int32_t         index,
  775.                                     VectorOfPToContractElement* value);
  776.         /**
  777.          * "Orphan" the pointer at the specified index.  The array will no
  778.          * longer contain a reference to the object, and the caller is
  779.          * now responsible for deleting its storage.
  780.          */
  781.         VectorOfPToContractElement*     orphanAt(int32_t    index);
  782.  
  783.         /**
  784.          * Returns the number of elements in the vector.
  785.          * @return the size of vector.
  786.          */
  787.         int32_t             size(void) const;
  788.  
  789.         /**
  790.          * Checks if this vector object is valid.
  791.          * @return TRUE if the vector object is valid, FALSE otherwise.
  792.          */
  793.         bool_t              isBogus(void) const;
  794.         /**
  795.          * The streamIn and streamOut methods read and write objects of this
  796.          * class as binary, platform-dependent data in the iostream.  The stream
  797.          * must be in ios::binary mode for this to work.  These methods are not
  798.          * intended for general public use; they are used by the framework to improve
  799.          * performance by storing certain objects in binary files.
  800.          */
  801.         void                streamOut(FileStream* os) const;
  802.         void                streamIn(FileStream* is);
  803.  
  804.     private:
  805.         /**
  806.          * Resizes the vector if necessary when compared to a new size.
  807.          * @param newSize the new size.
  808.          */
  809.         void                resize(int32_t      newSize);
  810.  
  811.         int32_t             fSize;
  812.         int32_t             fCapacity;
  813.         VectorOfPToContractElement**        fElements;
  814.         bool_t              fBogus;
  815. };
  816.  
  817. class PatternEntry;
  818.  
  819. /**
  820.  *  Proxy class for accessing elements of a VectorOfPointersToPatternEntry
  821.  *  <P>
  822.  *  This class is a simple proxy class that implements the owning semantics for the
  823.  *  operator[] and at() functions on VectorOfPointersToPatternEntry.  It enables
  824.  *  expressions like "v[3] = someNewValue".  One never creates a PointerToPatternEntry
  825.  *  directly, and one never declares variables of this type.  It just exists to
  826.  *  implement the API of VectorOfPointersToPatternEntry.
  827.  */
  828.  
  829. class PointerToPatternEntry {
  830.     public:
  831.         /**
  832.          * Destructor.
  833.          */
  834.                                             ~PointerToPatternEntry();
  835.         
  836.         /**
  837.          * Assignment operators
  838.          * The PatternEntry that this object already points to (if any) is deleted.
  839.          */
  840.         const PointerToPatternEntry&        operator=(PatternEntry* newValue);
  841.         const PointerToPatternEntry&        operator=(const PointerToPatternEntry&  pointerToNewValue);
  842.  
  843.         /**
  844.          * Pointer operator override
  845.          */
  846.                                             operator PatternEntry*() const;
  847.  
  848.     private:
  849.         /**
  850.          * Constructor
  851.          */
  852.                                             PointerToPatternEntry(PatternEntry*&    value);
  853.         /**
  854.          * Copy constructor.
  855.          */
  856.                                             PointerToPatternEntry(const PointerToPatternEntry&  that);
  857.  
  858.         PatternEntry*&                      fValue;
  859.  
  860.         friend class VectorOfPointersToPatternEntry;
  861. };
  862.  
  863. /**
  864.  *  Simple owning-vector class
  865.  *  This is a vector class that is designed to be used with pointer types and which implements
  866.  *  owning semantics.  That is, once a value is placed an element of the vector, the vector is
  867.  *  considered to own it and is responsible for disposing it.  This will happen both when the
  868.  *  element is changed using atPut() or through an PointerTo****, and when the vector itself is
  869.  *  disposed.  
  870.  *  <P>
  871.  *  WARNING:  The caller must be careful to avoid holding onto any dangling references
  872.  *  after the vector is disposed, and the caller must also be careful not to put the same
  873.  *  value into more than one element in the vector (unless the value is NULL).
  874.  *  <P>
  875.  *  As with VectorOf***>, the vector grows as necessary to accommodate all elements, the
  876.  *  size is one plus the index of the highest element that's been set, and any elements below
  877.  *  the highest element that aren't explicitly initialized are initialized to NULL.
  878.  */
  879.  
  880. class VectorOfPointersToPatternEntry {
  881.     public:
  882.         /**
  883.          * The chunk size by which the array is grown.
  884.          * This probably shouldn't be in the API
  885.          */
  886.         enum EGrowthRate { GROWTH_RATE = 4 };
  887.         /**
  888.          * Creates a vector that contains elements of PointerToPatternEntry.
  889.          * @param initialSize the initial size of the vector object.
  890.          */
  891.                                             VectorOfPointersToPatternEntry(int32_t  initialSize = 0);
  892.         /**
  893.          * Copy constructor.
  894.          */
  895.                                             VectorOfPointersToPatternEntry(const VectorOfPointersToPatternEntry& that);
  896.  
  897.         /**
  898.          * Destructor.
  899.          */
  900.                                             ~VectorOfPointersToPatternEntry();
  901.  
  902.         /**
  903.          * Assignment operator.
  904.          */
  905.         const VectorOfPointersToPatternEntry& operator=(const VectorOfPointersToPatternEntry& that);
  906.  
  907.         /**
  908.          * Return a modifiable smart-pointer to the contraction table
  909.          * at the given index.  Assigning to this smart pointer will work, e.g.
  910.          * <pre>
  911.          *  VectorOfPointersToPatternEntry foo = ....;
  912.          *  foo[5] = ...;
  913.          * </pre>
  914.          * This does range-checking; access to elements beyond the end of the
  915.          * array will cause the array to grow.
  916.          */
  917.         PointerToPatternEntry               operator[](int32_t  index);
  918.         inline PointerToPatternEntry        at(int32_t  index) { return (*this)[index]; }
  919.  
  920.         /**
  921.          * Return a pointer to the EntryPair at the given index.
  922.          * The pointer itself cannot be modified, but the elements it points to may:
  923.          * <pre>
  924.          *  const VectorOfPointersToPatternEntryfoo = ....;
  925.          *  foo[5] = ....;              // NOT ALLOWED
  926.          *  foo[5]->getStrength();      // ok
  927.          * </pre>
  928.          * This does not do range-checking; an invalid index may cause a crash.
  929.          * @return the accessed element.
  930.          */
  931.         PatternEntry*                       operator[](int32_t  index) const;
  932.         inline PatternEntry*                at(int32_t  index) const { return (*this)[index]; }
  933.  
  934.         /**
  935.          * Sets the element at the specified index to a different value.
  936.          * If there was aready an object stored at this index, it is deleted.
  937.          * @param index the specified index.
  938.          * @param value the new value.
  939.          */
  940.         void                                atPut(  int32_t     index,
  941.                                                     PatternEntry*   value);
  942.         /**
  943.          * Inserts a value at the specified index, sliding the rest of
  944.          * the elements in the array over to make room.
  945.          * @param index the specified index.
  946.          * @param value the value.
  947.          */
  948.         void                                atInsert(   int32_t     index,
  949.                                                         PatternEntry*   value);
  950.         /**
  951.          * "Orphan" the pointer at the specified index.  The array will no
  952.          * longer contain a reference to the object, and the caller is
  953.          * now responsible for deleting its storage.
  954.          */
  955.         PatternEntry*                       orphanAt(int32_t    index);
  956.  
  957.         /**
  958.          * Remove all elements from the vector.
  959.          */
  960.         void                                clear(void);
  961.  
  962.         /**
  963.          * Returns the number of elements in the vector.
  964.          * @return the size of vector.
  965.          */
  966.         int32_t                             size(void) const;
  967.  
  968.         /**
  969.          * If the specified value exists in the vector, return its index.
  970.          * If not, return -1.
  971.          */
  972.         int32_t                             indexOf(const PatternEntry* value) const;
  973.  
  974.         /**
  975.          * Return the index of the last occurance of value in the vector,
  976.          * or -1 if the vector doesn't contain value.
  977.          */
  978.         int32_t                             lastIndexOf(const PatternEntry* value) const;
  979.  
  980.         /**
  981.          * Checks if this vector object is valid.
  982.          * @return TRUE if the vector object is valid, FALSE otherwise.
  983.          */
  984.         bool_t                              isBogus(void) const;
  985.     private:
  986.         /**
  987.          * Resizes the vector if necessary when compared to a new size.
  988.          * @param newSize the new size.
  989.          */
  990.         void                                resize(int32_t      newSize);
  991.  
  992.         int32_t                             fSize;
  993.         int32_t                             fCapacity;
  994.         PatternEntry**                      fElements;
  995.         bool_t                              fBogus;
  996. };
  997.  
  998. inline
  999. EntryPair::EntryPair()
  1000.   : entryName(), value(0xffffffff), fwd(TRUE)
  1001. {
  1002. }
  1003.  
  1004. inline
  1005. EntryPair::EntryPair(const UnicodeString &name, int32_t aValue, bool_t aFwd)
  1006.   : entryName(name), value(aValue), fwd(aFwd)
  1007. {
  1008. }
  1009.  
  1010. //=======================================================================================
  1011. // METHODS ON VectorOfInt
  1012. //=======================================================================================
  1013.  
  1014. inline int32_t
  1015. VectorOfInt::operator[](int32_t index) const
  1016. {
  1017.     return (index < fCapacity) ? fElements[index] : 0;
  1018. }
  1019.  
  1020.  
  1021. inline int32_t
  1022. VectorOfInt::at(int32_t index) const
  1023. {
  1024.     return (*this)[index];
  1025. }
  1026.  
  1027. inline int32_t&
  1028. VectorOfInt::at(int32_t index)
  1029. {
  1030.     return (*this)[index];
  1031. }
  1032.  
  1033. inline int32_t
  1034. VectorOfInt::size() const
  1035. {
  1036.     return fSize;
  1037. }
  1038.  
  1039. //=======================================================================================
  1040. // METHODS ON VectorOfPointer
  1041. //=======================================================================================
  1042.  
  1043. inline void*
  1044. VectorOfPointer::operator[](int32_t index) const
  1045. {
  1046.     return (index < fCapacity) ? fElements[index] : 0;
  1047. }
  1048.  
  1049.  
  1050. inline void*
  1051. VectorOfPointer::at(int32_t index) const
  1052. {
  1053.     return (*this)[index];
  1054. }
  1055.  
  1056. inline void*&
  1057. VectorOfPointer::at(int32_t index)
  1058. {
  1059.     return (*this)[index];
  1060. }
  1061.  
  1062. inline int32_t
  1063. VectorOfPointer::size() const
  1064. {
  1065.     return fSize;
  1066. }
  1067. //=======================================================================================
  1068. // METHODS ON PToExpandTable
  1069. //=======================================================================================
  1070.  
  1071. inline
  1072. PToExpandTable::operator VectorOfInt*() const
  1073. {
  1074.     return fValue;
  1075. }
  1076.  
  1077. inline
  1078. PToExpandTable::PToExpandTable(VectorOfInt*&    value)
  1079. : fValue(value)
  1080. {
  1081. }
  1082.  
  1083. inline
  1084. PToExpandTable::PToExpandTable(const PToExpandTable&    that)
  1085. : fValue(that.fValue)
  1086. {
  1087. }
  1088.  
  1089. inline
  1090. PToExpandTable::~PToExpandTable()
  1091. {
  1092. }
  1093.  
  1094. inline const PToExpandTable&
  1095. PToExpandTable::operator=(VectorOfInt*  newValue)
  1096. {
  1097.     delete fValue;
  1098.     fValue = newValue;
  1099.     return *this;
  1100. }
  1101.  
  1102. inline const PToExpandTable&
  1103. PToExpandTable::operator=(const PToExpandTable& pointerToNewValue)
  1104. {
  1105.     delete fValue;
  1106.     fValue = (VectorOfInt*)(pointerToNewValue);
  1107.     return *this;
  1108. }
  1109.  
  1110. //=======================================================================================
  1111. // METHODS ON VectorOfPToExpandTable
  1112. //=======================================================================================
  1113. inline VectorOfInt*
  1114. VectorOfPToExpandTable::operator[](int32_t  index) const
  1115. {
  1116.     return (index < fCapacity) ? fElements[index] : 0;
  1117. }
  1118.  
  1119. inline VectorOfInt*
  1120. VectorOfPToExpandTable::at(int32_t  index) const
  1121. {
  1122.     return (*this)[index];
  1123. }
  1124.  
  1125. inline PToExpandTable
  1126. VectorOfPToExpandTable::at(int32_t  index)
  1127. {
  1128.     return (*this)[index];
  1129. }
  1130.  
  1131. inline int32_t
  1132. VectorOfPToExpandTable::size() const
  1133. {
  1134.     return fSize;
  1135. }
  1136.  
  1137. //=======================================================================================
  1138. // METHODS ON PToContractElement
  1139. //=======================================================================================
  1140.  
  1141. inline
  1142. PToContractElement::operator EntryPair*() const
  1143. {
  1144.     return fValue;
  1145. }
  1146.  
  1147. inline
  1148. PToContractElement::PToContractElement(EntryPair*&  value)
  1149. : fValue(value)
  1150. {
  1151. }
  1152.  
  1153. inline
  1154. PToContractElement::PToContractElement(const PToContractElement&    that)
  1155. : fValue(that.fValue)
  1156. {
  1157. }
  1158.  
  1159. inline
  1160. PToContractElement::~PToContractElement()
  1161. {
  1162. }
  1163.  
  1164. inline const PToContractElement&
  1165. PToContractElement::operator=(EntryPair*    newValue)
  1166. {
  1167.     delete fValue;
  1168.     fValue = newValue;
  1169.     return *this;
  1170. }
  1171.  
  1172. inline const PToContractElement&
  1173. PToContractElement::operator=(const PToContractElement& pointerToNewValue)
  1174. {
  1175.     delete fValue;
  1176.     fValue = (EntryPair*)(pointerToNewValue);
  1177.     return *this;
  1178. }
  1179.  
  1180. //=======================================================================================
  1181. // METHODS ON VectorOfPToContractElement
  1182. //=======================================================================================
  1183.  
  1184. inline EntryPair*
  1185. VectorOfPToContractElement::operator[](int32_t  index) const
  1186. {
  1187.     return (index < fCapacity) ? fElements[index] : 0;
  1188. }
  1189.  
  1190. inline EntryPair*
  1191. VectorOfPToContractElement::at(int32_t  index) const
  1192. {
  1193.     return (*this)[index];
  1194. }
  1195.  
  1196. inline PToContractElement
  1197. VectorOfPToContractElement::at(int32_t  index)
  1198. {
  1199.     return (*this)[index];
  1200. }
  1201.  
  1202. inline int32_t
  1203. VectorOfPToContractElement::size() const
  1204. {
  1205.     return fSize;
  1206. }
  1207.  
  1208. //=======================================================================================
  1209. // METHODS ON PToContractTable
  1210. //=======================================================================================
  1211.  
  1212. inline
  1213. PToContractTable::operator VectorOfPToContractElement*() const
  1214. {
  1215.     return fValue;
  1216. }
  1217.  
  1218. inline
  1219. PToContractTable::PToContractTable(VectorOfPToContractElement*& value)
  1220. : fValue(value)
  1221. {
  1222. }
  1223.  
  1224. inline
  1225. PToContractTable::PToContractTable(const PToContractTable&  that)
  1226. : fValue(that.fValue)
  1227. {
  1228. }
  1229.  
  1230. inline
  1231. PToContractTable::~PToContractTable()
  1232. {
  1233. }
  1234.  
  1235. inline const PToContractTable&
  1236. PToContractTable::operator=(VectorOfPToContractElement* newValue)
  1237. {
  1238.     delete fValue;
  1239.     fValue = newValue;
  1240.     return *this;
  1241. }
  1242.  
  1243. inline const PToContractTable&
  1244. PToContractTable::operator=(const PToContractTable& pointerToNewValue)
  1245. {
  1246.     delete fValue;
  1247.     fValue = (VectorOfPToContractElement*)(pointerToNewValue);
  1248.     return *this;
  1249. }
  1250.  
  1251. //=======================================================================================
  1252. // METHODS ON VectorOfPToContractTable
  1253. //=======================================================================================
  1254.  
  1255. inline VectorOfPToContractElement*
  1256. VectorOfPToContractTable::operator[](int32_t    index) const
  1257. {
  1258.     return (index < fCapacity) ? fElements[index] : 0;
  1259. }
  1260.  
  1261. inline VectorOfPToContractElement*
  1262. VectorOfPToContractTable::at(int32_t    index) const
  1263. {
  1264.     return (*this)[index];
  1265. }
  1266.  
  1267. inline PToContractTable
  1268. VectorOfPToContractTable::at(int32_t    index)
  1269. {
  1270.     return (*this)[index];
  1271. }
  1272.  
  1273. inline int32_t
  1274. VectorOfPToContractTable::size() const
  1275. {
  1276.     return fSize;
  1277. }
  1278.  
  1279. #endif
  1280.