simdjson  3.11.0
Ridiculously Fast JSON
implementation.h
1 #ifndef SIMDJSON_IMPLEMENTATION_H
2 #define SIMDJSON_IMPLEMENTATION_H
3 
4 #include "simdjson/internal/atomic_ptr.h"
5 #include "simdjson/internal/dom_parser_implementation.h"
6 
7 #include <memory>
8 
9 namespace simdjson {
10 
18 simdjson_warn_unused bool validate_utf8(const char * buf, size_t len) noexcept;
25 simdjson_inline simdjson_warn_unused bool validate_utf8(const std::string_view sv) noexcept {
26  return validate_utf8(sv.data(), sv.size());
27 }
28 
35 simdjson_inline simdjson_warn_unused bool validate_utf8(const std::string& s) noexcept {
36  return validate_utf8(s.data(), s.size());
37 }
38 
46 public:
47 
56  virtual std::string name() const { return std::string(_name); }
57 
66  virtual std::string description() const { return std::string(_description); }
67 
76 
84  virtual uint32_t required_instruction_sets() const { return _required_instruction_sets; }
85 
97  virtual error_code create_dom_parser_implementation(
98  size_t capacity,
99  size_t max_depth,
100  std::unique_ptr<internal::dom_parser_implementation> &dst
101  ) const noexcept = 0;
102 
116  simdjson_warn_unused virtual error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) const noexcept = 0;
117 
118 
128  simdjson_warn_unused virtual bool validate_utf8(const char *buf, size_t len) const noexcept = 0;
129 
130 protected:
132  simdjson_inline implementation(
133  std::string_view name,
134  std::string_view description,
135  uint32_t required_instruction_sets
136  ) :
137  _name(name),
138  _description(description),
139  _required_instruction_sets(required_instruction_sets)
140  {
141  }
142 protected:
143  ~implementation() = default;
144 
145 private:
149  std::string_view _name;
150 
154  std::string_view _description;
155 
159  const uint32_t _required_instruction_sets;
160 };
161 
163 namespace internal {
164 
168 class available_implementation_list {
169 public:
171  simdjson_inline available_implementation_list() {}
173  size_t size() const noexcept;
175  const implementation * const *begin() const noexcept;
177  const implementation * const *end() const noexcept;
178 
192  const implementation * operator[](const std::string_view &name) const noexcept {
193  for (const implementation * impl : *this) {
194  if (impl->name() == name) { return impl; }
195  }
196  return nullptr;
197  }
198 
211  const implementation *detect_best_supported() const noexcept;
212 };
213 
214 } // namespace internal
215 
219 extern SIMDJSON_DLLIMPORTEXPORT const internal::available_implementation_list& get_available_implementations();
220 
226 extern SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr<const implementation>& get_active_implementation();
227 
228 } // namespace simdjson
229 
230 #endif // SIMDJSON_IMPLEMENTATION_H
An implementation of simdjson for a particular CPU architecture.
virtual std::string name() const
The name of this implementation.
virtual simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) const noexcept=0
Validate the UTF-8 string.
virtual std::string description() const
The description of this implementation.
bool supported_by_runtime_system() const
The instruction sets this implementation is compiled against and the current CPU match.
The top level simdjson namespace, containing everything the library provides.
Definition: base.h:8
simdjson_warn_unused bool validate_utf8(const char *buf, size_t len) noexcept
Validate the UTF-8 string.
error_code
All possible errors returned by simdjson.
Definition: error.h:19
SIMDJSON_DLLIMPORTEXPORT const internal::available_implementation_list & get_available_implementations()
The list of available implementations compiled into simdjson.
SIMDJSON_DLLIMPORTEXPORT internal::atomic_ptr< const implementation > & get_active_implementation()
The active implementation.