yum-archive/TaSTT-Whisper
High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model
git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper
8c4603c
master
1// https://github.com/tobias-loew/constexpr-GUID-cpp-11 2 3//------------------------------------------------------------------------------------------------------- 4// constexpr GUID parsing 5// Written by Alexander Bessonov 6// Written by Tobias Loew 7// 8// Licensed under the MIT license. 9//------------------------------------------------------------------------------------------------------- 10 11#pragma once 12#include <stdexcept> 13#include <string> 14#include <cassert> 15#include <cstdint> 16 17#if !defined(GUID_DEFINED ) 18#define GUID_DEFINED 19struct GUID { 20uint32_t Data1 ; 21uint16_t Data2 ; 22uint16_t Data3 ; 23uint8_t Data4 [8 ]; 24}; 25#endif 26 27namespace ComLight 28{ 29namespace details 30 { 31constexpr const size_t short_guid_form_length = 36 ;// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 32constexpr const size_t long_guid_form_length = 38 ;// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} 33 34constexpr uint8_t parse_hex_digit (const char c ) 35 { 36using namespace std::string_literals ; 37return 38 ('0' <=c && c <='9' ) 39 ?c - '0' 40 : ('a' <=c && c <='f' ) 41 ?10 + c - 'a' 42 : ('A' <=c && c <='F' ) 43 ?10 + c - 'A' 44 : 45 throwstd ::domain_error {"invalid character in GUID" s }; 46 } 47 48constexpr uint8_t parse_hex_uint8_t (const char * ptr ) 49 { 50return (parse_hex_digit (ptr [0 ] ) <<4 )+ parse_hex_digit (ptr [1 ] ); 51 } 52 53constexpr uint16_t parse_hex_uint16_t (const char * ptr ) 54 { 55return (parse_hex_uint8_t (ptr ) <<8 )+ parse_hex_uint8_t (ptr + 2 ); 56 } 57 58constexpr uint32_t parse_hex_uint32_t (const char * ptr ) 59 { 60return (parse_hex_uint16_t (ptr ) <<16 )+ parse_hex_uint16_t (ptr + 4 ); 61 } 62 63constexpr GUID parse_guid (const char * begin ) 64 { 65return GUID { 66parse_hex_uint32_t (begin ), 67parse_hex_uint16_t (begin + 8 + 1 ), 68parse_hex_uint16_t (begin + 8 + 1 + 4 + 1 ), 69 { 70parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 ), 71parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 ), 72parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 + 2 + 1 ), 73parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 + 2 + 1 + 2 ), 74parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 + 2 + 1 + 2 + 2 ), 75parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 + 2 + 1 + 2 + 2 + 2 ), 76parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 + 2 + 1 + 2 + 2 + 2 + 2 ), 77parse_hex_uint8_t (begin + 8 + 1 + 4 + 1 + 4 + 1 + 2 + 2 + 1 + 2 + 2 + 2 + 2 + 2 ) 78 } 79 }; 80 } 81 82constexpr GUID make_guid_helper (const char * str ,size_t N ) 83 { 84using namespace std::string_literals ; 85using namespace details ; 86 87return ( !(N == long_guid_form_length || N == short_guid_form_length ) ) 88 ? throwstd ::domain_error {"String GUID of the form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} or XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX is expected" s } 89 : (N == long_guid_form_length && (str [0 ]!= '{' || str [long_guid_form_length - 1 ]!= '}' ) ) 90 ? throwstd ::domain_error {"Missing opening or closing brace" s } 91 92 :parse_guid (str + (N == long_guid_form_length ?1 :0 ) ); 93 } 94 95 96template < size_t N > 97constexpr GUID make_guid (const char (& str )[N ] ) 98 { 99return make_guid_helper (str ,N - 1 ); 100 } 101 } 102using details::make_guid ; 103}