| 105 | } |
| 106 | |
| 107 | template <class T> T fromValueString(const string& value) |
| 108 | { |
| 109 | T data; |
| 110 | |
| 111 | if constexpr(std::is_same_v<T, string>) |
| 112 | { |
| 113 | data = value; |
| 114 | } |
| 115 | else if constexpr(std::is_same_v<T, bool>) |
| 116 | { |
| 117 | if (value == VALUE_STRING_TRUE) |
| 118 | data = true; |
| 119 | else if (value == VALUE_STRING_FALSE) |
| 120 | data = false; |
| 121 | else |
| 122 | throw ExceptionTypeError("Type mismatch in boolean fromValueString: " + value); |
| 123 | } |
| 124 | else if constexpr(std::is_base_of_v<VectorBase, T>) |
| 125 | { |
| 126 | StringVec tokens = splitString(value, ARRAY_VALID_SEPARATORS); |
| 127 | if (tokens.size() != data.numElements()) |
| 128 | { |
| 129 | throw ExceptionTypeError("Type mismatch in vector fromValueString: " + value); |
| 130 | } |
| 131 | for (size_t i = 0; i < data.numElements(); i++) |
| 132 | { |
| 133 | data[i] = fromValueString<float>(tokens[i]); |
| 134 | } |
| 135 | } |
| 136 | else if constexpr(std::is_base_of_v<MatrixBase, T>) |
| 137 | { |
| 138 | StringVec tokens = splitString(value, ARRAY_VALID_SEPARATORS); |
| 139 | if (tokens.size() != data.numRows() * data.numColumns()) |
| 140 | { |
| 141 | throw ExceptionTypeError("Type mismatch in matrix fromValueString: " + value); |
| 142 | } |
| 143 | for (size_t i = 0; i < data.numRows(); i++) |
| 144 | { |
| 145 | for (size_t j = 0; j < data.numColumns(); j++) |
| 146 | { |
| 147 | data[i][j] = fromValueString<float>(tokens[i * data.numRows() + j]); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | else if constexpr(is_std_vector_v<T>) |
| 152 | { |
| 153 | // This code path parses an array of arbitrary substrings, so we split the string |
| 154 | // in a fashion that preserves substrings with internal spaces. |
| 155 | const string COMMA_SEPARATOR = ","; |
| 156 | for (const string& token : splitString(value, COMMA_SEPARATOR)) |
| 157 | { |
| 158 | typename T::value_type val = fromValueString<typename T::value_type>(trimSpaces(token)); |
| 159 | data.push_back(val); |
| 160 | } |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | std::stringstream ss(value); |
nothing calls this directly
no test coverage detected