Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Nov 26, 2024
1 parent 1f17201 commit a260336
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
1 change: 0 additions & 1 deletion library/private/interactor_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class interactor_impl : public interactor
std::vector<std::string> getCommandActions() const override;
bool triggerCommand(std::string_view command) override;

using documentation_callback_t = std::function<std::pair<std::string, std::string>()>;
interactor& initBindings() override;
interactor& addBinding(const interaction_bind_t& bind, std::vector<std::string> commands,
std::string group = std::string(),
Expand Down
19 changes: 9 additions & 10 deletions library/public/interactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ struct interaction_bind_t

bool operator<(const interaction_bind_t& bind) const
{
return this->inter < bind.inter || (this->inter == bind.inter && this->mod < bind.mod);
return this->mod < bind.mod || (this->mod == bind.mod && this->inter < bind.inter);
}

bool operator==(const interaction_bind_t& bind) const
{
return this->inter == bind.inter && this->mod == bind.mod;
return this->mod == bind.mod && this->inter == bind.inter;
}

/**
Expand Down Expand Up @@ -116,6 +116,8 @@ class F3D_EXPORT interactor
///@}

///@{ @name Bindings
using documentation_callback_t = std::function<std::pair<std::string, std::string>();

/**
* Remove all existing interaction commands and add all default bindings
* see INTERACTIONS.md for details.
Expand Down Expand Up @@ -148,8 +150,7 @@ class F3D_EXPORT interactor
* Adding commands for an existing bind will throw a interactor::already_exists_exception.
*/
virtual interactor& addBinding(const interaction_bind_t& bind, std::vector<std::string> commands,
std::string group = {},
std::function<std::pair<std::string, std::string>()> documentationCallback = nullptr) = 0;
std::string group = {}, documentation_callback_t documentationCallback = nullptr) = 0;

/**
* See addBinding
Expand All @@ -159,15 +160,13 @@ class F3D_EXPORT interactor
* Adding command for an existing bind will throw a interactor::already_exists_exception.
*/
virtual interactor& addBinding(const interaction_bind_t& bind, std::string command,
std::string group = {},
std::function<std::pair<std::string, std::string>()> documentationCallback = nullptr) = 0;
std::string group = {}, documentation_callback_t documentationCallback = nullptr) = 0;

/**
* Convenience initializer list signature for add binding method
*/
interactor& addBinding(const interaction_bind_t& bind, std::initializer_list<std::string> list,
std::string group = {},
std::function<std::pair<std::string, std::string>()> documentationCallback = nullptr)
std::string group = {}, documentation_callback_t documentationCallback = nullptr)
{
return this->addBinding(
bind, std::vector<std::string>(list), std::move(group), std::move(documentationCallback));
Expand All @@ -187,7 +186,7 @@ class F3D_EXPORT interactor
/**
* Return a vector of bind for the specified group, in order of addition
*
* Geting binds for a group that does not exists will throw a does_not_exists_exception.
* Getting binds for a group that does not exists will throw a does_not_exists_exception.
*/
virtual std::vector<interaction_bind_t> getBindsForGroup(std::string group) const = 0;

Expand All @@ -206,7 +205,7 @@ class F3D_EXPORT interactor
* The possible string can depends on the bindings but boolean value are expected to be
* "ON", "OFF", "N/A" (for optional values).
*
* Geting documentation for a bind that does not exists will throw a does_not_exists_exception.
* Getting documentation for a bind that does not exists will throw a does_not_exists_exception.
*/
virtual std::pair<std::string, std::string> getBindingDocumentation(
const interaction_bind_t& bind) const = 0;
Expand Down
24 changes: 10 additions & 14 deletions library/testing/TestSDKInteractorDocumentation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ int TestSDKInteractorDocumentation(int argc, char* argv[])

{
// check exceptions for invalid args
test.expect<f3d::interactor::does_not_exists_exception>("Initial invalid group", [&]() {
inter.getBindsForGroup("Invalid");
});
test.expect<f3d::interactor::does_not_exists_exception>(
"Initial invalid group", [&]() { inter.getBindsForGroup("Invalid"); });

test.expect<f3d::interactor::does_not_exists_exception>("Initial invalid bind", [&]() {
inter.getBindingDocumentation({ mod_t::ANY, "Invalid" });
});
test.expect<f3d::interactor::does_not_exists_exception>(
"Initial invalid bind", [&]() { inter.getBindingDocumentation({ mod_t::ANY, "Invalid" }); });
}

// Remove all bindings
Expand All @@ -53,13 +51,11 @@ int TestSDKInteractorDocumentation(int argc, char* argv[])
test("Empty group size", inter.getBindGroups().size() == 0);
test("Empty binds size", inter.getBinds().size() == 0);
// check exceptions for invalid args
test.expect<f3d::interactor::does_not_exists_exception>("Empty group", [&]() {
inter.getBindsForGroup("Camera");
});
test.expect<f3d::interactor::does_not_exists_exception>(
"Empty group", [&]() { inter.getBindsForGroup("Camera"); });

test.expect<f3d::interactor::does_not_exists_exception>("Empty bind", [&]() {
inter.getBindingDocumentation({ mod_t::ANY, "5" });
});
test.expect<f3d::interactor::does_not_exists_exception>(
"Empty bind", [&]() { inter.getBindingDocumentation({ mod_t::ANY, "5" }); });
}

// Add a dummy binding
Expand All @@ -82,8 +78,8 @@ int TestSDKInteractorDocumentation(int argc, char* argv[])
// Test initial state
test("Initial group size after init", inter.getBindGroups().size() == nGroup);
test("Initial binds size", inter.getBinds().size() == nBinds);
test("Initial nBinds Camera after init",
inter.getBindsForGroup("Camera").size() == nBindsCamera);
test(
"Initial nBinds Camera after init", inter.getBindsForGroup("Camera").size() == nBindsCamera);
const auto& [doc, val] = inter.getBindingDocumentation({ mod_t::ANY, "5" });
test("Initial doc and val after init", doc == initDoc && val == initVal);
}
Expand Down

0 comments on commit a260336

Please sign in to comment.