Gazebo Physics

API Reference

5.4.0
gz/physics/CompositeData.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 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_COMPOSITEDATA_HH_
19 #define GZ_PHYSICS_COMPOSITEDATA_HH_
20 
21 #include <string>
22 #include <map>
23 #include <set>
24 
25 #include <gz/utils/SuppressWarning.hh>
26 
27 #include "gz/physics/Cloneable.hh"
28 #include "gz/physics/Export.hh"
29 
30 namespace ignition
31 {
32  namespace physics
33  {
34  // Forward declarations
35  namespace detail
36  {
37  template <typename> class PrivateExpectData;
38  template <typename> class PrivateRequireData;
39  }
40 
43  class IGNITION_PHYSICS_VISIBLE CompositeData
44  {
46  public: CompositeData();
47 
49  public: virtual ~CompositeData() = default;
50 
99  public: template <typename Data>
100  Data &Get();
101 
105  public: template <typename Data>
107  {
110  public: Data &data;
111 
118  public: const bool inserted;
119 
120  // We explicitly delete the copy assignment operator, because we don't
121  // want someone to inadvertently assign a value to the data that's being
122  // referenced (users must do so explicitly by calling on the `data`
123  // member variable). Note that this operator is already implicitly
124  // deleted by having the const bool member variable, but we are also
125  // deleting it explicitly for clarity.
126  public: InsertResult &operator=(const InsertResult&) = delete;
127  };
128 
211  public: template <typename Data, typename... Args>
212  InsertResult<Data> Insert(Args &&..._args);
213 
288  public: template <typename Data, typename... Args>
290 
352  public: template <typename Data>
353  bool Remove();
354 
359  enum class QueryMode : int
360  {
364  NORMAL = 0,
365 
368  SILENT
369  };
370 
465  public: template <typename Data>
466  Data *Query(const QueryMode _mode = QueryMode::NORMAL);
467 
539  public: template <typename Data>
540  const Data *Query(const QueryMode mode = QueryMode::NORMAL) const;
541 
550  public: template <typename Data>
551  bool Has() const;
552 
554  struct IGNITION_PHYSICS_VISIBLE DataStatus
555  {
558  public: bool exists;
559 
563  public: bool queried;
564 
567  public: bool required;
568 
571  };
572 
580  public: template <typename Data>
582 
640  public: template <typename Data>
641  bool Unquery() const;
642 
697  public: template <typename Data, typename... Args>
698  Data &MakeRequired(Args &&..._args);
699 
710  public: template <typename Data>
711  bool Requires() const;
712 
723  public: template <typename Data>
724  static constexpr bool Expects();
725 
743  public: template <typename Data>
744  static constexpr bool AlwaysRequires();
745 
751  public: std::size_t EntryCount() const;
752 
760 
770  public: void ResetQueries() const;
771 
823 
901 
916  public: CompositeData &Copy(const CompositeData &_other,
917  const bool _mergeRequirements = false);
918 
921  public: CompositeData &Copy(CompositeData &&_other,
922  const bool _mergeRequirements = false);
923 
937  public: CompositeData &Merge(const CompositeData &_other,
938  const bool _mergeRequirements = false);
939 
942  public: CompositeData &Merge(CompositeData &&_other,
943  const bool _mergeRequirements = false);
944 
946  public: CompositeData(const CompositeData &_other);
947 
949  public: CompositeData(CompositeData &&_other);
950 
952  public: CompositeData &operator=(const CompositeData &_other);
953 
956 
962  public: struct DataEntry;
963 
964  // We make this typedef public so that helper functions can use it without
965  // being friends of the class.
967 
968  IGN_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
970  protected: MapOfData dataMap;
971  IGN_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
972 
977 
980  protected: mutable std::size_t numQueries;
981 
982  // Declare friendship
983  template <typename> friend class detail::PrivateExpectData;
984  template <typename> friend class detail::PrivateRequireData;
985  };
986  }
987 }
988 
989 #include "gz/physics/detail/CompositeData.hh"
990 
991 #endif
The CompositeData class allows arbitrary data structures to be composed together, copied,...
Definition: gz/physics/CompositeData.hh:44
virtual ~CompositeData()=default
Virtual destructor.
std::size_t numEntries
Total number of data entries currently in this CompositeData. Note that this may differ from the size...
Definition: gz/physics/CompositeData.hh:976
bool Unquery() const
Returns true if this CompositeData has a Data-type object which was marked as queried,...
DataStatus StatusOf() const
Returns a DataStatus object that describes the status of the requested data type.
bool Requires() const
Returns true if the specified Data type is required by this CompositeData object. Otherwise,...
CompositeData & Merge(const CompositeData &_other, const bool _mergeRequirements=false)
Merge the data from _other into this CompositeData. If there are any conflicting data entries,...
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:360
Data & Get()
Get a reference to a Data object. If an object of the Data type does not already exist in this Compos...
const Data * Query(const QueryMode mode=QueryMode::NORMAL) const
Const-qualified version of Query. This can be used to retrieve data from a const CompositeData.
CompositeData(CompositeData &&_other)
Move constructor. Same as Copy(_other).
CompositeData & Copy(CompositeData &&_other, const bool _mergeRequirements=false)
An alternative to Copy(const CompositeData &, bool) that takes advantage of move semantics.
std::size_t numQueries
Total number of unique queries which have been performed since either construction or the last call t...
Definition: gz/physics/CompositeData.hh:980
Data * Query(const QueryMode _mode=QueryMode::NORMAL)
Query this CompositeData for a Data-type entry. If it contains a Data-type object,...
CompositeData(const CompositeData &_other)
Copy constructor. Same as Copy(_other).
CompositeData & operator=(CompositeData &&_other)
Move operator. Same as Copy(_other).
static constexpr bool Expects()
When called from a generic CompositeData type, this always returns false. More highly specified Compo...
bool Remove()
This will remove a Data-type object from this CompositeData and delete it if one is present....
InsertResult< Data > Insert(Args &&..._args)
This will attempt to insert a new Data entry into the CompositeData object, forwarding _args to the c...
CompositeData()
Default constructor. Creates an empty CompositeData object.
CompositeData & operator=(const CompositeData &_other)
Copy operator. Same as Copy(_other).
InsertResult< Data > InsertOrAssign(Args &&... _args)
Attempt to insert a Data-type entry. If a Data-type entry did not already exist, it will be construct...
std::set< std::string > AllEntries() const
Get an ordered set of all data entries in this CompositeData. Runs with O(N) complexity.
void ResetQueries() const
Reset the query flags on all data entries. This will make it appear as though no entries have ever be...
CompositeData & Copy(const CompositeData &_other, const bool _mergeRequirements=false)
Make this CompositeData a copy of _other. However, any data entries in this CompositeData which are m...
std::size_t EntryCount() const
Check how many data entries are in this CompositeData. Runs with O(1) complexity.
static constexpr bool AlwaysRequires()
When called from a generic CompositeData type, this always returns false. Static (Always) requirement...
std::set< std::string > UnqueriedEntries() const
Get an ordered (alphabetical) set of the data entries in this CompositeData which have not been queri...
bool Has() const
Returns true if this CompositeData has an object of type Data, otherwise returns false....
CompositeData & Merge(CompositeData &&_other, const bool _mergeRequirements=false)
An alternative to Merge(const CompositeData &, bool) that takes advantage of move semantics.
MapOfData dataMap
Map from the label of a data object type to its entry.
Definition: gz/physics/CompositeData.hh:970
Data & MakeRequired(Args &&..._args)
Marks the specified type of Data as required, creates one with the given arguments if it did not exis...
std::size_t UnqueriedEntryCount() const
Check how many data entries in this CompositeData have not been queried. See UnqueriedEntries() for m...
Struct that describes the status of data.
Definition: gz/physics/CompositeData.hh:555
bool exists
If the data exists in the CompositeData, this will be true, otherwise it is false.
Definition: gz/physics/CompositeData.hh:558
bool required
If the data is marked as required, this will be true, otherwise it is false.
Definition: gz/physics/CompositeData.hh:567
DataStatus()
Default constructor. Initializes everything to false.
bool queried
If the data was marked as queried BEFORE calling StatusOf (regardless of what QueryMode is used),...
Definition: gz/physics/CompositeData.hh:563
This struct is the return type of the various Insert...<T>() functions. It returns a reference to the...
Definition: gz/physics/CompositeData.hh:107
InsertResult & operator=(const InsertResult &)=delete
const bool inserted
True if the operation resulted in inserting a new data entry.
Definition: gz/physics/CompositeData.hh:118
Data & data
A reference to the Data entry within the CompositeData object.
Definition: gz/physics/CompositeData.hh:110