Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/core/options.h
- This file was moved from extern/draco/dracoenc/src/draco/core/options.h.
| Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | private: | ||||
| std::map<std::string, std::string> options_; | std::map<std::string, std::string> options_; | ||||
| }; | }; | ||||
| template <typename DataTypeT> | template <typename DataTypeT> | ||||
| void Options::SetVector(const std::string &name, const DataTypeT *vec, | void Options::SetVector(const std::string &name, const DataTypeT *vec, | ||||
| int num_dims) { | int num_dims) { | ||||
| std::string out; | std::string out; | ||||
| for (int i = 0; i < num_dims; ++i) { | for (int i = 0; i < num_dims; ++i) { | ||||
| if (i > 0) | if (i > 0) { | ||||
| out += " "; | out += " "; | ||||
| } | |||||
| // GNU STL on android doesn't include a proper std::to_string, but the libc++ | // GNU STL on android doesn't include a proper std::to_string, but the libc++ | ||||
| // version does | // version does | ||||
| #if defined(ANDROID) && !defined(_LIBCPP_VERSION) | #if defined(ANDROID) && !defined(_LIBCPP_VERSION) | ||||
| out += to_string(vec[i]); | out += to_string(vec[i]); | ||||
| #else | #else | ||||
| out += std::to_string(vec[i]); | out += std::to_string(vec[i]); | ||||
| #endif | #endif | ||||
| } | } | ||||
| options_[name] = out; | options_[name] = out; | ||||
| } | } | ||||
| template <class VectorT> | template <class VectorT> | ||||
| VectorT Options::GetVector(const std::string &name, | VectorT Options::GetVector(const std::string &name, | ||||
| const VectorT &default_val) const { | const VectorT &default_val) const { | ||||
| VectorT ret = default_val; | VectorT ret = default_val; | ||||
| GetVector(name, VectorT::dimension, &ret[0]); | GetVector(name, VectorT::dimension, &ret[0]); | ||||
| return ret; | return ret; | ||||
| } | } | ||||
| template <typename DataTypeT> | template <typename DataTypeT> | ||||
| bool Options::GetVector(const std::string &name, int num_dims, | bool Options::GetVector(const std::string &name, int num_dims, | ||||
| DataTypeT *out_val) const { | DataTypeT *out_val) const { | ||||
| const auto it = options_.find(name); | const auto it = options_.find(name); | ||||
| if (it == options_.end()) | if (it == options_.end()) { | ||||
| return false; | return false; | ||||
| } | |||||
| const std::string value = it->second; | const std::string value = it->second; | ||||
| if (value.length() == 0) | if (value.length() == 0) { | ||||
| return true; // Option set but no data is present | return true; // Option set but no data is present | ||||
| } | |||||
| const char *act_str = value.c_str(); | const char *act_str = value.c_str(); | ||||
| char *next_str; | char *next_str; | ||||
| for (int i = 0; i < num_dims; ++i) { | for (int i = 0; i < num_dims; ++i) { | ||||
| if (std::is_integral<DataTypeT>::value) { | if (std::is_integral<DataTypeT>::value) { | ||||
| #ifdef ANDROID | #ifdef ANDROID | ||||
| const int val = strtol(act_str, &next_str, 10); | const int val = strtol(act_str, &next_str, 10); | ||||
| #else | #else | ||||
| const int val = std::strtol(act_str, &next_str, 10); | const int val = static_cast<int>(std::strtol(act_str, &next_str, 10)); | ||||
| #endif | #endif | ||||
| if (act_str == next_str) | if (act_str == next_str) { | ||||
| return true; // End reached. | return true; // End reached. | ||||
| } | |||||
| act_str = next_str; | act_str = next_str; | ||||
| out_val[i] = static_cast<DataTypeT>(val); | out_val[i] = static_cast<DataTypeT>(val); | ||||
| } else { | } else { | ||||
| #ifdef ANDROID | #ifdef ANDROID | ||||
| const float val = strtof(act_str, &next_str); | const float val = strtof(act_str, &next_str); | ||||
| #else | #else | ||||
| const float val = std::strtof(act_str, &next_str); | const float val = std::strtof(act_str, &next_str); | ||||
| #endif | #endif | ||||
| if (act_str == next_str) | if (act_str == next_str) { | ||||
| return true; // End reached. | return true; // End reached. | ||||
| } | |||||
| act_str = next_str; | act_str = next_str; | ||||
| out_val[i] = static_cast<DataTypeT>(val); | out_val[i] = static_cast<DataTypeT>(val); | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_CORE_OPTIONS_H_ | #endif // DRACO_CORE_OPTIONS_H_ | ||||