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#pragma once 2 3namespace ComLight 4{ 5// COM smart pointer, very comparable to CComPtr from ATL 6template < class I > 7class CComPtr 8 { 9I * p ; 10 11void callAddRef ()const 12 { 13if (nullptr == p ) 14return ; 15p -> AddRef (); 16 } 17 18public : 19 20// Construct with nullptr 21CComPtr () :p (nullptr ) { } 22 23// Release the pointer 24void release () 25 { 26if (nullptr == p ) 27return ; 28p -> Release (); 29p = nullptr ; 30 } 31 32 ~CComPtr () 33 { 34release (); 35 } 36 37// Attach without AddRef() 38void attach (I * raw ) 39 { 40release (); 41p = raw ; 42 } 43 44// Detach without Release(), set this pointer to nullptr 45I * detach () 46 { 47I * const result = p ; 48p = nullptr ; 49return result ; 50 } 51 52// Detach without Release() and place to the specified address, set this pointer to nullptr 53template < class Other > 54void detach (Other ** pp ) 55 { 56// If the argument points to a non-empty object, release the old instance: would leak memory otherwise. 57if (nullptr != * pp ) 58 (* pp )-> Release (); 59 (* pp )= detach (); 60 } 61 62// Set and AddRef() 63void assign (I * raw ) 64 { 65release (); 66attach (raw ); 67callAddRef (); 68 } 69 70void swap (CComPtr < I >& that ) 71 { 72 std::swap (p ,that .p ); 73 } 74 75// Set and AddRef() 76CComPtr (I * raw ) :p (raw ) 77 { 78callAddRef (); 79 } 80 81// Set and AddRef() 82CComPtr (const CComPtr < I >& that ) :CComPtr (that .p ) { } 83// Move constructor 84CComPtr (CComPtr < I >&& that ) :p (that .p ) {that .p = nullptr ; } 85 86// Set and AddRef() 87void operator= (I * raw ) 88 { 89assign (raw ); 90 } 91 92// Set and AddRef() 93void operator= (const CComPtr < I >& that ) 94 { 95assign (that .p ); 96 } 97 98// Move assignment operator, destroys the other one 99void operator= (CComPtr < I >&& that ) 100 { 101attach (that .detach () ); 102 } 103 104 operatorI * ( )const {return p ; } 105I * operator-> ()const {return p ; } 106I ** operator& () {return & p ; } 107 108 operatorbool ()const {return nullptr != p ; } 109 }; 110}