SuperDex Physics C++ API
Loading...
Searching...
No Matches
dynamic_string.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
21
22#include <string>
23#include <string_view>
24
25namespace superdex {
26
27/**
28 * @brief Alias for std::string using a polymorphic superdex::Allocator pointer.
29 *
30 * @note It is safe to return this type of string from a DLL exported method (unlike std::string).
31 *
32 * @code{.cpp}
33 * DynamicString myString; // Uses GetDefaultAllocator()
34 * DynamicString myStringWithValue("Hello!"); // Uses GetDefaultAllocator()
35 * DynamicString myAllocatedString(&allocator);
36 * DynamicString myAllocatedStringWithValue("Hello!", &allocator);
37 * @endcode
38 */
39using DynamicString = std::basic_string<char, std::char_traits<char>, StlAllocator<char>>;
40
41} // namespace superdex
42
43/// @cond
44template <>
45struct std::hash<superdex::DynamicString> {
46 std::size_t operator()(superdex::DynamicString const& s) const noexcept {
47 return std::hash<std::string_view>{}(std::string_view{s.data(), s.size()});
48 }
49};
50/// @endcond
51
52// Reflection support for superdex::String
53#if MOCHI_USE_REFLECTION
54template <>
55struct SReflectTypeTraits<superdex::DynamicString> {
56 static constexpr SReflect::CoreType coreType = SReflect::CoreType::CT_string;
57 static SReflect::StringTypeInfo const& GetTypeInfo();
58};
59
60#endif // MOCHI_USE_REFLECTION
std::basic_string< char, std::char_traits< char >, StlAllocator< char > > DynamicString
Alias for std::string using a polymorphic superdex::Allocator pointer.