diff --git a/src/memory.hpp b/src/memory.hpp
index 377e3f2..9c4c765 100644
--- a/src/memory.hpp
+++ b/src/memory.hpp
@@ -36,6 +36,4 @@ public:
static void free(void *ptr) throw();
};
-
-
#endif // VIDEO2P_MEMORY_HPP
diff --git a/src/move.hpp b/src/move.hpp
deleted file mode 100644
index 22d97e5..0000000
--- a/src/move.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- Video2P -- video hosting engine for I2P network.
- Copyright (C) 2023 - 2025 Video2P Team
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
-*/
-
-#ifndef VIDEO2P_MOVE_HPP
-#define VIDEO2P_MOVE_HPP
-
-#define VIDEO2P_MOVE_REF(TYPE) ::V2PMove::Ref&
-
-#define VIDEO2P_MOVE_IMPLEMENTATION(TYPE) \
- public: \
- inline operator ::V2PMove::Ref&() \
- { \
- return *reinterpret_cast< ::V2PMove::Ref*>(this); \
- } \
- \
- inline operator const ::V2PMove::Ref&() const \
- { \
- return *reinterpret_cast*>(this); \
- } \
-private:
-
-
-class V2PMove {
-public:
- template
- class Ref : public T {
- private:
- Ref();
- ~Ref() throw();
- Ref(const Ref&);
- void operator=(const Ref&);
- };
-
- template
- static Ref&
- move(T &object)
- {
- return *reinterpret_cast[*>(&object);
- }
-};
-
-#endif // VIDEO2P_MOVE_HPP
diff --git a/src/mysql.cpp b/src/mysql.cpp
index 79b7d8f..dd8b9fe 100644
--- a/src/mysql.cpp
+++ b/src/mysql.cpp
@@ -121,55 +121,31 @@ V2PMySQLResultSet::V2PMySQLResultSet(MYSQL_RES *result)
{
}
-V2PMySQLResultSet::V2PMySQLResultSet(VIDEO2P_MOVE_REF(V2PMySQLResultSet) other)
- throw()
- : m_result(other.m_result)
- , m_num_rows(other.m_num_rows)
- , m_cur_row_index(other.m_cur_row_index)
-{
- other.m_result = NULL;
- other.m_num_rows = 0;
- other.m_cur_row_index = 0;
-}
-
-V2PMySQLResultSet&
-V2PMySQLResultSet::operator=(VIDEO2P_MOVE_REF(V2PMySQLResultSet) other)
- throw()
-{
- m_result = other.m_result;
- m_num_rows = other.m_num_rows;
- m_cur_row_index = other.m_cur_row_index;
- other.m_result = NULL;
- other.m_num_rows = 0;
- other.m_cur_row_index = 0;
- return *this;
-}
-
V2PMySQLResultSet::~V2PMySQLResultSet()
throw()
{
mysql_free_result(m_result);
}
-V2PMySQLResultRow
+V2PMySQLResultRow*
V2PMySQLResultSet::getNextRow()
throw(V2PMySQLResultException)
{
if (m_cur_row_index++ < m_num_rows) {
- return V2PMySQLResultRow(mysql_fetch_row(m_result),
- mysql_num_fields(m_result));
+ return new V2PMySQLResultRow(mysql_fetch_row(m_result),
+ mysql_num_fields(m_result));
} else {
throw V2PMySQLResultException("ResultSet out of range");
}
}
-V2PMySQLResultRow
+V2PMySQLResultRow*
V2PMySQLResultSet::getRowByIndex(size_t index)
throw(V2PMySQLResultException)
{
if (index < m_num_rows) {
- return V2PMySQLResultRow(mysql_fetch_row(m_result),
- mysql_num_fields(m_result));
+ return new V2PMySQLResultRow(mysql_fetch_row(m_result),
+ mysql_num_fields(m_result));
} else {
throw V2PMySQLResultException("ResultSet out of range");
}
@@ -266,7 +242,7 @@ V2PMySQLConnection::ping() const
return mysql_ping(m_connection);
}
-VIDEO2P_MOVE_REF(V2PMySQLResultSet)
+V2PMySQLResultSet*
V2PMySQLConnection::query(const char *sql)
throw(V2PMySQLQueryException, V2PMySQLResultException)
{
@@ -279,6 +255,5 @@ V2PMySQLConnection::query(const char *sql)
throw V2PMySQLResultException(mysql_error(m_connection));
}
- V2PMySQLResultSet rs(result);
- return V2PMove::move(rs);
+ return new V2PMySQLResultSet(result);
}
diff --git a/src/mysql.hpp b/src/mysql.hpp
index dc3e8b4..0d5ebc8 100644
--- a/src/mysql.hpp
+++ b/src/mysql.hpp
@@ -21,7 +21,6 @@
#include "exception.hpp"
#include "string.hpp"
-#include "move.hpp"
#include
class V2PMySQLException : public V2PException {
@@ -69,35 +68,37 @@ public:
// Valid only util valid V2PMySQLResultSet
class V2PMySQLResultRow {
+public:
+ typedef unsigned index_t;
private:
MYSQL_ROW m_row;
- unsigned m_num_columns;
+ index_t m_num_columns;
public:
V2PMySQLResultRow(MYSQL_ROW row, unsigned num_columns) throw();
+private:
+ V2PMySQLResultRow(const V2PMySQLResultRow&);
+ V2PMySQLResultRow& operator=(const V2PMySQLResultRow&);
public:
size_t getSize() const throw();
const char *getColumn(size_t index) const throw();
};
class V2PMySQLResultSet {
- VIDEO2P_MOVE_IMPLEMENTATION(V2PMySQLResultSet)
+public:
+ typedef uint64_t index_t;
private:
MYSQL_RES *m_result;
- unsigned m_num_rows;
- unsigned m_cur_row_index;
+ index_t m_num_rows;
+ index_t m_cur_row_index;
public:
V2PMySQLResultSet(MYSQL_RES *result) throw();
private:
V2PMySQLResultSet(const V2PMySQLResultSet&);
V2PMySQLResultSet& operator=(const V2PMySQLResultSet&);
public:
- V2PMySQLResultSet(VIDEO2P_MOVE_REF(V2PMySQLResultSet) other)
- throw();
- V2PMySQLResultSet& operator=(VIDEO2P_MOVE_REF(V2PMySQLResultSet) other)
- throw();
~V2PMySQLResultSet() throw();
- V2PMySQLResultRow getNextRow() throw(V2PMySQLResultException);
- V2PMySQLResultRow getRowByIndex(size_t index)
+ V2PMySQLResultRow* getNextRow() throw(V2PMySQLResultException);
+ V2PMySQLResultRow* getRowByIndex(size_t index)
throw(V2PMySQLResultException);
size_t getSize() const throw();
size_t getCurrentIndex() const throw();
@@ -140,10 +141,8 @@ public:
void reconnect()
throw(V2PMySQLInitException, V2PMySQLConnectionException);
int ping() const throw();
- VIDEO2P_MOVE_REF(V2PMySQLResultSet) query(const char *sql)
+ V2PMySQLResultSet* query(const char *sql)
throw(V2PMySQLQueryException, V2PMySQLResultException);
-
- friend class V2PMySQLResultSet;
};
diff --git a/src/scoped_ptr.hpp b/src/scoped_ptr.hpp
new file mode 100644
index 0000000..76819ea
--- /dev/null
+++ b/src/scoped_ptr.hpp
@@ -0,0 +1,124 @@
+/*
+ Video2P -- video hosting engine for I2P network.
+ Copyright (C) 2023 - 2025 Video2P Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+#ifndef VIDEO2P_SCOPED_PTR_HPP
+#define VIDEO2P_SCOPED_PTR_HPP
+
+#include
+
+template
+class V2PScopedPtr {
+private:
+ T *m_ptr;
+public:
+ V2PScopedPtr(T *ptr)
+ throw()
+ : m_ptr(ptr)
+ {
+ }
+private:
+ V2PScopedPtr(const V2PScopedPtr&);
+ V2PScopedPtr& operator=(const V2PScopedPtr&);
+public:
+ ~V2PScopedPtr()
+ throw()
+ {
+ delete m_ptr;
+ }
+
+ T*
+ moveFrom()
+ throw()
+ {
+ T *ret = m_ptr;
+ m_ptr = NULL;
+ return ret;
+ }
+
+ T*
+ get() const
+ throw()
+ {
+ return m_ptr;
+ }
+
+ T&
+ operator*() const
+ throw()
+ {
+ return *m_ptr;
+ }
+
+ T*
+ operator->() const
+ throw()
+ {
+ return m_ptr;
+ }
+};
+
+template
+class V2PScopedPtr {
+private:
+ T *m_ptr;
+public:
+ V2PScopedPtr(T *ptr)
+ : m_ptr(ptr)
+ {
+ }
+private:
+ V2PScopedPtr(const V2PScopedPtr&);
+ V2PScopedPtr& operator=(const V2PScopedPtr&);
+public:
+ ~V2PScopedPtr()
+ {
+ delete[] m_ptr;
+ }
+
+ T*
+ moveFrom()
+ {
+ T *ret = m_ptr;
+ m_ptr = NULL;
+ return ret;
+ }
+
+ T*
+ get() const
+ throw()
+ {
+ return m_ptr;
+ }
+
+ T&
+ operator*() const
+ throw()
+ {
+ return *m_ptr;
+ }
+
+ T&
+ operator[](size_t index) const
+ throw()
+ {
+ return m_ptr[index];
+ }
+};
+
+
+#endif // VIDEO2P_SCOPED_PTR_HPP
]