Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/core/options.cc
- This file was moved from extern/draco/dracoenc/src/draco/core/options.cc.
| Show All 17 Lines | |||||
| #include <string> | #include <string> | ||||
| #include <utility> | #include <utility> | ||||
| namespace draco { | namespace draco { | ||||
| Options::Options() {} | Options::Options() {} | ||||
| void Options::MergeAndReplace(const Options &other_options) { | void Options::MergeAndReplace(const Options &other_options) { | ||||
| for (const auto &item : other_options.options_) | for (const auto &item : other_options.options_) { | ||||
| options_[item.first] = item.second; | options_[item.first] = item.second; | ||||
| } | } | ||||
| } | |||||
| void Options::SetInt(const std::string &name, int val) { | void Options::SetInt(const std::string &name, int val) { | ||||
| options_[name] = std::to_string(val); | options_[name] = std::to_string(val); | ||||
| } | } | ||||
| void Options::SetFloat(const std::string &name, float val) { | void Options::SetFloat(const std::string &name, float val) { | ||||
| options_[name] = std::to_string(val); | options_[name] = std::to_string(val); | ||||
| } | } | ||||
| void Options::SetBool(const std::string &name, bool val) { | void Options::SetBool(const std::string &name, bool val) { | ||||
| options_[name] = std::to_string(val ? 1 : 0); | options_[name] = std::to_string(val ? 1 : 0); | ||||
| } | } | ||||
| void Options::SetString(const std::string &name, const std::string &val) { | void Options::SetString(const std::string &name, const std::string &val) { | ||||
| options_[name] = val; | options_[name] = val; | ||||
| } | } | ||||
| int Options::GetInt(const std::string &name) const { return GetInt(name, -1); } | int Options::GetInt(const std::string &name) const { return GetInt(name, -1); } | ||||
| int Options::GetInt(const std::string &name, int default_val) const { | int Options::GetInt(const std::string &name, int default_val) const { | ||||
| const auto it = options_.find(name); | const auto it = options_.find(name); | ||||
| if (it == options_.end()) | if (it == options_.end()) { | ||||
| return default_val; | return default_val; | ||||
| } | |||||
| return std::atoi(it->second.c_str()); | return std::atoi(it->second.c_str()); | ||||
| } | } | ||||
| float Options::GetFloat(const std::string &name) const { | float Options::GetFloat(const std::string &name) const { | ||||
| return GetFloat(name, -1); | return GetFloat(name, -1); | ||||
| } | } | ||||
| float Options::GetFloat(const std::string &name, float default_val) const { | float Options::GetFloat(const std::string &name, float default_val) const { | ||||
| const auto it = options_.find(name); | const auto it = options_.find(name); | ||||
| if (it == options_.end()) | if (it == options_.end()) { | ||||
| return default_val; | return default_val; | ||||
| } | |||||
| return static_cast<float>(std::atof(it->second.c_str())); | return static_cast<float>(std::atof(it->second.c_str())); | ||||
| } | } | ||||
| bool Options::GetBool(const std::string &name) const { | bool Options::GetBool(const std::string &name) const { | ||||
| return GetBool(name, false); | return GetBool(name, false); | ||||
| } | } | ||||
| bool Options::GetBool(const std::string &name, bool default_val) const { | bool Options::GetBool(const std::string &name, bool default_val) const { | ||||
| const int ret = GetInt(name, -1); | const int ret = GetInt(name, -1); | ||||
| if (ret == -1) | if (ret == -1) { | ||||
| return default_val; | return default_val; | ||||
| } | |||||
| return static_cast<bool>(ret); | return static_cast<bool>(ret); | ||||
| } | } | ||||
| std::string Options::GetString(const std::string &name) const { | std::string Options::GetString(const std::string &name) const { | ||||
| return GetString(name, ""); | return GetString(name, ""); | ||||
| } | } | ||||
| std::string Options::GetString(const std::string &name, | std::string Options::GetString(const std::string &name, | ||||
| const std::string &default_val) const { | const std::string &default_val) const { | ||||
| const auto it = options_.find(name); | const auto it = options_.find(name); | ||||
| if (it == options_.end()) | if (it == options_.end()) { | ||||
| return default_val; | return default_val; | ||||
| } | |||||
| return it->second; | return it->second; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||