Gazebo Physics

API Reference

2.6.2
gz/physics/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 
23 namespace ignition
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>
81  InsertResult<Data> InsertOrAssign(Args&&... _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>
116  DataStatus StatusOf() const;
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.
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.
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>
265  class SpecifyData;
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
This struct is the return type of the various Insert...<T>() functions. It returns a reference to the...
Definition: gz/physics/CompositeData.hh:106
RequireData is an extension of ExpectData which indicates that the composite requires the existence o...
Definition: gz/physics/SpecifyData.hh:176
Struct that describes the status of data.
Definition: gz/physics/CompositeData.hh:554
typename Specification::RequiredData Data
Definition: gz/physics/SpecifyData.hh:321
Provides a constexpr field named value whose value is true if and only if Data is expected by Specifi...
Definition: gz/physics/SpecifyData.hh:337
The SpecifyData class allows you to form combinations of data specifications. In other words,...
Definition: gz/physics/SpecifyData.hh:265
Provides a constexpr field named value whose value is true if and only if Data is required by Specifi...
Definition: gz/physics/SpecifyData.hh:349
constexpr std::size_t CountUpperLimitOfRequiredData()
Same as CountUpperLimitOfExpectedData() except it will count required data instead.
This allows us to specify that we are interested in required data while performing template metaprogr...
Definition: gz/physics/SpecifyData.hh:319
void RequiredData
Definition: gz/physics/SpecifyData.hh:151
constexpr std::size_t CountUpperLimitOfSpecifiedData()
Same as CountUpperLimitOfExpectedData() except you can specify what kind of data to count using SpecF...
ExpectData is an extension of CompositeData which indicates that the composite expects to be operatin...
Definition: gz/physics/SpecifyData.hh:46
detail::PrivateExpectData< Expected > privateExpectData
Provides the implementation for delegating the functions provided by the ExpectData class.
Definition: gz/physics/SpecifyData.hh:145
The CompositeData class allows arbitrary data structures to be composed together, copied,...
Definition: gz/physics/CompositeData.hh:43
Required RequiredData
Definition: gz/physics/SpecifyData.hh:181
This allows us to specify that we are interested in expected data while performing template metaprogr...
Definition: gz/physics/SpecifyData.hh:299
Expected ExpectedData
Definition: gz/physics/SpecifyData.hh:150
constexpr std::size_t CountUpperLimitOfExpectedData()
This provides an upper limit on the number of expected data types in a CompositeData specification....
typename Specification::ExpectedData Data
Definition: gz/physics/SpecifyData.hh:301
void SubSpecification2
Definition: gz/physics/SpecifyData.hh:154
detail::PrivateRequireData< Required > privateRequireData
Provides the implementation for delegating the functions provided by the RequireData class.
Definition: gz/physics/SpecifyData.hh:209
QueryMode
Use these flags in Query(), Has(), and StatusOf() to change their effects on the meta info of the dat...
Definition: gz/physics/CompositeData.hh:359
void SubSpecification1
Definition: gz/physics/SpecifyData.hh:153