Skip to content

Commit

Permalink
Update struct json (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Jul 26, 2023
1 parent 507769a commit 405c81f
Show file tree
Hide file tree
Showing 14 changed files with 709 additions and 540 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,14 @@ see [Build Website](https://github.com/alibaba/yalantinglibs/blob/main/website/R
4. Choose one or more reviewers from contributors: (e.g., qicosmos, poor-circle, PikachuHyA).
5. Get approved and merged.

# Discussion group

DingTalk group

<center>
<img src="./website/docs/public/img/yalantinglibs_ding_talk_group.png" alt="dingtalk" width="200" height="200" align="bottom" />
</center>

## License

yaLanTingLibs is distributed under the Apache License (Version 2.0)
Expand Down
14 changes: 8 additions & 6 deletions include/ylt/struct_json/json_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ IGUANA_INLINE void from_json(T &value, It &&it, It &&end,
iguana::from_json(value, it, end, ec);
}

template <typename T, iguana::json_view View>
template <typename T, typename View>
IGUANA_INLINE void from_json(T &value, const View &view) {
iguana::from_json(value, view);
}

template <typename T, iguana::json_view View>
template <typename T, typename View>
IGUANA_INLINE void from_json(T &value, const View &view,
std::error_code &ec) noexcept {
iguana::from_json(value, view, ec);
}

template <typename T, iguana::json_byte Byte>
template <typename T, typename Byte>
IGUANA_INLINE void from_json(T &value, const Byte *data, size_t size) {
iguana::from_json(value, data, size);
}

template <typename T, iguana::json_byte Byte>
template <typename T, typename Byte>
IGUANA_INLINE void from_json(T &value, const Byte *data, size_t size,
std::error_code &ec) noexcept {
iguana::from_json(value, data, size, ec);
Expand All @@ -61,6 +61,8 @@ IGUANA_INLINE void from_json_file(T &value, const std::string &filename,
iguana::from_json_file(value, filename, ec);
}

using numeric_str = iguana::numeric_str;

// dom parse
using jvalue = iguana::jvalue;
using jarray = iguana::jarray;
Expand All @@ -76,12 +78,12 @@ inline void parse(jvalue &result, It &&it, It &&end, std::error_code &ec) {
iguana::parse(result, it, end, ec);
}

template <typename T, iguana::json_view View>
template <typename T, typename View>
inline void parse(T &result, const View &view) {
iguana::parse(result, view);
}

template <typename T, iguana::json_view View>
template <typename T, typename View>
inline void parse(T &result, const View &view, std::error_code &ec) {
iguana::parse(result, view, ec);
}
Expand Down
2 changes: 1 addition & 1 deletion include/ylt/struct_pack/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1895,4 +1895,4 @@ STRUCT_PACK_EXPAND_EACH(,STRUCT_PACK_GET_INDEX_CONST,STRUCT_PACK_MAKE_ARGS(Type,
template <std::size_t I> \
friend auto& STRUCT_PACK_GET(Type& c); \
template <std::size_t I> \
friend const auto& STRUCT_PACK_GET(const Type& c); \
friend const auto& STRUCT_PACK_GET(const Type& c);
89 changes: 89 additions & 0 deletions include/ylt/thirdparty/iguana/define.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#pragma once

#include <array>
#include <bit>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>

#if defined __clang__
#define IGUANA_INLINE __attribute__((always_inline)) inline
#define IGUANA__INLINE_LAMBDA __attribute__((always_inline)) constexpr
Expand All @@ -10,3 +17,85 @@
#define IGUANA_INLINE __attribute__((always_inline)) inline
#define IGUANA__INLINE_LAMBDA constexpr __attribute__((always_inline))
#endif

#if __has_cpp_attribute(likely) && __has_cpp_attribute(unlikely)
#define IGUANA_LIKELY [[likely]]
#define IGUANA_UNLIKELY [[unlikely]]
#else
#define IGUANA_LIKELY
#define IGUANA_UNLIKELY
#endif

#ifdef _MSC_VER

#if _MSC_VER >= 1920 && _MSVC_LANG >= 202002L
IGUANA_INLINE int countr_zero(unsigned long long x) {
return std::countr_zero(x);
}
template <typename T>
constexpr inline bool contiguous_iterator = std::contiguous_iterator<T>;

#else
IGUANA_INLINE int countr_zero(unsigned long long x) {
// x will never be zero in iguana
unsigned long pos;
_BitScanForward64(&pos, x);
return pos;
}

namespace std {
template <typename T>
using remove_cvref_t =
typename remove_cv<typename remove_reference<T>::type>::type;
}
template <typename T>
constexpr inline bool contiguous_iterator =
std::is_same_v<std::remove_cvref_t<T>,
typename std::vector<char>::iterator> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::vector<char>::const_iterator> ||
std::is_same_v<std::remove_cvref_t<T>, typename std::string::iterator> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::string::const_iterator> ||
std::is_same_v<std::remove_cvref_t<T>, char *> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::string_view::iterator> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::string_view::const_iterator>;
#endif

#else

#if __cplusplus >= 202002L
IGUANA_INLINE int countr_zero(unsigned long long x) {
return std::countr_zero(x);
}
template <typename T>
constexpr inline bool contiguous_iterator = std::contiguous_iterator<T>;
#else
IGUANA_INLINE int countr_zero(unsigned long long x) {
// x will never be zero in iguana
return __builtin_ctzll(x);
}
namespace std {
template <typename T>
using remove_cvref_t =
typename remove_cv<typename remove_reference<T>::type>::type;
}
template <typename T>
constexpr inline bool contiguous_iterator =
std::is_same_v<std::remove_cvref_t<T>,
typename std::vector<char>::iterator> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::vector<char>::const_iterator> ||
std::is_same_v<std::remove_cvref_t<T>, typename std::string::iterator> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::string::const_iterator> ||
std::is_same_v<std::remove_cvref_t<T>, char *> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::string_view::iterator> ||
std::is_same_v<std::remove_cvref_t<T>,
typename std::string_view::const_iterator>;
#endif

#endif
4 changes: 4 additions & 0 deletions include/ylt/thirdparty/iguana/detail/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include <type_traits>
#include <unordered_map>
#include <vector>

#include "iguana/define.h"

namespace iguana {

template <class T>
struct is_signed_intergral_like
: std::integral_constant<bool, (std::is_integral<T>::value) &&
Expand Down
Loading

0 comments on commit 405c81f

Please sign in to comment.