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 <cstring>
19#include <cstdint>
20#include <string>
21#include <type_traits>
22
23template <class T = uint64_t, std::size_t N>
24constexpr T qStr2Tag(const char (&str)[N])
25{
26 static_assert(std::is_trivially_copyable_v<T>);
27 static_assert(N - 1 == sizeof(T), "Invalid tag length");
28 T value{};
29 for (std::size_t i = 0; i < sizeof(T); ++i) {
30 value |= T(static_cast<unsigned char>(str[i])) << (i * 8);
31 }
32 return value;
33}
34
35template <class T>
36std::string qTag2Str(const T tag)
37{
38 T str[2];
39 str[0] = tag;
40 str[1] = 0;
41 return std::string((const char*)str);
42}
43
44#endif
int32_t i
GLsizei const GLfloat * value
Definition glcorearb.h:819
constexpr T qStr2Tag(const char(&str)[N])
Definition strtag.h:24
std::string qTag2Str(const T tag)
Definition strtag.h:36
const std::string str