skia2/include/sksl/DSLCase.h
Ethan Nicholas 885c1d3048 Removed Position::Capture
It was decided that being able to report positions from C++ code is not
worth the cost of having all of these captures everywhere.

Change-Id: I94981d9f780bd95df8b56198210c9cdd5f16239c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528366
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2022-04-08 17:26:24 +00:00

69 lines
1.6 KiB
C++

/*
* 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/private/SkTArray.h"
#include "include/sksl/DSLExpression.h"
#include "include/sksl/DSLStatement.h"
#include "include/sksl/SkSLPosition.h"
#include <utility>
namespace SkSL {
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,
Position pos = {});
DSLCase(DSLExpression value, SkSL::StatementArray statements,
Position pos = {});
DSLCase(DSLCase&&);
~DSLCase();
DSLCase& operator=(DSLCase&&);
void append(DSLStatement stmt);
private:
DSLExpression fValue;
SkSL::StatementArray fStatements;
Position fPosition;
friend class DSLCore;
template<class... Cases>
friend DSLPossibleStatement Switch(DSLExpression value, Cases... cases);
};
} // namespace dsl
} // namespace SkSL
#endif