.. _program_listing_file__tmp_ws_src_apex_containers_apex_containers_include_string_to_string.hpp: Program Listing for File to_string.hpp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/apex_containers/apex_containers/include/string/to_string.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2017-2018 Apex.AI, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // //    http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef STRING__TO_STRING_HPP_ #define STRING__TO_STRING_HPP_ #include #include #include #include #include #include #include #include #include "base_string.hpp" #include "string_strict.hpp" #include "string_silent.hpp" namespace apex { APEX_CONTAINERS_PUBLIC apex::string256_t to_string(const char8_t * const c_text_ptr) noexcept; APEX_CONTAINERS_PUBLIC apex::string8_t to_string(const bool value) noexcept; APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::uint8_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::uint16_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::uint32_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string32_t to_string(const uint64_t value) noexcept; #ifndef APEX_WINDOWS inline apex::string32_t to_string(const long long unsigned int value) noexcept // NOLINT { return apex::to_string(static_cast(value)); } #endif // APEX_WINDOWS APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::int8_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::int16_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::int32_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string32_t to_string(const ::int64_t value) noexcept; #ifndef APEX_WINDOWS inline apex::string32_t to_string(const long long int value) noexcept // NOLINT { return apex::to_string(static_cast(value)); } #endif // APEX_WINDOWS APEX_CONTAINERS_PUBLIC apex::string16_t to_string(const ::float32_t value) noexcept; APEX_CONTAINERS_PUBLIC apex::string32_t to_string(const ::float64_t value) noexcept; inline auto to_string(const std::string & value) noexcept { return apex::to_string(value.c_str()); } template<::size64_t STRING_BUFFER_SIZE> inline auto to_string(const StringStrict & value) noexcept { return apex::to_string(value.c_str()); } // this is implementation. See the declaration in the String class. template<::size64_t STRING_BUFFER_SIZE> inline StringStrict StringStrict::to_string(const uint32_t value) { StringStrict retval = apex::to_string(value); return retval; } // this is implementation. See the declaration in the String class. template<::size64_t STRING_BUFFER_SIZE> inline String String::to_string(const uint32_t value) { apex::string16_t result = apex::to_string(value); if (result.size() >= String::get_buffer_size_static()) { throw std::overflow_error("result.size() >= this->capacity()"); } String retval = result; return retval; } template APEX_CONTAINERS_PUBLIC apex::string256_t varargs_to_string(Args const & ... args) noexcept { // This implementation is based on variadic template parameter pack // See https://en.cppreference.com/w/cpp/language/parameter_pack apex::string256_t result_str; const size64_t argc = sizeof ... (args); size64_t counter = 0U; // On the every element of the array add a parameter to the result_str. // If the parameter is not the last one, add a space separator after char8_t const string_filler[]{ '\0', // The "value" to put into the string_filler array when the parameter list is empty ( result_str += apex::to_string(args), // Add parameter string representation to result result_str += (counter < (argc - 1U)) ? " " : "", // Add a separator counter++, // Increment the parameter counter '\0') ... // The "value" to put into the string_filler array }; // We don't need string_filler array in the active code, we need its curved brackets initializer. // The below construct is a command to static analysis tools to ignore non-use of the array (void)string_filler; return result_str; } struct no_separator {}; template APEX_CONTAINERS_PUBLIC apex::string256_t varargs_to_string(no_separator tag, Args const & ... args) noexcept { (void)tag; apex::string256_t result_str; char8_t const string_filler[]{'\0', (result_str += apex::to_string(args), '\0') ...}; (void)string_filler; return result_str; } } // namespace apex #endif // STRING__TO_STRING_HPP_