/** * @file common/event/Value.cpp * @author The ARTIS Development Team * See the AUTHORS or Authors.txt file */ /* * ARTIS - the multimodeling and simulation environment * This file is a part of the ARTIS environment * * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "Value.hpp" namespace artis::common::event { const Value::ConvertFunctions Value::convert = { { typeid(double).hash_code(), [](const Value &value) { double v; value.operator()(v); return std::to_string(v); }}, { typeid(int).hash_code(), [](const Value &value) { int v; value.operator()(v); return std::to_string(v); }}, { typeid(unsigned int).hash_code(), [](const Value &value) { unsigned int v; value.operator()(v); return std::to_string(v); }}, { typeid(bool).hash_code(), [](const Value &value) { bool v; value.operator()(v); return v ? "true" : "false"; }}, { typeid(char).hash_code(), [](const Value &value) { char v; value.operator()(v); return std::string(&v, 1); }}, { typeid(double *).hash_code(), [](const Value &value) { double *v; std::string str; size_t size = value._size / sizeof(double); value.operator()(v); for (size_t i = 0; i < size; ++i) { str += std::to_string(v[i]) + std::string(" "); } return str; }}, { typeid(int *).hash_code(), [](const Value &value) { int *v; std::string str; size_t size = value._size / sizeof(int); value.operator()(v); for (size_t i = 0; i < size; ++i) { str += std::to_string(v[i]) + std::string(" "); } return str; }}, { typeid(unsigned int *).hash_code(), [](const Value &value) { unsigned int *v; std::string str; size_t size = value._size / sizeof(unsigned int); value.operator()(v); for (size_t i = 0; i < size; ++i) { str += std::to_string(v[i]) + std::string(" "); } return str; }}, { typeid(bool *).hash_code(), [](const Value &value) { bool *v; std::string str; size_t size = value._size / sizeof(bool); value.operator()(v); for (size_t i = 0; i < size; ++i) { str += (v[i] ? "true" : "false") + std::string(" "); } return str; }}, { typeid(char *).hash_code(), [](const Value &value) { char *v; value.operator()(v); return std::string(v, value._size / sizeof(char)); } }}; std::ostream &operator<<(std::ostream &o, const artis::common::event::Value &value) { o << value.to_string(); return o; } } // namespace artis common event