inlined_string_field.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
32 #define GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
33 
34 #include <string>
35 #include <utility>
36 
37 #include <google/protobuf/port.h>
39 
40 #include <google/protobuf/port_def.inc>
41 
42 #ifdef SWIG
43 #error "You cannot SWIG proto headers"
44 #endif
45 
46 namespace google {
47 namespace protobuf {
48 
49 class Arena;
50 
51 namespace internal {
52 
53 // InlinedStringField wraps a std::string instance and exposes an API similar to
54 // ArenaStringPtr's wrapping of a std::string* instance. As std::string is
55 // never allocated on the Arena, we expose only the *NoArena methods of
56 // ArenaStringPtr.
57 //
58 // default_value parameters are taken for consistency with ArenaStringPtr, but
59 // are not used for most methods. With inlining, these should be removed from
60 // the generated binary.
61 class PROTOBUF_EXPORT InlinedStringField {
62  public:
63  InlinedStringField() PROTOBUF_ALWAYS_INLINE;
65 
66  void AssignWithDefault(const std::string* default_value,
67  const InlinedStringField& from) PROTOBUF_ALWAYS_INLINE;
68 
69  void ClearToEmpty(const std::string* default_value,
70  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
71  ClearToEmptyNoArena(default_value);
72  }
73  void ClearNonDefaultToEmpty() PROTOBUF_ALWAYS_INLINE {
74  ClearNonDefaultToEmptyNoArena();
75  }
76  void ClearToEmptyNoArena(const std::string* /*default_value*/)
77  PROTOBUF_ALWAYS_INLINE {
78  ClearNonDefaultToEmptyNoArena();
79  }
80  void ClearNonDefaultToEmptyNoArena() PROTOBUF_ALWAYS_INLINE;
81 
82  void ClearToDefault(const std::string* default_value,
83  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
84  ClearToDefaultNoArena(default_value);
85  }
86  void ClearToDefaultNoArena(const std::string* default_value)
87  PROTOBUF_ALWAYS_INLINE;
88 
89  void Destroy(const std::string* default_value,
90  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
91  DestroyNoArena(default_value);
92  }
93  void DestroyNoArena(const std::string* default_value) PROTOBUF_ALWAYS_INLINE;
94 
95  const std::string& Get() const PROTOBUF_ALWAYS_INLINE { return GetNoArena(); }
96  const std::string& GetNoArena() const PROTOBUF_ALWAYS_INLINE;
97 
98  std::string* Mutable(const std::string* default_value,
99  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
100  return MutableNoArena(default_value);
101  }
102  std::string* MutableNoArena(const std::string* default_value)
103  PROTOBUF_ALWAYS_INLINE;
104 
105  std::string* Release(const std::string* default_value, Arena* /*arena*/) {
106  return ReleaseNoArena(default_value);
107  }
109  Arena* /*arena*/) {
110  return ReleaseNonDefaultNoArena(default_value);
111  }
112  std::string* ReleaseNoArena(const std::string* default_value) {
113  return ReleaseNonDefaultNoArena(default_value);
114  }
115  std::string* ReleaseNonDefaultNoArena(const std::string* default_value);
116 
117  void Set(const std::string* default_value, StringPiece value,
118  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
119  SetNoArena(default_value, value);
120  }
121  void SetLite(const std::string* default_value, StringPiece value,
122  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
123  SetNoArena(default_value, value);
124  }
125  void SetNoArena(const std::string* default_value,
126  StringPiece value) PROTOBUF_ALWAYS_INLINE;
127 
128  void Set(const std::string* default_value, const std::string& value,
129  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
130  SetNoArena(default_value, value);
131  }
132  void SetLite(const std::string* default_value, const std::string& value,
133  Arena* /*arena*/) PROTOBUF_ALWAYS_INLINE {
134  SetNoArena(default_value, value);
135  }
136  void SetNoArena(const std::string* default_value,
137  const std::string& value) PROTOBUF_ALWAYS_INLINE;
138 
139  void SetNoArena(const std::string* default_value,
140  std::string&& value) PROTOBUF_ALWAYS_INLINE;
141  void SetAllocated(const std::string* default_value, std::string* value,
142  Arena* /*arena*/) {
143  SetAllocatedNoArena(default_value, value);
144  }
145  void SetAllocatedNoArena(const std::string* default_value,
146  std::string* value);
147  void Swap(InlinedStringField* from) PROTOBUF_ALWAYS_INLINE;
148  std::string* UnsafeMutablePointer();
149  void UnsafeSetDefault(const std::string* default_value);
150  std::string* UnsafeArenaRelease(const std::string* default_value,
151  Arena* arena);
152  void UnsafeArenaSetAllocated(const std::string* default_value,
153  std::string* value, Arena* arena);
154 
155  bool IsDefault(const std::string* /*default_value*/) { return false; }
156 
157  private:
159 };
160 
162 
164  : value_(default_value) {}
165 
167  const std::string* /*default_value*/, const InlinedStringField& from) {
168  value_ = from.value_;
169 }
170 
172  return value_;
173 }
174 
176  return &value_;
177 }
178 
180  const std::string* default_value, std::string* value) {
181  if (value == NULL) {
182  value_.assign(*default_value);
183  } else {
184  value_.assign(std::move(*value));
185  delete value;
186  }
187 }
188 
190  // This is invoked from the generated message's ArenaDtor, which is used to
191  // clean up objects not allocated on the Arena.
192  this->~InlinedStringField();
193 }
194 
196  value_.clear();
197 }
198 
200  const std::string* default_value) {
201  value_.assign(*default_value);
202 }
203 
205  const std::string* default_value) {
206  std::string* released = new std::string(*default_value);
207  value_.swap(*released);
208  return released;
209 }
210 
211 inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
212  StringPiece value) {
213  value_.assign(value.data(), value.length());
214 }
215 
216 inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
217  const std::string& value) {
218  value_.assign(value);
219 }
220 
221 inline void InlinedStringField::SetNoArena(const std::string* /*default_value*/,
222  std::string&& value) {
223  value_.assign(std::move(value));
224 }
225 
227  value_.swap(from->value_);
228 }
229 
231  return &value_;
232 }
233 
235  const std::string* default_value) {
236  value_.assign(*default_value);
237 }
238 
240  const std::string* default_value, Arena* /*arena*/) {
242 }
243 
245  const std::string* default_value, std::string* value, Arena* /*arena*/) {
246  if (value == NULL) {
247  value_.assign(*default_value);
248  } else {
249  value_.assign(*value);
250  }
251 }
252 
253 } // namespace internal
254 } // namespace protobuf
255 } // namespace google
256 
257 #include <google/protobuf/port_undef.inc>
258 
259 #endif // GOOGLE_PROTOBUF_INLINED_STRING_FIELD_H__
google::protobuf.internal::InlinedStringField::UnsafeMutablePointer
std::string * UnsafeMutablePointer()
Definition: inlined_string_field.h:230
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
google::protobuf.internal::InlinedStringField::Set
void Set(const std::string *default_value, StringPiece value, Arena *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:117
benchmarks.python.py_benchmark.const
const
Definition: py_benchmark.py:14
NULL
NULL
Definition: test_security_zap.cpp:405
google::protobuf.internal::InlinedStringField::Release
std::string * Release(const std::string *default_value, Arena *)
Definition: inlined_string_field.h:105
google::protobuf.internal::InlinedStringField::AssignWithDefault
void AssignWithDefault(const std::string *default_value, const InlinedStringField &from) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:166
google::protobuf.internal::InlinedStringField::ClearToDefaultNoArena
void ClearToDefaultNoArena(const std::string *default_value) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:199
google::protobuf.internal::InlinedStringField::UnsafeSetDefault
void UnsafeSetDefault(const std::string *default_value)
Definition: inlined_string_field.h:234
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf.internal::InlinedStringField::UnsafeArenaSetAllocated
void UnsafeArenaSetAllocated(const std::string *default_value, std::string *value, Arena *arena)
Definition: inlined_string_field.h:244
google::protobuf.internal::InlinedStringField::GetNoArena
const std::string & GetNoArena() const PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:171
port.h
google::protobuf.internal::InlinedStringField::DestroyNoArena
void DestroyNoArena(const std::string *default_value) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:189
google::protobuf.internal::InlinedStringField::UnsafeArenaRelease
std::string * UnsafeArenaRelease(const std::string *default_value, Arena *arena)
Definition: inlined_string_field.h:239
google::protobuf.internal::InlinedStringField::ClearToEmptyNoArena
void ClearToEmptyNoArena(const std::string *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:76
stringpiece.h
google::protobuf.internal::InlinedStringField::value_
std::string value_
Definition: inlined_string_field.h:158
google::protobuf::StringPiece
Definition: stringpiece.h:180
google::protobuf.internal::InlinedStringField::SetNoArena
void SetNoArena(const std::string *default_value, StringPiece value) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:211
google::protobuf.internal::InlinedStringField::ReleaseNonDefault
std::string * ReleaseNonDefault(const std::string *default_value, Arena *)
Definition: inlined_string_field.h:108
google::protobuf.internal::InlinedStringField::Swap
void Swap(InlinedStringField *from) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:226
google::protobuf.internal::InlinedStringField
Definition: inlined_string_field.h:61
google::protobuf.internal::InlinedStringField::ClearNonDefaultToEmptyNoArena
void ClearNonDefaultToEmptyNoArena() PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:195
value_
int value_
Definition: gmock-matchers_test.cc:571
google::protobuf.internal::InlinedStringField::SetAllocated
void SetAllocated(const std::string *default_value, std::string *value, Arena *)
Definition: inlined_string_field.h:141
google::protobuf.internal::InlinedStringField::ClearToEmpty
void ClearToEmpty(const std::string *default_value, Arena *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:69
google::protobuf.internal::InlinedStringField::Destroy
void Destroy(const std::string *default_value, Arena *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:89
std
google::protobuf.internal::InlinedStringField::ReleaseNoArena
std::string * ReleaseNoArena(const std::string *default_value)
Definition: inlined_string_field.h:112
google::protobuf.internal::InlinedStringField::SetAllocatedNoArena
void SetAllocatedNoArena(const std::string *default_value, std::string *value)
Definition: inlined_string_field.h:179
google::protobuf.internal::InlinedStringField::InlinedStringField
InlinedStringField() PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:161
default_value
def default_value(type_)
google::protobuf.internal::InlinedStringField::MutableNoArena
std::string * MutableNoArena(const std::string *default_value) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:175
internal
Definition: any.pb.h:40
google::protobuf.internal::InlinedStringField::SetLite
void SetLite(const std::string *default_value, StringPiece value, Arena *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:121
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google::protobuf.internal::InlinedStringField::ReleaseNonDefaultNoArena
std::string * ReleaseNonDefaultNoArena(const std::string *default_value)
Definition: inlined_string_field.h:204
google
Definition: data_proto2_to_proto3_util.h:11
google::protobuf.internal::InlinedStringField::SetLite
void SetLite(const std::string *default_value, const std::string &value, Arena *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:132
google::protobuf.internal::InlinedStringField::Get
const std::string & Get() const PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:95
google::protobuf.internal::InlinedStringField::Set
void Set(const std::string *default_value, const std::string &value, Arena *) PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:128
google::protobuf.internal::InlinedStringField::ClearNonDefaultToEmpty
void ClearNonDefaultToEmpty() PROTOBUF_ALWAYS_INLINE
Definition: inlined_string_field.h:73
google::protobuf.internal::InlinedStringField::IsDefault
bool IsDefault(const std::string *)
Definition: inlined_string_field.h:155


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54