Flutter Engine
The Flutter Engine
Namespaces | Classes | Typedefs | Functions | Variables
base Namespace Reference

Namespaces

namespace  internal
 
namespace  testing
 
namespace  win
 

Classes

class  AutoReset
 
struct  DefaultSingletonTraits
 
class  LogMessage
 
class  LogMessageVoidify
 
class  NoDestructor
 
class  scoped_nsobject
 
class  scoped_nsobject< id >
 
class  scoped_nsobject< NSAutoreleasePool >
 
class  scoped_nsprotocol
 
class  SimpleToken
 

Typedefs

using SizeT = StrictNumeric< size_t >
 

Functions

template<class T , class Allocator , class Predicate >
size_t EraseIf (std::vector< T, Allocator > &container, Predicate pred)
 
template<typename Container , typename Value >
bool Contains (const Container &container, const Value &value)
 
template<typename T >
bool Contains (const std::vector< T > &container, const T &value)
 
void KillProcess ()
 
template<class T >
constexpr const TClampToRange (const T &value, const T &min, const T &max)
 
template<typename T >
constexpr bool IsApproximatelyEqual (T lhs, T rhs, T tolerance)
 
template<typename Dst = int, typename Src , typename = std::enable_if_t<std::is_integral<Dst>::value && std::is_floating_point<Src>::value>>
Dst ClampFloor (Src value)
 
template<typename Dst = int, typename Src , typename = std::enable_if_t<std::is_integral<Dst>::value && std::is_floating_point<Src>::value>>
Dst ClampCeil (Src value)
 
template<typename Dst = int, typename Src , typename = std::enable_if_t<std::is_integral<Dst>::value && std::is_floating_point<Src>::value>>
Dst ClampRound (Src value)
 
