roboligo
Loading...
Searching...
No Matches
Trigger.hpp
Go to the documentation of this file.
1// Copyright 2026 Juan S. Cely G.
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7// https://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ROBOLIGO_COMMON_CLASSIFICATION__TRIGGER_HPP_
16#define ROBOLIGO_COMMON_CLASSIFICATION__TRIGGER_HPP_
17
18#include <memory>
19#include <vector>
20#include <string>
21#include <functional>
22#include <iostream>
23
25
26namespace roboligo
27{
35 class Trigger
36 {
37 public:
45 Trigger(std::string name, std::string value, std::vector<Mode> previous, std::vector<Mode> next)
46 :name_(name), value_(value), previous_(std::move(previous)), next_(std::move(next)) {}
47
51 virtual ~Trigger() = default;
52
57 std::string get_name(void);
58
63 std::string get_value(void);
64
69 void set_name(std::string new_name);
70
75 void set_value(std::string new_value);
76
81 void set_previous_modes(std::vector<Mode> modes);
82
87 void set_next_modes(std::vector<Mode> modes);
88
93 bool is_available(void);
94
99 void register_callback(const std::function<void()>& callback);
100
104 void execute(void);
105
106 std::function<void()> cb;
107
108 protected:
109
110 std::string name_;
111
112 std::string value_;
113
114 std::vector<Mode> previous_;
115
116 std::vector<Mode> next_;
117
118 bool available_{false};
119
120 };
121
122} // namespace roboligo
123#endif // ROBOLIGO_COMMON_CLASSIFICATION__TRIGGER_HPP_
std::string get_value(void)
Gets the value of the trigger.
Definition Trigger.cpp:26
bool available_
If trigger is available.
Definition Trigger.hpp:118
std::string value_
Value for the trigger.
Definition Trigger.hpp:112
std::function< void()> cb
Callback function.
Definition Trigger.hpp:106
bool is_available(void)
Checks if the trigger is available for execution.
Definition Trigger.cpp:56
void execute(void)
Executes the trigger and invokes its registered callback.
Definition Trigger.cpp:69
std::vector< Mode > next_
Vector of next modes.
Definition Trigger.hpp:116
std::string name_
Trigger name.
Definition Trigger.hpp:110
void register_callback(const std::function< void()> &callback)
Registers a callback function to be executed when the trigger fires.
Definition Trigger.cpp:62
std::vector< Mode > previous_
Vector of previous modes.
Definition Trigger.hpp:114
std::string get_name(void)
Gets the name of the trigger.
Definition Trigger.cpp:20
void set_value(std::string new_value)
Sets a new value for the trigger.
Definition Trigger.cpp:38
void set_next_modes(std::vector< Mode > modes)
Sets the next modes for this trigger.
Definition Trigger.cpp:50
void set_previous_modes(std::vector< Mode > modes)
Sets the previous modes for this trigger.
Definition Trigger.cpp:44
virtual ~Trigger()=default
Destructor.
Trigger(std::string name, std::string value, std::vector< Mode > previous, std::vector< Mode > next)
Constructor for Trigger.
Definition Trigger.hpp:45
void set_name(std::string new_name)
Sets a new name for the trigger.
Definition Trigger.cpp:32
Definition ClassificationBase.hpp:28