ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SKSL_UTIL |
| 9 | #define SKSL_UTIL |
| 10 | |
ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 11 | #include <iomanip> |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <sstream> |
| 14 | #include "stdlib.h" |
| 15 | #include "assert.h" |
| 16 | #include "SkTypes.h" |
| 17 | |
| 18 | namespace SkSL { |
| 19 | |
| 20 | // our own definitions of certain std:: functions, because they are not always present on Android |
| 21 | |
fmalita | d214d6a | 2016-09-30 08:05:24 -0700 | [diff] [blame] | 22 | template <typename T> std::string to_string(T value) { |
| 23 | std::stringstream buffer; |
| 24 | buffer << std::setprecision(std::numeric_limits<T>::digits10) << value; |
| 25 | return buffer.str(); |
| 26 | } |
ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 27 | |
| 28 | #if _MSC_VER |
| 29 | #define NORETURN __declspec(noreturn) |
| 30 | #else |
| 31 | #define NORETURN __attribute__((__noreturn__)) |
| 32 | #endif |
| 33 | int stoi(std::string s); |
| 34 | |
| 35 | double stod(std::string s); |
| 36 | |
| 37 | long stol(std::string s); |
| 38 | |
| 39 | NORETURN void sksl_abort(); |
| 40 | |
| 41 | } // namespace |
| 42 | |
| 43 | #ifdef DEBUG |
| 44 | #define ASSERT(x) assert(x) |
| 45 | #define ASSERT_RESULT(x) ASSERT(x); |
| 46 | #else |
| 47 | #define ASSERT(x) |
| 48 | #define ASSERT_RESULT(x) x |
| 49 | #endif |
| 50 | |
| 51 | #ifdef SKIA |
| 52 | #define ABORT(...) { SkDebugf(__VA_ARGS__); sksl_abort(); } |
| 53 | #else |
| 54 | #define ABORT(...) { sksl_abort(); } |
| 55 | #endif |
| 56 | |
| 57 | #endif |