template<class C >
void swap (scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
 
template<class C >
bool operator== (C p1, const scoped_nsprotocol< C > &p2)
 
template<class C >
bool operator!= (C p1, const scoped_nsprotocol< C > &p2)
 
std::ostream & operator<< (std::ostream &out, const SimpleToken &token)
 
std::optional< base::SimpleTokenValueToSimpleToken (std::string str)
 
std::string SimpleTokenToValue (const SimpleToken &token)
 
size_t SimpleTokenHash (const SimpleToken &SimpleToken)
 
std::u16string ASCIIToUTF16 (std::string src)
 
std::u16string UTF8ToUTF16 (std::string src)
 
std::string UTF16ToUTF8 (std::u16string src)
 
std::u16string NumberToString16 (float number)
 
std::u16string NumberToString16 (int32_t number)
 
std::u16string NumberToString16 (unsigned int number)
 
std::u16string NumberToString16 (double number)
 
std::string NumberToString (int32_t number)
 
std::string NumberToString (unsigned int number)
 
std::string NumberToString (float number)
 
std::string NumberToString (double number)
 
std::string JoinString (std::vector< std::string > tokens, std::string delimiter)
 
std::u16string JoinString (std::vector< std::u16string > tokens, std::u16string delimiter)
 
void ReplaceChars (std::string in, std::string from, std::string to, std::string *out)
 
void ReplaceChars (std::u16string in, std::u16string from, std::u16string to, std::u16string *out)
 
const std::string & EmptyString ()
 
std::string ToUpperASCII (std::string str)
 
std::string ToLowerASCII (std::string str)
 
bool LowerCaseEqualsASCII (std::string a, std::string b)
 
bool ContainsOnlyChars (std::u16string str, char16_t ch)
 
template<typename... Args>
std::string StringPrintf (const std::string &format, Args... args)
 
 TEST (StringUtilsTest, StringPrintfEmpty)
 
 TEST (StringUtilsTest, StringPrintfMisc)
 
 TEST (StringUtilsTest, StringPrintfErrno)
 
 TEST (StringUtilsTest, canASCIIToUTF16)
 
 TEST (StringUtilsTest, canUTF8ToUTF16)
 
 TEST (StringUtilsTest, canUTF16ToUTF8)
 
 TEST (StringUtilsTest, canNumberToString16)
 
 TEST (StringUtilsTest, numberToStringSimplifiesOutput)
 

Variables

constexpr double kPiDouble = 3.14159265358979323846
 
constexpr float kPiFloat = 3.14159265358979323846f
 
constexpr double kMeanGravityDouble = 9.80665
 
constexpr float kMeanGravityFloat = 9.80665f
 
constexpr size_t kRandomTokenLength = 10
 
constexpr char16_t kWhitespaceUTF16 = u' '
 

Typedef Documentation

◆ SizeT

using base::SizeT = typedef StrictNumeric<size_t>

Definition at line 357 of file safe_conversions.h.

Function Documentation

◆ ASCIIToUTF16()

std::u16string base::ASCIIToUTF16 ( std::string  src)

Definition at line 63 of file string_utils.cc.

63 {
64 return std::u16string(src.begin(), src.end());
65}

◆ ClampCeil()

template<typename Dst = int, typename Src , typename = std::enable_if_t<std::is_integral<Dst>::value && std::is_floating_point<Src>::value>>
Dst base::ClampCeil ( Src  value)

Definition at line 373 of file safe_conversions.h.

373 {
374 return saturated_cast<Dst>(std::ceil(value));
375}
uint8_t value
SIN Vec< N, float > ceil(const Vec< N, float > &x)
Definition: SkVx.h:702

◆ ClampFloor()

template<typename Dst = int, typename Src , typename = std::enable_if_t<std::is_integral<Dst>::value && std::is_floating_point<Src>::value>>
Dst base::ClampFloor ( Src  value)

Definition at line 366 of file safe_conversions.h.

366 {
367 return saturated_cast<Dst>(std::floor(value));
368}
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition: SkVx.h:703

◆ ClampRound()

template<typename Dst = int, typename Src , typename = std::enable_if_t<std::is_integral<Dst>::value && std::is_floating_point<Src>::value>>
Dst base::ClampRound ( Src  value)

Definition at line 380 of file safe_conversions.h.

380 {
381 const Src rounded =
382 (value >= 0.0f) ? std::floor(value + 0.5f) : std::ceil(value - 0.5f);
383 return saturated_cast<Dst>(rounded);
384}

◆ ClampToRange()

template<class T >
constexpr const T & base::ClampToRange ( const T value,
const T min,
const T max 
)
constexpr

Definition at line 15 of file ranges.h.

15 {
16 return std::min(std::max(value, min), max);
17}
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ Contains() [1/2]

template<typename Container , typename Value >
bool base::Contains ( const Container &  container,
const Value value 
)

Definition at line 22 of file container_utils.h.

22 {
23 return container.find(value) != container.end();
24}

◆ Contains() [2/2]

template<typename T >
bool base::Contains ( const std::vector< T > &  container,
const T value 
)

Definition at line 27 of file container_utils.h.

27 {
28 return std::find(container.begin(), container.end(), value) !=
29 container.end();
30}
int find(T *array, int N, T item)

◆ ContainsOnlyChars()

bool base::ContainsOnlyChars ( std::u16string  str,
char16_t  ch 
)

Definition at line 183 of file string_utils.cc.

183 {
184 return std::find_if(str.begin(), str.end(),
185 [ch](char16_t c) { return c != ch; }) == str.end();
186}

◆ EmptyString()

const std::string & base::EmptyString ( )

Definition at line 157 of file string_utils.cc.

157 {
159 return *s;
160}
struct MyStruct s

◆ EraseIf()

template<class T , class Allocator , class Predicate >
size_t base::EraseIf ( std::vector< T, Allocator > &  container,
Predicate  pred 
)

Definition at line 14 of file container_utils.h.

14 {
15 auto it = std::remove_if(container.begin(), container.end(), pred);
16 size_t removed = std::distance(it, container.end());
17 container.erase(it, container.end());
18 return removed;
19}

◆ IsApproximatelyEqual()

template<typename T >
constexpr bool base::IsApproximatelyEqual ( T  lhs,
T  rhs,
T  tolerance 
)
constexpr

Definition at line 20 of file ranges.h.

20 {
21 static_assert(std::is_arithmetic<T>::value, "Argument must be arithmetic");
22 return std::abs(rhs - lhs) <= tolerance;
23}
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition: SkVx.h:707

◆ JoinString() [1/2]

std::string base::JoinString ( std::vector< std::string >  tokens,
std::string  delimiter 
)

Definition at line 107 of file string_utils.cc.

107 {
108 std::ostringstream imploded;
109 for (size_t i = 0; i < tokens.size(); i++) {
110 if (i == tokens.size() - 1) {
111 imploded << tokens[i];
112 } else {
113 imploded << tokens[i] << delimiter;
114 }
115 }
116 return imploded.str();
117}

◆ JoinString() [2/2]

std::u16string base::JoinString ( std::vector< std::u16string >  tokens,
std::u16string  delimiter 
)

Definition at line 119 of file string_utils.cc.

120 {
121 std::u16string result;
122 for (size_t i = 0; i < tokens.size(); i++) {
123 if (i == tokens.size() - 1) {
124 result.append(tokens[i]);
125 } else {
126 result.append(tokens[i]);
127 result.append(delimiter);
128 }
129 }
130 return result;
131}
GAsyncResult * result

◆ KillProcess()

void base::KillProcess ( )

Definition at line 61 of file logging.cc.

61 {
62 abort();
63}

◆ LowerCaseEqualsASCII()

bool base::LowerCaseEqualsASCII ( std::string  a,
std::string  b 
)

Definition at line 178 of file string_utils.cc.

178 {
179 std::string lower_a = ToLowerASCII(a);
180 return lower_a.compare(ToLowerASCII(b)) == 0;
181}
static bool b
struct MyStruct a[10]
std::string ToLowerASCII(std::string str)

◆ NumberToString() [1/4]

std::string base::NumberToString ( double  number)

Definition at line 103 of file string_utils.cc.

103 {
104 return NumberToStringImpl(number, false);
105}

◆ NumberToString() [2/4]

std::string base::NumberToString ( float  number)

Definition at line 99 of file string_utils.cc.

99 {
100 return NumberToStringImpl(number, true);
101}

◆ NumberToString() [3/4]

std::string base::NumberToString ( int32_t  number)

Definition at line 91 of file string_utils.cc.

91 {
92 return std::to_string(number);
93}
static SkString to_string(int n)
Definition: nanobench.cpp:119

◆ NumberToString() [4/4]

std::string base::NumberToString ( unsigned int  number)

Definition at line 95 of file string_utils.cc.

95 {
96 return std::to_string(number);
97}

◆ NumberToString16() [1/4]

std::u16string base::NumberToString16 ( double  number)

Definition at line 87 of file string_utils.cc.

87 {
88 return ASCIIToUTF16(NumberToString(number));
89}
std::u16string ASCIIToUTF16(std::string src)
Definition: string_utils.cc:63
std::string NumberToString(double number)

◆ NumberToString16() [2/4]

std::u16string base::NumberToString16 ( float  number)

Definition at line 75 of file string_utils.cc.

75 {
76 return ASCIIToUTF16(NumberToString(number));
77}

◆ NumberToString16() [3/4]

std::u16string base::NumberToString16 ( int32_t  number)

Definition at line 79 of file string_utils.cc.

79 {
80 return ASCIIToUTF16(NumberToString(number));
81}

◆ NumberToString16() [4/4]

std::u16string base::NumberToString16 ( unsigned int  number)

Definition at line 83 of file string_utils.cc.

83 {
84 return ASCIIToUTF16(NumberToString(number));
85}

◆ operator!=()

template<class C >
bool base::operator!= ( C  p1,
const scoped_nsprotocol< C > &  p2 
)

Definition at line 107 of file scoped_nsobject.h.

107 {
108 return p1 != p2.get();
109}

◆ operator<<()

std::ostream & base::operator<< ( std::ostream &  out,
const SimpleToken token 
)

Definition at line 31 of file simple_token.cc.

31 {
32 return out << "(" << token.ToString() << ")";
33}
std::string ToString() const
Definition: simple_token.h:28

◆ operator==()

template<class C >
bool base::operator== ( C  p1,
const scoped_nsprotocol< C > &  p2 
)

Definition at line 102 of file scoped_nsobject.h.

102 {
103 return p1 == p2.get();
104}

◆ ReplaceChars() [1/2]

void base::ReplaceChars ( std::string  in,
std::string  from,
std::string  to,
std::string *  out 
)

Definition at line 133 of file string_utils.cc.

136 {
137 size_t pos = in.find(from);
138 while (pos != std::string::npos) {
139 in.replace(pos, from.size(), to);
140 pos = in.find(from, pos + to.size());
141 }
142 *out = in;
143}
SkPoint pos

◆ ReplaceChars() [2/2]

void base::ReplaceChars ( std::u16string  in,
std::u16string  from,
std::u16string  to,
std::u16string *  out 
)

Definition at line 145 of file string_utils.cc.

148 {
149 size_t pos = in.find(from);
150 while (pos != std::u16string::npos) {
151 in.replace(pos, from.size(), to);
152 pos = in.find(from, pos + to.size());
153 }
154 *out = in;
155}

◆ SimpleTokenHash()

size_t base::SimpleTokenHash ( const SimpleToken SimpleToken)

Definition at line 43 of file simple_token.cc.

43 {
44 return std::hash<std::string>()(SimpleToken.ToString());
45}

◆ SimpleTokenToValue()

std::string base::SimpleTokenToValue ( const SimpleToken token)

Definition at line 39 of file simple_token.cc.

39 {
40 return token.ToString();
41}

◆ StringPrintf()

template<typename... Args>
std::string base::StringPrintf ( const std::string &  format,
Args...  args 
)

Definition at line 18 of file string_utils.h.

18 {
19 // Calculate the buffer size.
20 int size = snprintf(nullptr, 0, format.c_str(), args...) + 1;
21 std::unique_ptr<char[]> buf = std::make_unique<char[]>(size);
22 snprintf(buf.get(), size, format.c_str(), args...);
23 return std::string(buf.get(), buf.get() + size - 1);
24}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
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

◆ swap()

template<class C >
void base::swap ( scoped_nsprotocol< C > &  p1,
scoped_nsprotocol< C > &  p2 
)

Definition at line 97 of file scoped_nsobject.h.

97 {
98 p1.swap(p2);
99}
void swap(scoped_nsprotocol &that)

◆ TEST() [1/8]

base::TEST ( StringUtilsTest  ,
canASCIIToUTF16   
)

Definition at line 30 of file string_utils_unittest.cc.

30 {
31 std::string ascii = "abcdefg";
32 EXPECT_EQ(ASCIIToUTF16(ascii).compare(u"abcdefg"), 0);
33}
int compare(const void *untyped_lhs, const void *untyped_rhs)
Definition: skdiff.h:161

◆ TEST() [2/8]

base::TEST ( StringUtilsTest  ,
canNumberToString16   
)

Definition at line 45 of file string_utils_unittest.cc.

45 {
46 EXPECT_EQ(NumberToString16(1.123f), std::u16string(u"1.123"));
47}
std::u16string NumberToString16(float number)
Definition: string_utils.cc:75

◆ TEST() [3/8]

base::TEST ( StringUtilsTest  ,
canUTF16ToUTF8   
)

Definition at line 40 of file string_utils_unittest.cc.

40 {
41 std::u16string utf16 = u"äåè";
42 EXPECT_EQ(UTF16ToUTF8(utf16).compare("äåè"), 0);
43}
std::string UTF16ToUTF8(std::u16string src)
Definition: string_utils.cc:71

◆ TEST() [4/8]

base::TEST ( StringUtilsTest  ,
canUTF8ToUTF16   
)

Definition at line 35 of file string_utils_unittest.cc.

35 {
36 std::string utf8 = "äåè";
37 EXPECT_EQ(UTF8ToUTF16(utf8).compare(u"äåè"), 0);
38}
std::u16string UTF8ToUTF16(std::string src)
Definition: string_utils.cc:67

◆ TEST() [5/8]

base::TEST ( StringUtilsTest  ,
numberToStringSimplifiesOutput   
)

Definition at line 49 of file string_utils_unittest.cc.

49 {
50 EXPECT_STREQ(NumberToString(0.0).c_str(), "0");
51 EXPECT_STREQ(NumberToString(0.0f).c_str(), "0");
52 EXPECT_STREQ(NumberToString(1.123).c_str(), "1.123");
53 EXPECT_STREQ(NumberToString(1.123f).c_str(), "1.123");
54 EXPECT_STREQ(NumberToString(-1.123).c_str(), "-1.123");
55 EXPECT_STREQ(NumberToString(-1.123f).c_str(), "-1.123");
56 EXPECT_STREQ(NumberToString(1.00001).c_str(), "1.00001");
57 EXPECT_STREQ(NumberToString(1.00001f).c_str(), "1.00001");
58 EXPECT_STREQ(NumberToString(1000.000001).c_str(), "1000.000001");
59 EXPECT_STREQ(NumberToString(10.00001f).c_str(), "10.00001");
60 EXPECT_STREQ(NumberToString(1.0 + 1e-8).c_str(), "1.00000001");
61 EXPECT_STREQ(NumberToString(1.0f + 1e-8f).c_str(), "1");
62 EXPECT_STREQ(NumberToString(1e-6).c_str(), "0.000001");
63 EXPECT_STREQ(NumberToString(1e-6f).c_str(), "0.000001");
64 EXPECT_STREQ(NumberToString(1e-8).c_str(), "1e-8");
65 EXPECT_STREQ(NumberToString(1e-8f).c_str(), "1e-8");
66 EXPECT_STREQ(NumberToString(100.0).c_str(), "100");
67 EXPECT_STREQ(NumberToString(100.0f).c_str(), "100");
68 EXPECT_STREQ(NumberToString(-1.0 - 1e-7).c_str(), "-1.0000001");
69 EXPECT_STREQ(NumberToString(-1.0f - 1e-7f).c_str(), "-1.0000001");
70 EXPECT_STREQ(NumberToString(0.00000012345678).c_str(), "1.2345678e-7");
71 // Difference in output is due to differences in double and float precision.
72 EXPECT_STREQ(NumberToString(0.00000012345678f).c_str(), "1.2345679e-7");
73 EXPECT_STREQ(NumberToString(-0.00000012345678).c_str(), "-1.2345678e-7");
74 // Difference in output is due to differences in double and float precision.
75 EXPECT_STREQ(NumberToString(-0.00000012345678f).c_str(), "-1.2345679e-7");
76 EXPECT_STREQ(NumberToString(static_cast<unsigned int>(11)).c_str(), "11");
77 EXPECT_STREQ(NumberToString(static_cast<int32_t>(-23)).c_str(), "-23");
78}
std::string NumberToString(int32_t number)
Definition: string_utils.cc:91

◆ TEST() [6/8]

base::TEST ( StringUtilsTest  ,
StringPrintfEmpty   
)

Definition at line 16 of file string_utils_unittest.cc.

16 {
17 EXPECT_EQ("", base::StringPrintf("%s", ""));
18}
std::string StringPrintf(const std::string &format, Args... args)
Definition: string_utils.h:18

◆ TEST() [7/8]

base::TEST ( StringUtilsTest  ,
StringPrintfErrno   
)

Definition at line 24 of file string_utils_unittest.cc.

24 {
25 errno = 1;
26 EXPECT_EQ("", StringPrintf("%s", ""));
27 EXPECT_EQ(1, errno);
28}

◆ TEST() [8/8]

base::TEST ( StringUtilsTest  ,
StringPrintfMisc   
)

Definition at line 20 of file string_utils_unittest.cc.

20 {
21 EXPECT_EQ("123hello w", StringPrintf("%3d%2s %1c", 123, "hello", 'w'));
22}

◆ ToLowerASCII()

std::string base::ToLowerASCII ( std::string  str)

Definition at line 170 of file string_utils.cc.

170 {
171 std::string ret;
172 ret.reserve(str.size());
173 for (size_t i = 0; i < str.size(); i++)
174 ret.push_back(std::tolower(str[i]));
175 return ret;
176}

◆ ToUpperASCII()

std::string base::ToUpperASCII ( std::string  str)

Definition at line 162 of file string_utils.cc.

162 {
163 std::string ret;
164 ret.reserve(str.size());
165 for (size_t i = 0; i < str.size(); i++)
166 ret.push_back(std::toupper(str[i]));
167 return ret;
168}

◆ UTF16ToUTF8()

std::string base::UTF16ToUTF8 ( std::u16string  src)

Definition at line 71 of file string_utils.cc.

71 {
72 return fml::Utf16ToUtf8(src);
73}
std::string Utf16ToUtf8(const std::u16string_view string)

◆ UTF8ToUTF16()

std::u16string base::UTF8ToUTF16 ( std::string  src)

Definition at line 67 of file string_utils.cc.

67 {
68 return fml::Utf8ToUtf16(src);
69}
std::u16string Utf8ToUtf16(const std::string_view string)

◆ ValueToSimpleToken()

std::optional< base::SimpleToken > base::ValueToSimpleToken ( std::string  str)

Definition at line 35 of file simple_token.cc.

35 {
36 return std::make_optional<base::SimpleToken>(str);
37}

Variable Documentation

◆ kMeanGravityDouble

constexpr double base::kMeanGravityDouble = 9.80665
constexpr

Definition at line 14 of file math_constants.h.

◆ kMeanGravityFloat

constexpr float base::kMeanGravityFloat = 9.80665f
constexpr

Definition at line 15 of file math_constants.h.

◆ kPiDouble

constexpr double base::kPiDouble = 3.14159265358979323846
constexpr

Definition at line 10 of file math_constants.h.

◆ kPiFloat

constexpr float base::kPiFloat = 3.14159265358979323846f
constexpr

Definition at line 11 of file math_constants.h.

◆ kRandomTokenLength

constexpr size_t base::kRandomTokenLength = 10
constexpr

Definition at line 12 of file simple_token.cc.

◆ kWhitespaceUTF16

constexpr char16_t base::kWhitespaceUTF16 = u' '
constexpr

Definition at line 14 of file string_utils.h.