Files
fs2open.github.com/code/pilotfile/FileHandler.h
T
asarium 41e370fd2e Add option for writing pilot files in JSON format
This is a new implementation of the JSON dumping which was already
proposed in #22 but this version tries to allow implementing both
reading and writing JSON files without having to change the existing
code too much. This is done by using an abstract class to hide the
differences between writing the JSON and binary files.

This is currently only capable of writing the files but not reading them
so if the option is enabled all changes to the pilot file are lost. I
will implement reading after this PR has been merged since I would like
to reduce the amount of changes that need to be reviewed.
2016-08-19 18:48:29 +02:00

69 lines
1.6 KiB
C++

#ifndef FILEHANDLER_H
#define FILEHANDLER_H
#pragma once
#include <cstdint>
#include <memory>
#include "globalincs/pstypes.h"
#if SCP_COMPILER_IS_GNU
#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 {
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
};
#if SCP_COMPILER_IS_GNU
#pragma GCC diagnostic pop
#endif
namespace pilot {
class FileHandler {
public:
virtual ~FileHandler() {}
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 startSectionWrite(Section id) = 0;
virtual void endSectionWrite() = 0;
virtual void startArrayWrite(const char* name, size_t size, bool short_length = false) = 0;
virtual void endArrayWrite() = 0;
virtual void flush() = 0;
};
}
#endif // FILEHANDLER_H