##

MsgFactory.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GAZEBO_MSGS_MSGFACTORY_HH_
#define GAZEBO_MSGS_MSGFACTORY_HH_
#include <string>
#include <map>
#include <vector>
#include <google/protobuf/message.h>
#include <boost/shared_ptr.hpp>
#include "gazebo/util/system.hh"
namespace gazebo
{
namespace msgs
{
typedef boost::shared_ptr<google::protobuf::Message> (*MsgFactoryFn) ();
class GAZEBO_VISIBLE MsgFactory
{
public: static void RegisterMsg(const std::string &_msgType,
MsgFactoryFn _factoryfn);
public: static boost::shared_ptr<google::protobuf::Message> NewMsg(
const std::string &_msgType);
public: static void GetMsgTypes(std::vector<std::string> &_types);
private: static std::map<std::string, MsgFactoryFn> *msgMap;
};
#define GZ_REGISTER_STATIC_MSG(_msgtype, _classname) \
GAZEBO_VISIBLE \
boost::shared_ptr<google::protobuf::Message> New##_classname() \
{ \
return boost::shared_ptr<gazebo::msgs::_classname>(\
new gazebo::msgs::_classname); \
} \
class GAZEBO_VISIBLE Msg##_classname \
{ \
public: Msg##_classname() \
{ \
gazebo::msgs::MsgFactory::RegisterMsg(_msgtype, New##_classname);\
} \
}; \
static Msg##_classname GzMsgInitializer;
}
}
#endif
gazebo::msgs::MsgFactory
A factory that generates protobuf message based on a string type.
Definition: MsgFactory.hh:41
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
system.hh
gazebo::msgs::MsgFactoryFn
boost::shared_ptr< google::protobuf::Message >(* MsgFactoryFn)()
Definition: MsgFactory.hh:34
GAZEBO_VISIBLE
#define GAZEBO_VISIBLE
Definition: system.hh:59