Agrarsense
CSVFile.h
Go to the documentation of this file.
1// Copyright (c) 2024 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "UObject/NoExportTypes.h"
10
11#include <fstream>
12
13#include "CSVFile.generated.h"
14
15UENUM(BlueprintType)
16enum class ECSVDelimiter : uint8
17{
18 Comma,
20 Tab
21};
22
23UENUM(BlueprintType)
24enum class FCSVFileWriteOptions : uint8
25{
26 Immediate = 0 UMETA(DisplayName = "Immediate"),
27 Queue = 1 UMETA(DisplayName = "Queue")
28};
29
30USTRUCT(BlueprintType)
32{
33 GENERATED_BODY()
34
35 UPROPERTY(EditAnywhere, BlueprintReadWrite)
36 ECSVDelimiter Delimiter = ECSVDelimiter::Comma;
37
38 UPROPERTY(EditAnywhere, BlueprintReadWrite)
39 bool Append = false;
40
41 UPROPERTY(EditAnywhere, BlueprintReadWrite)
42 bool CreateUnique = false;
43
44 UPROPERTY(EditAnywhere, BlueprintReadWrite)
45 FCSVFileWriteOptions FileWriteOption = FCSVFileWriteOptions::Immediate;
46
47 UPROPERTY(EditAnywhere, BlueprintReadWrite)
48 int32 QueueSize = 256;
49
50 UPROPERTY(EditAnywhere, BlueprintReadWrite)
51 FString CustomPath;
52};
53
64UCLASS()
65class AGRARSENSE_API UCSVFile : public UObject
66{
67 GENERATED_BODY()
68
69public:
70 static UCSVFile* CreateCSVFile(const FString& FileNameWithoutExtension, const FCSVFileSettings& Settings);
71
72 void WriteRow(const TArray<FString>& Cells);
73
74 void Close();
75
76 void Destroy();
77
78private:
79
80 void Create(const FString& FileNameWithoutExtension, const FCSVFileSettings& Settings);
81
82 void OpenStream();
83
84 void WriteRaw(const FString& Line);
85
86 TArray<FString> PendingRows;
87
88 FString FilePath;
89
91
92 std::ofstream CSVStream;
93
94};
ECSVDelimiter
Definition: CSVFile.h:17
FCSVFileWriteOptions
Definition: CSVFile.h:25
std::ofstream CSVStream
Definition: CSVFile.h:92
FString FilePath
Definition: CSVFile.h:88
TArray< FString > PendingRows
Definition: CSVFile.h:86
FCSVFileSettings CurrentSettings
Definition: CSVFile.h:90