aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/sksl/DSLCase.h
blob: 5b006e7e2837a73c311ca2be22a361a6f61dfd59 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright 2021 Google LLC.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SKSL_DSL_CASE
#define SKSL_DSL_CASE

#include "include/private/SkSLDefines.h"
#include "include/sksl/DSLExpression.h"
#include "include/sksl/DSLStatement.h"

#include <memory>

namespace SkSL {

class Statement;

namespace dsl {

class DSLCase {
public:
    // An empty expression means 'default:'.
    template<class... Statements>
    DSLCase(DSLExpression value, Statements... statements)
        : fValue(std::move(value)) {
        fStatements.reserve_back(sizeof...(statements));
        // in C++17, we could just do:
        // (fStatements.push_back(DSLStatement(std::move(statements)).release()), ...);
        int unused[] =
          {0,
           (static_cast<void>(fStatements.push_back(DSLStatement(std::move(statements)).release())),
            0)...};
        static_cast<void>(unused);
    }

    DSLCase(DSLExpression value, SkTArray<DSLStatement> statements,
            PositionInfo info = PositionInfo::Capture());

    DSLCase(DSLExpression value, SkSL::StatementArray statements,
            PositionInfo info = PositionInfo::Capture());

    DSLCase(DSLCase&&);

    ~DSLCase();

    DSLCase& operator=(DSLCase&&);

    void append(DSLStatement stmt);

private:
    DSLExpression fValue;
    SkSL::StatementArray fStatements;
    PositionInfo fPosition;

    friend class DSLCore;

    template<class... Cases>
    friend DSLPossibleStatement Switch(DSLExpression value, Cases... cases);
};

} // namespace dsl

} // namespace SkSL

#endif