Ignition Physics

API Reference

2.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 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 
52  public: virtual ~ExpectData() = default;
53 
57  public: template <typename Data>
58  Data &Get();
59 
63  public: template <typename Data, typename... Args>
64  InsertResult<Data> InsertOrAssign(Args&&... _args);
65 
69  public: template <typename Data, typename... Args>
70  InsertResult<Data> Insert(Args&&... _args);
71 
75  public: template <typename Data>
76  bool Remove();
77 
81  public: template <typename Data>
82  Data *Query(const QueryMode _mode = QueryMode::NORMAL);
83 
86  public: template <typename Data>
87  const Data *Query(const QueryMode _mode = QueryMode::NORMAL) const;
88 
92  public: template <typename Data>
93  bool Has() const;
94 
98  public: template <typename Data>
99  DataStatus StatusOf() const;
100 
104  public: template <typename Data>
105  bool Unquery() const;
106 
110  public: template <typename Data, typename... Args>
111  Data &MakeRequired(Args&&... _args);
112 
117  public: template <typename Data>
118  bool Requires() const;
119 
123  public: template <typename Data>
124  static constexpr bool Expects();
125 
128  protected: detail::PrivateExpectData<Expected> privateExpectData;
129 
130  // This allows outside users to identify this expected data type at
131  // compile time, which can be useful for doing template metaprogramming.
133  public: using ExpectedData = Expected;
134  public: using RequiredData = void;
135 
136  public: using SubSpecification1 = void;
137  public: using SubSpecification2 = void;
138  };
139 
158  template <typename Required>
159  class RequireData<Required> : public virtual ExpectData<Required>
160  {
161  // This allows outside users to identify this Required data type at
162  // compile time, which can be useful for doing template metaprogramming.
164  public: using RequiredData = Required;
165 
168  public: RequireData();
169 
171  public: virtual ~RequireData() = default;
172 
173  // Do not shadow the ExpectData<Required> implementation
174  using ExpectData<Required>::Get;
175 
182  public: template <typename Data>
183  const Data &Get() const;
184 
187  public: template <typename Data>
188  static constexpr bool AlwaysRequires();
189 
192  protected: detail::PrivateRequireData<Required> privateRequireData;
193  };
194 
247  template <typename... Specifications>
248  class SpecifyData;
249 
250 
251  // ----------------------- Utility Templates ----------------------------
252 
261  template <typename Specification>
263 
266  template <typename Specification>
268 
273  template <typename Specification, template<typename> class SpecFinder>
275 
276 
281  template <typename Specification>
283  {
284  using Data = typename Specification::ExpectedData;
285  };
286 
290  template <>
291  struct FindExpected<void>
292  {
293  using Data = void;
294  };
295 
296 
301  template <typename Specification>
303  {
304  using Data = typename Specification::RequiredData;
305  };
306 
310  template <>
311  struct FindRequired<void>
312  {
313  using Data = void;
314  };
315 
316 
319  template <typename Data, typename Specification>
321  bool, Specification::template Expects<Data>() > { };
322 
326  template <typename Data>
327  struct IsExpectedBy<Data, void> : std::false_type { };
328 
331  template <typename Data, typename Specification>
333  bool, Specification::template AlwaysRequires<Data>() > { };
334 
338  template <typename Data>
339  struct IsRequiredBy<Data, void> : std::false_type { };
340  }
341 }
342 
343 #include "ignition/physics/detail/SpecifyData.hh"
344 
345 #endif
constexpr std::size_t CountUpperLimitOfRequiredData()
Same as CountUpperLimitOfExpectedData() except it will count required data instead.
void RequiredData
Definition: SpecifyData.hh:134
Required RequiredData
Definition: SpecifyData.hh:164
Provides a constexpr field named value whose value is true if and only if Data is required by Specifi...
Definition: SpecifyData.hh:332
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:304
detail::PrivateExpectData< Expected > privateExpectData
Provides the implementation for delegating the functions provided by the ExpectData class...
Definition: SpecifyData.hh:128
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:282
detail::PrivateRequireData< Required > privateRequireData
Provides the implementation for delegating the functions provided by the RequireData class...
Definition: SpecifyData.hh:192
RequireData is an extension of ExpectData which indicates that the composite requires the existence o...
Definition: SpecifyData.hh:159
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:284
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:136
Provides a constexpr field named value whose value is true if and only if Data is expected by Specifi...
Definition: SpecifyData.hh:320
This allows us to specify that we are interested in required data while performing template metaprogr...
Definition: SpecifyData.hh:302
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:248
void SubSpecification2
Definition: SpecifyData.hh:137
Expected ExpectedData
Definition: SpecifyData.hh:133