-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration and environment variable improvements (#4613)
* Move env utilities to `nano::env::...` * Env get_int helpers * Hardware concurrency override * App path override * Convert legacy calls to `nano::env::get (...)` * Use generic get * Inform about environment overrides * Consteval sanitizer info * Print stats logging info * Replace `get_env_threshold_or_default` * Allow overriding io threads from env variable * Ensure configured thread counts are in reasonable ranges * Use `std::clamp`
- Loading branch information
1 parent
e4901db
commit 147a375
Showing
21 changed files
with
215 additions
and
148 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 |
---|---|---|
@@ -1,15 +1,42 @@ | ||
#pragma once | ||
|
||
#include <boost/lexical_cast.hpp> | ||
|
||
#include <optional> | ||
#include <string_view> | ||
|
||
namespace nano | ||
namespace nano::env | ||
{ | ||
/* | ||
/** | ||
* Get environment variable as a specific type or none if variable is not present. | ||
*/ | ||
std::optional<std::string> get (std::string_view name); | ||
|
||
/** | ||
* Get environment variable as a specific type or none if variable is not present. | ||
* @throws std::invalid_argument if the value cannot be converted | ||
*/ | ||
std::optional<std::string> get_env (std::string_view name); | ||
template <typename T> | ||
std::optional<T> get (std::string_view name) | ||
{ | ||
if (auto value = get (name)) | ||
{ | ||
try | ||
{ | ||
return boost::lexical_cast<T> (*value); | ||
} | ||
catch (boost::bad_lexical_cast const &) | ||
{ | ||
throw std::invalid_argument ("Invalid environment value: " + *value); | ||
} | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
// @throws std::invalid_argument if the value is not a valid boolean | ||
std::optional<bool> get_env_bool (std::string_view name); | ||
/** | ||
* Specialization for boolean values. | ||
* @throws std::invalid_argument if the value is not a valid boolean | ||
*/ | ||
template <> | ||
std::optional<bool> get (std::string_view name); | ||
} |
Oops, something went wrong.