SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
event.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file event.cc Discrete events base class
3
//
4
// Copyright (c) 1991-2004 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
// implementation of class Event
10
11
////////////////////////////////////////////////////////////////////////////
12
// interface
13
//
14
15
#include "
simlib.h
"
16
#include "
internal.h
"
17
18
////////////////////////////////////////////////////////////////////////////
19
// implementation
20
//
21
22
namespace
simlib3
{
23
24
SIMLIB_IMPLEMENTATION
;
25
26
////////////////////////////////////////////////////////////////////////////
27
/// constructor, default priority if not specified
28
Event::Event
(
Priority_t
p) :
Entity
(p)
29
{
30
Dprintf
((
"Event::Event(%u)"
, p));
31
}
32
33
////////////////////////////////////////////////////////////////////////////
34
/// destructor
35
Event::~Event
()
36
{
37
Dprintf
((
"Event::~Event()"
));
38
}
39
40
////////////////////////////////////////////////////////////////////////////
41
/// activation method, called from simulation control algorithm
42
void
Event::_Run
() noexcept
43
{
44
Behavior
();
45
if
(
Idle
())
// not scheduled
46
Terminate
();
47
}
48
49
////////////////////////////////////////////////////////////////////////////
50
/// passivate event, it will be destroyed if not activated later in Behavior()
51
/// <br> Should not be used. It is there only for backwards compatibility.
52
void
Event::Terminate
()
53
{
54
Dprintf
((
"%s.Terminate()"
,
Name
().c_str()));
55
if
(!
Idle
())
// if scheduled
56
SQS::Get
(
this
);
// remove from calendar
57
if
(
isAllocated
() &&
this
!=
SIMLIB_Current
)
58
delete
this
;
// destroy entity (if not currently running Behavior)
59
}
60
61
// Event activation (scheduling) at time t
62
void
Event::Activate
(
double
t
)
63
{
64
Dprintf
((
"Event#%lu.Activate(%g)"
,
_Ident
,
t
));
65
Entity::Activate
(
t
);
66
}
67
68
#if 1
69
////////////////////////////////////////////////////////////////////////////
70
/// get name of event. It is generic "Event#" if not explicitly named
71
std::string
Event::Name
()
const
72
{
73
const
std::string name =
SimObject::Name
();
74
if
(!name.empty())
return
name;
// has explicit name
75
else
return
SIMLIB_create_tmp_name
(
"Event#%lu"
,
_Ident
);
76
}
77
#endif
78
79
}
// namespace
80
t
Test t(F)
simlib3::Entity::Priority_t
EntityPriority_t Priority_t
Definition
simlib.h:402
simlib3::Entity::Entity
Entity(Priority_t p=DEFAULT_PRIORITY)
constructor
Definition
entity.cc:33
simlib3::Entity::Idle
bool Idle()
entity activation is not scheduled in calendar
Definition
simlib.h:417
simlib3::Entity::Activate
void Activate()
activate now
Definition
simlib.h:413
simlib3::Entity::_Ident
unsigned long _Ident
unique identification number of entity
Definition
simlib.h:383
simlib3::Event::Behavior
virtual void Behavior()=0
behavior description
simlib3::Event::Activate
void Activate()
activate now
Definition
simlib.h:413
simlib3::Event::~Event
virtual ~Event()
destructor
Definition
event.cc:35
simlib3::Event::Terminate
virtual void Terminate() override
passivate event, it will be destroyed if not activated later in Behavior() Should not be used.
Definition
event.cc:52
simlib3::Event::Name
virtual std::string Name() const override
name of object
Definition
event.cc:71
simlib3::Event::_Run
virtual void _Run() noexcept override
activation method, called from simulation control algorithm
Definition
event.cc:42
simlib3::Event::Event
Event(Priority_t p=DEFAULT_PRIORITY)
constructor, default priority if not specified
Definition
event.cc:28
simlib3::SimObject::isAllocated
bool isAllocated() const
Definition
simlib.h:323
simlib3::SimObject::Name
virtual std::string Name() const
get object name
Definition
object.cc:134
internal.h
Internal header file for SIMLIB/C++.
Dprintf
#define Dprintf(f)
Definition
internal.h:100
simlib3::SQS::Get
void Get(Entity *e)
remove selected entity activation record from calendar
Definition
calendar.cc:1308
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::SIMLIB_IMPLEMENTATION
SIMLIB_IMPLEMENTATION
Definition
algloop.cc:34
simlib3::SIMLIB_Current
Entity * SIMLIB_Current
Definition
run.cc:53
simlib3::SIMLIB_create_tmp_name
std::string SIMLIB_create_tmp_name(const char *fmt,...)
printf-like function to create temporary name (the length of temporary names is limited) used only ...
Definition
name.cc:80
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0