|
21 | 21 | #include <unordered_map> |
22 | 22 | #include <vector> |
23 | 23 |
|
| 24 | +#if __cplusplus >= 201703L |
| 25 | +#include <string_view> |
| 26 | +#endif |
| 27 | +#if __cplusplus >= 202002L |
| 28 | +#include <span> |
| 29 | +#endif |
| 30 | + |
24 | 31 | #ifdef _WIN32 |
25 | 32 | # ifdef SIMPLECPP_EXPORT |
26 | 33 | # define SIMPLECPP_LIB __declspec(dllexport) |
|
46 | 53 | # pragma warning(disable : 4244) |
47 | 54 | #endif |
48 | 55 |
|
| 56 | +// provide unsafe (i.e. raw pointer) API for TokenList |
| 57 | +// note: std::istream has an overhead compared to raw pointers |
| 58 | +#ifndef SIMPLECPP_UNSAFE_API |
| 59 | +// still provide the unsafe API for standards which lack the performant wrappers |
| 60 | +# if __cplusplus < 201703L |
| 61 | +# define SIMPLECPP_UNSAFE_API |
| 62 | +# endif |
| 63 | +#endif |
| 64 | + |
49 | 65 | namespace simplecpp { |
50 | 66 | /** C code standard */ |
51 | 67 | enum cstd_t { CUnknown=-1, C89, C99, C11, C17, C23 }; |
@@ -217,10 +233,27 @@ namespace simplecpp { |
217 | 233 | explicit TokenList(std::vector<std::string> &filenames); |
218 | 234 | /** generates a token list from the given std::istream parameter */ |
219 | 235 | TokenList(std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); |
| 236 | +#ifdef SIMPLECPP_UNSAFE_API |
220 | 237 | /** generates a token list from the given buffer */ |
221 | 238 | TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); |
222 | 239 | /** generates a token list from the given buffer */ |
223 | 240 | TokenList(const char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr); |
| 241 | +#endif |
| 242 | +#if __cplusplus >= 201703L |
| 243 | + /** generates a token list from the given buffer */ |
| 244 | + TokenList(std::string_view data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 245 | + : TokenList(data.data(), data.size(), filenames, filename, outputList) |
| 246 | + { |
| 247 | + } |
| 248 | +#endif |
| 249 | +#if __cplusplus >= 202002L |
| 250 | + /** generates a token list from the given buffer */ |
| 251 | + TokenList(std::span<char> data, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = nullptr) |
| 252 | + : TokenList(data.data(), data.size(), filenames, filename, outputList) |
| 253 | + { |
| 254 | + } |
| 255 | +#endif |
| 256 | + |
224 | 257 | /** generates a token list from the given filename parameter */ |
225 | 258 | TokenList(const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList = nullptr); |
226 | 259 | TokenList(const TokenList &other); |
|
0 commit comments