MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / tstring

Class tstring

tensorflow/core/platform/tstring.h:49–187  ·  view source on GitHub ↗

tensorflow::tstring is the scalar type for DT_STRING tensors. TODO(b/138799229): In order to ease migration from tensorflow::string to tensorflow::tstring, we define a simplified tstring class which wraps std::string. The API defined below is the expected subset of methods for tstring. The underlying implementation of tstring will be replaced with the one defined in [1] once the migration in te

Source from the content-addressed store, hash-verified

47//
48// [1] https://github.com/tensorflow/community/pull/91
49class tstring {
50 std::string str_;
51
52 template <typename T, typename = void>
53 struct ResizeUninitialized {
54 static void Resize(T& s, size_t new_size) { s.resize(new_size); }
55 };
56
57 template <typename T>
58 struct ResizeUninitialized<
59 T, decltype(std::declval<T>().__resize_default_init(0))> {
60 static void Resize(T& s, size_t new_size) {
61 s.__resize_default_init(new_size);
62 }
63 };
64
65 public:
66 tstring() = default;
67
68 tstring(const tstring&) = default;
69
70 tstring(const std::string& str) : str_(str) {}
71
72 tstring(const char* str, size_t len) : str_(str, len) {}
73
74 tstring(const char* str) : str_(str) {}
75
76 explicit tstring(const StringPiece str) : tstring(str.data(), str.size()) {}
77
78 template <typename T,
79 typename std::enable_if<std::is_same<T, absl::string_view>::value,
80 T>::type* = nullptr>
81 explicit tstring(const T& str) : str_(str.data(), str.size()) {}
82
83 tstring(tstring&&) noexcept = default;
84
85 ~tstring() = default;
86
87 tstring& operator=(const tstring& str) = default;
88
89 tstring& operator=(const StringPiece str) {
90 str_.assign(str.data(), str.size());
91 return *this;
92 }
93
94 tstring& operator=(const std::string& str) {
95 str_ = str;
96
97 return *this;
98 }
99
100 template <typename T,
101 typename std::enable_if<std::is_same<T, absl::string_view>::value,
102 T>::type* = nullptr>
103 tstring& operator=(const T& str) {
104 str_.assign(str.data(), str.size());
105
106 return *this;

Callers 9

ParseRowMethod · 0.85
ParseRowMethod · 0.85
TensorMethod · 0.85
TESTFunction · 0.85
operator()Method · 0.85
AsGraphDefInternalMethod · 0.85
AsGraphDefInternalMethod · 0.85
operator+Function · 0.85
ReadEntireFileFunction · 0.85

Calls 3

assignMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68