Gazebo Msgs

API Reference

10.3.1
Factory.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
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 GZ_MSGS_FACTORY_HH_
18 #define GZ_MSGS_FACTORY_HH_
19 
20 #include <string>
21 #include <map>
22 #include <memory>
23 #include <vector>
24 
25 #include "gz/msgs/config.hh"
26 #include "gz/msgs/Export.hh"
27 
29 
30 namespace gz::msgs
31 {
32  // Inline bracket to help doxygen filtering.
33  inline namespace GZ_MSGS_VERSION_NAMESPACE {
34 
39  class GZ_MSGS_VISIBLE Factory
40  {
43 
46 
49 
51  private: Factory() = default;
52 
54  public: Factory(const Factory&) = delete;
55 
57  public: void operator=(const Factory&) = delete;
58 
60  public: Factory(Factory&&) = delete;
61 
63  public: void operator=(Factory&&) = delete;
64 
67  public: static MessageFactory& Instance();
68 
72  public: static void Register(const std::string &_msgType,
73  FactoryFn _factoryfn);
74 
79  public: template<typename T>
80  static std::unique_ptr<T> New(const std::string &_msgType)
81  {
82  return Factory::Instance().New<T>(_msgType);
83  }
84 
90  public: template<typename T>
91  static std::unique_ptr<T> New(const std::string &_msgType,
92  const std::string &_args)
93  {
94  return Factory::Instance().New<T>(_msgType, _args);
95  }
96 
101  public: static MessagePtr New(const std::string &_msgType);
102 
108  public: static MessagePtr
109  New(const std::string &_msgType, const std::string &_args);
110 
113  public: static void Types(std::vector<std::string> &_types);
114 
118  public: static void LoadDescriptors(const std::string &_paths);
119  };
120 }
121 } // namespace gz::msgs
122 #endif