Project
Loading...
Searching...
No Matches
strtag.h
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
14
15#ifndef STRTAG_H
16#define STRTAG_H
17
18#include <stdexcept>
19#include <string>
20
21template <class T = uint64_t>
22constexpr T qStr2Tag(const char* str)
23{
24 if (strlen(str) != sizeof(T)) {
25 throw std::runtime_error("Invalid tag length");
26 }
27 T tmp;
28 for (uint32_t i = 0; i < sizeof(T); i++) {
29 ((char*)&tmp)[i] = str[i];
30 }
31 return tmp;
32}
33
34template <class T>
35std::string qTag2Str(const T tag)
36{
37 T str[2];
38 str[0] = tag;
39 str[1] = 0;
40 return std::string((const char*)str);
41}
42
43#endif
int32_t i
constexpr T qStr2Tag(const char *str)
Definition strtag.h:22
std::string qTag2Str(const T tag)
Definition strtag.h:35
const std::string str