ExpectData is an extension of CompositeData which indicates that the composite expects to be operating on the data types listed in its template arguments. All of the expected types will benefit from very high-speed operations when being accessed from an object of type ExpectData<Expected>. The ordinary CompositeData class needs to perform a map lookup on the data type whenever one of its functions is called, but an ExpectData<T> object does not need to perform any map lookup when performing an operation on T (e.g. .Get<T>(), .Insert<T>(), .Query<T>(), .Has<T>(), etc). More...
#include <SpecifyData.hh>
Public Types | |
using | ExpectedData = Expected |
using | RequiredData = void |
using | Specification = ExpectData< Expected > |
using | SubSpecification1 = void |
using | SubSpecification2 = void |
![]() | |
using | MapOfData = std::map< std::string, DataEntry > |
enum class | QueryMode : int { NORMAL = 0 , SILENT } |
Use these flags in Query(), Has(), and StatusOf() to change their effects on the meta info of the data being queried. More... | |
Public Member Functions | |
ExpectData () | |
Default constructor. | |
ExpectData (const ExpectData &_other) | |
Copy constructor. The copy constructor of the base class, CompositeData, is called before this copy constructor and it does the actual copying of the data contained in the MapData object of _other . Thus, this copy constructor simply calls the default constructor to initialize the MapData iterator of this object to point the appropriate iterator in the newly copied MapData. | |
virtual | ~ExpectData ()=default |
Virtual destructor. | |
template<typename Data > | |
Data & | Get () |
Provides extremely high-speed access to expected data types and normal access to unexpected data types. | |
template<typename Data > | |
bool | Has () const |
Provides extremely high-speed access for checking the existence of expected data types and normal access for unexpected data types. | |
template<typename Data , typename... Args> | |
InsertResult< Data > | Insert (Args &&... _args) |
Provides extremely high-speed access to getting or creating expected data types and normal access to unexpected data types. | |
template<typename Data , typename... Args> | |
InsertResult< Data > | InsertOrAssign (Args &&... _args) |
Provides extremely high-speed access to creating expected data types and normal access to unexpected data types. | |
template<typename Data , typename... Args> | |
Data & | MakeRequired (Args &&... _args) |
Provides extremely high-speed access for making expected data types required and normal access for unexpected data types. | |
ExpectData & | operator= (const ExpectData &_other)=default |
Copy assignment operator. | |
template<typename Data > | |
Data * | Query (const QueryMode _mode=QueryMode::NORMAL) |
Provides extremely high-speed access for querying expected data types and normal access for unexpected data types. | |
template<typename Data > | |
const Data * | Query (const QueryMode _mode=QueryMode::NORMAL) const |
Const-qualified version of Query<Data> | |
template<typename Data > | |
bool | Remove () |
Provides extremely high-speed access for removing expected data types and normal access for unexpected data types. | |
template<typename Data > | |
bool | Requires () const |
Provides extremely high-speed access for checking whether expected data types are required and normal access for unexpected data types. | |
template<typename Data > | |
DataStatus | StatusOf () const |
Provides extremely high-speed access to the status of expected data types and normal access for unexpected data types. | |
template<typename Data > | |
bool | Unquery () const |
Provides extremely high-speed access for unquerying expected data types and normal access for unexpected data types. | |
![]() | |
CompositeData () | |
Default constructor. Creates an empty CompositeData object. | |
CompositeData (CompositeData &&_other) | |
Move constructor. Same as Copy(_other). | |
CompositeData (const CompositeData &_other) | |
Copy constructor. Same as Copy(_other). | |
virtual | ~CompositeData ()=default |
Virtual destructor. | |
std::set< std::string > | AllEntries () const |
Get an ordered set of all data entries in this CompositeData. Runs with O(N) complexity. | |
CompositeData & | Copy (CompositeData &&_other, const bool _mergeRequirements=false) |
An alternative to Copy(const CompositeData &, bool) that takes advantage of move semantics. | |
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 marked as required will not be removed. | |
std::size_t | EntryCount () const |
Check how many data entries are in this CompositeData. Runs with O(1) complexity. | |
template<typename Data > | |
Data & | Get () |
Get a reference to a Data object. If an object of the Data type does not already exist in this CompositeData, then create one using its default constructor. This function will fail to compile if a default constructor is not available for the Data type. | |
template<typename Data > | |
bool | Has () const |
Returns true if this CompositeData has an object of type Data, otherwise returns false. This is literally equivalent to (nullptr != Query<Data>(QueryMode::SILENT)). | |
template<typename Data , typename... Args> | |
InsertResult< Data > | Insert (Args &&..._args) |
This will attempt to insert a new Data entry into the CompositeData object, forwarding _args to the constructor of the entry. If an entry already exists for this Data type, then nothing will be inserted. | |
template<typename Data , typename... Args> | |
InsertResult< Data > | InsertOrAssign (Args &&... _args) |
Attempt to insert a Data-type entry. If a Data-type entry did not already exist, it will be constructed by copying (or moving) the given arguments. If a Data-type entry already existed, the existing entry will be assigned the value of Data(_args...). | |
template<typename Data , typename... Args> | |
Data & | MakeRequired (Args &&..._args) |
Marks the specified type of Data as required, creates one with the given arguments if it did not exist, and returns a reference to it. | |
CompositeData & | Merge (CompositeData &&_other, const bool _mergeRequirements=false) |
An alternative to Merge(const CompositeData &, bool) that takes advantage of move semantics. | |
CompositeData & | Merge (const CompositeData &_other, const bool _mergeRequirements=false) |
Merge the data from _other into this CompositeData. If there are any conflicting data entries, the entry from _other will take precedence. | |
CompositeData & | operator= (CompositeData &&_other) |
Move operator. Same as Copy(_other). | |
CompositeData & | operator= (const CompositeData &_other) |
Copy operator. Same as Copy(_other). | |
template<typename Data > | |
Data * | Query (const QueryMode _mode=QueryMode::NORMAL) |
Query this CompositeData for a Data-type entry. If it contains a Data-type object, it gets returned as a Data*. Otherwise, a nullptr is returned. | |
template<typename Data > | |
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 . | |
template<typename Data > | |
bool | Remove () |
This will remove a Data-type object from this CompositeData and delete it if one is present. Otherwise, it will do nothing. Data-types that are marked as required will not (and cannot) be removed. | |
template<typename Data > | |
bool | Requires () const |
Returns true if the specified Data type is required by this CompositeData object. Otherwise, returns false. | |
void | ResetQueries () const |
Reset the query flags on all data entries. This will make it appear as though no entries have ever been queried. See UnqueriedEntries() for more information about the "queried" flag. | |
template<typename Data > | |
DataStatus | StatusOf () const |
Returns a DataStatus object that describes the status of the requested data type. | |
std::set< std::string > | UnqueriedEntries () const |
Get an ordered (alphabetical) set of the data entries in this CompositeData which have not been queried (Get, Insert, InsertOrAssign, Query, and MakeRequired all perform querying) since the data was implicitly created (e.g. by a copy or move operation) or since the last call to ResetQueries(), whichever is more recent. Runs with O(N) complexity. | |
std::size_t | UnqueriedEntryCount () const |
Check how many data entries in this CompositeData have not been queried. See UnqueriedEntries() for more information about the "queried" flag. Runs with O(1) complexity. | |
template<typename Data > | |
bool | Unquery () const |
Returns true if this CompositeData has a Data-type object which was marked as queried, and that object is now marked as unqueried. If an object of that type does not exist or it was already unqueried, this returns false. | |
Static Public Member Functions | |
template<typename Data > | |
static constexpr bool | Expects () |
Returns true if the Data type is expected. Data types for which this is true will be able to enjoy extremely high-speed access. | |
![]() | |
template<typename Data > | |
static constexpr bool | AlwaysRequires () |
When called from a generic CompositeData type, this always returns false. Static (Always) requirements are determined at compile-time and cannot be changed at runtime. Using the RequireData class can make this return true for more highly specified CompositeData types. | |
template<typename Data > | |
static constexpr bool | Expects () |
When called from a generic CompositeData type, this always returns false. More highly specified CompositeData types that use ExpectData or RequireData may return true if the type of Data is expected. | |
Protected Attributes | |
detail::PrivateExpectData< Expected > | privateExpectData |
Provides the implementation for delegating the functions provided by the ExpectData class. | |
![]() | |
MapOfData | dataMap |
Map from the label of a data object type to its entry. | |
std::size_t | numEntries |
Total number of data entries currently in this CompositeData. Note that this may differ from the size of dataMap, because some entries in dataMap will be referring to nullptrs. | |
std::size_t | numQueries |
Total number of unique queries which have been performed since either construction or the last call to ResetQueries(). | |
Detailed Description
class gz::physics::ExpectData< Expected >
ExpectData is an extension of CompositeData which indicates that the composite expects to be operating on the data types listed in its template arguments. All of the expected types will benefit from very high-speed operations when being accessed from an object of type ExpectData<Expected>. The ordinary CompositeData class needs to perform a map lookup on the data type whenever one of its functions is called, but an ExpectData<T> object does not need to perform any map lookup when performing an operation on T (e.g. .Get<T>(), .Insert<T>(), .Query<T>(), .Has<T>(), etc).
Note that there is no guarantee that any of the types listed in its template arguments will exist in the underlying CompositeData, but it will still provide very high-speed access for creating and querying them even if they are not yet present.
This template specialization implements ExpectData for a single type, but the ExpectData template can accept any number of types, e.g. ExpectData<T, U, V, W>.
Member Typedef Documentation
🔗ExpectedData
using ExpectedData = Expected |
🔗RequiredData
using RequiredData = void |
🔗Specification
using Specification = ExpectData<Expected> |
🔗SubSpecification1
using SubSpecification1 = void |
🔗SubSpecification2
using SubSpecification2 = void |
Constructor & Destructor Documentation
🔗ExpectData() [1/2]
ExpectData | ( | ) |
Default constructor.
🔗ExpectData() [2/2]
ExpectData | ( | const ExpectData< Expected > & | _other | ) |
Copy constructor. The copy constructor of the base class, CompositeData, is called before this copy constructor and it does the actual copying of the data contained in the MapData object of _other
. Thus, this copy constructor simply calls the default constructor to initialize the MapData iterator of this object to point the appropriate iterator in the newly copied MapData.
🔗~ExpectData()
|
virtualdefault |
Virtual destructor.
TODO(anyone) Implement move constructor and assignment operator. Due to the multiple inheritence used to implement SpcifyData, care must be taken when implementing move constructs to avoid calling a move constructor on a moved-from object.
Member Function Documentation
🔗Expects()
|
staticconstexpr |
Returns true if the Data type is expected. Data types for which this is true will be able to enjoy extremely high-speed access.
- See also
- CompositeData::Expects()
🔗Get()
Data & Get | ( | ) |
Provides extremely high-speed access to expected data types and normal access to unexpected data types.
- See also
- CompositeData::Get()
🔗Has()
bool Has | ( | ) | const |
Provides extremely high-speed access for checking the existence of expected data types and normal access for unexpected data types.
- See also
- CompositeData::Has() const
🔗Insert()
InsertResult< Data > Insert | ( | Args &&... | _args | ) |
Provides extremely high-speed access to getting or creating expected data types and normal access to unexpected data types.
- See also
- CompositeData::Insert()
🔗InsertOrAssign()
InsertResult< Data > InsertOrAssign | ( | Args &&... | _args | ) |
Provides extremely high-speed access to creating expected data types and normal access to unexpected data types.
- See also
- CompositeData::InsertOrAssign()
🔗MakeRequired()
Data & MakeRequired | ( | Args &&... | _args | ) |
Provides extremely high-speed access for making expected data types required and normal access for unexpected data types.
- See also
- CompositeData::MakeRequired()
🔗operator=()
|
default |
Copy assignment operator.
🔗Query() [1/2]
Data * Query | ( | const QueryMode | _mode = QueryMode::NORMAL | ) |
Provides extremely high-speed access for querying expected data types and normal access for unexpected data types.
- See also
- CompositeData::Query()
🔗Query() [2/2]
const Data * Query | ( | const QueryMode | _mode = QueryMode::NORMAL | ) | const |
Const-qualified version of Query<Data>
- See also
- CompositeData::Query()
🔗Remove()
bool Remove | ( | ) |
Provides extremely high-speed access for removing expected data types and normal access for unexpected data types.
- See also
- CompositeData::Remove()
🔗Requires()
bool Requires | ( | ) | const |
Provides extremely high-speed access for checking whether expected data types are required and normal access for unexpected data types.
- See also
- CompositeData::Requires() const
🔗StatusOf()
Provides extremely high-speed access to the status of expected data types and normal access for unexpected data types.
- See also
- CompositeData::StatusOf() const
🔗Unquery()
bool Unquery | ( | ) | const |
Provides extremely high-speed access for unquerying expected data types and normal access for unexpected data types.
- See also
- CompositeData::Unquery() const
Member Data Documentation
🔗privateExpectData
|
protected |
Provides the implementation for delegating the functions provided by the ExpectData class.
The documentation for this class was generated from the following file: