7 namespace simpleformatter {
9 template <
typename ObjectType>
20 template <
typename ObjectType>
24 virtual std::string
const &
name()
const = 0;
28 ObjectType
const &
object)
const = 0;
45 ObjectType
const &
object)
const = 0;
52 ObjectType
const &
object)
const = 0;
57 template <
typename ObjectType,
typename ValueType>
62 typedef std::function<ValueType(ObjectType
const &
object)>
ValueF;
68 std::string
const &
name()
const override;
71 ValueType
value(ObjectType
const &
object)
const;
75 ObjectType
const &
object)
const override;
84 throw std::runtime_error{
"DatumEvaluator::is_fixed_size: Not implemented"};
91 throw std::runtime_error{
92 "DatumEvaluator::component_names: Not implemented"};
98 ObjectType
const &
object)
const override {
99 throw std::runtime_error{
100 "DatumEvaluator::format_vectorized_value: Not implemented"};
119 template <
typename ObjectType,
typename VectorizedValueType>
125 typedef std::function<VectorizedValueType(ObjectType
const &)>
129 typedef std::function<VectorizedValueType(ObjectType
const &,
130 std::vector<std::string> &)>
177 ObjectType
const &
object)
const override;
361 template <
typename ObjectType>
398 virtual void format(std::string
const &value_name,
bool const &value) = 0;
399 virtual void format(std::string
const &value_name,
long const &value) = 0;
400 virtual void format(std::string
const &value_name,
double const &value) = 0;
401 virtual void format(std::string
const &value_name,
402 std::string
const &value) = 0;
403 virtual void format(std::string
const &value_name,
405 virtual void format(std::string
const &value_name,
407 virtual void format(std::string
const &value_name,
416 std::vector<std::string>
const &
errors()
const;
423 std::vector<std::unique_ptr<BaseDatumEvaluator<ObjectType>>>
m_evaluators;
428 template <
typename ObjectType,
typename ValueType>
431 : m_name(_name), m_value_f(_value_f) {}
434 template <
typename ObjectType,
typename ValueType>
440 template <
typename ObjectType,
typename ValueType>
442 ObjectType
const &
object)
const {
443 return m_value_f(
object);
447 template <
typename ObjectType,
typename ValueType>
450 formatter.
format(this->
name(), this->value(
object));
454 template <
typename ObjectType,
typename VectorizedValueType>
458 : m_dynamic_vectorized_value_f(_dynamic_vectorized_value_f),
459 m_is_fixed_size(false) {}
462 template <
typename ObjectType,
typename VectorizedValueType>
465 VectorizedValueF _fixed_vectorized_value_f)
466 : m_fixed_vectorized_value_f(_fixed_vectorized_value_f),
467 m_is_fixed_size(true),
468 m_component_names(_component_names) {}
471 template <
typename ObjectType,
typename ValueType,
typename VectorizedValueType>
472 VectorizedValueType VectorizedDatumEvaluator<
473 ObjectType, ValueType,
474 VectorizedValueType>::vectorized_value(ObjectType
const &
object)
const {
475 if (this->is_fixed_size()) {
476 return m_fixed_vectorized_value_f(
object);
478 return m_vectorized_value_f(
object, m_component_names);
484 template <
typename ObjectType,
typename ValueType,
typename VectorizedValueType>
487 ObjectType
const &
object)
const {
490 auto _vectorized_value = this->vectorized_value(
object);
492 if (_vectorized_value.size() != m_component_names.size()) {
493 std::stringstream msg;
494 msg <<
"Error in DatumEvaluator: component_names.size() != "
495 "vectorized_value.size() ";
496 msg << m_component_names.size() <<
" != " << _vectorized_value.size();
497 throw std::runtime_error(msg.str());
501 auto it = std::begin(_vectorized_value);
502 auto end = std::end(_vectorized_value);
503 auto name_it = m_component_names().begin();
504 for (; it != end; ++it, ++name_it) {
505 formatter.
format(*name_it, *it);
511 template <
typename ObjectType>
513 std::unique_ptr<BaseDatumEvaluator<ObjectType>> evaluator_ptr) {
514 m_evaluators.push_back(std::move(evaluator_ptr));
519 template <
typename ObjectType>
520 template <
typename... Args>
522 std::unique_ptr<BaseDatumEvaluator<ObjectType>> evaluator_ptr,
524 push_back(std::move(evaluator_ptr));
525 push_back(std::forward<Args>(args)...);
529 std::vector<std::string>
const &
errors()
const {
return m_errors; }
581 auto it =
std::find(m_errors.begin(), m_errors.end(), what);
583 if (it == m_errors.end()) {
584 error_index = m_errors.size();
585 m_errors.push_back(what);
587 error_index = std::distance(m_errors.begin(), it);
GenericDatumFormatter< std::string, DataObject > name()
Iterator find(Iterator begin, Iterator end, const T &value, BinaryCompare q)
Equivalent to std::find(begin, end, value), but with custom comparison.
Matrix< long int, Dynamic, Dynamic > MatrixXl