blob: fddd9e2741251abd84c2ba7c741749bb6648bb4a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#ifndef MYGRATE_OUTPUT_PQ_TYPEMAPPER_H
#define MYGRATE_OUTPUT_PQ_TYPEMAPPER_H
#include <optional>
#include <regex>
#include <string>
#include <string_view>
#include <vector>
namespace MyGrate::Output::Pq {
class TypeMapper {
public:
class ObsRegex : public std::regex {
public:
explicit ObsRegex(const std::string & src, std::regex_constants::syntax_option_type sot = {}) :
std::regex {src, sot}, src {src}
{
}
const std::string src;
};
struct Mapping {
virtual ~Mapping() = default;
virtual std::optional<std::string_view> map(std::string_view t, std::string_view n) const = 0;
};
using MappingPtr = std::unique_ptr<Mapping>;
struct RegexMapper : public Mapping {
RegexMapper(std::optional<ObsRegex>, std::optional<ObsRegex>, std::string);
std::optional<std::string_view> map(std::string_view t, std::string_view n) const override;
std::optional<ObsRegex> typeMatch;
std::optional<ObsRegex> columnMatch;
std::string targetType;
};
TypeMapper();
std::string_view map(std::string_view t, std::string_view n) const;
private:
std::vector<MappingPtr> mappings;
};
TypeMapper::ObsRegex operator""_r(const char * input, std::size_t);
}
#endif
|