Skip to content

Commit

Permalink
update some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Feb 11, 2024
1 parent 771612e commit 05d78bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions wombat/src/main/cpp/behaviour/Trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ Trigger* Trigger::operator||(std::pair<std::function<bool()>, std::string> rhs)
rhs.second);
}

Trigger* Trigger::operator||(std::function<bool()> rhs) {
return new Trigger([condition = m_condition, rhs = std::move(rhs)]() { return condition() || rhs(); },
"Logical or of " + k_name);
}

Trigger* Trigger::operator&&(std::pair<std::function<bool()>, std::string> rhs) {
return new Trigger([condition = m_condition, rhs = std::move(rhs)]() { return condition() && rhs.first(); },
rhs.second);
}

Trigger* Trigger::operator&&(std::function<bool()> rhs) {
return new Trigger([condition = m_condition, rhs = std::move(rhs)]() { return condition() && rhs(); },
"Logical and of " + k_name);
}
22 changes: 20 additions & 2 deletions wombat/src/main/include/behaviour/Trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,35 @@ class Trigger {
/**
* Returns a Trigger* from a logical OR with m_condition and the provided condition.
*
* @param rhs A std::pair of the right hand condition of the logical OR operation and the name for the new trigger.
* @param rhs A std::pair of the right hand condition of the logical OR operation and the name for the new
* trigger.
*/
Trigger* operator||(std::pair<std::function<bool()>, std::string> rhs);

/**
* Returns a Trigger* from a logical OR with m_condition and the provided condition. <br> <b> WARNING </b>
* The name for this isn't unique so you can only use one operator like this.
*
* @param rhs The hand condition of the logical OR operation
*/
Trigger* operator||(std::function<bool()> rhs);

/**
* Returns a Trigger* from a logical AND with m_condition and the provided condition.
*
* @param rhs A std::pair of the right hand condition of the logical AND operation and the name for the new trigger.
* @param rhs A std::pair of the right hand condition of the logical AND operation and the name for the new
* trigger.
*/
Trigger* operator&&(std::pair<std::function<bool()>, std::string> rhs);

/**
* Returns a Trigger* from a logical AND with m_condition and the provided condition. <br> <b> WARNING </b>
* The name for this isn't unique so you can only use one operator like this.
*
* @param rhs The hand condition of the logical AND operation
*/
Trigger* operator&&(std::function<bool()> rhs);

private:
std::string k_name;
std::function<bool()> m_condition;
Expand Down

0 comments on commit 05d78bc

Please sign in to comment.