MessageFieldCollection.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2014 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
23 #ifndef VARIANT_TOPIC_TOOLS_MESSAGE_FIELD_COLLECTION_H
24 #define VARIANT_TOPIC_TOOLS_MESSAGE_FIELD_COLLECTION_H
25 
26 #include <vector>
27 
28 #include <boost/unordered_map.hpp>
29 
30 #include <ros/ros.h>
31 
33 
34 namespace variant_topic_tools {
37  template <typename T> class MessageFieldCollection {
38  public:
42 
45  MessageFieldCollection(const MessageFieldCollection<T>& src);
46 
49  virtual ~MessageFieldCollection();
50 
53  size_t getNumFields() const;
54 
58  MessageField<T>& getField(int index);
59 
63  const MessageField<T>& getField(int index) const;
64 
68  MessageField<T>& getField(const std::string& name);
69 
73  const MessageField<T>& getField(const std::string& name) const;
74 
78  bool hasField(const std::string& name) const;
79 
82  bool isEmpty() const;
83 
86  void appendField(const MessageField<T>& field);
87 
91  void appendField(const std::string& name, const T& value = T());
92 
96  void merge(const MessageFieldCollection<T>& collection);
97 
100  virtual void clear();
101 
104  virtual void write(std::ostream& stream, const std::string& indent =
105  std::string()) const;
106 
110  MessageField<T>& operator[](int index);
111 
115  const MessageField<T>& operator[](int index) const;
116 
120  MessageField<T>& operator[](const std::string& name);
121 
125  const MessageField<T>& operator[](const std::string& name) const;
126 
129  MessageFieldCollection<T>& operator+=(const MessageField<T>& field);
130 
134  bool operator==(const MessageFieldCollection<T>& collection) const;
135 
139  bool operator!=(const MessageFieldCollection<T>& collection) const;
140 
141  protected:
145 
148  typedef boost::weak_ptr<MessageField<T> > MessageFieldWPtr;
149 
152  std::vector<MessageFieldPtr> fieldsInOrder;
153 
156  boost::unordered_map<std::string, MessageFieldPtr> fieldsByName;
157 
161  MessageField<T>& getField(const std::string& name, size_t pos) const;
162 
166  bool hasField(const std::string& name, size_t pos) const;
167  };
168 
171  template <typename T> std::ostream& operator<<(std::ostream& stream,
172  const MessageFieldCollection<T>& collection);
173 };
174 
175 #include <variant_topic_tools/MessageFieldCollection.tpp>
176 
177 #endif
MessageField< T > & getField(int index)
Retrieve a field of the message field collection by index (non-const version)
Header file providing forward declarations for the variant topic tools.
boost::unordered_map< std::string, MessageFieldPtr > fieldsByName
The message fields of the collection by name.
bool hasField(const std::string &name) const
True, if the message field collection contains the field with the specified name. ...
virtual void write(std::ostream &stream, const std::string &indent=std::string()) const
Write the message field collection to a stream.
void appendField(const MessageField< T > &field)
Append a field to the message field collection.
std::vector< MessageFieldPtr > fieldsInOrder
The message fields of the collection in order.
std::ostream & operator<<(std::ostream &stream, const DataType &dataType)
Operator for writing the data type to a stream.
Definition: DataType.cpp:190
Forward declaration of the message field.
Definition: Forwards.h:68
bool operator==(const MessageFieldCollection< T > &collection) const
True, if this message field collection is equal to another message field collection.
void merge(const MessageFieldCollection< T > &collection)
Merge this message field collection with another message field collection.
bool operator!=(const MessageFieldCollection< T > &collection) const
True, if this message field collection is not equal to another message field collection.
MessageField< T > & operator[](int index)
Operator for retrieving the fields of the message field collection by index (non-const version) ...
MessageFieldCollection< T > & operator+=(const MessageField< T > &field)
Operator for appending a field to the message field collection.
size_t getNumFields() const
Retrieve the number of fields of the message field collection.
boost::weak_ptr< MessageField< T > > MessageFieldWPtr
Declaration of the message field weak pointer type.
MessageFieldCollection()
Default constructor.
virtual void clear()
Clear the message field collection.
Forward declaration of the message field collection.
Definition: Forwards.h:64
bool isEmpty() const
True, if the message field collections is empty.
boost::shared_ptr< MessageField< T > > MessageFieldPtr
Declaration of the message field pointer type.


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Sat Jan 9 2021 03:56:49