microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
01d3905801f25bb0a159c4de6a5ae5120ca5c6a0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

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
11class 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
38namespace std {
39template <>
40struct 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
49void GetTensorMutableDataString(const OrtApi& api, OrtW::CustomOpApi& ort, OrtKernelContext* context,
50 const OrtValue* value, std::vector<ustring>& output);
51
52void FillTensorDataString(const OrtApi& api, OrtW::CustomOpApi& ort, OrtKernelContext* context,
53 const std::vector<ustring>& value, OrtValue* output);
54