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 FString CustomPath;
49};
50
61UCLASS()
62class AGRARSENSE_API UCSVFile : public UObject
63{
64 GENERATED_BODY()
65
66public:
67 static UCSVFile* CreateCSVFile(const FString& FileNameWithoutExtension, const FCSVFileSettings& Settings);
68
69 void WriteRow(const TArray<FString>& Cells);
70
71 void OpenFilePath();
72
73 void Close();
74
75 void Destroy();
76
77private:
78
79 void Create(const FString& FileNameWithoutExtension, const FCSVFileSettings& Settings);
80
81 void OpenStream();
82
83 void WriteRaw(const FString& Line);
84
85 TArray<FString> PendingRows;
86
87 FString FilePath;
88
90
91 std::ofstream CSVStream;
92
93};
ECSVDelimiter
Definition: CSVFile.h:17
FCSVFileWriteOptions
Definition: CSVFile.h:25
std::ofstream CSVStream
Definition: CSVFile.h:91
FString FilePath
Definition: CSVFile.h:87
TArray< FString > PendingRows
Definition: CSVFile.h:85
FCSVFileSettings CurrentSettings
Definition: CSVFile.h:89