Ignition Physics

API Reference

5.1.0
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 IGNITION_PHYSICS_COMPOSITEDATA_HH_
19 #define IGNITION_PHYSICS_COMPOSITEDATA_HH_
20 
21 #include <string>
22 #include <map>
23 #include <set>
24 
25 #include <ignition/utils/SuppressWarning.hh>
26 
28 #include "ignition/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 "ignition/physics/detail/CompositeData.hh"
990 
991 #endif
const bool inserted
True if the operation resulted in inserting a new data entry.
Definition: CompositeData.hh:118
bool required
If the data is marked as required, this will be true, otherwise it is false.
Definition: CompositeData.hh:567
QueryMode
Use these flags in Query(), Has(), and StatusOf() to change their effects on the meta info of the dat...
Definition: CompositeData.hh:359
std::size_t numQueries
Total number of unique queries which have been performed since either construction or the last call t...
Definition: CompositeData.hh:980
bool exists
If the data exists in the CompositeData, this will be true, otherwise it is false.
Definition: CompositeData.hh:558
This struct is the return type of the various Insert...<T>() functions. It returns a reference to the...
Definition: CompositeData.hh:106
The CompositeData class allows arbitrary data structures to be composed together, copied...
Definition: CompositeData.hh:43
bool queried
If the data was marked as queried BEFORE calling StatusOf (regardless of what QueryMode is used)...
Definition: CompositeData.hh:563
MapOfData dataMap
Map from the label of a data object type to its entry.
Definition: CompositeData.hh:970
std::size_t numEntries
Total number of data entries currently in this CompositeData. Note that this may differ from the size...
Definition: CompositeData.hh:976
Struct that describes the status of data.
Definition: CompositeData.hh:554
Data & data
A reference to the Data entry within the CompositeData object.
Definition: CompositeData.hh:110