Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Prog2
/
eloadas_peldak
/
ea_09
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
90b5b05d
authored
Apr 18, 2021
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CB+Boost
parent
80e44aab
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
13 deletions
+79
-13
nyomogomb/callback.h
+1
-1
nyomogomb/felhfelulet.h
+3
-2
nyomogomb/gomb_demo.cpp
+1
-1
nyomogomb_boost/felhfelulet.h
+5
-4
nyomogomb_boost/gomb_demo.cpp
+22
-5
nyomogomb_boost/nyomogomb.cbp
+47
-0
No files found.
nyomogomb/callback.h
View file @
90b5b05d
...
...
@@ -2,7 +2,7 @@
#define CALLBACK_H
/// Callback objektum.
/// Nem ismeri modellt
se,
és a felhasználói felületet se.
/// Nem ismeri modellt és a felhasználói felületet se.
class
GombCallback
{
// callback funkcióhoz
public:
virtual
void
callBack
()
=
0
;
// virtuális cb. függvény
...
...
nyomogomb/felhfelulet.h
View file @
90b5b05d
...
...
@@ -10,10 +10,11 @@
#include "callback.h"
/// Gomb.
/// A gomb "megnyomására" meghívódik a n
n
yom() tagfüggvény
/// A gomb "megnyomására" meghívódik a nyom() tagfüggvény
class
Gomb
{
GombCallback
&
cb
;
// callback objektum referencia
GombCallback
&
cb
;
//
/
callback objektum referencia
public:
/// konstruktor egy GombcallBack típusú objektumot kap, amiben a meghívandó cb. függvény van.
Gomb
(
GombCallback
&
t
)
:
cb
(
t
)
{}
// referencia inic.
/// A felhasználó felületen megnyomták a gombot
...
...
nyomogomb/gomb_demo.cpp
View file @
90b5b05d
...
...
@@ -13,7 +13,7 @@ using std::cin;
int
main
()
{
Kapcsolo
k1
;
Gomb
g1
(
k1
);
// itt kötjük össze a felhasználói felületet és a modellt.
Gomb
g1
(
k1
);
//
/
itt kötjük össze a felhasználói felületet és a modellt.
cout
<<
"Megyomjuk a gombot: "
<<
endl
;
cin
.
ignore
(
100
,
'\n'
);
...
...
nyomogomb_boost/felhfelulet.h
View file @
90b5b05d
...
...
@@ -11,18 +11,19 @@
#include <boost/signals2.hpp>
/// Gomb.
/// A gomb "megnyomására" meghívódik a n
n
yom() tagfüggvény
/// A gomb "megnyomására" meghívódik a nyom() tagfüggvény
class
Gomb
{
boost
::
signals2
::
signal
<
void
()
>
sig
;
public
:
/// A konstruktor egy funtort kap, ez lesz a slot.
template
<
typename
F
>
Gomb
(
F
f
)
{
sig
.
connect
(
f
);
sig
.
connect
(
f
);
/// itt kötjük össze
}
/// A felhasználó felületen megnyomták a gombot
void
nyom
()
{
// megnyomták
sig
();
void
nyom
()
{
//
/
megnyomták
sig
();
/// küldjük a signált
}
};
#endif // FELULET_H
nyomogomb_boost/gomb_demo.cpp
View file @
90b5b05d
/**
* Felhasználói felület és a modell kapcsolata
* Callback fv. demó
* Boost lib demo
*
* CodeBloks-ban arra a könytárra kell állítani a boost globális változót,
* ahova a boost (boost/include és boost/lib) telepítve van.
* (Settings->Global variables...)
*
*/
#include <iostream>
#include "modell.h"
#include "felhfelulet.h"
#include <boost/signals2.hpp>
#include <boost/bind.hpp>
#include <boost/bind/bind.hpp>
#include <boost/optional/optional_io.hpp>
using
std
::
cout
;
using
std
::
endl
;
using
std
::
cin
;
/// Játék függvény a paramétarátaás bemutatásához
int
osszead
(
int
a
,
int
b
)
{
return
a
+
b
;
}
int
main
()
{
Kapcsolo
k1
(
"k1"
);
Gomb
g1
(
boost
::
bind
(
&
Kapcsolo
::
callBack
,
&
k1
));
// itt kötjük össze a felhasználói felületet és a modellt.
Gomb
g1
(
boost
::
bind
(
&
Kapcsolo
::
callBack
,
&
k1
));
/// Itt kötjük össze a felhasználói felületet és a modellt.
/// A bind készít funktort a tagfüggvényből és az objektum címéből.
cout
<<
"Megyomjuk a gombot: "
<<
endl
;
cin
.
ignore
(
100
,
'\n'
);
...
...
@@ -31,8 +40,8 @@ int main() {
g1
.
nyom
();
// újra
/// Eddig nem sokban különbözött
, csupán nem kellett e callback osztály.
///
De sokkal rugalmasabb. Csupán egy példa:
/// Eddig nem sokban különbözött
a töbszörös örökléses megoldástól, csupán nem kellett e callback osztály.
///
A signal-slot azonban sokkal rugalmasabb. Itt csupán egy példa:
std
::
cout
<<
"
\n
Mindent elpszor be-, majd kikapcsol.
\n
"
;
Kapcsolo
k2
(
"k2"
);
...
...
@@ -43,5 +52,13 @@ int main() {
beki
.
connect
(
0
,
boost
::
bind
(
&
Kapcsolo
::
be
,
&
k2
));
beki
();
/// Máik példa, ami azt mutatja, hogy könnyú paramétert is átadni:
std
::
cout
<<
"
\n
Hogy megy a parameteratadas?
\n
"
;
boost
::
signals2
::
signal
<
int
(
int
,
int
)
>
ad
;
ad
.
connect
(
osszead
);
std
::
cout
<<
"1+2="
<<
ad
(
1
,
2
)
<<
std
::
endl
;
std
::
cout
<<
"10+100="
<<
ad
(
10
,
100
)
<<
std
::
endl
;
return
0
;
}
nyomogomb_boost/nyomogomb.cbp
0 → 100644
View file @
90b5b05d
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion
major=
"1"
minor=
"6"
/>
<Project>
<Option
title=
"nyomogomb"
/>
<Option
pch_mode=
"2"
/>
<Option
compiler=
"gcc"
/>
<Build>
<Target
title=
"Debug"
>
<Option
output=
"bin/Debug/nyomogomb"
prefix_auto=
"1"
extension_auto=
"1"
/>
<Option
object_output=
"obj/Debug/"
/>
<Option
type=
"1"
/>
<Option
compiler=
"gcc"
/>
<Compiler>
<Add
option=
"-g"
/>
</Compiler>
</Target>
<Target
title=
"Release"
>
<Option
output=
"bin/Release/nyomogomb"
prefix_auto=
"1"
extension_auto=
"1"
/>
<Option
object_output=
"obj/Release/"
/>
<Option
type=
"1"
/>
<Option
compiler=
"gcc"
/>
<Compiler>
<Add
option=
"-O2"
/>
</Compiler>
<Linker>
<Add
option=
"-s"
/>
</Linker>
</Target>
</Build>
<Compiler>
<Add
option=
"-pedantic"
/>
<Add
option=
"-Wfatal-errors"
/>
<Add
option=
"-Wall"
/>
<Add
option=
"-std=c++14"
/>
<Add
directory=
"$(#boost.include)"
/>
</Compiler>
<Linker>
<Add
directory=
"$(#boost.lib)"
/>
</Linker>
<Unit
filename=
"felhfelulet.h"
/>
<Unit
filename=
"gomb_demo.cpp"
/>
<Unit
filename=
"modell.cpp"
/>
<Unit
filename=
"modell.h"
/>
<Extensions
/>
</Project>
</CodeBlocks_project_file>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment