Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions
utils.h File Reference
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <stdint.h>

Go to the source code of this file.

Classes

class  double_conversion::Vector< T >
 
class  double_conversion::StringBuilder
 

Namespaces

namespace  double_conversion
 

Macros

#define DOUBLE_CONVERSION_NULLPTR   NULL
 
#define DOUBLE_CONVERSION_ASSERT(condition)    assert(condition)
 
#define DOUBLE_CONVERSION_UNIMPLEMENTED()   (abort())
 
#define DOUBLE_CONVERSION_NO_RETURN   __attribute__((noreturn))
 
#define DOUBLE_CONVERSION_UNREACHABLE()   (abort())
 
#define DOUBLE_CONVERSION_HAS_ATTRIBUTE(x)   0
 
#define DOUBLE_CONVERSION_UNUSED
 
#define DOUBLE_CONVERSION_STACK_UNINITIALIZED
 
#define DOUBLE_CONVERSION_UINT64_2PART_C(a, b)   (((static_cast<uint64_t>(a) << 32) + 0x##b##u))
 
#define DOUBLE_CONVERSION_ARRAY_SIZE(a)
 
#define DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN(TypeName)
 
#define DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
 

Typedefs

typedef uint16_t uc16
 

Functions

int double_conversion::StrLength (const char *string)
 
template<class Dest , class Source >
Dest double_conversion::BitCast (const Source &source)
 
template<class Dest , class Source >
Dest double_conversion::BitCast (Source *source)
 

Macro Definition Documentation

◆ DOUBLE_CONVERSION_ARRAY_SIZE

#define DOUBLE_CONVERSION_ARRAY_SIZE (   a)
Value:
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
struct MyStruct a[10]

Definition at line 205 of file utils.h.

239 {
240
241inline int StrLength(const char* string) {
242 size_t length = strlen(string);
243 DOUBLE_CONVERSION_ASSERT(length == static_cast<size_t>(static_cast<int>(length)));
244 return static_cast<int>(length);
245}
246
247// This is a simplified version of V8's Vector class.
248template <typename T>
249class Vector {
250 public:
251 Vector() : start_(DOUBLE_CONVERSION_NULLPTR), length_(0) {}
252 Vector(T* data, int len) : start_(data), length_(len) {
253 DOUBLE_CONVERSION_ASSERT(len == 0 || (len > 0 && data != DOUBLE_CONVERSION_NULLPTR));
254 }
255
256 // Returns a vector using the same backing storage as this one,
257 // spanning from and including 'from', to but not including 'to'.
258 Vector<T> SubVector(int from, int to) {
259 DOUBLE_CONVERSION_ASSERT(to <= length_);
260 DOUBLE_CONVERSION_ASSERT(from < to);
261 DOUBLE_CONVERSION_ASSERT(0 <= from);
262 return Vector<T>(start() + from, to - from);
263 }
264
265 // Returns the length of the vector.
266 int length() const { return length_; }
267
268 // Returns whether or not the vector is empty.
269 bool is_empty() const { return length_ == 0; }
270
271 // Returns the pointer to the start of the data in the vector.
272 T* start() const { return start_; }
273
274 // Access individual vector elements - checks bounds in debug mode.
275 T& operator[](int index) const {
276 DOUBLE_CONVERSION_ASSERT(0 <= index && index < length_);
277 return start_[index];
278 }
279
280 T& first() { return start_[0]; }
281
282 T& last() { return start_[length_ - 1]; }
283
284 void pop_back() {
286 --length_;
287 }
288
289 private:
290 T* start_;
291 int length_;
292};
293
294
295// Helper class for building result strings in a character buffer. The
296// purpose of the class is to use safe operations that checks the
297// buffer bounds on all operations in debug mode.
298class StringBuilder {
299 public:
300 StringBuilder(char* buffer, int buffer_size)
301 : buffer_(buffer, buffer_size), position_(0) { }
302
303 ~StringBuilder() { if (!is_finalized()) Finalize(); }
304
305 int size() const { return buffer_.length(); }
306
307 // Get the current position in the builder.
308 int position() const {
309 DOUBLE_CONVERSION_ASSERT(!is_finalized());
310 return position_;
311 }
312
313 // Reset the position.
314 void Reset() { position_ = 0; }
315
316 // Add a single character to the builder. It is not allowed to add
317 // 0-characters; use the Finalize() method to terminate the string
318 // instead.
319 void AddCharacter(char c) {
320 DOUBLE_CONVERSION_ASSERT(c != '\0');
321 DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ < buffer_.length());
322 buffer_[position_++] = c;
323 }
324
325 // Add an entire string to the builder. Uses strlen() internally to
326 // compute the length of the input string.
327 void AddString(const char* s) {
328 AddSubstring(s, StrLength(s));
329 }
330
331 // Add the first 'n' characters of the given string 's' to the
332 // builder. The input string must have enough characters.
333 void AddSubstring(const char* s, int n) {
334 DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ + n < buffer_.length());
335 DOUBLE_CONVERSION_ASSERT(static_cast<size_t>(n) <= strlen(s));
336 memmove(&buffer_[position_], s, static_cast<size_t>(n));
337 position_ += n;
338 }
339
340
341 // Add character padding to the builder. If count is non-positive,
342 // nothing is added to the builder.
343 void AddPadding(char c, int count) {
344 for (int i = 0; i < count; i++) {
345 AddCharacter(c);
346 }
347 }
348
349 // Finalize the string by 0-terminating it and returning the buffer.
350 char* Finalize() {
351 DOUBLE_CONVERSION_ASSERT(!is_finalized() && position_ < buffer_.length());
352 buffer_[position_] = '\0';
353 // Make sure nobody managed to add a 0-character to the
354 // buffer while building the string.
355 DOUBLE_CONVERSION_ASSERT(strlen(buffer_.start()) == static_cast<size_t>(position_));
356 position_ = -1;
357 DOUBLE_CONVERSION_ASSERT(is_finalized());
358 return buffer_.start();
359 }
360
361 private:
362 Vector<char> buffer_;
363 int position_;
364
365 bool is_finalized() const { return position_ < 0; }
366
368};
369
370// The type-based aliasing rule allows the compiler to assume that pointers of
371// different types (for some definition of different) never alias each other.
372// Thus the following code does not work:
373//
374// float f = foo();
375// int fbits = *(int*)(&f);
376//
377// The compiler 'knows' that the int pointer can't refer to f since the types
378// don't match, so the compiler may cache f in a register, leaving random data
379// in fbits. Using C++ style casts makes no difference, however a pointer to
380// char data is assumed to alias any other pointer. This is the 'memcpy
381// exception'.
382//
383// Bit_cast uses the memcpy exception to move the bits from a variable of one
384// type of a variable of another type. Of course the end result is likely to
385// be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005)
386// will completely optimize BitCast away.
387//
388// There is an additional use for BitCast.
389// Recent gccs will warn when they see casts that may result in breakage due to
390// the type-based aliasing rule. If you have checked that there is no breakage
391// you can use BitCast to cast one pointer type to another. This confuses gcc
392// enough that it can no longer see that you have cast one pointer type to
393// another thus avoiding the warning.
394template <class Dest, class Source>
395Dest BitCast(const Source& source) {
396 // Compile time assertion: sizeof(Dest) == sizeof(Source)
397 // A compile error here means your Dest and Source have different sizes.
398#if __cplusplus >= 201103L
399 static_assert(sizeof(Dest) == sizeof(Source),
400 "source and destination size mismatch");
401#else
403 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
404#endif
405
406 Dest dest;
407 memmove(&dest, &source, sizeof(dest));
408 return dest;
409}
410
411template <class Dest, class Source>
412Dest BitCast(Source* source) {
413 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source));
414}
415
416} // namespace double_conversion
417
418#endif // DOUBLE_CONVERSION_UTILS_H_
int count
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
static void is_empty(skiatest::Reporter *reporter, const SkPath &p)
SkBitmap source
Definition examples.cpp:28
struct MyStruct s
static const uint8_t buffer[]
size_t length
Dest BitCast(const Source &source)
Definition utils.h:395
int StrLength(const char *string)
Definition utils.h:241
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
void Reset(SkPath *path)
Definition path_ops.cc:40
dest
Definition zip.py:79
#define T
#define DOUBLE_CONVERSION_NULLPTR
Definition utils.h:41
#define DOUBLE_CONVERSION_UNUSED
Definition utils.h:96
#define DOUBLE_CONVERSION_ASSERT(condition)
Definition utils.h:46
#define DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName)
Definition utils.h:231

◆ DOUBLE_CONVERSION_ASSERT

#define DOUBLE_CONVERSION_ASSERT (   condition)     assert(condition)

Definition at line 46 of file utils.h.

◆ DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN

#define DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN (   TypeName)
Value:
TypeName(const TypeName&); \
void operator=(const TypeName&)

Definition at line 216 of file utils.h.

◆ DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS

#define DOUBLE_CONVERSION_DISALLOW_IMPLICIT_CONSTRUCTORS (   TypeName)
Value:
TypeName(); \
DOUBLE_CONVERSION_DISALLOW_COPY_AND_ASSIGN(TypeName)

Definition at line 231 of file utils.h.

◆ DOUBLE_CONVERSION_HAS_ATTRIBUTE

#define DOUBLE_CONVERSION_HAS_ATTRIBUTE (   x)    0

Definition at line 89 of file utils.h.

◆ DOUBLE_CONVERSION_NO_RETURN

#define DOUBLE_CONVERSION_NO_RETURN   __attribute__((noreturn))

Definition at line 64 of file utils.h.

◆ DOUBLE_CONVERSION_NULLPTR

#define DOUBLE_CONVERSION_NULLPTR   NULL

Definition at line 41 of file utils.h.

◆ DOUBLE_CONVERSION_STACK_UNINITIALIZED

#define DOUBLE_CONVERSION_STACK_UNINITIALIZED

Definition at line 106 of file utils.h.

◆ DOUBLE_CONVERSION_UINT64_2PART_C

#define DOUBLE_CONVERSION_UINT64_2PART_C (   a,
  b 
)    (((static_cast<uint64_t>(a) << 32) + 0x##b##u))

Definition at line 195 of file utils.h.

◆ DOUBLE_CONVERSION_UNIMPLEMENTED

#define DOUBLE_CONVERSION_UNIMPLEMENTED ( )    (abort())

Definition at line 54 of file utils.h.

◆ DOUBLE_CONVERSION_UNREACHABLE

#define DOUBLE_CONVERSION_UNREACHABLE ( )    (abort())

Definition at line 77 of file utils.h.

◆ DOUBLE_CONVERSION_UNUSED

#define DOUBLE_CONVERSION_UNUSED

Definition at line 96 of file utils.h.

Typedef Documentation

◆ uc16

typedef uint16_t uc16

Definition at line 190 of file utils.h.