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 class ROSMessage;
36 
37 using RosMessageLibrary = std::unordered_map<ROSType, std::shared_ptr<ROSMessage>>;
38 
39 class Parser;
40 
45 class ROSField {
46 
47 public:
48 
49  ROSField(const ROSType& type, const std::string& name );
50 
51  ROSField(const std::string& definition );
52 
53  const std::string& name() const { return _fieldname; }
54 
55  const ROSType& type() const { return _type; }
56 
57  void changeType(const ROSType& type) { _type = type; }
58 
60  bool isConstant() const
61  {
62  return _is_constant;
63  }
64 
66  const std::string& value() const { return _value; }
67 
69  bool isArray() const { return _is_array; }
70 
73  int arraySize() const { return _array_size; }
74 
75  friend class ROSMessage;
76 
77  std::shared_ptr<ROSMessage> getMessagePtr(const RosMessageLibrary& library) const;
78 
79 protected:
80  std::string _fieldname;
82  std::string _value;
83  bool _is_array;
84  bool _is_constant = false;
86 
87  mutable const RosMessageLibrary* _cache_library = nullptr;
88  mutable std::shared_ptr<ROSMessage> _cache_message;
89 };
90 
91 void TrimStringLeft(std::string& s);
92 
93 void TrimStringRight(std::string& s);
94 
95 void TrimString(std::string& s);
96 
97 }
98 
99 
const std::string & name() const
Definition: ros_field.hpp:53
void TrimStringRight(std::string &s)
Definition: ros_field.cpp:171
std::shared_ptr< ROSMessage > _cache_message
Definition: ros_field.hpp:88
std::shared_ptr< ROSMessage > getMessagePtr(const RosMessageLibrary &library) const
Definition: ros_field.cpp:144
int arraySize() const
Definition: ros_field.hpp:73
bool isArray() const
True if the type is an array.
Definition: ros_field.hpp:69
type
Definition: core.h:1059
const RosMessageLibrary * _cache_library
Definition: ros_field.hpp:87
const std::string & value() const
If constant, value of field, else undefined.
Definition: ros_field.hpp:66
A ROSMessage will contain one or more ROSField(s). Each field is little more than a name / type pair...
Definition: ros_field.hpp:45
void TrimStringLeft(std::string &s)
Definition: ros_field.cpp:164
void TrimString(std::string &s)
Definition: ros_field.cpp:178
bool isConstant() const
True if field is a constant in message definition.
Definition: ros_field.hpp:60
std::unordered_map< ROSType, std::shared_ptr< ROSMessage > > RosMessageLibrary
Definition: ros_field.hpp:37
std::string _fieldname
Definition: ros_field.hpp:80
const ROSType & type() const
Definition: ros_field.hpp:55
const char * definition()
void changeType(const ROSType &type)
Definition: ros_field.hpp:57
ROSField(const ROSType &type, const std::string &name)
Definition: ros_field.cpp:32


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:39