1 /* 2 * Copyright 2021 Google LLC. 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_DSL_CASE 9 #define SKSL_DSL_CASE 10 11 #include "include/private/SkSLDefines.h" 12 #include "include/private/base/SkTArray.h" 13 #include "include/sksl/DSLExpression.h" 14 #include "include/sksl/DSLStatement.h" 15 #include "include/sksl/SkSLPosition.h" 16 17 #include <utility> 18 19 namespace SkSL { 20 21 namespace dsl { 22 23 class DSLCase { 24 public: 25 // An empty expression means 'default:'. 26 template<class... Statements> DSLCase(DSLExpression value,Statements...statements)27 DSLCase(DSLExpression value, Statements... statements) 28 : fValue(std::move(value)) { 29 fStatements.reserve_back(sizeof...(statements)); 30 ((void)fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); 31 } 32 33 DSLCase(DSLExpression value, SkTArray<DSLStatement> statements, 34 Position pos = {}); 35 36 DSLCase(DSLExpression value, SkSL::StatementArray statements, 37 Position pos = {}); 38 39 DSLCase(DSLCase&&); 40 41 ~DSLCase(); 42 43 DSLCase& operator=(DSLCase&&); 44 45 void append(DSLStatement stmt); 46 47 private: 48 DSLExpression fValue; 49 SkSL::StatementArray fStatements; 50 Position fPosition; 51 52 friend class DSLCore; 53 54 template<class... Cases> 55 friend DSLStatement Switch(DSLExpression value, Cases... cases); 56 }; 57 58 } // namespace dsl 59 60 } // namespace SkSL 61 62 #endif 63