home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / i18n / wdbktbl.h < prev   
Encoding:
C/C++ Source or Header  |  1999-08-16  |  4.0 KB  |  126 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. * File WDBKTBL.H
  14. *
  15. * WordBreakTable implements a state transition table.
  16. *
  17. * @package  Text and International
  18. * @category Text Scanning
  19. *
  20. * Modification History:
  21. *
  22. *   Date        Name        Description
  23. *   02/18/97    aliu        Converted from OpenClass.  Made statics const.
  24. *****************************************************************************************
  25. */
  26.  
  27. #ifndef WDBKTBL_H
  28. #define WDBKTBL_H
  29.  
  30. #include "utypes.h"
  31. #include "txtbdat.h"
  32.  
  33. /**
  34.  * This class implements a state transition table.
  35.  * After each transition, using the get method, the
  36.  * new state is returned along with information about
  37.  * the state change (ex. was it a "marked" transition").
  38.  * For efficiency, none of the arguments to any of these
  39.  * methods are validated.
  40.  */
  41. class WordBreakTable {
  42. public:
  43.     // For convenience
  44.     typedef TextBoundaryData::Node Node;
  45.     typedef TextBoundaryData::Type Type;
  46.  
  47.     /**
  48.      * Construct a table from the provided data.  See CharacterBreakData or
  49.      * the other TextBoundaryData subclasses for examples.  Each row represents
  50.      * a state, each column within a row represents a transition.  The values
  51.      * in the table represent the new state and mark information.
  52.      * @param cols number of columns in the table (transitions)
  53.      * @param data an encoded byte array containing state and transition data
  54.      * @param data_length the length of the byte array data
  55.      */
  56.     WordBreakTable(int32_t cols, const Node data[], int32_t data_length);
  57.  
  58.     /**
  59.      * Get the resulting state moving from oldState accepting input.
  60.      * @param oldState current state
  61.      * @param input input
  62.      * @return resulting state and transition data
  63.      */
  64.     Node get(Node oldState, Type input) const;
  65.  
  66.     /**
  67.      * Checks to see if the transition into the specified state was "marked."
  68.      * @param state the state as returned by get, initialState, or endState
  69.      * @return true if transition into state was marked.
  70.      */
  71.     bool_t isMarkState(Node state) const;
  72.  
  73.     /**
  74.      * Check to see if the state is the end state
  75.      * @param state the state to check
  76.      * @return true if state is an end state
  77.      */
  78.     bool_t isEndState(Node state) const;
  79.  
  80.     /**
  81.      * Get the initial state
  82.      * @return the initial state
  83.      */
  84.     Node initialState(void) const;
  85.  
  86. private:
  87.     static const Node  kMark_mask;
  88.     static const Node  kIndex_mask;
  89.  
  90.     static const Node   kInitial_state;
  91.     static const Node   kEnd_state;
  92.  
  93.     const TextBoundaryData::Node* fData;
  94.     int32_t fData_length;
  95.     int32_t fCols;
  96. };
  97.  
  98. // -------------------------------------
  99.  
  100. inline WordBreakTable::Node
  101. WordBreakTable::get(WordBreakTable::Node oldState, WordBreakTable::Type input) const
  102. {
  103.     return fData[(oldState & kIndex_mask) * fCols + input];
  104. }
  105.  
  106. inline bool_t
  107. WordBreakTable::isMarkState(WordBreakTable::Node state) const
  108. {
  109.     return (state & kMark_mask) != 0;
  110. }
  111.  
  112. inline bool_t
  113. WordBreakTable::isEndState(WordBreakTable::Node state) const
  114. {
  115.     return (state & kIndex_mask) == kEnd_state;
  116. }
  117.  
  118. inline WordBreakTable::Node
  119. WordBreakTable::initialState() const
  120. {
  121.     return kInitial_state;
  122. }
  123.  
  124. #endif // _WDBKTBL
  125. //eof
  126.