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