/** Converts @p str to an enum. * @throw illegal_enum_value @p str is not a legal identifier. * */ void from_string(std::string const& str) { for (unsigned i = 0; i < THE_MAX; ++i) { if (str == our_strings_[i]) { value_ = static_cast<ENUM>(i); return; } } throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_); }
/** Converts @p str to an enum. * @throw illegal_enum_value @p str is not a legal identifier. * */ void from_string(std::string const& str) { // TODO: Enum value strings with underscore are deprecated in Mapnik 3.x // and support will be removed in Mapnik 4.x. bool deprecated = false; std::string str_copy(str); if (str_copy.find('_') != std::string::npos) { std::replace(str_copy.begin(), str_copy.end(), '_', '-'); deprecated = true; } for (unsigned i = 0; i < THE_MAX; ++i) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-pragmas" // clang+gcc #pragma GCC diagnostic ignored "-Wpragmas" // gcc #pragma GCC diagnostic ignored "-Wundefined-var-template" if (str_copy == our_strings_[i]) #pragma GCC diagnostic pop { value_ = static_cast<ENUM>(i); if (deprecated) { MAPNIK_LOG_ERROR(enumerations) << "enumeration value (" << str << ") using \"_\" is deprecated and will be removed in Mapnik 4.x, use '" << str_copy << "' instead"; } return; } } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunknown-pragmas" // clang+gcc #pragma GCC diagnostic ignored "-Wpragmas" // gcc #pragma GCC diagnostic ignored "-Wundefined-var-template" throw illegal_enum_value(std::string("Illegal enumeration value '") + str + "' for enum " + our_name_); #pragma GCC diagnostic pop }