38 template<
typename TContext>
63 virtual void Begin(TContext& ctx,
const frxml::dom& parent,
const frxml::dom& current,
int depth) = 0;
71 virtual void End(TContext& ctx,
const frxml::dom& parent,
const frxml::dom& current,
int depth) = 0;
74 template<
typename T,
typename TContext>
75 concept TVisitor = std::is_base_of_v<InterfaceVisitor<TContext>, T>;
83 template<
typename TContext, TVisitor<TContext>... TVisitor>
86 std::map<std::string, std::shared_ptr<InterfaceVisitor<TContext>>> m_Visitors;
92 static_cast<std::shared_ptr<InterfaceVisitor<TContext>
>>(std::make_shared<TVisitor>())...
94 m_Visitors.emplace(visitor->GetName(), std::move(visitor));
100 return "__generic__";
103 void Begin(TContext& ctx,
const frxml::dom& parent,
const frxml::dom& current,
int depth)
override
105 auto v =
static_cast<std::string
>(current.tag().view());
106 if (!m_Visitors.contains(v))
107 throw exception(std::format(
"undefined tag '{}'", v), current);
109 m_Visitors.at(v)->Begin(ctx, parent, current, depth);
112 void End(TContext& ctx,
const frxml::dom& parent,
const frxml::dom& current,
int depth)
override
114 auto v =
static_cast<std::string
>(current.tag().view());
115 if (!m_Visitors.contains(v))
116 throw exception(std::format(
"undefined tag '{}'", v), current);
118 m_Visitors.at(v)->End(ctx, parent, current, depth);
133 template<
typename TContext>
143 void Begin(TContext& ctx,
const frxml::dom& parent,
const frxml::dom& current,
int depth)
override = 0;
145 void End(TContext& ctx,
const frxml::dom& parent,
const frxml::dom& current,
int depth)
override = 0;
An interface visitor for a whole assembly.
void Begin(TContext &ctx, const frxml::dom &parent, const frxml::dom ¤t, int depth) override=0
void End(TContext &ctx, const frxml::dom &parent, const frxml::dom ¤t, int depth) override=0
std::string GetName() const final
Gets the name of this interface visitor.
A composite ASTVisitor wrapping other ASTVisitor(s)
GenericInterfaceVisitor()
void End(TContext &ctx, const frxml::dom &parent, const frxml::dom ¤t, int depth) override
std::string GetName() const override
Gets the name of this interface visitor.
void Begin(TContext &ctx, const frxml::dom &parent, const frxml::dom ¤t, int depth) override
A helper class to traverse interface graph.
virtual ~InterfaceVisitor()=default
virtual std::string GetName() const =0
Gets the name of this interface visitor.
virtual void Begin(TContext &ctx, const frxml::dom &parent, const frxml::dom ¤t, int depth)=0
virtual void End(TContext &ctx, const frxml::dom &parent, const frxml::dom ¤t, int depth)=0