TrinityCore
Loading...
Searching...
No Matches
QueryResultStructured.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_QUERY_RESULT_STRUCTURED_H
19#define TRINITYCORE_QUERY_RESULT_STRUCTURED_H
20
21#include <boost/preprocessor/cat.hpp>
22#include <boost/preprocessor/comma_if.hpp>
23#include <boost/preprocessor/facilities/empty.hpp>
24#include <boost/preprocessor/seq/enum.hpp>
25#include <boost/preprocessor/seq/for_each.hpp>
26#include <boost/preprocessor/seq/for_each_i.hpp>
27#include <boost/preprocessor/stringize.hpp>
28
29#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)
30
31#define DEFINE_FIELD_ACCESSOR_CACHE_FIELD(r, data, field) Field const& field() const\
32 {\
33 return Fields[indexes.field];\
34 }
35
36#define DEFINE_FIELD_ACCESSOR_CACHE(namespace_name, struct_name, result_type, fields_list) \
37 struct namespace_name struct_name \
38 { \
39 struct Indexes\
40 {\
41 Indexes(result_type const& result) :\
42 BOOST_PP_SEQ_FOR_EACH_I(DEFINE_FIELD_ACCESSOR_CACHE_FIELD_INDEX_INIT, ~, fields_list) { }\
43 std::size_t BOOST_PP_SEQ_ENUM(fields_list);\
44 };\
45 BOOST_PP_SEQ_FOR_EACH(DEFINE_FIELD_ACCESSOR_CACHE_FIELD, ~, fields_list) \
46 struct_name(result_type const& result) : Fields(result.Fetch()), indexes(indexes_impl(result)) { }\
47 Field* Fields; \
48 static Indexes const& indexes_impl(result_type const& result) noexcept { static Indexes const instance(result); return instance; }\
49 Indexes const& indexes;\
50 }
51
52#define DEFINE_FIELD_ACCESSOR_CACHE_ANONYMOUS(result_type, fields_list) DEFINE_FIELD_ACCESSOR_CACHE(BOOST_PP_EMPTY(), BOOST_PP_CAT(FieldAccessors, __LINE__), result_type, fields_list)
53
54#endif // TRINITYCORE_QUERY_RESULT_STRUCTURED_H