Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Plugins/SWIG/SWIG_DotNET/API_NWNXLib.i
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ MarshalPtr(Task::CExoTaskManager*, void*)
%shared_ptr(DataView)
%shared_ptr(DataBlock)
%shared_ptr(DataView::Shared)
%shared_ptr(sqlite3)

// Rename constants to unique classes.
%rename("%(regex:/(?:NWNXLib::API::Constants)::\s*(\w+)(?:.+)$/\\1/)s", regextarget=1, fullname=1, %$isenum) "NWNXLib::API::Constants::*";
%rename(SqliteDatabase) sqlite::database;

// Rename/ignore operators methods
%rename(_OpNot) operator!;
Expand Down Expand Up @@ -278,6 +280,7 @@ MapArray(CNWClass_Skill, CNWClass_Skill, CNWClass_SkillArray);
%template(CExoArrayListCNWSStatsSpellPtr) CExoArrayList<CNWSStats_Spell *>;
%template(CExoArrayListCNWSTagNode) CExoArrayList<CNWSTagNode>;
%template(CExoArrayListCNWVisibilityNodePtr) CExoArrayList<CNWVisibilityNode *>;
%template(CExoArrayListCNWVisibilityNode) CExoArrayList<CNWVisibilityNode>;
%template(CExoArrayListCResRef) CExoArrayList<CResRef>;
%template(CExoArrayListCScriptLogPtr) CExoArrayList<CScriptLog *>;
%template(CExoArrayListCSpellAddPtr) CExoArrayList<CSpell_Add *>;
Expand Down
1 change: 1 addition & 0 deletions Plugins/SWIG/SWIG_DotNET/NamespaceUsings.i
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ using namespace Task;
using namespace NWSync;
using namespace Hash;
using namespace InstanceLookup;
using namespace sqlite;
%}
69 changes: 69 additions & 0 deletions Plugins/SWIG/SWIG_DotNET/sqlite3.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

#include <algorithm>
#include <cctype>
#include <string>
#include <functional>
#include <ctime>
#include <tuple>
#include <memory>
#include <vector>
#include <optional>

struct sqlite_config;

namespace sqlite {

template<class T>
using optional = std::optional<T>;

class database;
class database_binder;

template<std::size_t> class binder;

typedef std::shared_ptr<sqlite3> connection_type;

template<typename Tuple, int Element = 0, bool Last = (std::tuple_size<Tuple>::value == Element)> struct tuple_iterate {
static void iterate(Tuple& t, database_binder& db) {
get_col_from_db(db, Element, std::get<Element>(t));
tuple_iterate<Tuple, Element + 1>::iterate(t, db);
}
};

template<typename Tuple, int Element> struct tuple_iterate<Tuple, Element, true> {
static void iterate(Tuple&, database_binder&) {}
};

class database {
protected:
std::shared_ptr<sqlite3> _db;

public:
database(const std::string &db_name, const sqlite_config &config = {}): _db(nullptr);

database(const std::u16string &db_name, const sqlite_config &config = {}): _db(nullptr);

database(std::shared_ptr<sqlite3> db): _db(db);

database_binder operator<<(const std::string& sql);

database_binder operator<<(const char* sql);

database_binder operator<<(const std::u16string& sql);

database_binder operator<<(const char16_t* sql);

connection_type connection() const;

sqlite3_int64 last_insert_rowid();

template <typename Function>
void define(const std::string &name, Function&& func);

template <typename StepFunction, typename FinalFunction>
void define(const std::string &name, StepFunction&& step, FinalFunction&& final);

};

}
4 changes: 4 additions & 0 deletions Plugins/SWIG/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ for exclude in "${EXCLUDES[@]}"; do
done

echo "%{" > $NWNXLIB_SWG
echo "#include \"External/sqlite3/include/sqlite3.h\"" >> $NWNXLIB_SWG
echo "#include \"External/sqlite3/sqlite_modern_cpp/sqlite_modern_cpp.h\"" >> $NWNXLIB_SWG

find ../../../NWNXLib/API -type f -name '*.hpp' "${FIND_ARGS[@]}" -printf '#include "%P"\n' | sort >> $NWNXLIB_SWG
echo "%}" >> $NWNXLIB_SWG

echo "%include NamespaceUsings.i" >> $NWNXLIB_SWG
echo "%include sqlite3.i" >> $NWNXLIB_SWG

for include in "${FIRST_INCLUDES[@]}"
do
Expand Down