Skip to content

iceoryx_utils/internal/cxx/string_internal.hpp🔗

Namespaces🔗

Name
iox
building block to easily create free function for logging in a library context
iox::cxx
iox::cxx::internal

Classes🔗

Name
class iox::cxx::string
string implementation with some adjustments in the API, because we are not allowed to throw exceptions or use heap. Please see iceoryx/iceoryx_utils/doc/fixedString.adoc for further information.
struct iox::cxx::internal::GetCapa
struct to get capacity of fixed string/string literal
struct iox::cxx::internal::GetCapa< string< N > >
struct iox::cxx::internal::GetCapa< char[N]>
struct iox::cxx::internal::GetSize
struct to get size of fixed string/string literal/std::string
struct iox::cxx::internal::GetSize< string< N > >
struct iox::cxx::internal::GetSize< char[N]>
struct iox::cxx::internal::GetSize< std::string >
struct iox::cxx::internal::GetData
struct to get a pointer to the char array of the fixed string/string literal/std::string
struct iox::cxx::internal::GetData< string< N > >
struct iox::cxx::internal::GetData< char[N]>
struct iox::cxx::internal::GetData< std::string >
struct iox::cxx::internal::SumCapa
struct to get the sum of the capacities of fixed strings/string literals
struct iox::cxx::internal::SumCapa<>
struct iox::cxx::internal::SumCapa< T, Targs... >
struct iox::cxx::internal::IsCharArray
struct to check whether an argument is a char array
struct iox::cxx::internal::IsCharArray< char[N]>
struct iox::cxx::internal::IsCxxString
struct to check whether an argument is a cxx string
struct iox::cxx::internal::IsCxxString< string< N > >

Source code🔗

// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_UTILS_CXX_STRING_INTERNAL_HPP
#define IOX_UTILS_CXX_STRING_INTERNAL_HPP

#include <cstdint>
#include <cstring>
#include <string>

namespace iox
{
namespace cxx
{
template <uint64_t>
class string;

namespace internal
{
template <uint64_t N>
using charArray = char[N];

template <typename T>
struct GetCapa
{
    static constexpr uint64_t capa = 0U;
};

template <uint64_t N>
struct GetCapa<string<N>>
{
    static constexpr uint64_t capa = N;
};

template <uint64_t N>
struct GetCapa<char[N]>
{
    static constexpr uint64_t capa = N - 1U;
};

template <typename T>
struct GetSize;

template <uint64_t N>
struct GetSize<string<N>>
{
    static uint64_t call(const string<N>& data) noexcept
    {
        return data.size();
    }
};

template <uint64_t N>
struct GetSize<char[N]>
{
    static uint64_t call(const charArray<N>& data) noexcept
    {
        return strnlen(data, N);
    }
};

template <>
struct GetSize<std::string>
{
    static uint64_t call(const std::string& data) noexcept
    {
        return data.size();
    }
};

template <typename T>
struct GetData;

template <uint64_t N>
struct GetData<string<N>>
{
    static const char* call(const string<N>& data) noexcept
    {
        return data.c_str();
    }
};

template <uint64_t N>
struct GetData<char[N]>
{
    static const char* call(const charArray<N>& data) noexcept
    {
        return &data[0];
    }
};

template <>
struct GetData<std::string>
{
    static const char* call(const std::string& data) noexcept
    {
        return data.data();
    }
};

template <typename... Targs>
struct SumCapa;

template <>
struct SumCapa<>
{
    static constexpr uint64_t value = 0U;
};

template <typename T, typename... Targs>
struct SumCapa<T, Targs...>
{
    static constexpr uint64_t value = GetCapa<T>::capa + SumCapa<Targs...>::value;
};

template <typename T>
struct IsCharArray
{
    static constexpr bool value = false;
};

template <uint64_t N>
struct IsCharArray<char[N]>
{
    static constexpr bool value = true;
};

template <typename T>
struct IsCxxString
{
    static constexpr bool value = false;
};

template <uint64_t N>
struct IsCxxString<string<N>>
{
    static constexpr bool value = true;
};
} // namespace internal
} // namespace cxx
} // namespace iox
#endif // IOX_UTILS_CXX_STRING_INTERNAL_HPP

Updated on 31 May 2022 at 15:29:15 CEST