Project
Loading...
Searching...
No Matches
RootSerializableKeyValueStore.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <iostream>
14
15using namespace o2::utils;
16
17namespace
18{
19template <typename T>
20std::string stringFromType(char* buffer)
21{
22 T value;
23 std::memcpy(&value, buffer, sizeof(T));
24 return std::to_string(value);
25}
26} // namespace
27
28void RootSerializableKeyValueStore::print(bool includetypeinfo) const
29{
30 for (auto& p : mStore) {
31 const auto& key = p.first;
32 const auto info = p.second;
33 auto tinfo = info.typeinfo_name;
34
35 std::string value("unknown-value");
36 // let's try to decode the value as a string if we can
37 if (tinfo == typeid(int).name()) {
38 value = stringFromType<int>(info.bufferptr);
39 }
40 // let's try to decode the value as a string if we can
41 else if (tinfo == typeid(unsigned int).name()) {
42 value = stringFromType<unsigned int>(info.bufferptr);
43 }
44 // let's try to decode the value as a string if we can
45 else if (tinfo == typeid(short).name()) {
46 value = stringFromType<short>(info.bufferptr);
47 }
48 // let's try to decode the value as a string if we can
49 else if (tinfo == typeid(unsigned short).name()) {
50 value = stringFromType<unsigned short>(info.bufferptr);
51 }
52 // let's try to decode the value as a string if we can
53 else if (tinfo == typeid(double).name()) {
54 value = stringFromType<double>(info.bufferptr);
55 }
56 // let's try to decode the value as a string if we can
57 else if (tinfo == typeid(float).name()) {
58 value = stringFromType<float>(info.bufferptr);
59 }
60 // let's try to decode the value as a string if we can
61 else if (tinfo == typeid(std::string).name()) {
63 }
64 std::cout << "key: " << key << " value: " << value;
65 if (includetypeinfo) {
66 std::cout << " type: " << info.typeinfo_name;
67 }
68 std::cout << "\n";
69 }
70}
StringRef key
void print(bool includetypeinfo=false) const
print list of keys, values (and optionally type information)
GLuint buffer
Definition glcorearb.h:655
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
template std::string ConfigParamRegistry::get< std::string >(const char *key) const
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52