-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuant.cpp
More file actions
74 lines (66 loc) · 2.02 KB
/
Quant.cpp
File metadata and controls
74 lines (66 loc) · 2.02 KB
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
/*******************************************************************
*
* DESCRIPTION: Simple quantizer
*
* AUTHOR: Gabriel Wainer
*
* EMAIL: mailto://gabrielw@dc.uba.ar
*
* DATE: 21/7/99
*
*******************************************************************/
/** include files **/
#include <math.h> // fabs( ... )
#include "Quant.h" // base header
#include "message.h" // InternalMessage ....
#include "parsimu.h" // class ParallelMainSimulator
#include "strutil.h" // str2float( ... )
#include "realfunc.h" // value with quantum
using namespace std;
/*******************************************************************
* Function Name: Quant
* Description: constructor
********************************************************************/
Quant::Quant( const string &name )
: Atomic( name )
, in( addInputPort( "in" ) )
, out( addOutputPort( "out" ) )
{
quantum = UseQuantum().Value();
}
/*******************************************************************
* Function Name: externalFunction
* Description: the Quant receives one job
********************************************************************/
Model &Quant::externalFunction( const ExternalMessage &msg )
{
if (quantum != 0) {
double ss;
modf(msg.value()/quantum, &ss);
// Dejo en ss la part entera de v/q
quant_value = ss * quantum;
}
else
quant_value = msg.value();
holdIn( AtomicState::active, VTime( static_cast<float>( 0 ) ) ) ;
return *this ;
}
/*******************************************************************
* Function Name: internalFunction
********************************************************************/
Model &Quant::internalFunction( const InternalMessage & )
{
passivate();
return *this;
}
/*******************************************************************
* Function Name: outputFunction
********************************************************************/
Model &Quant::outputFunction( const CollectMessage &msg )
{
sendOutput( msg.time(), out, quant_value );
return *this;
}
Quant::~Quant()
{
}