Ignition Physics

API Reference

2.0.0

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
 
- Public Types inherited from CompositeData
using MapOfData = std::map< std::string, DataEntry >
 
enum  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. More...
 
virtual ~ExpectData ()=default
 Virtual destructor. More...
 
template<typename Data >
Data & Get ()
 Provides extremely high-speed access to expected data types and normal access to unexpected data types. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
template<typename Data >
const Data * Query (const QueryMode _mode=QueryMode::NORMAL) const
 Const-qualified version of Query<Data> More...
 
template<typename Data >
bool Remove ()
 Provides extremely high-speed access for removing expected data types and normal access for unexpected data types. More...
 
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. More...
 
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. More...
 
template<typename Data >
bool Unquery () const
 Provides extremely high-speed access for unquerying expected data types and normal access for unexpected data types. More...
 
- Public Member Functions inherited from CompositeData
 CompositeData ()
 Default constructor. Creates an empty CompositeData object. More...
 
 CompositeData (const CompositeData &_other)
 Copy constructor. Same as Copy(_other). More...
 
 CompositeData (CompositeData &&_other)
 Move constructor. Same as Copy(_other). More...
 
virtual ~CompositeData ()=default
 Virtual destructor. More...
 
std::set< std::stringAllEntries () const
 Get an ordered set of all data entries in this CompositeData. Runs with O(N) complexity. More...
 
CompositeDataCopy (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. More...
 
CompositeDataCopy (CompositeData &&_other, const bool _mergeRequirements=false)
 An alternative to Copy(const CompositeData &, bool) that takes advantage of move semantics. More...
 
std::size_t EntryCount () const
 Check how many data entries are in this CompositeData. Runs with O(1) complexity. More...
 
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. More...
 
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)). More...
 
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. More...
 
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...). More...
 
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. More...
 
CompositeDataMerge (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. More...
 
CompositeDataMerge (CompositeData &&_other, const bool _mergeRequirements=false)
 An alternative to Merge(const CompositeData &, bool) that takes advantage of move semantics. More...
 
CompositeDataoperator= (const CompositeData &_other)
 Copy operator. Same as Copy(_other). More...
 
CompositeDataoperator= (CompositeData &&_other)
 Move operator. Same as Copy(_other). More...
 
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. More...
 
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. More...
 
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. More...
 
template<typename Data >
bool Requires () const
 Returns true if the specified Data type is required by this CompositeData object. Otherwise, returns false. More...
 
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. More...
 
template<typename Data >
DataStatus StatusOf () const
 Returns a DataStatus object that describes the status of the requested data type. More...
 
std::set< std::stringUnqueriedEntries () 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. More...
 
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. More...
 
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. More...
 

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. More...
 
- Static Public Member Functions inherited from CompositeData
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. More...
 
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. More...
 

Protected Attributes

detail::PrivateExpectData< Expected > privateExpectData
 Provides the implementation for delegating the functions provided by the ExpectData class. More...
 
- Protected Attributes inherited from CompositeData
MapOfData dataMap
 Map from the label of a data object type to its entry. More...
 
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. More...
 
std::size_t numQueries
 Total number of unique queries which have been performed since either construction or the last call to ResetQueries(). More...
 

Detailed Description

template<typename Expected>
class ignition::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()

ExpectData ( )

Default constructor.

◆ ~ExpectData()

virtual ~ExpectData ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ Expects()

static constexpr bool Expects ( )
static

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()

◆ 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()

DataStatus StatusOf ( ) const

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

detail::PrivateExpectData<Expected> 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: