All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SubscribeOptions.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _SUBSCRIBEOPTIONS_HH_
18 #define _SUBSCRIBEOPTIONS_HH_
19 
20 #include <boost/function.hpp>
21 #include <boost/shared_ptr.hpp>
22 #include <string>
24 
25 namespace gazebo
26 {
27  namespace transport
28  {
31 
35  {
37  public: SubscribeOptions()
38  : latching(false)
39  {}
40 
46  public: template<class M>
47  void Init(const std::string &_topic,
48  NodePtr _node,
49  bool _latching)
50  {
51  google::protobuf::Message *msg = NULL;
52  M msgtype;
53  msg = dynamic_cast<google::protobuf::Message *>(&msgtype);
54  if (!msg)
55  gzthrow("Subscribe requires a google protobuf type");
56 
57  this->node = _node;
58  this->topic = _topic;
59  this->msgType = msg->GetTypeName();
60  this->latching = _latching;
61  }
62 
65  public: NodePtr GetNode() const
66  {
67  return this->node;
68  }
69 
72  public: std::string GetTopic() const
73  {
74  return this->topic;
75  }
76 
79  public: std::string GetMsgType() const
80  {
81  return this->msgType;
82  }
83 
86  public: bool GetLatching() const
87  {
88  return this->latching;
89  }
90 
91  private: std::string topic;
92  private: std::string msgType;
93  private: NodePtr node;
94  private: bool latching;
95  };
97  }
98 }
99 
100 #endif
101 
102