.. _program_listing_file_src_microsoft_shortlist_utils_Converter.cpp: Program Listing for File Converter.cpp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``src/microsoft/shortlist/utils/Converter.cpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include "microsoft/shortlist/utils/Converter.h" namespace marian { namespace quicksand { #include "microsoft/shortlist/logging/LoggerMacros.h" int64_t Converter::ToInt64(const std::string& str) { return ConvertSingleInternal(str, "int64_t"); } uint64_t Converter::ToUInt64(const std::string& str) { return ConvertSingleInternal(str, "int64_t"); } int32_t Converter::ToInt32(const std::string& str) { return ConvertSingleInternal(str, "int32_t"); } float Converter::ToFloat(const std::string& str) { // In case the value is out of range of a 32-bit float, but in range of a 64-bit double, // it's better to convert as a double and then do the conersion. return (float)ConvertSingleInternal(str, "float"); } double Converter::ToDouble(const std::string& str) { return ConvertSingleInternal(str, "double"); } bool Converter::ToBool(const std::string& str) { bool value = false; if (!TryConvert(str, /* out */ value)) { LOG_ERROR_AND_THROW("The string '%s' is not interpretable as the type 'bool'", str.c_str()); } return value; } std::vector Converter::ToInt32Vector(const std::vector& items) { return ConvertVectorInternal::const_iterator>(items.begin(), items.end(), "int32_t"); } std::vector Converter::ToInt64Vector(const std::vector& items) { return ConvertVectorInternal::const_iterator>(items.begin(), items.end(), "int64_t"); } std::vector Converter::ToFloatVector(const std::vector& items) { return ConvertVectorInternal::const_iterator>(items.begin(), items.end(), "float"); } std::vector Converter::ToDoubleVector(const std::vector& items) { return ConvertVectorInternal::const_iterator>(items.begin(), items.end(), "double"); } void Converter::HandleConversionError(const std::string& str, const char * type_name) { str; type_name; // make compiler happy LOG_ERROR_AND_THROW("The string '%s' is not interpretable as the type '%s'", str.c_str(), type_name); } } // namespace quicksand } // namespace marian