Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1494078
basic-system.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Size
2 KB
Referenced Files
None
Subscribers
None
basic-system.cpp
View Options
/*******************************************************************************
*
* File: basic-system.cpp
*
* Contents: A simple example on the basic System and Unit classes of the RoSA
* Core library.
*
* Copyright 2017
*
* Author: David Juhasz (david.juhasz@tuwien.ac.at)
*
******************************************************************************/
#include
"rosa/config/version.h"
#include
"rosa/core/Unit.h"
#include
"rosa/core/System.hpp"
#include
"rosa/support/log.h"
#include
"rosa/support/terminal_colors.h"
#include
<iostream>
using
namespace
rosa
;
using
namespace
rosa
::
terminal
;
// A dummy wrapper for testing System.
// NOTE: Since we test System directly here, we need to get access to its
// protected members. That we do by imitating to be a decent subclass of
// System, while calling protected member functions on an object of a type from
// which we actually don't inherit.
struct
SystemTester
:
protected
System
{
static
constexpr
AtomValue
UnitKind
=
atom
(
"unit"
);
static
Unit
&
createMyUnit
(
System
*
S
,
const
std
::
string
&
Name
=
std
::
string
())
{
return
((
SystemTester
*
)
S
)
->
createUnit
<
Unit
>
([
&
Name
](
const
size_t
Id
,
System
&
S
)
noexcept
{
// NOTE: If Name is empty, construct a name with the number of the
// Unit being created right now.
const
std
::
string
N
(
Name
.
empty
()
?
"Unit_"
+
std
::
to_string
(
S
.
numberOfConstructedUnits
())
:
Name
);
return
new
Unit
(
UnitKind
,
Id
,
N
,
S
);
});
}
static
void
destroyMyUnit
(
System
*
S
,
Unit
&
U
)
{
((
SystemTester
*
)
S
)
->
destroyUnit
(
U
);
}
};
int
main
(
void
)
{
LOG_INFO_STREAM
<<
library_string
()
<<
" -- "
<<
Color
::
Red
<<
"basic-system example"
<<
Color
::
Default
<<
std
::
endl
;
std
::
unique_ptr
<
System
>
S
=
System
::
createSystem
(
"Sys"
);
System
*
SP
=
S
.
get
();
Unit
&
Unit1
=
SystemTester
::
createMyUnit
(
SP
),
&
Unit2
=
SystemTester
::
createMyUnit
(
SP
,
"Second"
),
&
Unit3
=
SystemTester
::
createMyUnit
(
SP
);
SystemTester
::
destroyMyUnit
(
SP
,
Unit1
);
SystemTester
::
destroyMyUnit
(
SP
,
Unit3
);
LOG_INFO_STREAM
<<
"Dumping Unit2"
<<
std
::
endl
<<
Unit2
<<
std
::
endl
;
SystemTester
::
destroyMyUnit
(
SP
,
Unit2
);
return
0
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sun, Mar 1, 6:31 PM (1 d, 9 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
281814
Default Alt Text
basic-system.cpp (2 KB)
Attached To
Mode
R20 SoC_Rosa_repo
Attached
Detach File
Event Timeline
Log In to Comment