xref: /AOO41X/main/autodoc/source/parser/inc/tokens/tkpstama.hxx (revision 1c78a5d6c0093dece4c096ba53051800fbad6e33)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef ADC_TKPSTAMA_HXX
25 #define ADC_TKPSTAMA_HXX
26 
27 // USED SERVICES
28     // BASE CLASSES
29 #include <tokens/tkpcontx.hxx>
30     // COMPONENTS
31 #include <tokens/stmstarr.hxx>
32 #include <tokens/stmstfin.hxx>
33 
34 /** @descr
35     This state-machine models state transitions from one state to another
36     per indices of branches. If the indices represent ascii-char-values,
37     the state-machine can be used for recognising tokens of text.
38 
39     The state-machine can be a status itself.
40 
41     StateMachine needs the array-size of all stati as a guess, how many stati
42     the state machine will contain, when at work.
43 
44 
45 **/
46 class StateMachine
47 {
48     public:
49         // Types
50         typedef StmStatus::Branch   Branch;
51         typedef StmStatus * *       StatusList;
52 
53     //# Interface self
54         // LIFECYCLE
55                         StateMachine(
56                             intt            in_nStatusSize,
57                             intt            in_nInitial_StatusListSize );   /// The user of the constructor should guess
58                                                                             ///   the approximate number of stati here to
59                                                                             ///   avoid multiple reallocations.
60         /// @#AddStatus
61         intt            AddStatus(      /// @return the new #Status' ID
62                             DYN StmStatus * let_dpStatus);
63         /// @#AddToken
64         void            AddToken(
65                             const char *        in_sToken,
66                             TextToken::F_CRTOK  in_fTokenCreateFunction,
67                             const INT16 *       in_aBranches,
68                             INT16               in_nBoundsStatus );
69                         ~StateMachine();
70 
71 
72         // OPERATIONS
73         StmBoundsStatus &
74                         GetCharChain(
75                             TextToken::F_CRTOK &
76                                                 o_nTokenCreateFunction,
77                             CharacterSource &   io_rText );
78     private:
79         // SERVICE FUNCTIONS
80         StmStatus &     Status(
81                             intt            in_nStatusNr) const;
82         StmArrayStatus &
83                         CurrentStatus() const;
84         StmBoundsStatus *
85                         BoundsStatus() const;
86 
87         /// Sets the PeekedStatus.
88         void            Peek(
89                             intt            in_nBranch);
90 
91         void            ResizeStati();      // Adds space for 32 stati.
92 
93         // DATA
94         StatusList      pStati;             /// List of Status, implemented as simple C-array of length #nStatiSpace
95                                             /// with nStatiLength valid members (beginning from zero).
96         intt            nCurrentStatus;
97         intt            nPeekedStatus;
98 
99         intt            nStatusSize;        /// Size of the branch array of a single status.
100 
101         intt            nNrofStati;         /// Nr of Stati so far.
102         intt            nStatiSpace;        /// Size of allocated array for #pStati (size in items).
103 };
104 
105 
106 
107 /** @#AddToken
108     @descr
109     Adds a token, which will be recogniszeds by the
110     statemachine.
111 
112 
113 **/
114 
115 
116 
117 #endif
118 
119 
120