1#ifndef NEFORCE_CORE_FILE_ENV_ENV_VALUE_HPP__
2#define NEFORCE_CORE_FILE_ENV_ENV_VALUE_HPP__
14NEFORCE_BEGIN_NAMESPACE__
26struct env_exception final : value_exception {
27 explicit env_exception(
const char* info =
"ENV Operation Failed.",
const char*
type = static_type,
28 const int code = 0) noexcept :
31 explicit env_exception(
const exception& e) :
34 ~env_exception()
override =
default;
35 static constexpr auto static_type =
"env_exception";
80 NEFORCE_NODISCARD
virtual types type() const noexcept = 0;
129 quote_type quote_type_ = None;
130 bool is_exported_ =
false;
140 value_(_NEFORCE
move(value)),
142 is_exported_(exported) {}
160 NEFORCE_NODISCARD
const string&
get_value() const noexcept {
return value_; }
184 NEFORCE_NODISCARD
bool is_exported() const noexcept {
return is_exported_; }
190 void set_exported(
const bool exported)
noexcept { is_exported_ = exported; }
197 NEFORCE_NODISCARD
int get_int(
int default_value = 0) const noexcept;
211 NEFORCE_NODISCARD
double get_double(
double default_value = 0.0) const noexcept;
218 NEFORCE_NODISCARD
bool get_bool(
bool default_value = false) const noexcept;
262 variables_[
name] = _NEFORCE
move(variable);
273 bool exported =
false) {
283 const auto it = variables_.find(
name);
284 if (it != variables_.end()) {
285 return it->second.get();
296 const auto it = variables_.find(
name);
297 if (it != variables_.end()) {
298 return it->second.get();
308 NEFORCE_NODISCARD
bool has_variable(
const string&
name)
const {
return variables_.find(
name) != variables_.end(); }
342 NEFORCE_NODISCARD
string get_string(
const string&
name,
const string& default_value =
"")
const {
344 return var !=
nullptr ? var->get_value() : default_value;
353 NEFORCE_NODISCARD
int get_int(
const string&
name,
const int default_value = 0)
const {
355 return var !=
nullptr ? var->get_int(default_value) : default_value;
366 return var !=
nullptr ? var->get_int64(default_value) : default_value;
375 NEFORCE_NODISCARD
double get_double(
const string&
name,
const double default_value = 0.0)
const {
377 return var !=
nullptr ? var->get_double(default_value) : default_value;
386 NEFORCE_NODISCARD
bool get_bool(
const string&
name,
const bool default_value =
false)
const {
388 return var !=
nullptr ? var->get_bool(default_value) : default_value;
402NEFORCE_END_NAMESPACE__
bool has_variable(const string &name) const
检查变量是否存在
const vector< string > & get_comments() const noexcept
获取所有注释
int64_t get_int64(const string &name, const int64_t default_value=0) const
获取64位整数值
void remove_variable(const string &name)
移除变量
env_document()=default
默认构造函数
int get_int(const string &name, const int default_value=0) const
获取整数值
env_document & operator=(env_document &&other) noexcept=default
移动赋值运算符
double get_double(const string &name, const double default_value=0.0) const
获取双精度浮点值
env_document(env_document &&other) noexcept=default
移动构造函数
void set_variable(const string &name, string value, env_variable::quote_type quote=env_variable::None, bool exported=false)
设置变量
string to_string() const
转换为字符串
void add_comment(string comment)
添加注释
string get_string(const string &name, const string &default_value="") const
获取字符串值
env_variable * get_variable(const string &name)
获取变量指针
bool get_bool(const string &name, const bool default_value=false) const
获取布尔值
const unordered_map< string, unique_ptr< env_variable > > & get_variables() const noexcept
获取所有变量的常量引用
void add_variable(const string &name, unique_ptr< env_variable > variable)
添加变量
const env_variable * get_variable(const string &name) const
获取常量变量指针
string to_document() const
转换为文档字符串
bool is_variable() const noexcept
判断是否为变量类型
virtual types type() const noexcept=0
获取环境值类型
virtual const env_variable * as_variable() const noexcept
转换为环境变量指针
string to_string() const
转换为字符串
virtual ~env_value()=default
虚析构函数
types type() const noexcept override
获取类型
const env_variable * as_variable() const noexcept override
转换为环境变量指针
quote_type get_quote_type() const noexcept
获取引号类型
void set_exported(const bool exported) noexcept
设置导出标记
int get_int(int default_value=0) const noexcept
获取整数值
int64_t get_int64(int64_t default_value=0) const noexcept
获取64位整数值
bool get_bool(bool default_value=false) const noexcept
获取布尔值
env_variable(string value, const quote_type quote=None, const bool exported=false) noexcept
构造函数
void set_quote_type(const quote_type quote) noexcept
设置引号类型
double get_double(double default_value=0.0) const noexcept
获取双精度浮点值
bool is_exported() const noexcept
检查是否导出
void set_value(string value) noexcept
设置变量值
const string & get_value() const noexcept
获取变量值
long long int64_t
64位有符号整数类型
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
bool name(char *buffer, size_t size)
获取当前线程名称
constexpr unique_ptr< T > make_unique(Args &&... args)
创建unique_ptr
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
const char * type() const noexcept
获取异常类型
int code() const noexcept
获取异常码