aboutsummaryrefslogtreecommitdiff
path: root/include/proj/io.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/proj/io.hpp')
-rw-r--r--include/proj/io.hpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/include/proj/io.hpp b/include/proj/io.hpp
index c553598d..9c99fc0e 100644
--- a/include/proj/io.hpp
+++ b/include/proj/io.hpp
@@ -38,6 +38,7 @@
#include "proj.h"
+#include "proj_json_streaming_writer.hpp"
#include "util.hpp"
NS_PROJ_START
@@ -455,6 +456,102 @@ class PROJ_GCC_DLL PROJStringFormatter {
// ---------------------------------------------------------------------------
+class JSONFormatter;
+/** JSONFormatter unique pointer. */
+using JSONFormatterPtr = std::unique_ptr<JSONFormatter>;
+/** Non-null JSONFormatter unique pointer. */
+using JSONFormatterNNPtr = util::nn<JSONFormatterPtr>;
+
+/** \brief Formatter to JSON strings.
+ *
+ * An instance of this class can only be used by a single
+ * thread at a time.
+ */
+class PROJ_GCC_DLL JSONFormatter {
+ public:
+ PROJ_DLL static JSONFormatterNNPtr
+ create(DatabaseContextPtr dbContext = nullptr);
+ //! @cond Doxygen_Suppress
+ PROJ_DLL ~JSONFormatter();
+ //! @endcond
+
+ PROJ_DLL JSONFormatter &setMultiLine(bool multiLine) noexcept;
+ PROJ_DLL JSONFormatter &setIndentationWidth(int width) noexcept;
+ PROJ_DLL JSONFormatter &setSchema(const std::string &schema) noexcept;
+
+ PROJ_DLL const std::string &toString() const;
+
+ PROJ_PRIVATE :
+
+ //! @cond Doxygen_Suppress
+ PROJ_INTERNAL CPLJSonStreamingWriter &
+ writer() const;
+
+ struct ObjectContext {
+ JSONFormatter &m_formatter;
+
+ ObjectContext(const ObjectContext &) = delete;
+ ObjectContext(ObjectContext &&) = default;
+
+ explicit ObjectContext(JSONFormatter &formatter, const char *objectType,
+ bool hasId);
+ ~ObjectContext();
+ };
+ PROJ_INTERNAL inline ObjectContext MakeObjectContext(const char *objectType,
+ bool hasId) {
+ return ObjectContext(*this, objectType, hasId);
+ }
+
+ PROJ_INTERNAL void setAllowIDInImmediateChild();
+
+ PROJ_INTERNAL void setOmitTypeInImmediateChild();
+
+ PROJ_INTERNAL void setAbridgedTransformation(bool abriged);
+ PROJ_INTERNAL bool abridgedTransformation() const;
+
+ // cppcheck-suppress functionStatic
+ PROJ_INTERNAL bool outputId() const;
+
+ PROJ_INTERNAL bool outputUsage() const;
+
+ //! @endcond
+
+ protected:
+ //! @cond Doxygen_Suppress
+ PROJ_INTERNAL explicit JSONFormatter();
+ JSONFormatter(const JSONFormatter &other) = delete;
+
+ INLINED_MAKE_UNIQUE
+ //! @endcond
+
+ private:
+ PROJ_OPAQUE_PRIVATE_DATA
+};
+
+// ---------------------------------------------------------------------------
+
+/** \brief Interface for an object that can be exported to JSON. */
+class PROJ_GCC_DLL IJSONExportable {
+ public:
+ //! @cond Doxygen_Suppress
+ PROJ_DLL virtual ~IJSONExportable();
+ //! @endcond
+
+ /** Builds a JSON representation. May throw a FormattingException */
+ PROJ_DLL std::string
+ exportToJSON(JSONFormatter *formatter) const; // throw(FormattingException)
+
+ PROJ_PRIVATE :
+
+ //! @cond Doxygen_Suppress
+ PROJ_INTERNAL virtual void
+ _exportToJSON(
+ JSONFormatter *formatter) const = 0; // throw(FormattingException)
+ //! @endcond
+};
+
+// ---------------------------------------------------------------------------
+
/** \brief Exception possibly thrown by IWKTExportable::exportToWKT() or
* IPROJStringExportable::exportToPROJString(). */
class PROJ_GCC_DLL FormattingException : public util::Exception {