1 // Copyright 2019 The SwiftShader Authors. All Rights Reserved. 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 "Variable.hpp" 16 17 namespace vk { 18 namespace dbg { 19 20 std::atomic<int> Variables::nextID{}; 21 22 Variables::~Variables() = default; 23 get(const std::string & name)24std::shared_ptr<Value> Variables::get(const std::string &name) 25 { 26 std::shared_ptr<Value> found; 27 foreach([&](const Variable &var) { 28 if(var.name == name) 29 { 30 found = var.value; 31 return false; 32 } 33 return true; 34 }); 35 return found; 36 } 37 string(const FormatFlags & fmt)38std::string Variables::string(const FormatFlags &fmt /* = FormatFlags::Default */) 39 { 40 std::string out = ""; 41 auto subfmt = *fmt.subListFmt; 42 subfmt.listIndent = fmt.listIndent + fmt.subListFmt->listIndent; 43 bool first = true; 44 foreach([&](const Variable &var) { 45 if(!first) { out += fmt.listDelimiter; } 46 first = false; 47 out += fmt.listIndent; 48 out += var.name; 49 out += ": "; 50 out += var.value->get(subfmt); 51 return true; 52 }); 53 return fmt.listPrefix + out + fmt.listSuffix; 54 } 55 56 } // namespace dbg 57 } // namespace vk 58