diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2019-07-06 02:03:50 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2019-07-06 02:27:46 +0200 |
| commit | 17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd (patch) | |
| tree | 5993d701145e2117fb8598faa186312b98d54f00 /include | |
| parent | 1da55c8be619a21153845607a553c9d1206bc792 (diff) | |
| download | PROJ-17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd.tar.gz PROJ-17f0b0b3bc65ffba39bf6f22a12b2cc7fcb9bafd.zip | |
Proof-of-concept of JSON export limited to PrimeMeridian (refs #1545)
Diffstat (limited to 'include')
| -rw-r--r-- | include/proj/common.hpp | 5 | ||||
| -rw-r--r-- | include/proj/datum.hpp | 6 | ||||
| -rw-r--r-- | include/proj/io.hpp | 72 | ||||
| -rw-r--r-- | include/proj/metadata.hpp | 6 |
4 files changed, 87 insertions, 2 deletions
diff --git a/include/proj/common.hpp b/include/proj/common.hpp index 7940f4fc..d857dafd 100644 --- a/include/proj/common.hpp +++ b/include/proj/common.hpp @@ -104,6 +104,9 @@ class PROJ_GCC_DLL UnitOfMeasure : public util::BaseObject { const std::string &unitType = std::string()) const; // throw(io::FormattingException) + PROJ_INTERNAL void _exportToJSON( + io::JSONFormatter *formatter) const; // throw(io::FormattingException) + PROJ_INTERNAL std::string exportToPROJString() const; PROJ_INTERNAL bool @@ -329,6 +332,8 @@ class PROJ_GCC_DLL IdentifiedObject : public util::BaseObject, formatID(io::WKTFormatter *formatter) const; PROJ_INTERNAL void formatRemarks(io::WKTFormatter *formatter) const; + PROJ_INTERNAL void formatID(io::JSONFormatter *formatter) const; + PROJ_INTERNAL bool _isEquivalentTo(const util::IComparable *other, util::IComparable::Criterion criterion = diff --git a/include/proj/datum.hpp b/include/proj/datum.hpp index b7416497..47bab4a0 100644 --- a/include/proj/datum.hpp +++ b/include/proj/datum.hpp @@ -171,7 +171,8 @@ using PrimeMeridianNNPtr = util::nn<PrimeMeridianPtr>; * \remark Implements PrimeMeridian from \ref ISO_19111_2019 */ class PROJ_GCC_DLL PrimeMeridian final : public common::IdentifiedObject, - public io::IPROJStringExportable { + public io::IPROJStringExportable, + public io::IJSONExportable { public: //! @cond Doxygen_Suppress PROJ_DLL ~PrimeMeridian() override; @@ -198,6 +199,9 @@ class PROJ_GCC_DLL PrimeMeridian final : public common::IdentifiedObject, PROJ_INTERNAL void _exportToWKT(io::WKTFormatter *formatter) const override; // throw(io::FormattingException) + PROJ_INTERNAL void _exportToJSON(io::JSONFormatter *formatter) + const override; // throw(io::FormattingException) + PROJ_INTERNAL bool _isEquivalentTo(const util::IComparable *other, util::IComparable::Criterion criterion = diff --git a/include/proj/io.hpp b/include/proj/io.hpp index c553598d..71a6430d 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,77 @@ 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 const std::string &toString() const; + + PROJ_PRIVATE : + + //! @cond Doxygen_Suppress + PROJ_INTERNAL PROJ::CPLJSonStreamingWriter & + writer() const; + + // cppcheck-suppress functionStatic + PROJ_INTERNAL bool outputId() 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 { diff --git a/include/proj/metadata.hpp b/include/proj/metadata.hpp index d32996fb..37241e6f 100644 --- a/include/proj/metadata.hpp +++ b/include/proj/metadata.hpp @@ -361,7 +361,8 @@ using IdentifierNNPtr = util::nn<IdentifierPtr>; * originates from \ref ISO_19115 */ class PROJ_GCC_DLL Identifier : public util::BaseObject, - public io::IWKTExportable { + public io::IWKTExportable, + public io::IJSONExportable { public: //! @cond Doxygen_Suppress PROJ_DLL Identifier(const Identifier &other); @@ -401,6 +402,9 @@ class PROJ_GCC_DLL Identifier : public util::BaseObject, PROJ_INTERNAL void _exportToWKT(io::WKTFormatter *formatter) const override; // throw(io::FormattingException) + PROJ_INTERNAL void _exportToJSON(io::JSONFormatter *formatter) + const override; // throw(io::FormattingException) + //! @endcond protected: |
