mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-11 04:31:35 -10:00
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.
57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
|
|
#ifndef JSON_FILE_HANDLER_H
|
|
#define JSON_FILE_HANDLER_H
|
|
#pragma once
|
|
|
|
#include "pilotfile/FileHandler.h"
|
|
|
|
#include "globalincs/pstypes.h"
|
|
#include "cfile/cfile.h"
|
|
|
|
#include <jansson.h>
|
|
|
|
namespace pilot {
|
|
class JSONFileHandler: public FileHandler {
|
|
CFILE* _cfp;
|
|
|
|
json_t* _rootObj;
|
|
|
|
json_t* _currentEl;
|
|
|
|
SCP_vector<json_t*> _elementStack;
|
|
|
|
void ensureNotExists(const char* name);
|
|
void writeInteger(const char* name, json_int_t value);
|
|
public:
|
|
explicit JSONFileHandler(CFILE* cfp);
|
|
|
|
~JSONFileHandler() override;
|
|
|
|
void writeUByte(const char* name, std::uint8_t value) override;
|
|
|
|
void writeShort(const char* name, std::int16_t value) override;
|
|
|
|
void writeInt(const char* name, std::int32_t value) override;
|
|
|
|
void writeUInt(const char* name, std::uint32_t value) override;
|
|
|
|
void writeFloat(const char* name, float value) override;
|
|
|
|
void writeString(const char* name, const char* str) override;
|
|
|
|
|
|
void startSectionWrite(Section id) override;
|
|
|
|
void endSectionWrite() override;
|
|
|
|
|
|
void startArrayWrite(const char* name, size_t size, bool short_length = false) override;
|
|
|
|
void endArrayWrite() override;
|
|
|
|
void flush() override;
|
|
};
|
|
}
|
|
|
|
#endif // JSON_FILE_HANDLER_H
|