SIMLIB/C++
3.09
Toggle main menu visibility
Loading...
Searching...
No Matches
src
entity.cc
Go to the documentation of this file.
1
/////////////////////////////////////////////////////////////////////////////
2
//! \file entity.cc Active entities base class
3
//
4
// Copyright (c) 1991-2016 Petr Peringer
5
//
6
// This library is licensed under GNU Library GPL. See the file COPYING.
7
//
8
9
// Entity is base class of the entity hierarchy (Process, 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
/// current number of entities in model
27
static
unsigned
long
SIMLIB_Entity_Count
= 0L;
// # of entities in model
28
/// serial number of created entity
29
unsigned
long
Entity::_Number
= 0L;
// # of entity creations
30
31
////////////////////////////////////////////////////////////////////////////
32
/// constructor
33
Entity::Entity
(
Priority_t
p) :
34
_Ident
(
SIMLIB_Entity_Count
++),
// unique identification
35
_MarkTime
(0.0),
36
_SPrio
(0),
37
Priority
(p),
38
_evn
(0)
// pointer to calendar item
39
{
40
_Number
++;
// # of entities
41
Dprintf
((
"Entity#%lu{%p}::Entity(%d)"
,
_Ident
,
this
, p));
42
}
43
44
////////////////////////////////////////////////////////////////////////////
45
/// destructor
46
Entity::~Entity
() {
47
Dprintf
((
"Entity#%lu{%p}::~Entity()"
,
_Ident
,
this
));
48
if
(!
Idle
()) {
49
SQS::Get
(
this
);
// remove from calendar
50
// _warning(DeletingActive); // TODO:can be important? if sim SIMLIB_error else _warn
51
}
52
Entity::_Number
--;
// # of entities in model
53
}
54
55
/// entity activation at given time
56
void
Entity::Activate
(
double
t
)
57
{
58
if
(!
Idle
()) {
// rescheduling
59
SQS::Get
(
this
);
// remove from calendar
60
}
61
SQS::ScheduleAt
(
this
,
t
);
62
}
63
64
65
////////////////////////////////////////////////////////////////////////////
66
// Passivate - deactivation of process (entity)
67
//
68
void
Entity::Passivate
()
69
{
70
if
(!
Idle
())
// if scheduled
71
SQS::Get
(
this
);
// remove from calendar
72
}
73
74
75
////////////////////////////////////////////////////////////////////////////
76
// Into --- inserting into queue (TODO: problem with continuation)
77
//
78
#if 0
79
void
Entity::Into
(
Queue
*q)
80
{
81
if
(!q)
SIMLIB_error
(
QueueRefError
);
82
if
(where()!=0)
Out
();
// if already in queue then remove ### +warning ???
83
q->
Insert
(
this
);
// insert
84
}
85
#endif
86
87
////////////////////////////////////////////////////////////////////////////
88
// Out - leaving queue
89
//
90
void
Entity::Out
()
91
{
92
Link::Out
();
// equal
93
}
94
95
////////////////////////////////////////////////////////////////////////////
96
/// passivate and destroy entity
97
void
Entity::Terminate
()
98
{
99
Dprintf
((
"%s.Terminate()"
,
Name
().c_str()));
100
if
(!
Idle
())
101
SQS::Get
(
this
);
// remove from calendar
102
103
if
(
isAllocated
() &&
this
!=
SIMLIB_Current
)
104
delete
this
;
// destroy entity (if not currently running Behavior)
105
}
106
107
#if 0
108
////////////////////////////////////////////////////////////////////////////
109
/// get name - either explicit or default "Entity#{ptr}"
110
const
char
*
Entity::Name
()
const
111
{
112
const
char
*name =
SimObject::Name
();
113
if
(*name)
return
name;
// return explicit name
114
else
return
SIMLIB_create_tmp_name
(
"Entity%lu{%p}"
,
_Ident
,
this
);
115
}
116
#endif
117
118
}
// namespace
119
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::_MarkTime
double _MarkTime
Definition
simlib.h:389
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::~Entity
virtual ~Entity()
destructor
Definition
entity.cc:46
simlib3::Entity::_evn
EventNotice * _evn
points to calendar item, iff scheduled
Definition
simlib.h:430
simlib3::Entity::Priority
Priority_t Priority
priority of the entity (scheduling,queues)
Definition
simlib.h:404
simlib3::Entity::_Number
static unsigned long _Number
current number of entities
Definition
simlib.h:382
simlib3::Entity::Terminate
virtual void Terminate()=0
end Behavior() and remove entity
Definition
entity.cc:97
simlib3::Entity::_SPrio
ServicePriority_t _SPrio
priority of service in Facility
Definition
simlib.h:398
simlib3::Entity::Out
virtual void Out() override
remove entity from queue
Definition
entity.cc:90
simlib3::Entity::Passivate
virtual void Passivate()
deactivation
Definition
entity.cc:68
simlib3::Entity::_Ident
unsigned long _Ident
unique identification number of entity
Definition
simlib.h:383
simlib3::Link::Out
virtual void Out()
remove from list
Definition
link.cc:63
simlib3::Link::Into
virtual void Into(List *l)
insert last
Definition
link.cc:53
simlib3::Queue
priority queue
Definition
simlib.h:690
simlib3::Queue::Insert
virtual void Insert(Entity *e)
Definition
queue.cc:50
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::SQS::ScheduleAt
void ScheduleAt(Entity *e, double t)
schedule entity e at given time t using scheduling priority from e
Definition
calendar.cc:1287
simlib3
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition
algloop.cc:32
simlib3::SIMLIB_error
void SIMLIB_error(const enum _ErrEnum N)
print error message and abort program
Definition
error.cc:38
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
simlib3::SIMLIB_Entity_Count
static unsigned long SIMLIB_Entity_Count
current number of entities in model
Definition
entity.cc:27
simlib3::QueueRefError
@ QueueRefError
Definition
errors.cc:37
simlib.h
Main SIMLIB/C++ interface.
Generated on
for SIMLIB/C++ by
1.18.0