blob: 33611cde0238b3cc6e9d8b071cc1b10bbab9132f [file] [log] [blame]
ethannicholasb3058bd2016-07-01 08:22:01 -07001/*
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
ethannicholasf789b382016-08-03 12:43:36 -070011#include <iomanip>
ethannicholasb3058bd2016-07-01 08:22:01 -070012#include <string>
13#include <sstream>
14#include "stdlib.h"
15#include "assert.h"
16#include "SkTypes.h"
17
18namespace SkSL {
19
20// our own definitions of certain std:: functions, because they are not always present on Android
21
fmalitad214d6a2016-09-30 08:05:24 -070022template <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}
ethannicholasb3058bd2016-07-01 08:22:01 -070027
28#if _MSC_VER
29#define NORETURN __declspec(noreturn)
30#else
31#define NORETURN __attribute__((__noreturn__))
32#endif
33int stoi(std::string s);
34
35double stod(std::string s);
36
37long stol(std::string s);
38
39NORETURN 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