-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged the number-item branch into master.
- All numeric items are now implemented by one code base in the `numeric_item<>` template class. - Each type of numeric item can show a unit; "ms" and "s" for time duration items. - `cfg::msg_duration` and `cfg::tolerance` are now of `std::chrono::duration<>` types. - `wupsxx/storage.{cpp,hpp}` now has specializations for `std::chrono::duration<>` types. - Some time-related code was moved from `utils.{cpp,hpp}` to `time_utils.{cpp,hpp}`. - "Seconds" are not passed around in a raw `double` type anymore, the `time_utils::dbl_seconds` type is used.
- Loading branch information
Showing
25 changed files
with
574 additions
and
379 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#ifndef TIME_UTILS_HPP | ||
#define TIME_UTILS_HPP | ||
|
||
#include <chrono> | ||
#include <string> | ||
#include <type_traits> | ||
|
||
|
||
namespace time_utils { | ||
|
||
// Type-safe way to pass seconds around as double | ||
using dbl_seconds = std::chrono::duration<double>; | ||
|
||
|
||
// Type trait to identify when a type is std::chrono::duration<> | ||
|
||
template<typename T> | ||
struct is_duration : std::false_type {}; | ||
|
||
template<typename R, typename P> | ||
struct is_duration<std::chrono::duration<R, P>> : std::true_type {}; | ||
|
||
// convenience variable template | ||
template<typename T> | ||
constexpr bool is_duration_v = is_duration<T>::value; | ||
|
||
|
||
template<typename T> | ||
concept duration = is_duration_v<T>; | ||
|
||
|
||
template<duration T> | ||
std::string to_string(T t); | ||
|
||
|
||
|
||
// Generate time duration strings for humans. | ||
std::string seconds_to_human(dbl_seconds s, bool show_positive = false); | ||
|
||
|
||
std::string tz_offset_to_string(std::chrono::minutes offset); | ||
|
||
} | ||
|
||
|
||
#endif |
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,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#ifndef WUPSXX_DURATION_ITEMS_HPP | ||
#define WUPSXX_DURATION_ITEMS_HPP | ||
|
||
#include <chrono> | ||
|
||
#include "numeric_item.hpp" | ||
|
||
|
||
namespace wups::config { | ||
|
||
using milliseconds_item = numeric_item<std::chrono::milliseconds>; | ||
|
||
using seconds_item = numeric_item<std::chrono::seconds>; | ||
|
||
} // namespace wups::config | ||
|
||
#endif |
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,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
#ifndef WUPSXX_NUMERIC_ITEM_HPP | ||
#define WUPSXX_NUMERIC_ITEM_HPP | ||
|
||
#include <memory> | ||
|
||
#include "item.hpp" | ||
#include "var_watch.hpp" | ||
|
||
|
||
namespace wups::config { | ||
|
||
|
||
template<typename T> | ||
class numeric_item : public item { | ||
|
||
protected: | ||
|
||
var_watch<T> variable; | ||
const T default_value; | ||
T min_value; | ||
T max_value; | ||
T fast_increment; | ||
T slow_increment; | ||
|
||
public: | ||
|
||
numeric_item(const std::optional<std::string>& key, | ||
const std::string& label, | ||
T& variable, T default_value, | ||
T min_value, T max_value, | ||
T fast_increment = T{10}, | ||
T slow_increment = T{1}); | ||
|
||
static | ||
std::unique_ptr<numeric_item> | ||
create(const std::optional<std::string>& key, | ||
const std::string& label, | ||
T& variable, T default_value, | ||
T min_value, T max_value, | ||
T fast_increment = T{10}, | ||
T slow_increment = T{1}); | ||
|
||
|
||
virtual int get_display(char* buf, std::size_t size) const override; | ||
|
||
virtual int get_selected_display(char* buf, std::size_t size) const override; | ||
|
||
virtual void restore() override; | ||
|
||
virtual void on_input(WUPSConfigSimplePadData input, | ||
WUPS_CONFIG_SIMPLE_INPUT repeat) override; | ||
|
||
private: | ||
|
||
void on_changed(); | ||
|
||
}; | ||
|
||
} // namespace wups::config | ||
|
||
#endif |
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.