MessageFieldCollection.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2014 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00023 #ifndef VARIANT_TOPIC_TOOLS_MESSAGE_FIELD_COLLECTION_H
00024 #define VARIANT_TOPIC_TOOLS_MESSAGE_FIELD_COLLECTION_H
00025 
00026 #include <vector>
00027 
00028 #include <boost/unordered_map.hpp>
00029 
00030 #include <ros/ros.h>
00031 
00032 #include <variant_topic_tools/Forwards.h>
00033 
00034 namespace variant_topic_tools {
00037   template <typename T> class MessageFieldCollection {
00038   public:
00041     MessageFieldCollection();
00042 
00045     MessageFieldCollection(const MessageFieldCollection<T>& src);
00046 
00049     virtual ~MessageFieldCollection();
00050 
00053     size_t getNumFields() const;
00054 
00058     MessageField<T>& getField(int index);
00059 
00063     const MessageField<T>& getField(int index) const;
00064 
00068     MessageField<T>& getField(const std::string& name);
00069 
00073     const MessageField<T>& getField(const std::string& name) const;
00074 
00078     bool hasField(const std::string& name) const;
00079 
00082     bool isEmpty() const;
00083 
00086     void appendField(const MessageField<T>& field);
00087 
00091     void appendField(const std::string& name, const T& value = T());
00092 
00096     void merge(const MessageFieldCollection<T>& collection);
00097 
00100     virtual void clear();
00101 
00104     virtual void write(std::ostream& stream, const std::string& indent =
00105       std::string()) const;
00106 
00110     MessageField<T>& operator[](int index);
00111 
00115     const MessageField<T>& operator[](int index) const;
00116 
00120     MessageField<T>& operator[](const std::string& name);
00121 
00125     const MessageField<T>& operator[](const std::string& name) const;
00126 
00129     MessageFieldCollection<T>& operator+=(const MessageField<T>& field);
00130 
00134     bool operator==(const MessageFieldCollection<T>& collection) const;
00135 
00139     bool operator!=(const MessageFieldCollection<T>& collection) const;
00140 
00141   protected:
00144     typedef boost::shared_ptr<MessageField<T> > MessageFieldPtr;
00145 
00148     typedef boost::weak_ptr<MessageField<T> > MessageFieldWPtr;
00149 
00152     std::vector<MessageFieldPtr> fieldsInOrder;
00153 
00156     boost::unordered_map<std::string, MessageFieldPtr> fieldsByName;
00157 
00161     MessageField<T>& getField(const std::string& name, size_t pos) const;
00162 
00166     bool hasField(const std::string& name, size_t pos) const;
00167   };
00168 
00171   template <typename T> std::ostream& operator<<(std::ostream& stream,
00172     const MessageFieldCollection<T>& collection);
00173 };
00174 
00175 #include <variant_topic_tools/MessageFieldCollection.tpp>
00176 
00177 #endif


variant_topic_tools
Author(s): Ralf Kaestner
autogenerated on Tue Jul 9 2019 03:18:42