OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 138 } |
139 | 139 |
140 std::ostream& operator<<(std::ostream& o, const uint128& b) { | 140 std::ostream& operator<<(std::ostream& o, const uint128& b) { |
141 std::ios_base::fmtflags flags = o.flags(); | 141 std::ios_base::fmtflags flags = o.flags(); |
142 | 142 |
143 // Select a divisor which is the largest power of the base < 2^64. | 143 // Select a divisor which is the largest power of the base < 2^64. |
144 uint128 div; | 144 uint128 div; |
145 std::streamsize div_base_log; | 145 std::streamsize div_base_log; |
146 switch (flags & std::ios::basefield) { | 146 switch (flags & std::ios::basefield) { |
147 case std::ios::hex: | 147 case std::ios::hex: |
148 div = GOOGLE_ULONGLONG(0x1000000000000000); // 16^15 | 148 div = static_cast<uint64>(GOOGLE_ULONGLONG(0x1000000000000000)); // 16^15 |
149 div_base_log = 15; | 149 div_base_log = 15; |
150 break; | 150 break; |
151 case std::ios::oct: | 151 case std::ios::oct: |
152 div = GOOGLE_ULONGLONG(01000000000000000000000); // 8^21 | 152 div = static_cast<uint64>(GOOGLE_ULONGLONG(01000000000000000000000)); //
8^21 |
153 div_base_log = 21; | 153 div_base_log = 21; |
154 break; | 154 break; |
155 default: // std::ios::dec | 155 default: // std::ios::dec |
156 div = GOOGLE_ULONGLONG(10000000000000000000); // 10^19 | 156 div = static_cast<uint64>(GOOGLE_ULONGLONG(10000000000000000000)); // 10^
19 |
157 div_base_log = 19; | 157 div_base_log = 19; |
158 break; | 158 break; |
159 } | 159 } |
160 | 160 |
161 // Now piece together the uint128 representation from three chunks of | 161 // Now piece together the uint128 representation from three chunks of |
162 // the original value, each less than "div" and therefore representable | 162 // the original value, each less than "div" and therefore representable |
163 // as a uint64. | 163 // as a uint64. |
164 std::ostringstream os; | 164 std::ostringstream os; |
165 std::ios_base::fmtflags copy_mask = | 165 std::ios_base::fmtflags copy_mask = |
166 std::ios::basefield | std::ios::showbase | std::ios::uppercase; | 166 std::ios::basefield | std::ios::showbase | std::ios::uppercase; |
(...skipping 25 matching lines...) Expand all Loading... |
192 width - rep.size(), o.fill()); | 192 width - rep.size(), o.fill()); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 // Stream the final representation in a single "<<" call. | 196 // Stream the final representation in a single "<<" call. |
197 return o << rep; | 197 return o << rep; |
198 } | 198 } |
199 | 199 |
200 } // namespace protobuf | 200 } // namespace protobuf |
201 } // namespace google | 201 } // namespace google |
OLD | NEW |