Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / third_party / re2 / util / util.h
blob49159c2e446768c75ba6f43599491a999e58f026
1 // Copyright 2009 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 #ifndef RE2_UTIL_UTIL_H__
6 #define RE2_UTIL_UTIL_H__
8 // C
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdint.h>
12 #include <stddef.h> // For size_t
13 #include <assert.h>
14 #include <stdarg.h>
15 #ifndef WIN32
16 #include <sys/time.h>
17 #endif
18 #include <time.h>
19 #include <ctype.h> // For isdigit, isalpha.
21 // C++
22 #include <vector>
23 #include <string>
24 #include <algorithm>
25 #include <iosfwd>
26 #include <map>
27 #include <stack>
28 #include <ostream>
29 #include <utility>
30 #include <set>
32 #include "build/build_config.h"
33 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
35 // Use std names.
36 using std::set;
37 using std::pair;
38 using std::vector;
39 using std::string;
40 using std::min;
41 using std::max;
42 using std::ostream;
43 using std::map;
44 using std::stack;
45 using std::sort;
46 using std::swap;
47 using std::make_pair;
49 #if defined(__GNUC__) && !defined(USE_CXX0X) && !defined(OS_ANDROID) && \
50 !defined(_LIBCPP_ABI_VERSION)
52 #include <tr1/unordered_set>
53 using std::tr1::unordered_set;
55 #else
57 #include <unordered_set>
58 #if defined(WIN32) || defined(OS_ANDROID)
59 using std::tr1::unordered_set;
60 #else
61 using std::unordered_set;
62 #endif
64 #endif
66 namespace re2 {
68 typedef int8_t int8;
69 typedef uint8_t uint8;
70 typedef int16_t int16;
71 typedef uint16_t uint16;
72 typedef int32_t int32;
73 typedef uint32_t uint32;
74 typedef int64_t int64;
75 typedef uint64_t uint64;
77 typedef unsigned long ulong;
78 typedef unsigned int uint;
79 typedef unsigned short ushort;
81 // COMPILE_ASSERT causes a compile error about msg if expr is not true.
82 template<bool> struct CompileAssert {};
83 #define COMPILE_ASSERT(expr, msg) \
84 typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
86 // DISALLOW_EVIL_CONSTRUCTORS disallows the copy and operator= functions.
87 // It goes in the private: declarations in a class.
88 #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
89 TypeName(const TypeName&); \
90 void operator=(const TypeName&)
92 #define arraysize(array) (sizeof(array)/sizeof((array)[0]))
94 // Fake lock annotations. For real ones, see
95 // http://code.google.com/p/data-race-test/
96 #ifndef ANNOTATE_PUBLISH_MEMORY_RANGE
97 #define ANNOTATE_PUBLISH_MEMORY_RANGE(a, b)
98 #define ANNOTATE_IGNORE_WRITES_BEGIN()
99 #define ANNOTATE_IGNORE_WRITES_END()
100 #define ANNOTATE_BENIGN_RACE(a, b)
101 #define NO_THREAD_SAFETY_ANALYSIS
102 #define ANNOTATE_HAPPENS_BEFORE(x)
103 #define ANNOTATE_HAPPENS_AFTER(x)
104 #define ANNOTATE_UNPROTECTED_READ(x) (x)
105 #endif
107 class StringPiece;
109 string CEscape(const StringPiece& src);
110 int CEscapeString(const char* src, int src_len, char* dest, int dest_len);
112 extern string StringPrintf(const char* format, ...);
113 extern void SStringPrintf(string* dst, const char* format, ...);
114 extern void StringAppendF(string* dst, const char* format, ...);
115 extern string PrefixSuccessor(const StringPiece& prefix);
117 uint32 hashword(const uint32*, size_t, uint32);
118 void hashword2(const uint32*, size_t, uint32*, uint32*);
120 static inline uint32 Hash32StringWithSeed(const char* s, int len, uint32 seed) {
121 return hashword((uint32*)s, len/4, seed);
124 static inline uint64 Hash64StringWithSeed(const char* s, int len, uint32 seed) {
125 uint32 x, y;
126 x = seed;
127 y = 0;
128 hashword2((uint32*)s, len/4, &x, &y);
129 return ((uint64)x << 32) | y;
132 inline bool RunningOnValgrindOrMemorySanitizer() {
133 #if defined(MEMORY_SANITIZER)
134 return true;
135 #else
136 return RunningOnValgrind();
137 #endif
140 } // namespace re2
142 #include "util/arena.h"
143 #include "util/logging.h"
144 #include "util/mutex.h"
145 #include "util/utf.h"
147 #endif // RE2_UTIL_UTIL_H__