| 1 | class CustomTable { |
| 2 | public: |
| 3 | |
| 4 | explicit CustomTable( |
| 5 | Napi::Env env, |
| 6 | Database* db, |
| 7 | const char* name, |
| 8 | Napi::Function factory |
| 9 | ) : |
| 10 | addon(db->GetAddon()), |
| 11 | env(env), |
| 12 | db(db), |
| 13 | name(name), |
| 14 | factory(Napi::Persistent(factory)) {} |
| 15 | |
| 16 | static void Destructor(void* self) { |
| 17 | delete static_cast<CustomTable*>(self); |
| 18 | } |
| 19 | |
| 20 | static sqlite3_module MODULE; |
| 21 | static sqlite3_module EPONYMOUS_MODULE; |
| 22 | |
| 23 | private: |
| 24 | |
| 25 | // This nested class is instantiated on each CREATE VIRTUAL TABLE statement. |
| 26 | class VTab { friend class CustomTable; |
| 27 | explicit VTab( |
| 28 | CustomTable* parent, |
| 29 | Napi::Function generator, |
| 30 | std::vector<std::string> parameter_names, |
| 31 | bool safe_ints |
| 32 | ) : |
| 33 | parent(parent), |
| 34 | parameter_count(parameter_names.size()), |
| 35 | safe_ints(safe_ints), |
| 36 | generator(Napi::Persistent(generator)), |
| 37 | parameter_names(parameter_names) { |
| 38 | ((void)base); |
| 39 | } |
| 40 | |
| 41 | static inline CustomTable::VTab* Upcast(sqlite3_vtab* vtab) { |
| 42 | return reinterpret_cast<VTab*>(vtab); |
| 43 | } |
| 44 | |
| 45 | inline sqlite3_vtab* Downcast() { |
| 46 | return reinterpret_cast<sqlite3_vtab*>(this); |
| 47 | } |
| 48 | |
| 49 | sqlite3_vtab base; |
| 50 | CustomTable * const parent; |
| 51 | const int parameter_count; |
| 52 | const bool safe_ints; |
| 53 | const Napi::FunctionReference generator; |
| 54 | const std::vector<std::string> parameter_names; |
| 55 | }; |
| 56 | |
| 57 | // This nested class is instantiated each time a virtual table is scanned. |
| 58 | class Cursor { friend class CustomTable; |
| 59 | static inline CustomTable::Cursor* Upcast(sqlite3_vtab_cursor* cursor) { |
| 60 | return reinterpret_cast<Cursor*>(cursor); |
nothing calls this directly
no outgoing calls
no test coverage detected