CARLA
 
载入中...
搜索中...
未找到
CarlaRecorderHelpers.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 <sstream>
10#include <vector>
11
12// get the final path + filename
13std::string GetRecorderFilename(std::string Filename);
14
15// ---------
16// recorder
17// ---------
18
19// write binary data (using sizeof())
20template <typename T>
21void WriteValue(std::ostream &OutFile, const T &InObj)
22{
23 OutFile.write(reinterpret_cast<const char *>(&InObj), sizeof(T));
24}
25
26template <typename T>
27void WriteStdVector(std::ostream &OutFile, const std::vector<T> &InVec)
28{
29 WriteValue<uint32_t>(OutFile, InVec.size());
30 for (const auto& InObj : InVec)
31 {
32 WriteValue<T>(OutFile, InObj);
33 }
34}
35
36template <typename T>
37void WriteTArray(std::ostream &OutFile, const TArray<T> &InVec)
38{
39 WriteValue<uint32_t>(OutFile, InVec.Num());
40 for (const auto& InObj : InVec)
41 {
42 WriteValue<T>(OutFile, InObj);
43 }
44}
45
46// write binary data from FVector
47void WriteFVector(std::ostream &OutFile, const FVector &InObj);
48
49// write binary data from FTransform
50void WriteFTransform(std::ofstream &OutFile, const FTransform &InObj);
51// write binary data from FString (length + text)
52void WriteFString(std::ostream &OutFile, const FString &InObj);
53
54// ---------
55// replayer
56// ---------
57
58// read binary data (using sizeof())
59template <typename T>
60void ReadValue(std::istream &InFile, T &OutObj)
61{
62 InFile.read(reinterpret_cast<char *>(&OutObj), sizeof(T));
63}
64
65template <typename T>
66void ReadStdVector(std::istream &InFile, std::vector<T> &OutVec)
67{
68 uint32_t VecSize;
69 ReadValue<uint32_t>(InFile, VecSize);
70 OutVec.clear();
71 for (uint32_t i = 0; i < VecSize; ++i)
72 {
73 T InObj;
74 ReadValue<T>(InFile, InObj);
75 OutVec.push_back(InObj);
76 }
77}
78
79template <typename T>
80void ReadTArray(std::istream &InFile, TArray<T> &OutVec)
81{
82 uint32_t VecSize;
83 ReadValue<uint32_t>(InFile, VecSize);
84 OutVec.Empty();
85 for (uint32_t i = 0; i < VecSize; ++i)
86 {
87 T InObj;
88 ReadValue<T>(InFile, InObj);
89 OutVec.Add(InObj);
90 }
91}
92
93// read binary data from FVector
94void ReadFVector(std::istream &InFile, FVector &OutObj);
95
96// read binary data from FTransform
97void ReadTransform(std::ifstream &InFile, FTransform &OutObj);
98// read binary data from FString (length + text)
99void ReadFString(std::istream &InFile, FString &OutObj);
void WriteTArray(std::ostream &OutFile, const TArray< T > &InVec)
void ReadTransform(std::ifstream &InFile, FTransform &OutObj)
void WriteFTransform(std::ofstream &OutFile, const FTransform &InObj)
void WriteFString(std::ostream &OutFile, const FString &InObj)
void ReadFString(std::istream &InFile, FString &OutObj)
void WriteStdVector(std::ostream &OutFile, const std::vector< T > &InVec)
void ReadTArray(std::istream &InFile, TArray< T > &OutVec)
void ReadStdVector(std::istream &InFile, std::vector< T > &OutVec)
void WriteFVector(std::ostream &OutFile, const FVector &InObj)
void WriteValue(std::ostream &OutFile, const T &InObj)
void ReadFVector(std::istream &InFile, FVector &OutObj)
std::string GetRecorderFilename(std::string Filename)
void ReadValue(std::istream &InFile, T &OutObj)