diff --git a/TestLibDlg/TestLibDlg/A2LFileData.cpp b/TestLibDlg/TestLibDlg/A2LFileData.cpp index 3583a55..888c94b 100644 --- a/TestLibDlg/TestLibDlg/A2LFileData.cpp +++ b/TestLibDlg/TestLibDlg/A2LFileData.cpp @@ -2,20 +2,120 @@ #include "pch.h" #include "A2LFileData.h" +CA2LFileData::Header::Header() +{ + m_strProjectNo = m_strComment = ""; +} + +CA2LFileData::Header::~Header() +{ + m_strProjectNo = m_strComment = ""; +} + +std::string CA2LFileData::Header::GetComment() +{ + return m_strComment; +} + +std::string CA2LFileData::Header::GetProjectNo() +{ + return m_strProjectNo; +} + +std::string CA2LFileData::Header::GetVersion() +{ + return m_strVersion; +} + +void CA2LFileData::Header::SetComment(std::string strHeader) +{ + m_strComment = strHeader; +} + +void CA2LFileData::Header::SetProjectNo(std::string strProjectNo) +{ + m_strProjectNo = strProjectNo; +} + +void CA2LFileData::Header::SetVersion(std::string strVersion) +{ + m_strVersion = strVersion; +} + + +/// +/// + CA2LFileData::CA2LFileData() { - + m_pHeader = std::make_shared(); + + m_strA2lFilePath = ""; } CA2LFileData::~CA2LFileData() { + m_pHeader = nullptr; +} + +bool CA2LFileData::LoadA2lFile(std::string strPath, bool bIsParse) +{ + bool bRet = false; + + if (m_pA2lFile != nullptr) { + m_pA2lFile = nullptr; + m_strA2lFilePath = ""; + } + + m_pA2lFile = std::make_shared(); + + if (m_pA2lFile != nullptr) { + + try { + m_strA2lFilePath = strPath; + bRet = std::filesystem::exists(strPath); + } + catch (const std::exception& error) { + std::cout << "Failed to fetch the A2l test files. Error: " + << error.what(); + } + m_pA2lFile->Filename(strPath); + + if (bIsParse) + ParseA2lFile(); + } + + // + + return bRet; } -bool CA2LFileData::LoadA2lFile(std::string strPath) +bool CA2LFileData::ParseA2lFile() { bool bRet = false; + const auto parse = m_pA2lFile->ParseFile(); + if (parse) { + const auto& project = m_pA2lFile->Project(); + + const auto& header = project.Header(); + + m_pHeader->SetComment(header.Comment); + m_pHeader->SetProjectNo(header.ProjectNo); + m_pHeader->SetVersion(header.VersionNo); + + bRet = true; + } + return bRet; +} + +CA2LFileData::Header* CA2LFileData::GetHeader() +{ + if (m_pHeader != nullptr) + return m_pHeader.get(); + else + return nullptr; } \ No newline at end of file diff --git a/TestLibDlg/TestLibDlg/A2LFileData.h b/TestLibDlg/TestLibDlg/A2LFileData.h index 71898b0..368be1e 100644 --- a/TestLibDlg/TestLibDlg/A2LFileData.h +++ b/TestLibDlg/TestLibDlg/A2LFileData.h @@ -2,13 +2,51 @@ #include #include +#include +#include +#include + +#include "a2l/a2lfile.h" +#include "a2l/a2mlblock.h" +#include "a2l/ifdatablock.h" + +using namespace std::filesystem; +using namespace std::chrono_literals; class CA2LFileData { +public: + class Header { + public: + Header(); + ~Header(); + + std::string GetComment(); + std::string GetProjectNo(); + std::string GetVersion(); + + void SetComment(std::string strHeader); + void SetProjectNo(std::string strProjectNo); + void SetVersion(std::string strVersion); + + private: + std::string m_strComment; + std::string m_strProjectNo; + std::string m_strVersion; + }; + public: CA2LFileData(); ~CA2LFileData(); - bool LoadA2lFile(std::string strPath); + bool LoadA2lFile(std::string strPath, bool bIsParse = false); + bool ParseA2lFile(); + + CA2LFileData::Header* GetHeader(); + +private: + std::shared_ptr m_pA2lFile; + std::string m_strA2lFilePath; + std::shared_ptr m_pHeader; };