simdjson  0.3.1
Ridiculously Fast JSON
padded_string.h
1 #ifndef SIMDJSON_PADDED_STRING_H
2 #define SIMDJSON_PADDED_STRING_H
3 #include "simdjson/portability.h"
4 #include "simdjson/common_defs.h" // for SIMDJSON_PADDING
5 #include "simdjson/error.h"
6 
7 #include <cstring>
8 #include <memory>
9 #include <string>
10 
11 namespace simdjson {
12 
18 struct padded_string final {
19 
23  explicit inline padded_string() noexcept;
29  explicit inline padded_string(size_t length) noexcept;
36  explicit inline padded_string(const char *data, size_t length) noexcept;
42  inline padded_string(const std::string & str_ ) noexcept;
48  inline padded_string(std::string_view sv_) noexcept;
56  inline padded_string(padded_string &&o) noexcept;
64  inline padded_string &operator=(padded_string &&o) noexcept;
65  inline void swap(padded_string &o) noexcept;
66  ~padded_string() noexcept;
67 
73  size_t size() const noexcept;
74 
80  size_t length() const noexcept;
81 
85  const char *data() const noexcept;
86 
90  char *data() noexcept;
91 
95  operator std::string_view() const;
96 
102  inline static simdjson_result<padded_string> load(const std::string &path) noexcept;
103 
104 private:
105  padded_string &operator=(const padded_string &o) = delete;
106  padded_string(const padded_string &o) = delete;
107 
108  size_t viable_size;
109  char *data_ptr{nullptr};
110 
111 }; // padded_string
112 
113 } // namespace simdjson
114 
115 // This is deliberately outside of simdjson so that people get it without having to use the namespace
116 inline simdjson::padded_string operator "" _padded(const char *str, size_t len) {
117  return simdjson::padded_string(str, len);
118 }
119 
120 namespace simdjson::internal {
121 
122 // low-level function to allocate memory with padding so we can read past the
123 // "length" bytes safely. if you must provide a pointer to some data, create it
124 // with this function: length is the max. size in bytes of the string caller is
125 // responsible to free the memory (free(...))
126 inline char *allocate_padded_buffer(size_t length) noexcept;
127 
128 } // namespace simdjson::internal;
129 
130 #endif // SIMDJSON_PADDED_STRING_H
simdjson::padded_string::data
const char * data() const noexcept
The string data.
Definition: padded_string.h:97
simdjson::padded_string::length
size_t length() const noexcept
The length of the string.
Definition: padded_string.h:95
simdjson::padded_string::operator=
padded_string & operator=(padded_string &&o) noexcept
Move one padded string into another.
Definition: padded_string.h:71
simdjson::padded_string::load
static simdjson_result< padded_string > load(const std::string &path) noexcept
Load this padded string from a file.
Definition: padded_string.h:103
simdjson::simdjson_result
The result of a simdjson operation that could fail.
Definition: error.h:166
simdjson::padded_string::size
size_t size() const noexcept
The length of the string.
Definition: padded_string.h:93
simdjson::padded_string::padded_string
padded_string() noexcept
Create a new, empty padded string.
Definition: padded_string.h:37
simdjson::padded_string
String with extra allocation for ease of use with parser::parse()
Definition: padded_string.h:18