File: FileHandler.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (115 lines) | stat: -rw-r--r-- 2,854 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

#ifndef FILEHANDLER_H
#define FILEHANDLER_H
#pragma once

#include <cstdint>
#include <memory>

#include "globalincs/pstypes.h"

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
// This suppresses a GCC bug where it thinks that the Cutscenes from the enum class below shadows a global variable
#pragma GCC diagnostic ignored "-Wshadow"
#endif

// sections of a pilot file. includes both plr and csg sections
enum class Section {
	Invalid = -1,
	Unnamed = 0, //!< Special unnamed section
	Flags = 0x0001,
	Info = 0x0002,
	Loadout = 0x0003,
	Controls = 0x0004,
	Multiplayer = 0x0005,
	Scoring = 0x0006,
	ScoringMulti = 0x0007,
	Techroom = 0x0008,
	HUD = 0x0009,
	Settings = 0x0010,
	RedAlert = 0x0011,
	Variables = 0x0012,
	Missions = 0x0013,
	Cutscenes = 0x0014,
	LastMissions = 0x0015,
	Containers = 0x0016
};
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

namespace pilot {
class FileHandler {
 public:
	virtual ~FileHandler() {}

	virtual void writeByte(const char* name, std::int8_t value) = 0;

	virtual void writeUByte(const char* name, std::uint8_t value) = 0;

	virtual void writeShort(const char* name, std::int16_t value) = 0;

	virtual void writeInt(const char* name, std::int32_t value) = 0;

	virtual void writeUInt(const char* name, std::uint32_t value) = 0;

	virtual void writeFloat(const char* name, float value) = 0;

	virtual void writeString(const char* name, const char* str) = 0;

	virtual void beginWritingSections() = 0;

	virtual void startSectionWrite(Section id) = 0;

	virtual void endSectionWrite() = 0;

	virtual void endWritingSections() = 0;

	virtual void startArrayWrite(const char* name, size_t size, bool short_length = false) = 0;

	virtual void endArrayWrite() = 0;

	virtual void flush() = 0;

	virtual std::int8_t readByte(const char* name) = 0;

	virtual std::uint8_t readUByte(const char* name) = 0;

	virtual std::int16_t readShort(const char* name) = 0;

	virtual std::int32_t readInt(const char* name) = 0;

	virtual std::uint32_t readUInt(const char* name) = 0;

	virtual float readFloat(const char* name) = 0;

	virtual SCP_string readString(const char* name) = 0;

	virtual void readString(const char* name, char* dest, size_t max_size) {
		auto string = readString(name);
		Assertion(string.size() < max_size, "String in file is too long! Maximum is "
			SIZE_T_ARG
			" but the file contained a string with length "
			SIZE_T_ARG
			"!", max_size, string.size());
		strcpy_s(dest, max_size, string.c_str());
	}

	virtual void beginSectionRead() = 0;

	virtual bool hasMoreSections() = 0;

	virtual Section nextSection() = 0;

	virtual void endSectionRead() = 0;

	virtual size_t startArrayRead(const char* name, bool short_index = false) = 0;

	virtual void nextArraySection() = 0;

	virtual void endArrayRead() = 0;
};
}

#endif // FILEHANDLER_H