CARLA
 
载入中...
搜索中...
未找到
rpc/String.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <string>
10
11#ifdef LIBCARLA_INCLUDED_FROM_UE4
13#include "UnrealString.h"
15#endif // LIBCARLA_INCLUDED_FROM_UE4
16
17namespace carla {
18namespace rpc {
19
20#ifdef LIBCARLA_INCLUDED_FROM_UE4
21
22 // 从FString到std:string的快速转换
23 // 与 FName 和 FText 不同,FString 可以与搜索、修改并且与其他字符串比较。
24 // 不过,这些操作会导致 FString 的开销比不可变字符串类更大。
25 static inline std::string FromFString(const FString &Str) {
26 return TCHAR_TO_UTF8(*Str);
27 }
28
29 // 从std:string到FString的快速转换
30 static inline FString ToFString(const std::string &str) {
31 return FString(str.size(), UTF8_TO_TCHAR(str.c_str()));
32 }
33
34 constexpr size_t MaxStringLength = 5000000; // 500万
35
36 // 从FString到长文本(std::string)更慢的转换
37 static inline std::string FromLongFString(const FString &Str) {
38 std::string result;
39 size_t i = 0;
40 while(i + MaxStringLength < Str.Len()) {
41 auto Substr = Str.Mid(i, MaxStringLength); // 取出Str中i开始,MaxStringLength结束的子串(下标从0开始)
42 std::string temp_string = TCHAR_TO_UTF8(*Substr);
43 result += temp_string; // 对于大于500万的字符串,每500万长度就附加到结果串中
44 i += MaxStringLength;
45 }
46 auto Substr = Str.Mid(i, Str.Len() - i); // 附上最后500万除不尽的子串
47 std::string temp_string = TCHAR_TO_UTF8(*Substr);
48 result += temp_string;
49 return result;
50 }
51
52 // 从长文本(std:string)到FString更慢的转换
53 static inline FString ToLongFString(const std::string &str) {
54 FString result = "";
55 for (size_t i = 0; i < str.size(); i++)
56 {
57 result += str[i];
58 }
59 return result;
60 }
61
62#endif // LIBCARLA_INCLUDED_FROM_UE4
63
64} // namespace rpc
65} // namespace carla
CARLA模拟器的主命名空间。
Definition Carla.cpp:139