MessageField.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_H
24 #define VARIANT_TOPIC_TOOLS_MESSAGE_FIELD_H
25 
26 #include <boost/type_traits.hpp>
27 
28 #include <ros/ros.h>
29 
33 
34 namespace variant_topic_tools {
37  template <typename T> class MessageField :
38  public MessageFieldCollection<T> {
39  public:
42  MessageField(const std::string& name = std::string(), const
43  T& value = T());
44 
47  MessageField(const MessageField<T>& src);
48 
51  virtual ~MessageField();
52 
55  void setName(const std::string& name);
56 
59  const std::string& getName() const;
60 
63  void setValue(const T& value);
64 
67  T& getValue();
68 
71  const T& getValue() const;
72 
75  bool isValid() const;
76 
79  void clear();
80 
83  void write(std::ostream& stream, const std::string& indent =
84  std::string()) const;
85 
88  bool operator==(const MessageField<T>& field) const;
89 
93  bool operator!=(const MessageField<T>& field) const;
94 
95  protected:
98  std::string name;
99 
102  T value;
103 
107  template <typename U> static bool isValid(const U& value, typename boost::
108  enable_if_c<MessageFieldTypeTraits::HasIsValid<U>::value>::type* = 0);
109 
113  template <typename U> static bool isValid(const U& value, typename boost::
114  disable_if_c<MessageFieldTypeTraits::HasIsValid<U>::value>::type* = 0);
115 
119  template <typename U> static void writeValue(std::ostream& stream, const
120  U& value, typename boost::enable_if<boost::has_left_shift<std::ostream,
121  const U&> >::type* = 0);
122 
126  template <typename U> static void writeValue(std::ostream& stream, const
127  U& value, typename boost::disable_if<boost::has_left_shift<std::ostream,
128  const U&> >::type* = 0);
129  };
130 
133  template <typename T> std::ostream& operator<<(std::ostream& stream,
134  const MessageField<T>& messageField);
135 };
136 
137 #include <variant_topic_tools/MessageField.tpp>
138 
139 #endif
virtual ~MessageField()
Destructor.
bool operator!=(const MessageField< T > &field) const
True, if this message field is not equal to another message field.
Header file providing the MessageFieldTypeTraits class interface.
void write(std::ostream &stream, const std::string &indent=std::string()) const
Write the message field to a stream.
void setValue(const T &value)
Set the value of the message field.
const std::string & getName() const
Retrieve the name of the message field.
Header file providing the MessageFieldCollection class interface.
bool operator==(const MessageField< T > &field) const
True, if this message field is equal to another message field.
std::ostream & operator<<(std::ostream &stream, const DataType &dataType)
Operator for writing the data type to a stream.
Definition: DataType.cpp:190
MessageField(const std::string &name=std::string(), const T &value=T())
Default constructor.
T value
The value of this message field.
Definition: MessageField.h:102
Forward declaration of the message field.
Definition: Forwards.h:68
bool isValid() const
True, if this message field is valid.
std::string name
The name of this message field.
Definition: MessageField.h:98
void setName(const std::string &name)
Set the name of the message field.
void clear()
Clear the message field.
static void writeValue(std::ostream &stream, const U &value, typename boost::enable_if< boost::has_left_shift< std::ostream, const U & > >::type *=0)
Write a message field value to a stream (overloaded version taking a stream-writable value) ...
Header file providing the MessageType class interface.
T & getValue()
Retrieve the value of the message field (non-const version)


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