Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ca6f67

Browse files
committed
recreated repo
1 parent29f53fe commit9ca6f67

File tree

52 files changed

+2572
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2572
-0
lines changed

‎.github/workflows/linux.yml‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name:Linux Build
2+
3+
on:
4+
push:
5+
branches:[ main ]
6+
pull_request:
7+
branches:[ main ]
8+
release:
9+
types:
10+
-published
11+
12+
concurrency:
13+
group:${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress:true
15+
16+
jobs:
17+
build:
18+
runs-on:ubuntu-22.04
19+
strategy:
20+
matrix:
21+
config:
22+
-name:GCC 12 Release
23+
cxx:g++-12
24+
cc:gcc-12
25+
mode:Release
26+
-name:GCC 12 Debug
27+
cxx:g++-12
28+
cc:gcc-12
29+
mode:Debug
30+
valgrind:true
31+
-name:Clang 16 Release
32+
cxx:clang++-16
33+
cc:clang-16
34+
mode:Release
35+
cxxflags:-stdlib=libc++
36+
ldflags:-lc++abi
37+
-name:Clang 16 Debug
38+
cxx:clang++-16
39+
cc:clang-16
40+
mode:Debug
41+
fuzz:true
42+
-key:GCC 12 Sanitizer
43+
cxx:g++-12
44+
cc:gcc-12
45+
mode:Debug
46+
cflags:-fsanitize=address,undefined -fno-omit-frame-pointer
47+
cxxflags:-fsanitize=address,undefined -fno-omit-frame-pointer
48+
49+
env:
50+
UBSAN_OPTIONS:halt_on_error=1:abort_on_error=1
51+
steps:
52+
-uses:actions/checkout@v3
53+
54+
# ==== INSTALL ====
55+
-name:Install GCC
56+
env:
57+
DEBIAN_FRONTEND:noninteractive
58+
run:sudo apt-get install -y gcc-12
59+
60+
-name:Install Clang
61+
if:matrix.config.cc == 'clang-16'
62+
env:
63+
DEBIAN_FRONTEND:noninteractive
64+
run:|
65+
sudo apt-get update
66+
wget https://apt.llvm.org/llvm.sh
67+
chmod +x llvm.sh
68+
sudo ./llvm.sh 16 || sudo ./llvm.sh 16 workaround
69+
rm llvm.sh
70+
sudo apt-get install -y --no-install-recommends libstdc++-12-dev libc++-16-dev libc++abi-16-dev clang-tidy-16 libunwind-16-dev llvm-16 libfuzzer-16-dev
71+
72+
-name:Install Qbs
73+
env:
74+
DEBIAN_FRONTEND:noninteractive
75+
run:sudo apt-get install -y qbs
76+
77+
# ==== BUILD ====
78+
-name:Build
79+
run:qbs build config:release

‎.github/workflows/windows.yml‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name:Windows Build
2+
3+
on:
4+
push:
5+
branches:[ main ]
6+
pull_request:
7+
branches:[ main ]
8+
release:
9+
types:
10+
-published
11+
12+
concurrency:
13+
group:${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress:true
15+
16+
jobs:
17+
build:
18+
runs-on:windows-latest
19+
20+
strategy:
21+
matrix:
22+
mode:[ Debug, Release ]
23+
arch:[ amd64, x86 ]
24+
25+
env:
26+
CXX:cl.exe
27+
CC:cl.exe
28+
29+
steps:
30+
-uses:actions/checkout@v3
31+
-uses:ilammy/msvc-dev-cmd@v1
32+
33+
-name:Install Qbs
34+
run:choco install qbs
35+
36+
-name:Build
37+
run:qbs build config:release
38+

‎co_fsm.qbs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
importqbs1.0
2+
3+
Project {
4+
references: [
5+
"source/library.qbs",
6+
"example/example.qbs"
7+
]
8+
}

‎example/example.qbs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importqbs1.0
2+
3+
Project {
4+
references: [
5+
"morse/morse.qbs",
6+
"ping-pong/ping-pong.qbs",
7+
"rgb/rgb.qbs",
8+
"ring/ring.qbs",
9+
]
10+
}
11+

‎example/morse/common.hpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
#include"event.hpp"
3+
4+
namespaceco_fsm::morse
5+
{
6+
using FSM = automaton<event, state<state_id>, automaton_id>;
7+
using Event = FSM::event_type;
8+
using State = FSM::state_type;
9+
}

‎example/morse/diagram.png‎

46.8 KB
Loading

‎example/morse/event.hpp‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
#include"morse.hpp"
3+
#include<co_fsm/headers.hpp>
4+
#include<variant>
5+
6+
namespaceco_fsm::morse
7+
{
8+
structevent: co_fsm::event_base<event_id>
9+
{
10+
using co_fsm::event_base<event_id>::set_id;
11+
12+
std::variant<std::string,const std::string_view*, std::uint32_t> data {};
13+
14+
const std::string&message()const {return std::get<std::string>(data); }
15+
std::string&message() {return std::get<std::string>(data); }
16+
17+
const std::string_view&symbol()const {return *std::get<const std::string_view*>(data); }
18+
19+
std::uint32_tbeep_time_in_ms()const {return std::get<std::uint32_t>(data); }
20+
21+
voidset(const event_id id)noexcept
22+
{
23+
set_id(id);
24+
data = {};
25+
}
26+
27+
voidset_message(const event_id id, std::string message)
28+
{
29+
set_id(id);
30+
data =std::move(message);
31+
}
32+
33+
voidset_symbol(const event_id id,const std::string_view& symbol)noexcept
34+
{
35+
set_id(id);
36+
data = &symbol;
37+
}
38+
39+
voidset_beep_time(const event_id id,const std::uint32_t beep_time_in_ms)noexcept
40+
{
41+
set_id(id);
42+
data = beep_time_in_ms;
43+
}
44+
};
45+
}

‎example/morse/morse.cpp‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include"simple_logger.hpp"
2+
#include"sound_controller.hpp"
3+
#include"sound_on_state_handler.hpp"
4+
#include"transmission_in_progress_state_handler.hpp"
5+
#include"transmission_ready_state_handler.hpp"
6+
7+
#include<array>
8+
#include<iostream>
9+
10+
namespaceco_fsm::morse
11+
{
12+
std::ostream&operator<< (std::ostream& out,const automaton_id item)
13+
{
14+
staticconst std::array<constchar*const,1U> texts {
15+
"morse_fsm",
16+
};
17+
18+
out << texts[static_cast<int>(item)];
19+
return out;
20+
}
21+
22+
std::ostream&operator<< (std::ostream& out,const event_id item)
23+
{
24+
staticconst std::array<constchar*const,5U> texts {
25+
"transmit_message","transmit_symbol","transmit_ready","do_beep","beep_done",
26+
};
27+
28+
out << texts[static_cast<int>(item)];
29+
return out;
30+
}
31+
32+
std::ostream&operator<< (std::ostream& out,const state_id item)
33+
{
34+
staticconst std::array<constchar*const,3U> texts {
35+
"transmission_ready",
36+
"transmission_in_progress",
37+
"sound_on",
38+
};
39+
40+
out << texts[static_cast<int>(item)];
41+
return out;
42+
}
43+
44+
voidsetup(FSM& fsm, sound_controller& sound_controller)
45+
{
46+
constexpr std::uint8_t wordsPerMinute =12U;// Approximate transmission speed in words per minute.
47+
48+
// Register the state coroutines and give them ids.
49+
fsm << (coroutine(fsm, transmission_ready_state_handler {}).set_id(state_id::transmission_ready))
50+
<< (coroutine(fsm, transmission_in_progress_state_handler {wordsPerMinute}).set_id(state_id::transmission_in_progress))
51+
<< (coroutine(fsm, sound_on_state_handler {sound_controller}).set_id(state_id::sound_on));
52+
53+
// Configure the transition table in format ("From State", "Event", "To State")
54+
// Example: event_id::transmit_symbol sent from state_id::transmission_ready state goes to
55+
// state_id::transmission_in_progress state
56+
fsm <<FSM::transition(state_id::transmission_ready, event_id::transmit_symbol, state_id::transmission_in_progress)
57+
<<FSM::transition(state_id::transmission_in_progress, event_id::transmit_ready, state_id::transmission_ready)
58+
<<FSM::transition(state_id::transmission_in_progress, event_id::do_beep, state_id::sound_on)
59+
<<FSM::transition(state_id::sound_on, event_id::beep_done, state_id::transmission_in_progress);
60+
61+
// Change to "#if 1" to use live tracing.
62+
// You can filter the log messages out by running "sudo ./fsm-example-morse 2> /dev/null"
63+
// The sudo is needed only if LEDs are used (i.e. built with "make linux")
64+
#if0
65+
fsm.set_logger(simple_logger<FSM> {std::cerr});
66+
#endif
67+
68+
// Launch the state coroutines and set the initial state.
69+
fsm.start().go_to(state_id::transmission_ready);
70+
}
71+
}
72+
73+
intmain()
74+
{
75+
usingnamespaceco_fsm::morse;
76+
sound_controller sound_controller {};
77+
FSM fsm {automaton_id::morse_fsm};
78+
setup(fsm, sound_controller);
79+
80+
// Make the first event which will start the show.
81+
Event event {};
82+
83+
// Send these sentences
84+
const std::vector<std::string> messages {"Hello World","SOS SOS","Wikipedia the free encyclopedia"};
85+
for (constauto& message: messages)
86+
{
87+
std::cout <<"Message = '" << message <<"'\n";
88+
event.set_message(event_id::transmit_message, message);
89+
fsm.send_event(std::move(event));
90+
}
91+
92+
std::cout <<"\n'" << fsm.id() <<"' is suspended at state '" << fsm.state_id() <<"'\n";
93+
return0;
94+
}

‎example/morse/morse.hpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
#include<iosfwd>
3+
4+
namespaceco_fsm::morse
5+
{
6+
enumclassautomaton_id
7+
{
8+
morse_fsm
9+
};
10+
11+
enumclassevent_id
12+
{
13+
transmit_message,
14+
transmit_symbol,
15+
transmit_ready,
16+
do_beep,
17+
beep_done,
18+
};
19+
20+
enumclassstate_id
21+
{
22+
transmission_ready,
23+
transmission_in_progress,
24+
sound_on,
25+
};
26+
27+
std::ostream&operator<< (std::ostream& out,const automaton_id item);
28+
std::ostream&operator<< (std::ostream& out,const event_id item);
29+
std::ostream&operator<< (std::ostream& out,const state_id item);
30+
}

‎example/morse/morse.qbs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import qbs
2+
3+
CppApplication {
4+
consoleApplication:true
5+
Depends {
6+
name:"co_fsm"
7+
}
8+
files: [
9+
"common.hpp",
10+
"diagram.png",
11+
"event.hpp",
12+
"morse.cpp",
13+
"morse.hpp",
14+
"simple_logger.hpp",
15+
"sound_controller.cpp",
16+
"sound_controller.hpp",
17+
"sound_on_state_handler.cpp",
18+
"sound_on_state_handler.hpp",
19+
"transmission_in_progress_state_handler.cpp",
20+
"transmission_in_progress_state_handler.hpp",
21+
"transmission_ready_state_handler.cpp",
22+
"transmission_ready_state_handler.hpp",
23+
]
24+
cpp.cxxLanguageVersion:"c++20"
25+
cpp.enableRtti:false
26+
cpp.includePaths: ["../../source"]
27+
28+
Properties {
29+
condition:qbs.buildVariant==="release"
30+
cpp.cxxFlags: ["-Ofast"]
31+
}
32+
Properties {
33+
condition:qbs.buildVariant==="debug"
34+
cpp.defines: ["ASAN_OPTIONS=abort_on_error=1:report_objects=1:sleep_before_dying=1"]
35+
cpp.cxxFlags:"-fsanitize=address"
36+
cpp.staticLibraries:"asan"
37+
}
38+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp