diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-05-20 12:45:23 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-05-20 12:45:23 +0200 |
| commit | 8240eff87bb928e12a093cc37aae78576cdf4f6c (patch) | |
| tree | fada3c8d25be0923327697d9480adcdeda3d53ce /include | |
| parent | 44b67786e23d4254b918f4ebaae5459f463979e6 (diff) | |
| download | libstrvec-c-8240eff87bb928e12a093cc37aae78576cdf4f6c.tar.gz libstrvec-c-8240eff87bb928e12a093cc37aae78576cdf4f6c.zip | |
Make struct non-opaque and fix build.jst
Diffstat (limited to 'include')
| -rw-r--r-- | include/strvec.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/include/strvec.h b/include/strvec.h index 648487c..a7f622c 100644 --- a/include/strvec.h +++ b/include/strvec.h @@ -1,5 +1,6 @@ #pragma once +#include "dvec.h" #include "allocator.h" #include <stdbool.h> @@ -21,7 +22,9 @@ #define LIBSTRVEC_ABORT_ON_ALLOC(cond) #endif -struct strvec; +struct strvec { + struct dvec vec; +}; int strvec_init(struct strvec *strvec, size_t cap, struct allocator *allocator); int strvec_deinit(struct strvec *strvec); @@ -38,16 +41,15 @@ void strvec_clear(struct strvec *strvec); int strvec_reserve(struct strvec *strvec, size_t cap); int strvec_shrink(struct strvec *strvec); -const char **strvec_stra(struct strvec *strvec); +static inline const char **strvec_stra(struct strvec *strvec); -const char **strvec_at(struct strvec *strvec, size_t index); +static inline const char **strvec_at(struct strvec *strvec, size_t index); static inline const char *strvec_get(struct strvec *strvec, size_t index); static inline const char *strvec_front(struct strvec *strvec); static inline const char *strvec_back(struct strvec *strvec); -size_t strvec_len(struct strvec *strvec); +static inline size_t strvec_len(struct strvec *strvec); static inline bool strvec_empty(struct strvec *strvec); - int strvec_pushn(struct strvec *strvec, const char **str, size_t n); static inline int strvec_push(struct strvec *strvec, const char *str); const char **strvec_popn(struct strvec *strvec, size_t n); @@ -58,6 +60,30 @@ void strvec_remove(struct strvec *strvec, size_t index, size_t n); const char **strvec_iter_fwd(const struct strvec *strvec, const char **p); const char **strvec_iter_bwd(const struct strvec *strvec, const char **p); +static inline const char ** +strvec_stra(struct strvec *strvec) +{ + LIBSTRVEC_ABORT_ON_ARGS(!strvec && !strvec->vec.data); + + return strvec->vec.data; +} + +static inline const char ** +strvec_at(struct strvec *strvec, size_t index) +{ + LIBSTRVEC_ABORT_ON_ARGS(!strvec); + + return dvec_at(&strvec->vec, index); +} + +static inline size_t +strvec_len(struct strvec *strvec) +{ + LIBSTRVEC_ABORT_ON_ARGS(!strvec); + + return strvec->vec.len; +} + static inline bool strvec_empty(struct strvec *strvec) { @@ -95,5 +121,3 @@ strvec_pop(struct strvec *strvec) { return *strvec_popn(strvec, 1); } - -extern const size_t strvec_dsize; |
