TinyURDF 1.0.0
A Modern C++ Library for Parsing and Visualizing URDF Model Files
Loading...
Searching...
No Matches
parser_base.h
Go to the documentation of this file.
1#ifndef INCLUDE_TINYURDF_CORE_PARSER_BASE_H_
2#define INCLUDE_TINYURDF_CORE_PARSER_BASE_H_
3
4// Copyright 2025 wissem CHIHA
5
6#include <loguru/loguru.hpp>
7#include <tinyxml2/tinyxml2.h>
8
9#include <string>
10#include <memory>
11
12#include "object_base.h"
13#include "property_base.h"
14
15template <class T>
16class ParserBase : public ObjectBase {
17 public:
18 const char* getNameOf(const tinyxml2::XMLElement* xml) {
19 const char* name = xml->Attribute("name");
20 if (!name) {
21 return "";
22 } else {
23 return name;
24 }
25 }
26
27 virtual void parse(const tinyxml2::XMLElement* xml) {
28 if (!xml) {
29 LOG_F(ERROR, "Parser::parse() passed nullptr");
30 return;
31 }
32 }
33
34 template <typename... Args>
35 void parse(const tinyxml2::XMLElement* xml) {
36 if (!xml) return;
37 this->parse(xml);
38 if constexpr (sizeof...(Args) > 0) {
39 parse<Args...>(xml);
40 }
41 }
42
43 template <typename Base, typename... Iter>
44 void parse(const tinyxml2::XMLElement* xml) {
45 if (!xml) return;
46 ParserBase<Base> parser;
47 parser.parse(xml);
48
49 if constexpr (sizeof...(Iter) > 0) {
50 parse<Iter...>(xml);
51 }
52 }
53
54 virtual std::shared_ptr<T> get() { return Tptr; }
55
56 protected:
58 virtual ~ParserBase() {}
59
60 std::shared_ptr<T> Tptr;
61};
62
63#endif // INCLUDE_TINYURDF_CORE_PARSER_BASE_H_
Definition object_base.h:11
Definition parser_base.h:16
const char * getNameOf(const tinyxml2::XMLElement *xml)
Definition parser_base.h:18
virtual std::shared_ptr< T > get()
Definition parser_base.h:54
ParserBase()
Definition parser_base.h:57
void parse(const tinyxml2::XMLElement *xml)
Definition parser_base.h:44
void parse(const tinyxml2::XMLElement *xml)
Definition parser_base.h:35
std::shared_ptr< T > Tptr
Definition parser_base.h:60
virtual ~ParserBase()
Definition parser_base.h:58
virtual void parse(const tinyxml2::XMLElement *xml)
Definition parser_base.h:27