21 #ifndef BM_BM_SIM_TABLES_H_
22 #define BM_BM_SIM_TABLES_H_
28 #include "control_flow.h"
29 #include "match_tables.h"
36 struct HasFactoryMethod {
37 using Signature = std::unique_ptr<T> (*)(
38 const std::string &,
const std::string &,
39 p4object_id_t, size_t,
const MatchKeyBuilder &,
40 LookupStructureFactory *,
43 template <
typename U, Signature>
struct SFINAE {};
44 template<
typename U>
static char Test(SFINAE<U, U::create>*);
45 template<
typename U>
static int Test(...);
46 static const bool value =
sizeof(Test<T>(
nullptr)) ==
sizeof(
char);
49 class MatchActionTable :
public ControlFlowNode {
51 MatchActionTable(
const std::string &name, p4object_id_t
id,
52 std::unique_ptr<MatchTableAbstract> match_table);
54 const ControlFlowNode *operator()(Packet *pkt)
const override;
56 MatchTableAbstract *get_match_table() {
return match_table.get(); }
59 template <
typename MT>
60 static std::unique_ptr<MatchActionTable> create_match_action_table(
61 const std::string &match_type,
62 const std::string &name, p4object_id_t
id,
63 size_t size,
const MatchKeyBuilder &match_key_builder,
64 bool with_counters,
bool with_ageing,
65 LookupStructureFactory *lookup_factory) {
67 std::is_base_of<MatchTableAbstract, MT>::value,
68 "incorrect template, needs to be a subclass of MatchTableAbstract");
71 HasFactoryMethod<MT>::value,
72 "template class needs to have a create() static factory method");
74 std::unique_ptr<MT> match_table = MT::create(
75 match_type, name,
id, size, match_key_builder,
76 lookup_factory, with_counters, with_ageing);
78 return std::unique_ptr<MatchActionTable>(
79 new MatchActionTable(name,
id, std::move(match_table)));
83 std::unique_ptr<MatchTableAbstract> match_table;
88 #endif // BM_BM_SIM_TABLES_H_