-
-
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.
Implemented numeric_item template class, switched to type-safer code …
…for passing seconds around.
- Loading branch information
Daniel K. O. (dkosmari)
committed
Jun 2, 2024
1 parent
eda3a25
commit 30f9d3b
Showing
27 changed files
with
540 additions
and
553 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 was deleted.
Oops, something went wrong.
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 |
Oops, something went wrong.