Closes #11
This commit is contained in:
1 parent
0067cb4ddd
commit
f17ddb6aad
104 files changed
+1928
-889
No files matched your search
@@ -0,0 +1,65 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#ifndef DBC_STATEMENT_HANDLER_H
|
||||
#define DBC_STATEMENT_HANDLER_H
|
||||
|
||||
#include "dbc_database.h"
|
||||
#include "typefactory.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
/** Mutable state belonging to one file parse. Handlers do not retain it. */
|
||||
struct DbcParseContext {
|
||||
DbcDatabase &database;
|
||||
FrameInfo *currentFrame = nullptr;
|
||||
};
|
||||
|
||||
class DbcStatementHandler {
|
||||
public:
|
||||
virtual ~DbcStatementHandler() = default;
|
||||
virtual void Handle(const std::string &line, DbcParseContext &context) const = 0;
|
||||
};
|
||||
|
||||
class DbcFrameHandler : public DbcStatementHandler {
|
||||
public:
|
||||
void Handle(const std::string &line, DbcParseContext &context) const override;
|
||||
|
||||
private:
|
||||
static FrameInfo ParseFrameLine(const std::string &line);
|
||||
};
|
||||
|
||||
class DbcSignalHandler : public DbcStatementHandler {
|
||||
public:
|
||||
void Handle(const std::string &line, DbcParseContext &context) const override;
|
||||
|
||||
private:
|
||||
static SignalInfo ParseSignalLine(const std::string &line);
|
||||
};
|
||||
|
||||
class DbcCommentHandler : public DbcStatementHandler {
|
||||
public:
|
||||
void Handle(const std::string &line, DbcParseContext &context) const override;
|
||||
|
||||
private:
|
||||
static void ParseCommentLine(const std::string &line, DbcDatabase &database);
|
||||
};
|
||||
|
||||
/** Exact-key dispatch to handlers created once per registration via TypeFactory. */
|
||||
class DbcStatementDispatcher {
|
||||
public:
|
||||
DbcStatementDispatcher();
|
||||
|
||||
template<class Handler>
|
||||
void RegisterType(const std::string &keyword) {
|
||||
m_factory.registerType<Handler>(keyword);
|
||||
m_handlers.insert_or_assign(keyword, m_factory.create(keyword));
|
||||
}
|
||||
|
||||
/** Returns false for an unregistered keyword; input must be trimmed. */
|
||||
bool Dispatch(const std::string &line, DbcParseContext &context) const;
|
||||
|
||||
private:
|
||||
TypeFactory<std::string, DbcStatementHandler> m_factory;
|
||||
std::unordered_map<std::string, std::shared_ptr<DbcStatementHandler>> m_handlers;
|
||||
};
|
||||
|
||||
#endif /* DBC_STATEMENT_HANDLER_H */
|
||||
Reference in new issue
Block a user