1#include "state_representation/DigitalIOState.hpp"
3#include "state_representation/exceptions/IONotFoundException.hpp"
5using namespace state_representation::exceptions;
10 this->
set_type(StateType::DIGITAL_IO_STATE);
14 this->
set_type(StateType::DIGITAL_IO_STATE);
15 this->
data_ = Eigen::Vector<bool, Eigen::Dynamic>::Zero(nb_ios);
46 random.
set_data(Eigen::Vector<bool, Eigen::Dynamic>::Random(random.
get_size()));
53 random.
set_data(Eigen::Vector<bool, Eigen::Dynamic>::Random(random.
get_size()));
70 return this->
data_(io_index) ==
true;
78 return !this->
is_true(io_index);
109 this->
data_.setZero();
117 s << std::endl <<
"digital io names: [";
118 for (
auto& n : this->
get_names()) { s << n <<
", "; }
123 s << std::endl <<
"values: [";
124 for (
auto& p : this->
data()) { s << p <<
", "; }
130 os << state.to_string();
std::string to_string() const override
Convert the state to its string representation.
void set_false()
Set all digital IOs false.
friend void swap(DigitalIOState &state1, DigitalIOState &state2)
Swap the values of the IO states.
static DigitalIOState Zero(const std::string &name, unsigned int nb_ios)
Constructor for a zero digital IO state.
bool is_true(const std::string &name) const
Check if a digital IO is true by its name, if it exists.
void reset() override
Reset the object to a post-construction state.
DigitalIOState()
Empty constructor for a digital IO state.
DigitalIOState & operator=(const DigitalIOState &state)
Copy assignment operator that has to be defined to the custom assignment operator.
DigitalIOState copy() const
Return a copy of the digital IO state.
bool is_false(const std::string &name) const
Check if a digital IO is false by its name, if it exists.
void set_true(const std::string &name)
Set the a digital IO to true by its name.
static DigitalIOState Random(const std::string &name, unsigned int nb_ios)
Constructor for a digital IO state with random data.
Eigen::Vector< bool, Eigen::Dynamic > data_
IO values.
void set_data(const Eigen::Vector< bool, Eigen::Dynamic > &data)
Set the values of the IO state from a single Eigen vector.
Eigen::Vector< T, Eigen::Dynamic > data() const
Returns the values of the IO state as an Eigen vector.
void set_names(unsigned int nb_ios)
Setter of the names from the number of IOs.
unsigned int get_size() const
Getter of the size.
void set_value(bool value, const std::string &name)
Set the value of an IO by its name.
const std::vector< std::string > & get_names() const
Getter of the names.
unsigned int get_io_index(const std::string &io_name) const
Get IO index by the name of the IO, if it exists.
void set_type(const StateType &type)
Setter of the state type attribute.
virtual std::string to_string() const
Convert the state to its string representation.
virtual void reset()
Reset the object to a post-construction state.
void assert_not_empty() const
Throw an exception if the state is empty.
bool is_empty() const
Getter of the empty attribute.
void set_empty(bool empty=true)
Setter of the empty attribute.
Core state variables and objects.
std::ostream & operator<<(std::ostream &os, const AnalogIOState &state)