Gazebo Physics

API Reference

2.6.2
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/utilities/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>
289  InsertResult<Data> InsertOrAssign(Args &&... _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 
570  DataStatus();
571  };
572 
580  public: template <typename Data>
581  DataStatus StatusOf() const;
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 
759  public: std::size_t UnqueriedEntryCount() const;
760 
770  public: void ResetQueries() const;
771 
822  public: std::set<std::string> AllEntries() const;
823 
900  public: std::set<std::string> UnqueriedEntries() const;
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 
955  public: CompositeData &operator=(CompositeData &&_other);
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
This struct is the return type of the various Insert...<T>() functions. It returns a reference to the...
Definition: gz/physics/CompositeData.hh:106
bool exists
If the data exists in the CompositeData, this will be true, otherwise it is false.
Definition: gz/physics/CompositeData.hh:558
InsertResult & operator=(const InsertResult &)=delete
Data * Query(const QueryMode _mode=QueryMode::NORMAL)
Query this CompositeData for a Data-type entry. If it contains a Data-type object,...
CompositeData & Merge(const CompositeData &_other, const bool _mergeRequirements=false)
Merge the data from _other into this CompositeData. If there are any conflicting data entries,...
static constexpr bool Expects()
When called from a generic CompositeData type, this always returns false. More highly specified Compo...
Struct that describes the status of data.
Definition: gz/physics/CompositeData.hh:554
@ SILENT
Performing the operation has no effect on whether data is marked as queried.
bool Unquery() const
Returns true if this CompositeData has a Data-type object which was marked as queried,...
std::set< std::string > AllEntries() const
Get an ordered set of all data entries in this CompositeData. Runs with O(N) complexity.
const bool inserted
True if the operation resulted in inserting a new data entry.
Definition: gz/physics/CompositeData.hh:118
CompositeData()
Default constructor. Creates an empty CompositeData object.
std::size_t UnqueriedEntryCount() const
Check how many data entries in this CompositeData have not been queried. See UnqueriedEntries() for m...
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
virtual ~CompositeData()=default
Virtual destructor.
bool Has() const
Returns true if this CompositeData has an object of type Data, otherwise returns false....
@ NORMAL
Performing the operation will cause an unqueried Data's status to flip to queried....
std::set< std::string > UnqueriedEntries() const
Get an ordered (alphabetical) set of the data entries in this CompositeData which have not been queri...
Data & Get()
Get a reference to a Data object. If an object of the Data type does not already exist in this Compos...
DataStatus()
Default constructor. Initializes everything to false.
bool Remove()
This will remove a Data-type object from this CompositeData and delete it if one is present....
DataStatus StatusOf() const
Returns a DataStatus object that describes the status of the requested data type.
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...
static constexpr bool AlwaysRequires()
When called from a generic CompositeData type, this always returns false. Static (Always) requirement...
The CompositeData class allows arbitrary data structures to be composed together, copied,...
Definition: gz/physics/CompositeData.hh:43
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 numEntries
Total number of data entries currently in this CompositeData. Note that this may differ from the size...
Definition: gz/physics/CompositeData.hh:976
MapOfData dataMap
Map from the label of a data object type to its entry.
Definition: gz/physics/CompositeData.hh:970
CompositeData & operator=(const CompositeData &_other)
Copy operator. Same as Copy(_other).
void ResetQueries() const
Reset the query flags on all data entries. This will make it appear as though no entries have ever be...
Data & MakeRequired(Args &&..._args)
Marks the specified type of Data as required, creates one with the given arguments if it did not exis...
bool Requires() const
Returns true if the specified Data type is required by this CompositeData object. Otherwise,...
Data & data
A reference to the Data entry within the CompositeData object.
Definition: gz/physics/CompositeData.hh:110
bool required
If the data is marked as required, this will be true, otherwise it is false.
Definition: gz/physics/CompositeData.hh:567
InsertResult< Data > Insert(Args &&..._args)
This will attempt to insert a new Data entry into the CompositeData object, forwarding _args to the c...
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
std::size_t EntryCount() const
Check how many data entries are in this CompositeData. Runs with O(1) complexity.
bool queried
If the data was marked as queried BEFORE calling StatusOf (regardless of what QueryMode is used),...
Definition: gz/physics/CompositeData.hh:563