Ignition Physics

API Reference

2.3.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 IGNITION_PHYSICS_SPECIFYDATA_HH_
19 #define IGNITION_PHYSICS_SPECIFYDATA_HH_
20 
21 #include "ignition/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 
64 
66  public: virtual ~ExpectData() = default;
67 
71  public: template <typename Data>
72  Data &Get();
73 
77  public: template <typename Data, typename... Args>
78  InsertResult<Data> InsertOrAssign(Args&&... _args);
79 
83  public: template <typename Data, typename... Args>
84  InsertResult<Data> Insert(Args&&... _args);
85 
89  public: template <typename Data>
90  bool Remove();
91 
95  public: template <typename Data>
96  Data *Query(const QueryMode _mode = QueryMode::NORMAL);
97 
100  public: template <typename Data>
101  const Data *Query(const QueryMode _mode = QueryMode::NORMAL) const;
102 
106  public: template <typename Data>
107  bool Has() const;
108 
112  public: template <typename Data>
113  DataStatus StatusOf() const;
114 
118  public: template <typename Data>
119  bool Unquery() const;
120 
124  public: template <typename Data, typename... Args>
125  Data &MakeRequired(Args&&... _args);
126 
131  public: template <typename Data>
132  bool Requires() const;
133 
137  public: template <typename Data>
138  static constexpr bool Expects();
139 
142  protected: detail::PrivateExpectData<Expected> privateExpectData;
143 
144  // This allows outside users to identify this expected data type at
145  // compile time, which can be useful for doing template metaprogramming.
147  public: using ExpectedData = Expected;
148  public: using RequiredData = void;
149 
150  public: using SubSpecification1 = void;
151  public: using SubSpecification2 = void;
152  };
153 
172  template <typename Required>
173  class RequireData<Required> : public virtual ExpectData<Required>
174  {
175  // This allows outside users to identify this Required data type at
176  // compile time, which can be useful for doing template metaprogramming.
178  public: using RequiredData = Required;
179 
182  public: RequireData();
183 
185  public: virtual ~RequireData() = default;
186 
187  // Do not shadow the ExpectData<Required> implementation
188  using ExpectData<Required>::Get;
189 
196  public: template <typename Data>
197  const Data &Get() const;
198 
201  public: template <typename Data>
202  static constexpr bool AlwaysRequires();
203 
206  protected: detail::PrivateRequireData<Required> privateRequireData;
207  };
208 
261  template <typename... Specifications>
262  class SpecifyData;
263 
264 
265  // ----------------------- Utility Templates ----------------------------
266 
275  template <typename Specification>
277 
280  template <typename Specification>
282 
287  template <typename Specification, template<typename> class SpecFinder>
289 
290 
295  template <typename Specification>
297  {
298  using Data = typename Specification::ExpectedData;
299  };
300 
304  template <>
305  struct FindExpected<void>
306  {
307  using Data = void;
308  };
309 
310 
315  template <typename Specification>
317  {
318  using Data = typename Specification::RequiredData;
319  };
320 
324  template <>
325  struct FindRequired<void>
326  {
327  using Data = void;
328  };
329 
330 
333  template <typename Data, typename Specification>
335  bool, Specification::template Expects<Data>() > { };
336 
340  template <typename Data>
341  struct IsExpectedBy<Data, void> : std::false_type { };
342 
345  template <typename Data, typename Specification>
347  bool, Specification::template AlwaysRequires<Data>() > { };
348 
352  template <typename Data>
353  struct IsRequiredBy<Data, void> : std::false_type { };
354  }
355 }
356 
357 #include "ignition/physics/detail/SpecifyData.hh"
358 
359 #endif
constexpr std::size_t CountUpperLimitOfRequiredData()
Same as CountUpperLimitOfExpectedData() except it will count required data instead.
void RequiredData
Definition: SpecifyData.hh:148
Required RequiredData
Definition: SpecifyData.hh:178
Provides a constexpr field named value whose value is true if and only if Data is required by Specifi...
Definition: SpecifyData.hh:346
QueryMode
Use these flags in Query(), Has(), and StatusOf() to change their effects on the meta info of the dat...
Definition: CompositeData.hh:359
typename Specification::RequiredData Data
Definition: SpecifyData.hh:318
detail::PrivateExpectData< Expected > privateExpectData
Provides the implementation for delegating the functions provided by the ExpectData class...
Definition: SpecifyData.hh:142
ExpectData is an extension of CompositeData which indicates that the composite expects to be operatin...
Definition: SpecifyData.hh:46
This allows us to specify that we are interested in expected data while performing template metaprogr...
Definition: SpecifyData.hh:296
detail::PrivateRequireData< Required > privateRequireData
Provides the implementation for delegating the functions provided by the RequireData class...
Definition: SpecifyData.hh:206
RequireData is an extension of ExpectData which indicates that the composite requires the existence o...
Definition: SpecifyData.hh:173
constexpr std::size_t CountUpperLimitOfSpecifiedData()
Same as CountUpperLimitOfExpectedData() except you can specify what kind of data to count using SpecF...
This struct is the return type of the various Insert...<T>() functions. It returns a reference to the...
Definition: CompositeData.hh:106
typename Specification::ExpectedData Data
Definition: SpecifyData.hh:298
The CompositeData class allows arbitrary data structures to be composed together, copied...
Definition: CompositeData.hh:43
constexpr std::size_t CountUpperLimitOfExpectedData()
This provides an upper limit on the number of expected data types in a CompositeData specification...
void SubSpecification1
Definition: SpecifyData.hh:150
Provides a constexpr field named value whose value is true if and only if Data is expected by Specifi...
Definition: SpecifyData.hh:334
This allows us to specify that we are interested in required data while performing template metaprogr...
Definition: SpecifyData.hh:316
Struct that describes the status of data.
Definition: CompositeData.hh:554
The SpecifyData class allows you to form combinations of data specifications. In other words...
Definition: SpecifyData.hh:262
void SubSpecification2
Definition: SpecifyData.hh:151
Expected ExpectedData
Definition: SpecifyData.hh:147