1e5c31af7Sopenharmony_ci#ifndef _TCUSTRINGTEMPLATE_HPP 2e5c31af7Sopenharmony_ci#define _TCUSTRINGTEMPLATE_HPP 3e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 4e5c31af7Sopenharmony_ci * drawElements Quality Program Tester Core 5e5c31af7Sopenharmony_ci * ---------------------------------------- 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 8e5c31af7Sopenharmony_ci * Copyright (c) 2020 The Khronos Group Inc. 9e5c31af7Sopenharmony_ci * Copyright (c) 2020 Advanced Micro Devices, Inc. 10e5c31af7Sopenharmony_ci * 11e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 12e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 13e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 14e5c31af7Sopenharmony_ci * 15e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 16e5c31af7Sopenharmony_ci * 17e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 18e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 19e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 21e5c31af7Sopenharmony_ci * limitations under the License. 22e5c31af7Sopenharmony_ci * 23e5c31af7Sopenharmony_ci *//*! 24e5c31af7Sopenharmony_ci * \file 25e5c31af7Sopenharmony_ci * \brief String template class. 26e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 27e5c31af7Sopenharmony_ci 28e5c31af7Sopenharmony_ci#include <deStringUtil.hpp> 29e5c31af7Sopenharmony_ci 30e5c31af7Sopenharmony_ci#include <map> 31e5c31af7Sopenharmony_ci#include <string> 32e5c31af7Sopenharmony_ci 33e5c31af7Sopenharmony_cinamespace tcu 34e5c31af7Sopenharmony_ci{ 35e5c31af7Sopenharmony_ci 36e5c31af7Sopenharmony_ciclass StringTemplate 37e5c31af7Sopenharmony_ci{ 38e5c31af7Sopenharmony_cipublic: 39e5c31af7Sopenharmony_ci StringTemplate (void); 40e5c31af7Sopenharmony_ci StringTemplate (const std::string& str); 41e5c31af7Sopenharmony_ci StringTemplate (StringTemplate&& other); 42e5c31af7Sopenharmony_ci ~StringTemplate (void); 43e5c31af7Sopenharmony_ci 44e5c31af7Sopenharmony_ci void setString (const std::string& str); 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci std::string specialize (const std::map<std::string, std::string>& params) const; 47e5c31af7Sopenharmony_ci 48e5c31af7Sopenharmony_ci template <typename... args_t> 49e5c31af7Sopenharmony_ci std::string format (args_t&&... args) const; 50e5c31af7Sopenharmony_ci 51e5c31af7Sopenharmony_ciprivate: 52e5c31af7Sopenharmony_ci StringTemplate (const StringTemplate&); // not allowed! 53e5c31af7Sopenharmony_ci StringTemplate& operator= (const StringTemplate&); // not allowed! 54e5c31af7Sopenharmony_ci 55e5c31af7Sopenharmony_ci std::string m_template; 56e5c31af7Sopenharmony_ci} DE_WARN_UNUSED_TYPE; 57e5c31af7Sopenharmony_ci 58e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 59e5c31af7Sopenharmony_ci * Utility to unpack consecutive arguments into a parameter map 60e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 61e5c31af7Sopenharmony_cinamespace detail 62e5c31af7Sopenharmony_ci{ 63e5c31af7Sopenharmony_cistatic constexpr const char* TOKENS[] = { 64e5c31af7Sopenharmony_ci "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", 65e5c31af7Sopenharmony_ci "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", 66e5c31af7Sopenharmony_ci "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", 67e5c31af7Sopenharmony_ci "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", 68e5c31af7Sopenharmony_ci "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", 69e5c31af7Sopenharmony_ci "55", "56", "57", "58", "59", "60", "61", "62", "63"}; 70e5c31af7Sopenharmony_ci 71e5c31af7Sopenharmony_citemplate <size_t ARG_NUM, typename unpacked_t> 72e5c31af7Sopenharmony_ciinline void unpackArgs(unpacked_t&) {} 73e5c31af7Sopenharmony_ci 74e5c31af7Sopenharmony_citemplate <size_t ARG_NUM, typename unpacked_t, typename arg_t, typename... args_t> 75e5c31af7Sopenharmony_ciinline void unpackArgs(unpacked_t& unpacked, arg_t&& cur, args_t&&... args) 76e5c31af7Sopenharmony_ci{ 77e5c31af7Sopenharmony_ci static_assert(ARG_NUM < DE_LENGTH_OF_ARRAY(TOKENS), 78e5c31af7Sopenharmony_ci "ARG_NUM must be less than DE_LENGTH_OF_ARRAY(TOKENS)"); 79e5c31af7Sopenharmony_ci unpacked[TOKENS[ARG_NUM]] = de::toString(cur); 80e5c31af7Sopenharmony_ci unpackArgs<ARG_NUM + 1>(unpacked, ::std::forward<args_t>(args)...); 81e5c31af7Sopenharmony_ci} 82e5c31af7Sopenharmony_ci} // detail 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ci/*--------------------------------------------------------------------*//*! 85e5c31af7Sopenharmony_ci * \brief Implementation of specialize() using a variable argument list 86e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 87e5c31af7Sopenharmony_citemplate <typename... args_t> 88e5c31af7Sopenharmony_cistd::string StringTemplate::format(args_t&&... args) const 89e5c31af7Sopenharmony_ci{ 90e5c31af7Sopenharmony_ci std::map<std::string, std::string> unpacked = {}; 91e5c31af7Sopenharmony_ci detail::unpackArgs<0>(unpacked, ::std::forward<args_t>(args)...); 92e5c31af7Sopenharmony_ci return specialize(unpacked); 93e5c31af7Sopenharmony_ci} 94e5c31af7Sopenharmony_ci 95e5c31af7Sopenharmony_ci} // tcu 96e5c31af7Sopenharmony_ci 97e5c31af7Sopenharmony_ci#endif // _TCUSTRINGTEMPLATE_HPP 98