aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/skotty/SkottyPriv.h
blob: 35b1e847a31505f0a9d501ca46964d9020a31014 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkottyPriv_DEFINED
#define SkottyPriv_DEFINED

#include "SkJSONCPP.h"
#include "SkScalar.h"
#include "SkString.h"

namespace skotty {

#define LOG SkDebugf

static inline SkScalar ParseScalar(const Json::Value& v, SkScalar defaultValue) {
    return !v.isNull() && v.isConvertibleTo(Json::realValue)
        ? v.asFloat() : defaultValue;
}

static inline SkString ParseString(const Json::Value& v, const char defaultValue[]) {
    return SkString(!v.isNull() && v.isConvertibleTo(Json::stringValue)
                    ? v.asCString() : defaultValue);
}

static inline int ParseInt(const Json::Value& v, int defaultValue) {
    return !v.isNull() && v.isConvertibleTo(Json::intValue)
        ? v.asInt() : defaultValue;
}

static inline bool ParseBool(const Json::Value& v, bool defaultValue) {
    return !v.isNull() && v.isConvertibleTo(Json::booleanValue)
        ? v.asBool() : defaultValue;
}

} // namespace

#endif // SkottyPriv_DEFINED