mirror of
https://github.com/supleed2/svd2cpp.git
synced 2024-12-22 05:35:50 +00:00
Added error checking in XmlParser, added sample file
This commit is contained in:
parent
a00ced6aa1
commit
e5605248ea
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
*.o
|
||||
*.a
|
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ SOURCE = Src/main.cpp tinyxml2/tinyxml2.cpp
|
|||
INCLUDE = -I tinyxml2 -I cxxopts/include -I Src
|
||||
OUT = svd2cpp
|
||||
CC = g++
|
||||
FLAGS = -g -c -Wall
|
||||
FLAGS = -g -c -Wall -std=c++17
|
||||
|
||||
all: $(OBJS)
|
||||
$(CC) -g $(OBJS) -o $(OUT) $(LFLAGS)
|
||||
|
|
24923
Sample/STM32F103xx.svd
Normal file
24923
Sample/STM32F103xx.svd
Normal file
File diff suppressed because it is too large
Load diff
|
@ -2,5 +2,15 @@
|
|||
#include <iostream>
|
||||
|
||||
XmlParser::XmlParser(const std::string& inputFile){
|
||||
std::cout << inputFile;
|
||||
xmlDocument.LoadFile(inputFile.c_str());
|
||||
}
|
||||
std::optional<std::string> XmlParser::isError() const{
|
||||
return xmlDocument.Error() ? std::optional<std::string>(xmlDocument.ErrorStr()) : std::nullopt;
|
||||
}
|
||||
|
||||
void XmlParser::parseXml(){
|
||||
root = xmlDocument.FirstChildElement();
|
||||
if(root == nullptr)
|
||||
return;
|
||||
std::cout << root->GetText();
|
||||
}
|
|
@ -3,12 +3,17 @@
|
|||
|
||||
#include <tinyxml2.h>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
struct XmlParser{
|
||||
XmlParser(const std::string& inputFile);
|
||||
std::optional<std::string> isError() const;
|
||||
void parseXml();
|
||||
|
||||
private:
|
||||
|
||||
tinyxml2::XMLDocument xmlDocument;
|
||||
tinyxml2::XMLElement* root;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -26,7 +26,13 @@ int main(int argc, char** argv){
|
|||
}
|
||||
catch(cxxopts::OptionException& ex){
|
||||
std::cout << ex.what() << std::endl;
|
||||
return -1;
|
||||
return 2;
|
||||
}
|
||||
//Try to parse the file
|
||||
XmlParser xmlParser(inputFile);
|
||||
if (auto err = xmlParser.isError()){
|
||||
std::cout << "There was an error while reading " << inputFile << ":" << std::endl << *err << std::endl;
|
||||
return 3;
|
||||
}
|
||||
xmlParser.parseXml();
|
||||
}
|
Loading…
Reference in a new issue