/
scan_diff.h
86 lines (78 loc) · 1.95 KB
/
scan_diff.h
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
85
86
// Copyright (c) 1994 Darren Erik Vengroff
//
// File: scan_diff.h
// Author: Darren Erik Vengroff <darrenv@eecs.umich.edu>
// Created: 10/7/94
//
// $Id: scan_diff.h,v 1.5 2005-11-17 17:07:41 jan Exp $
//
// A scanner to diff two streams of the same type of object, to verify that
// they are the same.
//
#ifndef _SCAN_DIFF_H
#define _SCAN_DIFF_H
template<class T> struct scan_diff_out {
unsigned int index;
T t0, t1;
};
template<class T> class scan_diff : AMI_scan_object {
private:
unsigned int input_index;
T null_t;
public:
scan_diff(const T &nt);
virtual ~scan_diff(void);
AMI_err initialize();
AMI_err operate(const T &in1, const T &in2, AMI_SCAN_FLAG *sfin,
scan_diff_out<T> *out,
AMI_SCAN_FLAG *sfout);
};
template<class T>
scan_diff<T>::scan_diff(const T &nt) : input_index(0), null_t(nt) {
}
template<class T>
scan_diff<T>::~scan_diff()
{
}
template<class T>
AMI_err scan_diff<T>::initialize(void)
{
input_index = 0;
return AMI_ERROR_NO_ERROR;
}
template<class T>
AMI_err scan_diff<T>::operate(const T &in1, const T &in2,
AMI_SCAN_FLAG *sfin,
scan_diff_out<T> *out,
AMI_SCAN_FLAG *sfout)
{
AMI_err ret;
if (sfin[0] && sfin[1]) {
if (in1 == in2) {
*sfout = false;
} else {
*sfout = true;
out->index = input_index;
out->t0 = in1;
out->t1 = in2;
}
ret = AMI_SCAN_CONTINUE;
} else if (!sfin[0] && !sfin[1]) {
*sfout = false;
ret = AMI_SCAN_DONE;
} else {
ret = AMI_SCAN_CONTINUE;
*sfout = true;
out->index = input_index;
if (!sfin[0]) {
out->t0 = null_t;
out->t1 = in2;
} else {
out->t1 = null_t;
out->t0 = in1;
}
}
input_index++;
return ret;
}
#endif // _SCAN_DIFF_H