Gazebo Physics

API Reference

8.0.0
SpecifyData.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 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
18#ifndef GZ_PHYSICS_SPECIFYDATA_HH_
19#define GZ_PHYSICS_SPECIFYDATA_HH_
20
21#include "gz/physics/detail/PrivateSpecifyData.hh"
22
23namespace gz
24{
25 namespace physics
26 {
45 template <typename Expected>
46 class ExpectData<Expected> : public virtual CompositeData
47 {
49 public: ExpectData();
50
58 public: ExpectData(const ExpectData &_other);
59
61 public: ExpectData& operator=(const ExpectData &_other) = default;
62
67
69 public: virtual ~ExpectData() = default;
70
74 public: template <typename Data>
75 Data &Get();
76
80 public: template <typename Data, typename... Args>
82
86 public: template <typename Data, typename... Args>
87 InsertResult<Data> Insert(Args&&... _args);
88
92 public: template <typename Data>
93 bool Remove();
94
98 public: template <typename Data>
99 Data *Query(const QueryMode _mode = QueryMode::NORMAL);
100
103 public: template <typename Data>
104 const Data *Query(const QueryMode _mode = QueryMode::NORMAL) const;
105
109 public: template <typename Data>
110 bool Has() const;
111
115 public: template <typename Data>
117
121 public: template <typename Data>
122 bool Unquery() const;
123
127 public: template <typename Data, typename... Args>
128 Data &MakeRequired(Args&&... _args);
129
134 public: template <typename Data>
135 bool Requires() const;
136
140 public: template <typename Data>
141 static constexpr bool Expects();
142
145 protected: detail::PrivateExpectData<Expected> privateExpectData;
146
147 // This allows outside users to identify this expected data type at
148 // compile time, which can be useful for doing template metaprogramming.
149 public: using Specification = ExpectData<Expected>;
150 public: using ExpectedData = Expected;
151 public: using RequiredData = void;
152
153 public: using SubSpecification1 = void;
154 public: using SubSpecification2 = void;
155 };
156
175 template <typename Required>
176 class RequireData<Required> : public virtual ExpectData<Required>
177 {
178 // This allows outside users to identify this Required data type at
179 // compile time, which can be useful for doing template metaprogramming.
180 public: using Specification = RequireData<Required>;
181 public: using RequiredData = Required;
182
185 public: RequireData();
186
188 public: virtual ~RequireData() = default;
189
190 // Do not shadow the ExpectData<Required> implementation
191 using ExpectData<Required>::Get;
192
199 public: template <typename Data>
200 const Data &Get() const;
201
204 public: template <typename Data>
205 static constexpr bool AlwaysRequires();
206
209 protected: detail::PrivateRequireData<Required> privateRequireData;
210 };
211
264 template <typename... Specifications>
266
267
268 // ----------------------- Utility Templates ----------------------------
269
278 template <typename Specification>
280
283 template <typename Specification>
285
290 template <typename Specification, template<typename> class SpecFinder>
292
293
298 template <typename Specification>
300 {
301 using Data = typename Specification::ExpectedData;
302 };
303
307 template <>
308 struct FindExpected<void>
309 {
310 using Data = void;
311 };
312
313
318 template <typename Specification>
320 {
321 using Data = typename Specification::RequiredData;
322 };
323
327 template <>
328 struct FindRequired<void>
329 {
330 using Data = void;
331 };
332
333
336 template <typename Data, typename Specification>
338 bool, Specification::template Expects<Data>() > { };
339
343 template <typename Data>
344 struct IsExpectedBy<Data, void> : std::false_type { };
345
348 template <typename Data, typename Specification>
350 bool, Specification::template AlwaysRequires<Data>() > { };
351
355 template <typename Data>
356 struct IsRequiredBy<Data, void> : std::false_type { };
357 }
358}
359
360#include "gz/physics/detail/SpecifyData.hh"
361
362#endif