153{
154 try
155 {
156
157 m_errors.erase(prop_type);
158
159
160 if (value.empty() && enable_test_empty)
161 throw std::invalid_argument (
_(
"Column value can not be empty."));
162
163 gnc_commodity *comm = nullptr;
164 switch (prop_type)
165 {
166 case GncPricePropType::DATE:
167 m_date.reset();
169 break;
170
171 case GncPricePropType::AMOUNT:
172 m_amount.reset();
173 m_amount = parse_amount_price (value, m_currency_format);
174 break;
175
176 case GncPricePropType::FROM_SYMBOL:
177 m_from_symbol.reset();
178
179 if (value.empty())
180 throw std::invalid_argument (
_(
"'From Symbol' can not be empty."));
181 else
182 m_from_symbol = value;
183
184 if (m_from_namespace)
185 {
186 comm = parse_commodity_price_comm (value, *m_from_namespace);
187 if (comm)
188 {
189 if (m_to_currency == comm)
190 throw std::invalid_argument (
_(
"'Commodity From' can not be the same as 'Currency To'."));
191 m_from_commodity = comm;
192 }
193 }
194 break;
195
196 case GncPricePropType::FROM_NAMESPACE:
197 m_from_namespace.reset();
198
199 if (value.empty())
200 throw std::invalid_argument (
_(
"'From Namespace' can not be empty."));
201
202 if (parse_namespace (value))
203 {
204 m_from_namespace = value;
205
206 if (m_from_symbol)
207 {
208 comm = parse_commodity_price_comm (*m_from_symbol, *m_from_namespace);
209 if (comm)
210 {
211 if (m_to_currency == comm)
212 throw std::invalid_argument (
_(
"'Commodity From' can not be the same as 'Currency To'."));
213 m_from_commodity = comm;
214 }
215 }
216 }
217 break;
218
219 case GncPricePropType::TO_CURRENCY:
220 m_to_currency.reset();
221 comm = parse_commodity_price_comm (value, GNC_COMMODITY_NS_CURRENCY);
222 if (comm)
223 {
224 if (m_from_commodity == comm)
225 throw std::invalid_argument (
_(
"'Currency To' can not be the same as 'Commodity From'."));
227 throw std::invalid_argument (
_(
"Value parsed into an invalid currency for a currency column type."));
228 m_to_currency = comm;
229 }
230 break;
231
232 default:
233
234 PWARN (
"%d is an invalid property for a Price",
static_cast<int>(prop_type));
235 break;
236 }
237 }
238 catch (const std::invalid_argument& e)
239 {
240 auto err_str = (bl::format (std::string{
_(
"{1}: {2}")}) %
241 std::string{
_(gnc_price_col_type_strs[prop_type])} %
242 e.what()).str();
243 m_errors.emplace(prop_type, err_str);
244 throw std::invalid_argument (err_str);
245 }
246 catch (const std::out_of_range& e)
247 {
248 auto err_str = (bl::format (std::string{
_(
"{1}: {2}")}) %
249 std::string{
_(gnc_price_col_type_strs[prop_type])} %
250 e.what()).str();
251 m_errors.emplace(prop_type, err_str);
252 throw std::invalid_argument (err_str);
253 }
254}
static const std::vector< GncDateFormat > c_formats
A vector with all the date formats supported by the string constructor.
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency.