query/demo/query_helper.hpp

53 lines
1005 B
C++

#ifndef QUERY_QUERY_HELPER_HPP
#define QUERY_QUERY_HELPER_HPP
#include "macro_map.hpp"
#include <string>
#include <ostream>
template<typename QueryClass>
struct basic_query;
struct table {
template<typename QueryClass>
table(const basic_query<QueryClass> &qc);
const std::string name;
};
struct field {
const std::string name;
friend std::ostream& operator<<(std::ostream &out, const field &f) {
out << f.name;
return out;
}
};
template<typename QueryClass>
struct basic_query {
const table& operator()() const {
return table_;
}
const table table_;
};
template<typename QueryClass>
table::table(const basic_query<QueryClass>&)
: name(QueryClass::internal_table_name_) {
}
#define FIELD(x) const field x{#x};
#define QUERY_HELPER(C, ...) \
namespace qh { \
namespace internal { \
struct C##_query { \
MAP(FIELD, __VA_ARGS__) \
}; } \
static const internal:: C##_query C; \
}
#endif //QUERY_QUERY_HELPER_HPP