-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
491 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
#ifndef FMU4CPP_VARIABLEACCESS_HPP | ||
#define FMU4CPP_VARIABLEACCESS_HPP | ||
|
||
#include <functional> | ||
#include <optional> | ||
#include <utility> | ||
|
||
namespace fmu4cpp { | ||
|
||
template<typename T> | ||
struct VariableAccess { | ||
virtual T get() = 0; | ||
virtual void set(T value) = 0; | ||
|
||
virtual ~VariableAccess() = default; | ||
}; | ||
|
||
template<typename T> | ||
class PtrAccess final : public VariableAccess<T> { | ||
|
||
public: | ||
explicit PtrAccess(T *ptr) : ptr_(ptr) {} | ||
|
||
T get() override { | ||
return *ptr_; | ||
} | ||
|
||
void set(T value) override { | ||
*ptr_ = value; | ||
} | ||
|
||
private: | ||
T *ptr_; | ||
}; | ||
|
||
template<typename T> | ||
class LambdaAccess final : public VariableAccess<T> { | ||
|
||
public: | ||
LambdaAccess(std::function<T()> getter, std::optional<std::function<void(T)>> setter) | ||
: getter_(std::move(getter)), | ||
setter_(std::move(setter)) {} | ||
|
||
T get() override { | ||
return getter_(); | ||
} | ||
|
||
void set(T value) override { | ||
if (setter_) { | ||
setter_->operator()(value); | ||
} | ||
} | ||
|
||
private: | ||
std::function<T()> getter_; | ||
std::optional<std::function<void(T)>> setter_; | ||
}; | ||
|
||
}// namespace fmu4cpp | ||
|
||
#endif//FMU4CPP_VARIABLEACCESS_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.