ros_field.hpp
Go to the documentation of this file.
1 /***** MIT License ****
2  *
3  * Copyright (c) 2016-2022 Davide Faconti
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #include <vector>
27 #include <map>
28 #include <memory>
29 #include <unordered_map>
30 #include <iostream>
32 
33 namespace RosMsgParser
34 {
35 
36 class ROSMessage;
37 
38 using RosMessageLibrary = std::unordered_map<ROSType, std::shared_ptr<ROSMessage>>;
39 
40 class Parser;
41 
46 class ROSField
47 {
48 public:
49  ROSField(const ROSType& type, const std::string& name);
50 
51  ROSField(const std::string& definition);
52 
53  const std::string& name() const
54  {
55  return _fieldname;
56  }
57 
58  const ROSType& type() const
59  {
60  return _type;
61  }
62 
63  void changeType(const ROSType& type)
64  {
65  _type = type;
66  }
67 
69  bool isConstant() const
70  {
71  return _is_constant;
72  }
73 
75  const std::string& value() const
76  {
77  return _value;
78  }
79 
81  bool isArray() const
82  {
83  return _is_array;
84  }
85 
88  int arraySize() const
89  {
90  return _array_size;
91  }
92 
93  friend class ROSMessage;
94 
95  std::shared_ptr<ROSMessage> getMessagePtr(const RosMessageLibrary& library) const;
96 
97 protected:
98  std::string _fieldname;
100  std::string _value;
101  bool _is_array;
102  bool _is_constant = false;
104 
105  mutable const RosMessageLibrary* _cache_library = nullptr;
106  mutable std::shared_ptr<ROSMessage> _cache_message;
107 };
108 
109 void TrimStringLeft(std::string& s);
110 
111 void TrimStringRight(std::string& s);
112 
113 void TrimString(std::string& s);
114 
115 } // namespace RosMsgParser
RosMsgParser::ROSField::type
const ROSType & type() const
Definition: ros_field.hpp:58
RosMsgParser::ROSType
ROSType.
Definition: ros_type.hpp:39
RosMsgParser::Parser
Definition: ros_parser.hpp:51
RosMsgParser::ROSField::ROSField
ROSField(const ROSType &type, const std::string &name)
Definition: ros_field.cpp:32
RosMsgParser::ROSField::getMessagePtr
std::shared_ptr< ROSMessage > getMessagePtr(const RosMessageLibrary &library) const
definition
const char * definition()
RosMsgParser::TrimStringLeft
void TrimStringLeft(std::string &s)
RosMsgParser::ROSField::changeType
void changeType(const ROSType &type)
Definition: ros_field.hpp:63
RosMsgParser::ROSField::_type
ROSType _type
Definition: ros_field.hpp:99
RosMsgParser::ROSField::value
const std::string & value() const
If constant, value of field, else undefined.
Definition: ros_field.hpp:75
RosMsgParser::ROSField::_array_size
int _array_size
Definition: ros_field.hpp:103
ros_type.hpp
RosMsgParser::ROSField::_is_array
bool _is_array
Definition: ros_field.hpp:101
RosMsgParser::ROSField::_cache_message
std::shared_ptr< ROSMessage > _cache_message
Definition: ros_field.hpp:106
RosMsgParser::TrimStringRight
void TrimStringRight(std::string &s)
RosMsgParser::RosMessageLibrary
std::unordered_map< ROSType, std::shared_ptr< ROSMessage > > RosMessageLibrary
Definition: ros_field.hpp:38
RosMsgParser
Definition: builtin_types.hpp:34
RosMsgParser::ROSMessage
Definition: ros_message.hpp:34
RosMsgParser::ROSField::_value
std::string _value
Definition: ros_field.hpp:100
RosMsgParser::ROSField::name
const std::string & name() const
Definition: ros_field.hpp:53
RosMsgParser::TrimString
void TrimString(std::string &s)
RosMsgParser::ROSField::_is_constant
bool _is_constant
Definition: ros_field.hpp:102
RosMsgParser::ROSField::_fieldname
std::string _fieldname
Definition: ros_field.hpp:98
RosMsgParser::ROSField::_cache_library
const RosMessageLibrary * _cache_library
Definition: ros_field.hpp:105
RosMsgParser::ROSField::isArray
bool isArray() const
True if the type is an array.
Definition: ros_field.hpp:81
RosMsgParser::ROSField::arraySize
int arraySize() const
Definition: ros_field.hpp:88
RosMsgParser::ROSField::isConstant
bool isConstant() const
True if field is a constant in message definition.
Definition: ros_field.hpp:69
RosMsgParser::ROSField
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair.
Definition: ros_field.hpp:46


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46