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/sksl/DSLExpression.h" 13 #include "include/sksl/DSLStatement.h" 14 15 #include <memory> 16 17 namespace SkSL { 18 19 class Statement; 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 // in C++17, we could just do: 31 // (fStatements.push_back(DSLStatement(std::move(statements)).release()), ...); 32 int unused[] = 33 {0, 34 (static_cast<void>(fStatements.push_back(DSLStatement(std::move(statements)).release())), 35 0)...}; 36 static_cast<void>(unused); 37 } 38 39 DSLCase(DSLExpression value, SkTArray<DSLStatement> statements, 40 PositionInfo info = PositionInfo::Capture()); 41 42 DSLCase(DSLExpression value, SkSL::StatementArray statements, 43 PositionInfo info = PositionInfo::Capture()); 44 45 DSLCase(DSLCase&&); 46 47 ~DSLCase(); 48 49 DSLCase& operator=(DSLCase&&); 50 51 void append(DSLStatement stmt); 52 53 private: 54 DSLExpression fValue; 55 SkSL::StatementArray fStatements; 56 PositionInfo fPosition; 57 58 friend class DSLCore; 59 60 template<class... Cases> 61 friend DSLPossibleStatement Switch(DSLExpression value, Cases... cases); 62 }; 63 64 } // namespace dsl 65 66 } // namespace SkSL 67 68 #endif 69