1 // Copyright 2020 The Tint Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "src/inspector/scalar.h" 16 17 namespace tint { 18 namespace inspector { 19 Scalar()20Scalar::Scalar() : type_(kNull) {} 21 Scalar(bool val)22Scalar::Scalar(bool val) : type_(kBool) { 23 value_.b = val; 24 } 25 Scalar(uint32_t val)26Scalar::Scalar(uint32_t val) : type_(kU32) { 27 value_.u = val; 28 } 29 Scalar(int32_t val)30Scalar::Scalar(int32_t val) : type_(kI32) { 31 value_.i = val; 32 } 33 Scalar(float val)34Scalar::Scalar(float val) : type_(kFloat) { 35 value_.f = val; 36 } 37 IsNull() const38bool Scalar::IsNull() const { 39 return type_ == kNull; 40 } 41 IsBool() const42bool Scalar::IsBool() const { 43 return type_ == kBool; 44 } 45 IsU32() const46bool Scalar::IsU32() const { 47 return type_ == kU32; 48 } 49 IsI32() const50bool Scalar::IsI32() const { 51 return type_ == kI32; 52 } 53 IsFloat() const54bool Scalar::IsFloat() const { 55 return type_ == kFloat; 56 } 57 AsBool() const58bool Scalar::AsBool() const { 59 return value_.b; 60 } 61 AsU32() const62uint32_t Scalar::AsU32() const { 63 return value_.u; 64 } 65 AsI32() const66int32_t Scalar::AsI32() const { 67 return value_.i; 68 } 69 AsFloat() const70float Scalar::AsFloat() const { 71 return value_.f; 72 } 73 74 } // namespace inspector 75 } // namespace tint 76