TinyURDF 1.0.0
A Modern C++ Library for Parsing and Visualizing URDF Model Files
Loading...
Searching...
No Matches
sphere_parser.h
Go to the documentation of this file.
1#ifndef INCLUDE_TINYURDF_GEOMETRY_SPHERE_PARSER_H_
2#define INCLUDE_TINYURDF_GEOMETRY_SPHERE_PARSER_H_
3
4// Copyright 2025 Wissem CHIHA
5
6#include "parser_base.h"
7#include "sphere.h"
8#include "utils.h"
9
14class SphereParser : public ParserBase<Sphere> {
15 public:
17 p_ = std::make_shared<Sphere>();
18 }
19
20 void parse(const tinyxml2::XMLElement* xml) override {
22
23 const char* radius_str = xml->Attribute("radius");
24 if (radius_str) {
25 double r;
26 str2double(radius_str, r);
27 p_ = std::make_shared<Sphere>();
28 p_->setRadius(r);
29 }
30 }
31
32 bool isA(const char* name) override {
33 return p_->isA(name);
34 }
35
36 const char* getTypename() override {
37 return p_->getTypename();
38 }
39
40 void print(std::ostream& os) override {
41 os << "Parsed Sphere = [";
42 p_->print(os);
43 os << "]";
44 }
45
46 bool empty() const override {
47 return p_ == nullptr;
48 }
49
50 void clear() override {
51 p_->clear();
52 }
53
54 std::shared_ptr<Sphere> get() override {
55 return p_;
56 }
57
58 ~SphereParser() = default;
59
60 private:
61 std::shared_ptr<Sphere> p_;
62};
63#endif // INCLUDE_TINYURDF_GEOMETRY_SPHERE_PARSER_H_
Definition parser_base.h:16
virtual void parse(const tinyxml2::XMLElement *xml)
Definition parser_base.h:27
Parser for Sphere geometry, inherits from ParserBase<Sphere> and provides the functionality to parse ...
Definition sphere_parser.h:14
void print(std::ostream &os) override
Definition sphere_parser.h:40
~SphereParser()=default
SphereParser()
Definition sphere_parser.h:16
const char * getTypename() override
Definition sphere_parser.h:36
void clear() override
Definition sphere_parser.h:50
bool empty() const override
Definition sphere_parser.h:46
std::shared_ptr< Sphere > get() override
Definition sphere_parser.h:54
void parse(const tinyxml2::XMLElement *xml) override
Definition sphere_parser.h:20
bool isA(const char *name) override
Definition sphere_parser.h:32
void str2double(const char *in, double &num_)
a locale-safe version of string-to-double
Definition utils.cc:14