Blame view

morfeusz/fsa/state_impl.hpp 1.82 KB
Michał Lenart authored
1
2
3
4
5
6
7
8
9
10
11
/* 
 * File:   _state_impl.hpp
 * Author: mlenart
 *
 * Created on 21 październik 2013, 15:20
 */

#ifndef _STATE_IMPL_HPP
#define	_STATE_IMPL_HPP

#include <typeinfo>
Michał Lenart authored
12
#include <cstdio>
Michał Lenart authored
13
14
#include "fsa.hpp"
Michał Lenart authored
15
16
namespace morfeusz {
Michał Lenart authored
17
template <class T>
Michał Lenart authored
18
19
20
21
22
23
24
25
26
State<T>::State()
: offset(0), accepting(false), sink(false), value(), valueSize(0) {
}

template <class T>
State<T> State<T>::getSink() {
    State<T> res;
    res.setNextAsSink();
    return res;
Michał Lenart authored
27
28
29
}

template <class T>
Michał Lenart authored
30
inline bool State<T>::isSink() const {
Michał Lenart authored
31
32
33
34
    return this->sink;
}

template <class T>
Michał Lenart authored
35
inline bool State<T>::isAccepting() const {
Michał Lenart authored
36
37
38
39
    return this->accepting;
}

template <class T>
Michał Lenart authored
40
inline void State<T>::proceedToNext(const FSA<T>& fsa, const char c) {
Michał Lenart authored
41
    if (this->sink) {
Michał Lenart authored
42
43
44
        return;
    }
    else {
Michał Lenart authored
45
        fsa.proceedToNext(c, *this);
Michał Lenart authored
46
47
48
49
    }
}

template <class T>
Michał Lenart authored
50
unsigned long State<T>::getOffset() const {
Michał Lenart authored
51
52
53
54
55
    assert(!this->isSink());
    return this->offset;
}

template <class T>
Michał Lenart authored
56
inline const T& State<T>::getValue() const {
Michał Lenart authored
57
58
59
60
61
    assert(this->isAccepting());
    return this->value;
}

template <class T>
Michał Lenart authored
62
inline unsigned long State<T>::getValueSize() const {
Michał Lenart authored
63
64
65
66
67
68
69
70
71
72
    assert(this->isAccepting());
    return this->valueSize;
}

template <class T>
State<T>::~State() {

}

template <class T>
Michał Lenart authored
73
void State<T>::setNext(const unsigned long offset) {
Michał Lenart authored
74
75
    assert(!this->isSink());
//    this->sink = false;
Michał Lenart authored
76
77
78
79
80
    this->offset = offset;
    this->accepting = false;
}

template <class T>
Michał Lenart authored
81
void State<T>::setNext(const unsigned long offset, const T& value, const unsigned long valueSize) {
Michał Lenart authored
82
83
    assert(!this->isSink());
//    this->sink = false;
Michał Lenart authored
84
85
86
87
88
89
90
91
92
93
94
95
    this->offset = offset;
    this->accepting = true;
    this->value = value;
    this->valueSize = valueSize;
}

template <class T>
void State<T>::setNextAsSink() {
    this->sink = true;
    this->accepting = false;
}
Michał Lenart authored
96
97
}
Michał Lenart authored
98
99
#endif	/* _STATE_IMPL_HPP */