1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*
* Copyright (C) 2005 Universitat d'Alacant / Universidad de Alicante
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <lttoolbox/node.h>
Node::Node()
{
}
Node::~Node()
{
destroy();
}
Node::Node(Node const &n)
{
copy(n);
}
Node &
Node::operator =(Node const &n)
{
if(this != &n)
{
destroy();
copy(n);
}
return *this;
}
void
Node::copy(Node const &n)
{
transitions = n.transitions;
}
void
Node::destroy()
{
}
void
Node::addTransition(int const i, int const o, Node * const d, double const wt)
{
Dest &aux = transitions[i];
aux.size++;
int *out_tag = new int[aux.size];
Node **dest = new Node*[aux.size];
double *out_weight = new double[aux.size];
for(int i = 0; i<aux.size-1; i++)
{
out_tag[i] = aux.out_tag[i];
dest[i] = aux.dest[i];
out_weight[i] = aux.out_weight[i];
}
if(aux.size > 1)
{
delete[] aux.out_tag;
delete[] aux.dest;
delete[] aux.out_weight;
}
out_tag[aux.size-1] = o;
dest[aux.size-1] = d;
out_weight[aux.size-1] = wt;
aux.out_tag = out_tag;
aux.dest = dest;
aux.out_weight = out_weight;
}
|