| 1 | class BindMap { |
| 2 | public: |
| 3 | |
| 4 | // This nested class represents a single mapping between a parameter name |
| 5 | // and its associated parameter index in a prepared statement. |
| 6 | class Pair { friend class BindMap; |
| 7 | public: |
| 8 | |
| 9 | inline int GetIndex() { |
| 10 | return index; |
| 11 | } |
| 12 | |
| 13 | inline Napi::String GetName(Napi::Env env) { |
| 14 | return name.Value(); |
| 15 | } |
| 16 | |
| 17 | private: |
| 18 | |
| 19 | explicit Pair(Napi::Env env, const char* name, int index) |
| 20 | : name(Napi::Persistent(InternalizedFromUtf8(env, name, -1))), index(index) {} |
| 21 | |
| 22 | explicit Pair(Napi::Env env, Pair* pair) |
| 23 | : name(Napi::Persistent(pair->name.Value())), index(pair->index) {} |
| 24 | |
| 25 | const Napi::Reference<Napi::String> name; |
| 26 | const int index; |
| 27 | }; |
| 28 | |
| 29 | explicit BindMap(char _) { |
| 30 | assert(_ == 0); |
| 31 | pairs = NULL; |
| 32 | capacity = 0; |
| 33 | length = 0; |
| 34 | } |
| 35 | |
| 36 | ~BindMap() { |
| 37 | while (length) pairs[--length].~Pair(); |
| 38 | FREE_ARRAY<Pair>(pairs); |
| 39 | } |
| 40 | |
| 41 | inline Pair* GetPairs() { |
| 42 | return pairs; |
| 43 | } |
| 44 | |
| 45 | inline int GetSize() { |
| 46 | return length; |
| 47 | } |
| 48 | |
| 49 | // Adds a pair to the bind map, expanding the capacity if necessary. |
| 50 | void Add(Napi::Env env, const char* name, int index) { |
| 51 | assert(name != NULL); |
| 52 | if (capacity == length) Grow(env); |
| 53 | new (pairs + length++) Pair(env, name, index); |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | |
| 58 | void Grow(Napi::Env env) { |
| 59 | assert(capacity == length); |
| 60 | capacity = (capacity << 1) | 2; |
nothing calls this directly
no outgoing calls
no test coverage detected