DayZ 1.24
Loading...
Searching...
No Matches
JsonFileLoader< Class T > Class Reference
Collaboration diagram for JsonFileLoader< Class T >:
[legend]

Static Protected Member Functions

static bool LoadFile (string filename, out T data, out string errorMessage)
 
static bool SaveFile (string filename, T data, out string errorMessage)
 
static bool LoadData (string string_data, out T data, out string errorMessage)
 
static bool MakeData (T inputData, out string outputData, out string errorMessage, bool prettyPrint=true)
 
static void JsonLoadFile (string filename, out T data)
 #ifndef DIAG_DEVELOPER
 
static void JsonSaveFile (string filename, T data)
 use JsonFileLoader::SaveFile instead
 
static void JsonLoadData (string string_data, out T data)
 use JsonFileLoader::LoadData instead
 
static string JsonMakeData (T data)
 use JsonFileLoader::MakeData instead
 

Static Protected Attributes

static ref JsonSerializer m_Serializer = new JsonSerializer()
 

Detailed Description

Definition at line 1 of file JsonFileLoader.c.

Member Function Documentation

◆ JsonLoadData()

static void JsonFileLoader< Class T >::JsonLoadData ( string string_data,
out T data )
inlinestaticprotected

use JsonFileLoader::LoadData instead

Definition at line 149 of file JsonFileLoader.c.

150 {
151 string error;
152 if (!m_Serializer)
154
155 if (!m_Serializer.ReadFromString(data, string_data, error))
156 ErrorEx(string.Format("Cannot load data %1", error));
157 }
static ref JsonSerializer m_Serializer
Class for sending RPC over network.
Definition gameplay.c:50
enum ShapeType ErrorEx

References ErrorEx.

◆ JsonLoadFile()

static void JsonFileLoader< Class T >::JsonLoadFile ( string filename,
out T data )
inlinestaticprotected

#ifndef DIAG_DEVELOPER

DEPRECATED

use JsonFileLoader::LoadFile instead

Definition at line 105 of file JsonFileLoader.c.

106 {
107
108 if (FileExist(filename))
109 {
110 string file_content;
111 string line_content;
112 string error;
113
114 FileHandle handle = OpenFile(filename, FileMode.READ);
115 if (handle == 0)
116 return;
117
118 while (FGets(handle, line_content) >= 0)
120
121 CloseFile(handle);
122
123 if (!m_Serializer)
125
126 if (!m_Serializer.ReadFromString(data, file_content, error))
127 ErrorEx(string.Format("Cannot load data from \"%1\":\n%2", filename, error));
128 }
129 }
FileMode
Definition EnSystem.c:383
proto void CloseFile(FileHandle file)
Close the File.
proto int FGets(FileHandle file, string var)
Get line from file, every next call of this function returns next line.
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
proto bool FileExist(string name)
Check existence of file.

References CloseFile(), ErrorEx, FGets(), FileExist(), and OpenFile().

◆ JsonMakeData()

static string JsonFileLoader< Class T >::JsonMakeData ( T data)
inlinestaticprotected

use JsonFileLoader::MakeData instead

Definition at line 160 of file JsonFileLoader.c.

161 {
162 string string_data;
163 if (!m_Serializer)
165
166 m_Serializer.WriteToString(data, true, string_data);
167 return string_data;
168 }

◆ JsonSaveFile()

static void JsonFileLoader< Class T >::JsonSaveFile ( string filename,
T data )
inlinestaticprotected

use JsonFileLoader::SaveFile instead

Definition at line 132 of file JsonFileLoader.c.

133 {
134 string file_content;
135 if (!m_Serializer)
137
138 m_Serializer.WriteToString(data, true, file_content);
139
140 FileHandle handle = OpenFile(filename, FileMode.WRITE);
141 if (handle == 0)
142 return;
143
144 FPrint(handle, file_content);
145 CloseFile(handle);
146 }
proto void FPrint(FileHandle file, void var)
Write to file.

References CloseFile(), FPrint(), and OpenFile().

◆ LoadData()

static bool JsonFileLoader< Class T >::LoadData ( string string_data,
out T data,
out string errorMessage )
inlinestaticprotected

Definition at line 69 of file JsonFileLoader.c.

70 {
71 string error;
72
73 if (!m_Serializer)
75
76 if (!m_Serializer.ReadFromString(data, string_data, error))
77 {
78 errorMessage = string.Format("Cannot load provided JSON data (deserialization error) - check syntax: %1", error);
79 return false;
80 }
81
82 return true;
83 }

◆ LoadFile()

static bool JsonFileLoader< Class T >::LoadFile ( string filename,
out T data,
out string errorMessage )
inlinestaticprotected

Definition at line 5 of file JsonFileLoader.c.

6 {
8 {
9 FileHandle handle = OpenFile(filename, FileMode.READ);
10 if (handle == 0)
11 {
12 errorMessage = string.Format("Cannot open file \"%1\" for reading", filename);
13 return false;
14 }
15
16 string fileContent;
17 string lineContent;
18 while (FGets(handle, lineContent) >= 0)
20
21 CloseFile(handle);
22
23 if (!m_Serializer)
25
26 string error;
27 if (!m_Serializer.ReadFromString(data, fileContent, error))
28 {
29 errorMessage = string.Format("Cannot load data from \"%1\":\n%2", filename, error);
30 return false;
31 }
32
33 return true;
34 }
35 else
36 {
37 errorMessage = string.Format("File \"%1\" does not exist, check the provided path", filename, error);
38 return false;
39 }
40 }

References CloseFile(), FGets(), FileExist(), and OpenFile().

◆ MakeData()

static bool JsonFileLoader< Class T >::MakeData ( T inputData,
out string outputData,
out string errorMessage,
bool prettyPrint = true )
inlinestaticprotected

Definition at line 85 of file JsonFileLoader.c.

86 {
87 if (!m_Serializer)
89
90 if (!m_Serializer.WriteToString(inputData, prettyPrint, outputData))
91 {
92 errorMessage = "Cannot create JSON from provided data (serialization error)";
93 return false;
94 }
95
96 return true;
97 }

◆ SaveFile()

static bool JsonFileLoader< Class T >::SaveFile ( string filename,
T data,
out string errorMessage )
inlinestaticprotected

Definition at line 42 of file JsonFileLoader.c.

43 {
44 string fileContent;
45
46 if (!m_Serializer)
48
49 string makeDataError;
51 {
52 errorMessage = string.Format("Cannot save data to file \"%1\", %2", filename, makeDataError);
53 return false;
54 }
55
56 FileHandle handle = OpenFile(filename, FileMode.WRITE);
57 if (handle == 0)
58 {
59 errorMessage = string.Format("Cannot open file \"%1\" for writing", filename);
60 return false;
61 }
62
63 FPrint(handle, fileContent);
64 CloseFile(handle);
65
66 return true;
67 }
static bool MakeData(T inputData, out string outputData, out string errorMessage, bool prettyPrint=true)

References CloseFile(), FPrint(), and OpenFile().

Member Data Documentation

◆ m_Serializer

ref JsonSerializer JsonFileLoader< Class T >::m_Serializer = new JsonSerializer()
staticprotected

Definition at line 3 of file JsonFileLoader.c.


The documentation for this class was generated from the following file: