71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
#ifndef QUERY_VALUE_GENERATOR_HPP
|
|
#define QUERY_VALUE_GENERATOR_HPP
|
|
|
|
#include "matador/sql/any_type.hpp"
|
|
|
|
#include "matador/utils/access.hpp"
|
|
#include "matador/utils/field_attributes.hpp"
|
|
#include "matador/utils/identifiable.hpp"
|
|
|
|
#include <vector>
|
|
|
|
namespace matador::utils {
|
|
enum class cascade_type;
|
|
}
|
|
namespace matador::sql {
|
|
|
|
class value_generator
|
|
{
|
|
private:
|
|
explicit value_generator(std::vector<any_type> &values);
|
|
|
|
public:
|
|
~value_generator() = default;
|
|
|
|
template < class Type >
|
|
static std::vector<any_type> generate()
|
|
{
|
|
std::vector<any_type> values;
|
|
value_generator gen(values);
|
|
Type obj;
|
|
matador::utils::access::process(gen, obj);
|
|
return std::move(values);
|
|
}
|
|
|
|
template<typename ValueType>
|
|
void on_primary_key(const char *, ValueType &x, typename std::enable_if<std::is_integral<ValueType>::value && !std::is_same<bool, ValueType>::value>::type* = 0)
|
|
{
|
|
append(x);
|
|
}
|
|
void on_primary_key(const char *id, std::string &pk, size_t size);
|
|
void on_revision(const char *id, unsigned long long &rev);
|
|
template < class Type >
|
|
void on_attribute(const char *, Type &x, const utils::field_attributes &/*attr*/ = utils::null_attributes)
|
|
{
|
|
append(x);
|
|
}
|
|
void on_attribute(const char *id, char *x, const utils::field_attributes &/*attr*/ = utils::null_attributes);
|
|
void on_attribute(const char *id, std::string &x, const utils::field_attributes &/*attr*/ = utils::null_attributes);
|
|
void on_belongs_to(const char *id, utils::identifiable &x, utils::cascade_type);
|
|
void on_has_one(const char *id, utils::identifiable &x, utils::cascade_type);
|
|
|
|
template<class ContainerType>
|
|
void on_has_many(const char *, ContainerType &, const char *, const char *, utils::cascade_type) {}
|
|
template<class ContainerType>
|
|
void on_has_many(const char *, ContainerType &, utils::cascade_type) {}
|
|
|
|
private:
|
|
template<typename Type>
|
|
void append(Type &value)
|
|
{
|
|
values_.emplace_back(value);
|
|
}
|
|
|
|
private:
|
|
std::vector<any_type> &values_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif //QUERY_VALUE_GENERATOR_HPP
|