2 * Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 #include <lttoolbox/TransExe.H>
21 #include <lttoolbox/Compression.H>
22 #include <lttoolbox/MyStdio.H>
33 TransExe::TransExe(TransExe const &te)
39 TransExe::operator =(TransExe const &te)
50 TransExe::copy(TransExe const &te)
52 initial_id = te.initial_id;
53 node_list = te.node_list;
63 TransExe::read(FILE *input, int encoding_base)
65 TransExe &new_t = *this;
67 new_t.initial_id = Compression::multibyte_read(input);
68 int finals_size = Compression::multibyte_read(input);
74 while(finals_size > 0)
78 base += Compression::multibyte_read(input);
79 myfinals.insert(base);
82 base = Compression::multibyte_read(input);
84 int number_of_states = base;
85 int current_state = 0;
86 new_t.node_list.resize(number_of_states);
88 for(set<int>::iterator it = myfinals.begin(), limit = myfinals.end();
91 new_t.finals.insert(&new_t.node_list[*it]);
94 while(number_of_states > 0)
96 int number_of_local_transitions = Compression::multibyte_read(input);
99 Node &mynode = new_t.node_list[current_state];
101 while(number_of_local_transitions > 0)
103 number_of_local_transitions--;
104 tagbase += Compression::multibyte_read(input);
105 int state = (current_state + Compression::multibyte_read(input)) % base;
107 unsigned short i_symbol = static_cast<unsigned short>(tagbase / encoding_base);
108 unsigned short o_symbol = static_cast<unsigned short>(tagbase % encoding_base);
110 mynode.addTransition(i_symbol, o_symbol, &new_t.node_list[state]);
118 TransExe::unifyFinals()
120 node_list.resize(node_list.size()+1);
122 Node *newfinal = &node_list[node_list.size()-1];
124 for(set<Node *>::iterator it = finals.begin(), limit = finals.end();
127 (*it)->addTransition(0, 0, newfinal);
131 finals.insert(newfinal);
135 TransExe::getInitial()
137 return &node_list[initial_id];
141 TransExe::getFinals()