Skip to content

Commit

Permalink
sarif: add adl serializers for optional an shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Jul 30, 2024
1 parent da2889b commit 31f041f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions sarif/include/gap/sarif/sarif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,44 @@

#include <nlohmann/json.hpp>

NLOHMANN_JSON_NAMESPACE_BEGIN

Check failure on line 27 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

‘NLOHMANN_JSON_NAMESPACE_BEGIN’ does not name a type

template< typename T >
struct adl_serializer< std::shared_ptr< T > > {
static void to_json(json &j, const std::shared_ptr< T > &opt) {
if (!opt)
j = nullptr;
else
j = *opt;
}

static std::shared_ptr< T > from_json(const json &j) {
if (j.is_null())
return std::make_shared< T >();
else
return std::make_shared< T >(j.get< T >());
}
};

template< typename T >
struct adl_serializer< std::optional< T > > {

Check failure on line 47 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

‘adl_serializer’ is not a class template
static void to_json(json &j, const std::optional< T > &opt) {

Check failure on line 48 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

‘json’ has not been declared
if (!opt)
j = nullptr;
else
j = *opt;
}

static std::optional< T > from_json(const json &j) {

Check failure on line 55 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

‘json’ does not name a type
if (j.is_null())

Check failure on line 56 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

request for member ‘is_null’ in ‘j’, which is of non-class type ‘const int’
return std::nullopt;
else
return std::make_optional< T >(j.get< T >());

Check failure on line 59 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

request for member ‘get’ in ‘j’, which is of non-class type ‘const int’

Check failure on line 59 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

expected primary-expression before ‘>’ token

Check failure on line 59 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

expected primary-expression before ‘)’ token
}
};

NLOHMANN_JSON_NAMESPACE_END

Check failure on line 63 in sarif/include/gap/sarif/sarif.hpp

View workflow job for this annotation

GitHub Actions / build

‘NLOHMANN_JSON_NAMESPACE_END’ does not name a type; did you mean ‘NLOHMANN_JSON_EXPAND’?

namespace gap::sarif
{
using json = nlohmann::json;
Expand Down

0 comments on commit 31f041f

Please sign in to comment.