language_detection 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.gitignore +19 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +85 -0
  5. data/Rakefile +11 -0
  6. data/ext/cld/Makefile +34 -0
  7. data/ext/cld/base/basictypes.h +348 -0
  8. data/ext/cld/base/build_config.h +124 -0
  9. data/ext/cld/base/casts.h +156 -0
  10. data/ext/cld/base/commandlineflags.h +443 -0
  11. data/ext/cld/base/crash.h +41 -0
  12. data/ext/cld/base/dynamic_annotations.h +358 -0
  13. data/ext/cld/base/global_strip_options.h +59 -0
  14. data/ext/cld/base/log_severity.h +46 -0
  15. data/ext/cld/base/logging.h +1403 -0
  16. data/ext/cld/base/macros.h +243 -0
  17. data/ext/cld/base/port.h +54 -0
  18. data/ext/cld/base/scoped_ptr.h +428 -0
  19. data/ext/cld/base/stl_decl.h +0 -0
  20. data/ext/cld/base/stl_decl_msvc.h +107 -0
  21. data/ext/cld/base/string_util.h +29 -0
  22. data/ext/cld/base/strtoint.h +93 -0
  23. data/ext/cld/base/template_util.h +96 -0
  24. data/ext/cld/base/type_traits.h +198 -0
  25. data/ext/cld/base/vlog_is_on.h +143 -0
  26. data/ext/cld/cld.so +0 -0
  27. data/ext/cld/encodings/compact_lang_det/cldutil.cc +905 -0
  28. data/ext/cld/encodings/compact_lang_det/cldutil.h +1205 -0
  29. data/ext/cld/encodings/compact_lang_det/cldutil_dbg.h +76 -0
  30. data/ext/cld/encodings/compact_lang_det/cldutil_dbg_empty.cc +76 -0
  31. data/ext/cld/encodings/compact_lang_det/compact_lang_det.cc +62 -0
  32. data/ext/cld/encodings/compact_lang_det/compact_lang_det.h +145 -0
  33. data/ext/cld/encodings/compact_lang_det/compact_lang_det_impl.cc +2574 -0
  34. data/ext/cld/encodings/compact_lang_det/compact_lang_det_impl.h +173 -0
  35. data/ext/cld/encodings/compact_lang_det/compact_lang_det_unittest_small.cc +406 -0
  36. data/ext/cld/encodings/compact_lang_det/compile.cmd +1 -0
  37. data/ext/cld/encodings/compact_lang_det/ext_lang_enc.cc +545 -0
  38. data/ext/cld/encodings/compact_lang_det/ext_lang_enc.h +119 -0
  39. data/ext/cld/encodings/compact_lang_det/generated/cld_generated_score_deltaoctachrome_0406.cc +380 -0
  40. data/ext/cld/encodings/compact_lang_det/generated/cld_generated_score_quadchrome_0406.cc +382 -0
  41. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_cjkbis_0.cc +49 -0
  42. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz.cc +7119 -0
  43. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_ctjkvz_0.cc +61 -0
  44. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_deltaoctachrome.cc +1263 -0
  45. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_longwords8_0.cc +53 -0
  46. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_meanscore.h +10 -0
  47. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_quads_0.cc +50 -0
  48. data/ext/cld/encodings/compact_lang_det/generated/compact_lang_det_generated_quadschrome.cc +70935 -0
  49. data/ext/cld/encodings/compact_lang_det/getonescriptspan.cc +570 -0
  50. data/ext/cld/encodings/compact_lang_det/getonescriptspan.h +131 -0
  51. data/ext/cld/encodings/compact_lang_det/letterscript_enum.cc +117 -0
  52. data/ext/cld/encodings/compact_lang_det/letterscript_enum.h +99 -0
  53. data/ext/cld/encodings/compact_lang_det/subsetsequence.cc +259 -0
  54. data/ext/cld/encodings/compact_lang_det/subsetsequence.h +44 -0
  55. data/ext/cld/encodings/compact_lang_det/subsetsequence_unittest.cc +99 -0
  56. data/ext/cld/encodings/compact_lang_det/tote.cc +299 -0
  57. data/ext/cld/encodings/compact_lang_det/tote.h +89 -0
  58. data/ext/cld/encodings/compact_lang_det/unittest_data.h +193 -0
  59. data/ext/cld/encodings/compact_lang_det/utf8propjustletter.h +1162 -0
  60. data/ext/cld/encodings/compact_lang_det/utf8propletterscriptnum.h +1222 -0
  61. data/ext/cld/encodings/compact_lang_det/utf8scannotjustletterspecial.h +1185 -0
  62. data/ext/cld/encodings/compact_lang_det/win/cld_basictypes.h +10 -0
  63. data/ext/cld/encodings/compact_lang_det/win/cld_commandlineflags.h +28 -0
  64. data/ext/cld/encodings/compact_lang_det/win/cld_google.h +18 -0
  65. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils.h +13 -0
  66. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils_google3.cc +32 -0
  67. data/ext/cld/encodings/compact_lang_det/win/cld_htmlutils_windows.cc +29 -0
  68. data/ext/cld/encodings/compact_lang_det/win/cld_logging.h +21 -0
  69. data/ext/cld/encodings/compact_lang_det/win/cld_macros.h +19 -0
  70. data/ext/cld/encodings/compact_lang_det/win/cld_strtoint.h +26 -0
  71. data/ext/cld/encodings/compact_lang_det/win/cld_unicodetext.cc +84 -0
  72. data/ext/cld/encodings/compact_lang_det/win/cld_unicodetext.h +40 -0
  73. data/ext/cld/encodings/compact_lang_det/win/cld_unilib.h +15 -0
  74. data/ext/cld/encodings/compact_lang_det/win/cld_unilib_google3.cc +18 -0
  75. data/ext/cld/encodings/compact_lang_det/win/cld_unilib_windows.cc +29 -0
  76. data/ext/cld/encodings/compact_lang_det/win/cld_utf.h +24 -0
  77. data/ext/cld/encodings/compact_lang_det/win/cld_utf8statetable.cc +224 -0
  78. data/ext/cld/encodings/compact_lang_det/win/cld_utf8statetable.h +141 -0
  79. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils.h +22 -0
  80. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils_google3.cc +18 -0
  81. data/ext/cld/encodings/compact_lang_det/win/cld_utf8utils_windows.cc +17 -0
  82. data/ext/cld/encodings/compact_lang_det/win/normalizedunicodetext.cc +172 -0
  83. data/ext/cld/encodings/compact_lang_det/win/normalizedunicodetext.h +67 -0
  84. data/ext/cld/encodings/internal/encodings.cc +12 -0
  85. data/ext/cld/encodings/lang_enc.h +254 -0
  86. data/ext/cld/encodings/proto/encodings.pb.h +169 -0
  87. data/ext/cld/encodings/public/encodings.h +301 -0
  88. data/ext/cld/extconf.rb +1 -0
  89. data/ext/cld/language_detection.cc +88 -0
  90. data/ext/cld/languages/internal/languages.cc +337 -0
  91. data/ext/cld/languages/proto/languages.pb.h +179 -0
  92. data/ext/cld/languages/public/languages.h +379 -0
  93. data/language_detection.gemspec +28 -0
  94. data/lib/language_detection/string.rb +1 -0
  95. data/lib/language_detection/version.rb +3 -0
  96. data/lib/language_detection.rb +54 -0
  97. data/test/_helper.rb +15 -0
  98. data/test/fixtures/languages.csv +80 -0
  99. data/test/language_detection_test.rb +88 -0
  100. metadata +250 -0
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Template metaprogramming utility functions.
6
+ //
7
+ // This code is compiled directly on many platforms, including client
8
+ // platforms like Windows, Mac, and embedded systems. Before making
9
+ // any changes here, make sure that you're not breaking any platforms.
10
+ //
11
+ // The names choosen here reflect those used in tr1 and the boost::mpl
12
+ // library, there are similar operations used in the Loki library as
13
+ // well. I prefer the boost names for 2 reasons:
14
+ // 1. I think that portions of the Boost libraries are more likely to
15
+ // be included in the c++ standard.
16
+ // 2. It is not impossible that some of the boost libraries will be
17
+ // included in our own build in the future.
18
+ // Both of these outcomes means that we may be able to directly replace
19
+ // some of these with boost equivalents.
20
+ //
21
+ #ifndef BASE_TEMPLATE_UTIL_H_
22
+ #define BASE_TEMPLATE_UTIL_H_
23
+
24
+ namespace base {
25
+
26
+ // Types small_ and big_ are guaranteed such that sizeof(small_) <
27
+ // sizeof(big_)
28
+ typedef char small_;
29
+
30
+ struct big_ {
31
+ char dummy[2];
32
+ };
33
+
34
+ // integral_constant, defined in tr1, is a wrapper for an integer
35
+ // value. We don't really need this generality; we could get away
36
+ // with hardcoding the integer type to bool. We use the fully
37
+ // general integer_constant for compatibility with tr1.
38
+
39
+ template<class T, T v>
40
+ struct integral_constant {
41
+ static const T value = v;
42
+ typedef T value_type;
43
+ typedef integral_constant<T, v> type;
44
+ };
45
+
46
+ template <class T, T v> const T integral_constant<T, v>::value;
47
+
48
+
49
+ // Abbreviations: true_type and false_type are structs that represent boolean
50
+ // true and false values. Also define the boost::mpl versions of those names,
51
+ // true_ and false_.
52
+ typedef integral_constant<bool, true> true_type;
53
+ typedef integral_constant<bool, false> false_type;
54
+ typedef true_type true_;
55
+ typedef false_type false_;
56
+
57
+ // if_ is a templatized conditional statement.
58
+ // if_<cond, A, B> is a compile time evaluation of cond.
59
+ // if_<>::type contains A if cond is true, B otherwise.
60
+ template<bool cond, typename A, typename B>
61
+ struct if_{
62
+ typedef A type;
63
+ };
64
+
65
+ template<typename A, typename B>
66
+ struct if_<false, A, B> {
67
+ typedef B type;
68
+ };
69
+
70
+
71
+ // type_equals_ is a template type comparator, similar to Loki IsSameType.
72
+ // type_equals_<A, B>::value is true iff "A" is the same type as "B".
73
+ template<typename A, typename B>
74
+ struct type_equals_ : public false_ {
75
+ };
76
+
77
+ template<typename A>
78
+ struct type_equals_<A, A> : public true_ {
79
+ };
80
+
81
+ // and_ is a template && operator.
82
+ // and_<A, B>::value evaluates "A::value && B::value".
83
+ template<typename A, typename B>
84
+ struct and_ : public integral_constant<bool, (A::value && B::value)> {
85
+ };
86
+
87
+ // or_ is a template || operator.
88
+ // or_<A, B>::value evaluates "A::value || B::value".
89
+ template<typename A, typename B>
90
+ struct or_ : public integral_constant<bool, (A::value || B::value)> {
91
+ };
92
+
93
+
94
+ } // Close namespace base
95
+
96
+ #endif // BASE_TEMPLATE_UTIL_H_
@@ -0,0 +1,198 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // This code is compiled directly on many platforms, including client
6
+ // platforms like Windows, Mac, and embedded systems. Before making
7
+ // any changes here, make sure that you're not breaking any platforms.
8
+ //
9
+ //
10
+ // Define a small subset of tr1 type traits. The traits we define are:
11
+ // is_integral
12
+ // is_floating_point
13
+ // is_pointer
14
+ // is_reference
15
+ // is_pod
16
+ // has_trivial_constructor
17
+ // has_trivial_copy
18
+ // has_trivial_assign
19
+ // has_trivial_destructor
20
+ // remove_const
21
+ // remove_volatile
22
+ // remove_cv
23
+ // remove_reference
24
+ // remove_pointer
25
+ // is_convertible
26
+ // We can add more type traits as required.
27
+
28
+ #ifndef BASE_TYPE_TRAITS_H_
29
+ #define BASE_TYPE_TRAITS_H_
30
+
31
+ #include "base/template_util.h" // For true_type and false_type
32
+ #include <utility> // For pair
33
+
34
+ namespace base {
35
+
36
+ // is_integral is false except for the built-in integer types.
37
+ template <class T> struct is_integral : false_type { };
38
+ template<> struct is_integral<bool> : true_type { };
39
+ template<> struct is_integral<char> : true_type { };
40
+ template<> struct is_integral<unsigned char> : true_type { };
41
+ template<> struct is_integral<signed char> : true_type { };
42
+ #if defined(_MSC_VER)
43
+ // wchar_t is not by default a distinct type from unsigned short in
44
+ // Microsoft C.
45
+ // See http://msdn2.microsoft.com/en-us/library/dh8che7s(VS.80).aspx
46
+ template<> struct is_integral<__wchar_t> : true_type { };
47
+ #else
48
+ template<> struct is_integral<wchar_t> : true_type { };
49
+ #endif
50
+ template<> struct is_integral<short> : true_type { };
51
+ template<> struct is_integral<unsigned short> : true_type { };
52
+ template<> struct is_integral<int> : true_type { };
53
+ template<> struct is_integral<unsigned int> : true_type { };
54
+ template<> struct is_integral<long> : true_type { };
55
+ template<> struct is_integral<unsigned long> : true_type { };
56
+ template<> struct is_integral<long long> : true_type { };
57
+ template<> struct is_integral<unsigned long long> : true_type { };
58
+
59
+
60
+ // is_floating_point is false except for the built-in floating-point types.
61
+ template <class T> struct is_floating_point : false_type { };
62
+ template<> struct is_floating_point<float> : true_type { };
63
+ template<> struct is_floating_point<double> : true_type { };
64
+ template<> struct is_floating_point<long double> : true_type { };
65
+
66
+
67
+ // is_pointer is false except for pointer types.
68
+ template <class T> struct is_pointer : false_type { };
69
+ template <class T> struct is_pointer<T*> : true_type { };
70
+
71
+
72
+ // is_reference is false except for reference types.
73
+ template<typename T> struct is_reference : false_type {};
74
+ template<typename T> struct is_reference<T&> : true_type {};
75
+
76
+
77
+ // We can't get is_pod right without compiler help, so fail conservatively.
78
+ // We will assume it's false except for arithmetic types and pointers,
79
+ // and const versions thereof. Note that std::pair is not a POD.
80
+ template <class T> struct is_pod
81
+ : integral_constant<bool, (is_integral<T>::value ||
82
+ is_floating_point<T>::value ||
83
+ is_pointer<T>::value)> { };
84
+ template <class T> struct is_pod<const T> : is_pod<T> { };
85
+
86
+
87
+ // We can't get has_trivial_constructor right without compiler help, so
88
+ // fail conservatively. We will assume it's false except for: (1) types
89
+ // for which is_pod is true. (2) std::pair of types with trivial
90
+ // constructors. (3) array of a type with a trivial constructor.
91
+ // (4) const versions thereof.
92
+ template <class T> struct has_trivial_constructor : is_pod<T> { };
93
+ template <class T, class U> struct has_trivial_constructor<std::pair<T, U> >
94
+ : integral_constant<bool,
95
+ (has_trivial_constructor<T>::value &&
96
+ has_trivial_constructor<U>::value)> { };
97
+ template <class A, int N> struct has_trivial_constructor<A[N]>
98
+ : has_trivial_constructor<A> { };
99
+ template <class T> struct has_trivial_constructor<const T>
100
+ : has_trivial_constructor<T> { };
101
+
102
+ // We can't get has_trivial_copy right without compiler help, so fail
103
+ // conservatively. We will assume it's false except for: (1) types
104
+ // for which is_pod is true. (2) std::pair of types with trivial copy
105
+ // constructors. (3) array of a type with a trivial copy constructor.
106
+ // (4) const versions thereof.
107
+ template <class T> struct has_trivial_copy : is_pod<T> { };
108
+ template <class T, class U> struct has_trivial_copy<std::pair<T, U> >
109
+ : integral_constant<bool,
110
+ (has_trivial_copy<T>::value &&
111
+ has_trivial_copy<U>::value)> { };
112
+ template <class A, int N> struct has_trivial_copy<A[N]>
113
+ : has_trivial_copy<A> { };
114
+ template <class T> struct has_trivial_copy<const T> : has_trivial_copy<T> { };
115
+
116
+ // We can't get has_trivial_assign right without compiler help, so fail
117
+ // conservatively. We will assume it's false except for: (1) types
118
+ // for which is_pod is true. (2) std::pair of types with trivial copy
119
+ // constructors. (3) array of a type with a trivial assign constructor.
120
+ template <class T> struct has_trivial_assign : is_pod<T> { };
121
+ template <class T, class U> struct has_trivial_assign<std::pair<T, U> >
122
+ : integral_constant<bool,
123
+ (has_trivial_assign<T>::value &&
124
+ has_trivial_assign<U>::value)> { };
125
+ template <class A, int N> struct has_trivial_assign<A[N]>
126
+ : has_trivial_assign<A> { };
127
+
128
+ // We can't get has_trivial_destructor right without compiler help, so
129
+ // fail conservatively. We will assume it's false except for: (1) types
130
+ // for which is_pod is true. (2) std::pair of types with trivial
131
+ // destructors. (3) array of a type with a trivial destructor.
132
+ // (4) const versions thereof.
133
+ template <class T> struct has_trivial_destructor : is_pod<T> { };
134
+ template <class T, class U> struct has_trivial_destructor<std::pair<T, U> >
135
+ : integral_constant<bool,
136
+ (has_trivial_destructor<T>::value &&
137
+ has_trivial_destructor<U>::value)> { };
138
+ template <class A, int N> struct has_trivial_destructor<A[N]>
139
+ : has_trivial_destructor<A> { };
140
+ template <class T> struct has_trivial_destructor<const T>
141
+ : has_trivial_destructor<T> { };
142
+
143
+ // Specified by TR1 [4.7.1]
144
+ template<typename T> struct remove_const { typedef T type; };
145
+ template<typename T> struct remove_const<T const> { typedef T type; };
146
+ template<typename T> struct remove_volatile { typedef T type; };
147
+ template<typename T> struct remove_volatile<T volatile> { typedef T type; };
148
+ template<typename T> struct remove_cv {
149
+ typedef typename remove_const<typename remove_volatile<T>::type>::type type;
150
+ };
151
+
152
+
153
+ // Specified by TR1 [4.7.2]
154
+ template<typename T> struct remove_reference { typedef T type; };
155
+ template<typename T> struct remove_reference<T&> { typedef T type; };
156
+
157
+ // Specified by TR1 [4.7.4] Pointer modifications.
158
+ template<typename T> struct remove_pointer { typedef T type; };
159
+ template<typename T> struct remove_pointer<T*> { typedef T type; };
160
+ template<typename T> struct remove_pointer<T* const> { typedef T type; };
161
+ template<typename T> struct remove_pointer<T* volatile> { typedef T type; };
162
+ template<typename T> struct remove_pointer<T* const volatile> {
163
+ typedef T type; };
164
+
165
+ // Specified by TR1 [4.6] Relationships between types
166
+ #ifndef _MSC_VER
167
+ namespace internal {
168
+
169
+ // This class is an implementation detail for is_convertible, and you
170
+ // don't need to know how it works to use is_convertible. For those
171
+ // who care: we declare two different functions, one whose argument is
172
+ // of type To and one with a variadic argument list. We give them
173
+ // return types of different size, so we can use sizeof to trick the
174
+ // compiler into telling us which function it would have chosen if we
175
+ // had called it with an argument of type From. See Alexandrescu's
176
+ // _Modern C++ Design_ for more details on this sort of trick.
177
+
178
+ template <typename From, typename To>
179
+ struct ConvertHelper {
180
+ static small_ Test(To);
181
+ static big_ Test(...);
182
+ static From Create();
183
+ };
184
+ } // namespace internal
185
+
186
+ // Inherits from true_type if From is convertible to To, false_type otherwise.
187
+ template <typename From, typename To>
188
+ struct is_convertible
189
+ : integral_constant<bool,
190
+ sizeof(internal::ConvertHelper<From, To>::Test(
191
+ internal::ConvertHelper<From, To>::Create()))
192
+ == sizeof(small_)> {
193
+ };
194
+ #endif
195
+
196
+ } // Close namespace base
197
+
198
+ #endif // BASE_TYPE_TRAITS_H_
@@ -0,0 +1,143 @@
1
+ // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ // Defines the VLOG_IS_ON macro that controls the variable-verbosity
6
+ // conditional logging.
7
+ //
8
+ // It's used by VLOG and VLOG_IF in logging.h
9
+ // and by RAW_VLOG in raw_logging.h to trigger the logging.
10
+ //
11
+ // It can also be used directly e.g. like this:
12
+ // if (VLOG_IS_ON(2)) {
13
+ // // do some logging preparation and logging
14
+ // // that can't be accomplished e.g. via just VLOG(2) << ...;
15
+ // }
16
+ //
17
+ // The truth value that VLOG_IS_ON(level) returns is determined by
18
+ // the three verbosity level flags:
19
+ // --v=<n> Gives the default maximal active V-logging level;
20
+ // 0 is the default.
21
+ // Normally positive values are used for V-logging levels.
22
+ // --vmodule=<str> Gives the per-module maximal V-logging levels to override
23
+ // the value given by --v.
24
+ // E.g. "my_module=2,foo*=3" would change the logging level
25
+ // for all code in source files "my_module.*" and "foo*.*"
26
+ // ("-inl" suffixes are also disregarded for this matching).
27
+ // --silent_init When true has the effect of increasing
28
+ // the argument of VLOG_IS_ON by 1,
29
+ // thus suppressing one more level of verbose logging.
30
+ //
31
+ // SetVLOGLevel helper function is provided to do limited dynamic control over
32
+ // V-logging by overriding the per-module settings given via --vmodule flag.
33
+ //
34
+ // CAVEAT: --vmodule functionality is not available in non gcc compilers.
35
+ //
36
+
37
+ #ifndef BASE_VLOG_IS_ON_H_
38
+ #define BASE_VLOG_IS_ON_H_
39
+
40
+ #include "base/atomicops.h"
41
+ #include "base/basictypes.h"
42
+ #include "base/port.h"
43
+ #include "base/commandlineflags.h"
44
+ #include "base/log_severity.h"
45
+
46
+ DECLARE_int32(v); // in vlog_is_on.cc
47
+ DECLARE_bool(silent_init); // in google.cc
48
+
49
+ #if defined(__GNUC__)
50
+ // We pack an int16 verbosity level and an int16 epoch into an
51
+ // Atomic32 at every VLOG_IS_ON() call site. The level determines
52
+ // whether the site should log, and the epoch determines whether the
53
+ // site is stale and should be reinitialized. A verbosity level of
54
+ // kUseFlag (-1) indicates that the value of FLAGS_v should be used as
55
+ // the verbosity level. When the site is (re)initialized, a verbosity
56
+ // level for the current source file is retrieved from an internal
57
+ // list. This list is mutated through calls to SetVLOGLevel() and
58
+ // mutations to the --vmodule flag. New log sites are initialized
59
+ // with a stale epoch and a verbosity level of kUseFlag.
60
+ //
61
+ // TODO(llansing): Investigate using GCC's __builtin_constant_p() to
62
+ // generate less code at call sites where verbositylevel is known to
63
+ // be a compile-time constant.
64
+ #define VLOG_IS_ON(verboselevel) \
65
+ ({ static Atomic32 site__ = ::base::internal::kDefaultSite; \
66
+ ::base::internal::VLogEnabled(&site__, (verboselevel), __FILE__); })
67
+ #else
68
+ // GNU extensions not available, so we do not support --vmodule.
69
+ // Dynamic value of FLAGS_v always controls the logging level.
70
+ //
71
+ // TODO(llansing): Investigate supporting --vmodule on other platforms.
72
+ #define VLOG_IS_ON(verboselevel) \
73
+ (FLAGS_v >= (verboselevel) + FLAGS_silent_init)
74
+ #endif
75
+
76
+ // Set VLOG(_IS_ON) level for module_pattern to log_level.
77
+ // This lets us dynamically control what is normally set by the --vmodule flag.
78
+ // Returns the level that previously applied to module_pattern.
79
+ // NOTE: To change the log level for VLOG(_IS_ON) sites
80
+ // that have already executed after/during InitGoogle,
81
+ // one needs to supply the exact --vmodule pattern that applied to them.
82
+ // (If no --vmodule pattern applied to them
83
+ // the value of FLAGS_v will continue to control them.)
84
+ int SetVLOGLevel(const char* module_pattern, int log_level);
85
+
86
+ // Private implementation details. No user-serviceable parts inside.
87
+ namespace base {
88
+ namespace internal {
89
+
90
+ // Each log site determines whether its log level is up to date by
91
+ // comparing its epoch to this global epoch. Whenever the program's
92
+ // vmodule configuration changes (ex: SetVLOGLevel is called), the
93
+ // global epoch is advanced, invalidating all site epochs.
94
+ extern Atomic32 vlog_epoch;
95
+
96
+ // A log level of kUseFlag means "read the logging level from FLAGS_v."
97
+ const int kUseFlag = -1;
98
+
99
+ // Log sites use FLAGS_v by default, and have an initial epoch of 0.
100
+ const Atomic32 kDefaultSite = kUseFlag << 16;
101
+
102
+ // The global epoch is the least significant half of an Atomic32, and
103
+ // may only be accessed through atomic operations.
104
+ inline Atomic32 GlobalEpoch() {
105
+ return Acquire_Load(&vlog_epoch) & 0x0000FFFF;
106
+ }
107
+
108
+ // The least significant half of a site is the epoch.
109
+ inline int SiteEpoch(Atomic32 site) { return site & 0x0000FFFF; }
110
+
111
+ // The most significant half of a site is the logging level.
112
+ inline int SiteLevel(Atomic32 site) { return site >> 16; }
113
+
114
+ // Construct a logging site from a logging level and epoch.
115
+ inline Atomic32 Site(int level, int epoch) {
116
+ return ((level & 0x0000FFFF) << 16) | (epoch & 0x0000FFFF);
117
+ }
118
+
119
+ // Attempt to initialize or reinitialize a VLOG site. Returns the
120
+ // level of the log site, regardless of whether the attempt succeeds
121
+ // or fails.
122
+ // site: The address of the log site's state.
123
+ // fname: The filename of the current source file.
124
+ int InitVLOG(Atomic32* site, const char* fname);
125
+
126
+ // Determine whether verbose logging should occur at a given log site.
127
+ //
128
+ // TODO(llansing): Find a way to eliminate FLAGS_silent_init from this
129
+ // function while preserving the silent initialization behavior. The
130
+ // common-case code path shouldn't pay for silent initialization.
131
+ inline bool VLogEnabled(Atomic32* site, int32 level, const char* const file) {
132
+ const Atomic32 site_copy = Acquire_Load(site);
133
+ const int32 site_level =
134
+ PREDICT_TRUE(SiteEpoch(site_copy) == GlobalEpoch()) ?
135
+ SiteLevel(site_copy) : InitVLOG(site, file);
136
+ return (site_level == kUseFlag ? FLAGS_v : site_level) >=
137
+ (level + FLAGS_silent_init);
138
+ }
139
+
140
+ } // namespace internal
141
+ } // namespace base
142
+
143
+ #endif // BASE_VLOG_IS_ON_H_
data/ext/cld/cld.so ADDED
Binary file