diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-04-25 19:54:38 +0200 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2025-05-11 11:41:28 +0200 |
commit | 6c6e147ba9b02d2adbf425f8f8b1371c4151fc67 (patch) | |
tree | ede0fd96b6fb6213b7c08700843b44588e77cdac /src/server/database/Database/QueryResultStructured.h | |
parent | 4eaa67e0a65c3956005dab2946312924e8e3e968 (diff) |
Core/Database: Added very simple macro to create named query result field accessors
(cherry picked from commit 29a680a1c264e5c8858b387fce4f6472a6d70a7e)
Diffstat (limited to 'src/server/database/Database/QueryResultStructured.h')
-rw-r--r-- | src/server/database/Database/QueryResultStructured.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/server/database/Database/QueryResultStructured.h b/src/server/database/Database/QueryResultStructured.h new file mode 100644 index 00000000000..9bb977ca540 --- /dev/null +++ b/src/server/database/Database/QueryResultStructured.h @@ -0,0 +1,52 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TRINITYCORE_QUERY_RESULT_STRUCTURED_H +#define TRINITYCORE_QUERY_RESULT_STRUCTURED_H + +#include <boost/preprocessor/cat.hpp> +#include <boost/preprocessor/comma_if.hpp> +#include <boost/preprocessor/seq/enum.hpp> +#include <boost/preprocessor/seq/for_each.hpp> +#include <boost/preprocessor/seq/for_each_i.hpp> +#include <boost/preprocessor/stringize.hpp> + +#define DEFINE_FIELD_ACCESSOR_CACHE_FIELD_INDEX_INIT(r, data, i, field) BOOST_PP_COMMA_IF(i) field(result.GetFieldMetadata(BOOST_PP_STRINGIZE(field)).Index) + +#define DEFINE_FIELD_ACCESSOR_CACHE_FIELD(r, data, field) Field const& field() const\ + {\ + return Result.Fetch()[indexes.field];\ + } + +#define DEFINE_FIELD_ACCESSOR_CACHE(struct_name, result_type, fields_list) \ + struct struct_name \ + { \ + struct Indexes\ + {\ + Indexes(result_type const& result) :\ + BOOST_PP_SEQ_FOR_EACH_I(DEFINE_FIELD_ACCESSOR_CACHE_FIELD_INDEX_INIT, ~, fields_list) { }\ + std::size_t BOOST_PP_SEQ_ENUM(fields_list);\ + };\ + BOOST_PP_SEQ_FOR_EACH(DEFINE_FIELD_ACCESSOR_CACHE_FIELD, ~, fields_list) \ + result_type const& Result; \ + static Indexes const& indexes_impl(result_type const& result) { static Indexes const instance(result); return instance; }\ + Indexes const& indexes = indexes_impl(Result);\ + } + +#define DEFINE_FIELD_ACCESSOR_CACHE_ANONYMOUS(fields_list) DEFINE_FIELD_ACCESSOR_CACHE(BOOST_PP_CAT(FieldAccessors, __LINE__), fields_list) + +#endif // TRINITYCORE_QUERY_RESULT_STRUCTURED_H |