-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatomic.cpp
More file actions
163 lines (137 loc) · 5.28 KB
/
atomic.cpp
File metadata and controls
163 lines (137 loc) · 5.28 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************
*
* DESCRIPTION: class Atomic
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* Version 2: Daniel A. Rodriguez
* Version 3: Alejandro Troccoli
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://drodrigu@dc.uba.ar
* mailto://atroccol@dc.uba.ar
*
* DATE: 27/6/1998
* DATE: 25/4/1999
* DATE: 07/11/2000
*
*******************************************************************/
/** include files **/
#include "atomic.h" // base header
#include "message.h"
#include "except.h"
using namespace std;
/*******************************************************************
* Function Name: Destructor
********************************************************************/
Atomic::~Atomic() // Destructor
{}
/*******************************************************************
* Function Name: Constructor
********************************************************************/
Atomic::Atomic( const string &name ) // Constructor
: Model( name )
{}
/*******************************************************************
* Function Name: holdIn
* Description: Changes the atomic state and the time left to the next change
********************************************************************/
Model &Atomic::holdIn( const AtomicState::State &s, const VTime &t )
{
state( s );
nextChange( t );
return *this;
}
/*******************************************************************
* Function Name: passivate
* Description: Sets thes passive state and the next change to infinity
********************************************************************/
Model &Atomic::passivate()
{
state( AtomicState::passive );
nextChange( VTime::Inf );
return *this;
}
/*******************************************************************
* Function Name: allocateState
* Description: Creates a new instance of the state object
********************************************************************/
ModelState*
Atomic::allocateState() {
return new AtomicState;
}
/*******************************************************************
* Function Name: externalFunction
* This function is provided for backward compatibility between DEVS
* and parallel DEVS code. Please, do not make abstract since it will
* require models to define this function which is obsolete for
* Parallel DEVS
********************************************************************/
Model &Atomic::externalFunction( const ExternalMessage & )
{
MException e ;
e.addText( "Can not call Atomic::externalFunction( const ExternalMessage&)!" ) ;
MTHROW( e ) ;
}
/*******************************************************************
* Function Name: externalFunction
* Description: The default definition allows to maintain backward compatibility
* it can only be used for external messages containing a real value!
********************************************************************/
Model &Atomic::externalFunction ( const MessageBag & msgs )
{
MessageBag::iterator cursor;
for( cursor = msgs.begin(); !(cursor == msgs.end()); cursor++ )
{
externalFunction( *(( ExternalMessage* )( *cursor )) );
}
return *this;
}
/*******************************************************************
* Function Name: confluentFunction
* Description: Returns the number of local processors for the model
********************************************************************/
Model &Atomic::confluentFunction ( const InternalMessage &intMsg, const MessageBag &extMsgs )
{
//Default behavior for confluent function:
//Proceed with the internal transition and the with the external
internalFunction( intMsg );
//Set the elapsed time to 0
lastChange( intMsg.time() );
//Call the external function
externalFunction( extMsgs );
return *this;
}
/*******************************************************************
* Function Name: localProcCount
* Description: Returns the number of local processors for the model
********************************************************************/
unsigned long Atomic::localProcCount() const {
if ( localProc() != ParallelProcessor::InvalidId )
return 1;
else
return 0;
}
/*******************************************************************
* Function Name: totalProcCount
* Description: Returns the number of total processors for the model
********************************************************************/
unsigned long Atomic::totalProcCount() const
{
return 1;
}
/*******************************************************************
* Function Name: getCurrentState
********************************************************************/
ModelState* Atomic::getCurrentState() const
{ return ((ParallelSimulatorState* )processor().state->current)->modelState;}
/*******************************************************************
* Function Name: getCurrentState
********************************************************************/
ModelState* Atomic::getCurrentState()
{ return ((ParallelSimulatorState* )processor().state->current)->modelState;}
/*******************************************************************
* Function Name: createParallelProcessor
********************************************************************/
ParallelProcessor &Atomic::createParallelProcessor()
{ return SingleParallelProcessorAdmin::Instance().generateProcessor(this, localProc());}