Browse Source

Use json forward-declarations

Desour 1 year ago
parent
commit
7f6b09dce8

+ 1 - 0
src/client/client.cpp

@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <sstream>
 #include <cmath>
 #include <IFileSystem.h>
+#include <json/json.h>
 #include "client.h"
 #include "network/clientopcodes.h"
 #include "network/connection.h"

+ 1 - 0
src/cmake_config.h.in

@@ -27,6 +27,7 @@
 #cmakedefine01 USE_PROMETHEUS
 #cmakedefine01 USE_SPATIAL
 #cmakedefine01 USE_SYSTEM_GMP
+#cmakedefine01 USE_SYSTEM_JSONCPP
 #cmakedefine01 USE_REDIS
 #cmakedefine01 HAVE_ENDIAN_H
 #cmakedefine01 CURSES_HAVE_CURSES_H

+ 1 - 1
src/content/mods.h

@@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <vector>
 #include <string>
 #include <map>
-#include <json/json.h>
+#include "json-forwards.h"
 #include <unordered_set>
 #include "util/basic_macros.h"
 #include "config.h"

+ 4 - 2
src/convert_json.cpp

@@ -17,12 +17,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include "convert_json.h"
+
+#include <json/json.h>
+
 #include <iostream>
 #include <sstream>
 #include <memory>
 
-#include "convert_json.h"
-
 void fastWriteJson(const Json::Value &value, std::ostream &to)
 {
 	Json::StreamWriterBuilder builder;

+ 1 - 1
src/convert_json.h

@@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #pragma once
 
-#include <json/json.h>
+#include "json-forwards.h"
 #include <ostream>
 
 void fastWriteJson(const Json::Value &value, std::ostream &to);

+ 2 - 2
src/database/database-files.cpp

@@ -17,15 +17,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#include <cassert>
-#include "convert_json.h"
 #include "database-files.h"
+#include "convert_json.h"
 #include "remoteplayer.h"
 #include "settings.h"
 #include "porting.h"
 #include "filesys.h"
 #include "server/player_sao.h"
 #include "util/string.h"
+#include <cassert>
 
 // !!! WARNING !!!
 // This backend is intended to be used on Minetest 0.4.16 only for the transition backend

+ 1 - 1
src/database/database-files.h

@@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "database.h"
 #include <unordered_map>
 #include <unordered_set>
-#include <json/json.h>
+#include <json/json.h> // for Json::Value
 
 class PlayerDatabaseFiles : public PlayerDatabase
 {

+ 31 - 0
src/json-forwards.h

@@ -0,0 +1,31 @@
+/*
+Minetest
+Copyright (C) 2023 DS
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include "config.h"
+
+#if USE_SYSTEM_JSONCPP
+#include <json/version.h>
+#include <json/allocator.h>
+#include <json/config.h>
+#include <json/forwards.h>
+#else
+#include <json/json-forwards.h>
+#endif

+ 1 - 0
src/serverenvironment.cpp

@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include <algorithm>
+#include <stack>
 #include "serverenvironment.h"
 #include "settings.h"
 #include "log.h"

+ 2 - 2
src/serverlist.h

@@ -17,10 +17,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#include <iostream>
 #include "config.h"
 #include "content/mods.h"
-#include <json/json.h>
+#include "json-forwards.h"
+#include <iostream>
 
 #pragma once
 

+ 1 - 0
src/tool.cpp

@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "convert_json.h"
 #include "util/serialize.h"
 #include "util/numeric.h"
+#include <json/json.h>
 
 void ToolGroupCap::toJson(Json::Value &object) const
 {

+ 1 - 1
src/tool.h

@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <string>
 #include <iostream>
 #include "itemgroup.h"
-#include <json/json.h>
+#include "json-forwards.h"
 
 struct ItemDefinition;