Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Prog2
/
szorgalmi_feladatok
/
CPPfsm
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
Commit
3ccbabda
authored
Apr 15, 2021
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v0
parents
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
199 additions
and
0 deletions
+199
-0
CPPfsm.cbp
+46
-0
fsm.hpp
+38
-0
ly.cpp
+58
-0
ly.h
+57
-0
No files found.
CPPfsm.cbp
0 → 100644
View file @
3ccbabda
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion
major=
"1"
minor=
"6"
/>
<Project>
<Option
title=
"CPPfsm"
/>
<Option
pch_mode=
"2"
/>
<Option
compiler=
"gcc"
/>
<Build>
<Target
title=
"Debug"
>
<Option
output=
"bin/Debug/CPPfsm"
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/CPPfsm"
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-errors"
/>
<Add
option=
"-pedantic"
/>
<Add
option=
"-Wall"
/>
</Compiler>
<Unit
filename=
"fsm.hpp"
/>
<Unit
filename=
"ly.cpp"
/>
<Unit
filename=
"ly.h"
/>
<Extensions>
<code_completion
/>
<envvars
/>
<debugger
/>
<lib_finder
disable_auto=
"1"
/>
</Extensions>
</Project>
</CodeBlocks_project_file>
fsm.hpp
0 → 100644
View file @
3ccbabda
/**
* \file fsm.hpp
*
* Generikus inputot kap finite state machine (FSM)
* fsm tervezsi minta felhasznlsval
*
*/
/// Eldeklarci
template
<
typename
T
>
class
Entity
;
/// llapotok absztrakt alposztlya
template
<
typename
T
>
class
EntityState
{
public
:
virtual
void
Input
(
Entity
<
T
>*
,
T
)
=
0
;
virtual
void
Enter
(
Entity
<
T
>*
)
=
0
;
virtual
void
Leave
(
Entity
<
T
>*
)
=
0
;
virtual
~
EntityState
()
{}
};
/// Entits alaposztlya
template
<
typename
T
>
class
Entity
{
EntityState
<
T
>*
currentState
;
public
:
Entity
(
EntityState
<
T
>*
st
)
:
currentState
(
st
)
{}
void
setState
(
EntityState
<
T
>*
st
)
{
currentState
->
Leave
(
this
);
currentState
=
st
;
currentState
->
Enter
(
this
);
}
void
Input
(
T
data
)
{
currentState
->
Input
(
this
,
data
);
}
virtual
~
Entity
()
{}
};
ly.cpp
0 → 100644
View file @
3ccbabda
/**
* \file ly.cpp
*
* Ly szmll s llapotainak megvalstsa
* fsm + singleton tervezsi minta felhasznlsval
*
*/
#include <iostream>
#include "ly.h"
/// Ly szmll osztly
class
Ly
:
public
Entity
<
char
>
{
int
sz
;
public
:
Ly
()
:
Entity
<
char
>
(
Alap
::
getInstance
()),
sz
(
0
)
{}
int
get
()
const
{
return
sz
;
}
void
add
(
int
i
)
{
sz
+=
i
;
}
};
/// Alap llapot inputja
void
Alap
::
Input
(
Entity
<
char
>*
ly
,
char
ch
)
{
if
(
ch
==
'l'
||
ch
==
'L'
)
{
ly
->
setState
(
Ljott
::
getInstance
());
}
}
/// Ljott llapot inputja
void
Ljott
::
Input
(
Entity
<
char
>*
ly
,
char
ch
)
{
if
(
ch
==
'l'
||
ch
==
'L'
)
{
ly
->
setState
(
LLjott
::
getInstance
());
}
else
{
if
(
ch
==
'y'
||
ch
==
'Y'
)
dynamic_cast
<
Ly
*>
(
ly
)
->
add
(
1
);
ly
->
setState
(
Alap
::
getInstance
());
}
}
/// LLjott llapot inputja
void
LLjott
::
Input
(
Entity
<
char
>*
ly
,
char
ch
)
{
if
(
ch
==
'y'
||
ch
==
'Y'
)
dynamic_cast
<
Ly
*>
(
ly
)
->
add
(
2
);
if
(
ch
!=
'l'
&&
ch
!=
'L'
)
ly
->
setState
(
Alap
::
getInstance
());
}
int
main
()
{
Ly
ly
;
char
ch
;
std
::
cout
<<
"Johet a duma:
\n
"
;
while
(
std
::
cin
>>
std
::
noskipws
>>
ch
)
ly
.
Input
(
ch
);
std
::
cout
<<
"ly-ok szama:"
<<
ly
.
get
()
<<
std
::
endl
;
return
0
;
}
ly.h
0 → 100644
View file @
3ccbabda
/**
* \file ly.cpp
*
* Ly számláló állapota és entitása.
* fsm + singleton tervezési minta felhasználásával
*
*/
#include "fsm.hpp"
/// LyState
/// Ly számláló állapotosztályának alapja
class
LyState
:
public
EntityState
<
char
>
{
public
:
void
Input
(
Entity
<
char
>*
,
char
)
{}
void
Enter
(
Entity
<
char
>*
)
{}
void
Leave
(
Entity
<
char
>*
)
{}
};
/// Alap állapot
class
Alap
:
public
LyState
{
Alap
()
{}
Alap
(
const
Alap
&
);
Alap
&
operator
=
(
const
Alap
&
);
public
:
static
Alap
*
getInstance
()
{
static
Alap
singleton
;
return
&
singleton
;
}
void
Input
(
Entity
<
char
>*
ly
,
char
ch
);
};
/// Ljott állapot
class
Ljott
:
public
LyState
{
Ljott
()
{}
Ljott
(
const
Ljott
&
);
Ljott
&
operator
=
(
const
Ljott
&
);
public
:
static
Ljott
*
getInstance
()
{
static
Ljott
singleton
;
return
&
singleton
;
}
void
Input
(
Entity
<
char
>*
ly
,
char
ch
);
};
/// LLjott állapot
class
LLjott
:
public
LyState
{
LLjott
()
{}
LLjott
(
const
LLjott
&
);
LLjott
&
operator
=
(
const
LLjott
&
);
public
:
static
LLjott
*
getInstance
()
{
static
LLjott
singleton
;
return
&
singleton
;
}
void
Input
(
Entity
<
char
>*
ly
,
char
ch
);
};
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