microsoft/onnxruntime-extensions
Publicmirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable
base/ustring.h
53lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | #pragma once |
| 4 | |
| 5 | #include "ocos.h" |
| 6 | #include <locale> |
| 7 | #include <codecvt> |
| 8 | |
| 9 | // ustring needs a new implementation, due to the std::codecvt deprecation. |
| 10 | // Wrap u32string with ustring, in case we will use other implementation in the future |
| 11 | class ustring : public std::u32string { |
| 12 | public: |
| 13 | ustring(); |
| 14 | explicit ustring(char* str); |
| 15 | explicit ustring(const char* str); |
| 16 | explicit ustring(std::string& str); |
| 17 | explicit ustring(const std::string& str); |
| 18 | explicit ustring(char32_t* str); |
| 19 | explicit ustring(const char32_t* str); |
| 20 | explicit ustring(std::u32string& str); |
| 21 | explicit ustring(std::u32string&& str); |
| 22 | explicit ustring(const std::u32string& str); |
| 23 | explicit ustring(const std::u32string&& str); |
| 24 | explicit ustring(std::string_view& str); |
| 25 | explicit ustring(const std::string_view& str); |
| 26 | explicit ustring(std::u32string_view& str); |
| 27 | explicit ustring(std::u32string_view&& str); |
| 28 | explicit ustring(const std::u32string_view& str); |
| 29 | explicit ustring(const std::u32string_view&& str); |
| 30 | |
| 31 | explicit operator std::string(); |
| 32 | explicit operator std::string() const; |
| 33 | |
| 34 | private: |
| 35 | using utf8_converter = std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t>; |
| 36 | }; |
| 37 | |
| 38 | namespace std { |
| 39 | template <> |
| 40 | struct hash<ustring> { |
| 41 | size_t operator()(const ustring& __str) const noexcept { |
| 42 | hash<u32string> standard_hash; |
| 43 | return standard_hash(static_cast<u32string>(__str)); |
| 44 | } |
| 45 | }; |
| 46 | } // namespace std |
| 47 | |
| 48 | |
| 49 | void GetTensorMutableDataString(const OrtApi& api, OrtW::CustomOpApi& ort, OrtKernelContext* context, |
| 50 | const OrtValue* value, std::vector<ustring>& output); |
| 51 | |
| 52 | void FillTensorDataString(const OrtApi& api, OrtW::CustomOpApi& ort, OrtKernelContext* context, |
| 53 | const std::vector<ustring>& value, OrtValue* output); |
| 54 | |