Value.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file common/event/Value.cpp
  3. * @author The ARTIS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * ARTIS - the multimodeling and simulation environment
  8. * This file is a part of the ARTIS environment
  9. *
  10. * Copyright (C) 2013-2022 ULCO http://www.univ-littoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #include "Value.hpp"
  26. namespace artis::common::event {
  27. const Value::ConvertFunctions Value::convert = {
  28. {
  29. typeid(double).hash_code(), [](const Value &value) {
  30. double v;
  31. value.operator()(v);
  32. return std::to_string(v);
  33. }},
  34. {
  35. typeid(int).hash_code(), [](const Value &value) {
  36. int v;
  37. value.operator()(v);
  38. return std::to_string(v);
  39. }},
  40. {
  41. typeid(unsigned int).hash_code(), [](const Value &value) {
  42. unsigned int v;
  43. value.operator()(v);
  44. return std::to_string(v);
  45. }},
  46. {
  47. typeid(bool).hash_code(), [](const Value &value) {
  48. bool v;
  49. value.operator()(v);
  50. return v ? "true" : "false";
  51. }},
  52. {
  53. typeid(char).hash_code(), [](const Value &value) {
  54. char v;
  55. value.operator()(v);
  56. return std::string(&v, 1);
  57. }},
  58. {
  59. typeid(double *).hash_code(), [](const Value &value) {
  60. double *v;
  61. std::string str;
  62. size_t size = value._size / sizeof(double);
  63. value.operator()(v);
  64. for (size_t i = 0; i < size; ++i) {
  65. str += std::to_string(v[i]) + std::string(" ");
  66. }
  67. return str;
  68. }},
  69. {
  70. typeid(int *).hash_code(), [](const Value &value) {
  71. int *v;
  72. std::string str;
  73. size_t size = value._size / sizeof(int);
  74. value.operator()(v);
  75. for (size_t i = 0; i < size; ++i) {
  76. str += std::to_string(v[i]) + std::string(" ");
  77. }
  78. return str;
  79. }},
  80. {
  81. typeid(unsigned int *).hash_code(), [](const Value &value) {
  82. unsigned int *v;
  83. std::string str;
  84. size_t size = value._size / sizeof(unsigned int);
  85. value.operator()(v);
  86. for (size_t i = 0; i < size; ++i) {
  87. str += std::to_string(v[i]) + std::string(" ");
  88. }
  89. return str;
  90. }},
  91. {
  92. typeid(bool *).hash_code(), [](const Value &value) {
  93. bool *v;
  94. std::string str;
  95. size_t size = value._size / sizeof(bool);
  96. value.operator()(v);
  97. for (size_t i = 0; i < size; ++i) {
  98. str += (v[i] ? "true" : "false") + std::string(" ");
  99. }
  100. return str;
  101. }},
  102. {
  103. typeid(char *).hash_code(), [](const Value &value) {
  104. char *v;
  105. value.operator()(v);
  106. return std::string(v, value._size / sizeof(char));
  107. }
  108. }};
  109. std::ostream &operator<<(std::ostream &o, const artis::common::event::Value &value) {
  110. o << value.to_string();
  111. return o;
  112. }
  113. } // namespace artis common event