DPsim
Public Types | Public Member Functions | Protected Attributes | List of all members
CPS::Attribute< T > Class Template Referenceabstract

#include <Attribute.h>

Inheritance diagram for CPS::Attribute< T >:
[legend]
Collaboration diagram for CPS::Attribute< T >:
[legend]

Public Types

using Type = T
 
using Ptr = AttributePointer< Attribute< T > >
 
- Public Types inherited from CPS::AttributeBase
typedef AttributePointer< AttributeBasePtr
 
typedef std::vector< PtrList
 
typedef std::set< Ptr, AttributeCmp< AttributeBase > > Set
 
typedef std::map< String, PtrMap
 

Public Member Functions

 Attribute (T initialValue=T())
 
virtual void set (T value)=0
 
virtual T & get ()=0
 
virtual void setReference (Attribute< T >::Ptr reference)=0
 
virtual std::shared_ptr< T > asRawPointer ()=0
 
String toString () override
 Fallback method for all attribute types not covered by the specifications in Attribute.cpp.
 
 operator const T & ()
 User-defined cast operator. More...
 
T & operator* ()
 User-defined dereference operator. More...
 
bool copyValue (AttributeBase::Ptr copyFrom) override
 Copy the attribute value of copyFrom onto this attribute. More...
 
const std::type_info & getType () override
 Get the type of this attribute. More...
 
AttributeBase::Ptr cloneValueOntoNewAttribute () override
 Generates a new attribute of the same type and copies the current value in the heap. Does not copy any dependency relations! More...
 
template<class U >
Attribute< U >::Ptr derive (typename AttributeUpdateTask< U, T >::Actor getter=typename AttributeUpdateTask< U, T >::Actor(), typename AttributeUpdateTask< U, T >::Actor setter=typename AttributeUpdateTask< U, T >::Actor())
 
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer< Attribute< Real > > deriveReal ()
 
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer< Attribute< Real > > deriveImag ()
 
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer< Attribute< Real > > deriveMag ()
 
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer< Attribute< Real > > derivePhase ()
 
template<typename U = T, std::enable_if_t< std::is_same_v< Real, U >||std::is_same_v< Complex, U >, bool > = true>
AttributePointer< Attribute< T > > deriveScaled (T scale)
 
template<class U , class V = T, std::enable_if_t< std::is_same_v< CPS::MatrixVar< U >, V >, bool > = true>
AttributePointer< Attribute< U > > deriveCoeff (typename CPS::MatrixVar< U >::Index row, typename CPS::MatrixVar< U >::Index column)
 
String toString ()
 
String toString ()
 
String toString ()
 
- Public Member Functions inherited from CPS::AttributeBase
virtual bool isStatic () const =0
 
virtual void appendDependencies (AttributeBase::Set *deps)=0
 
virtual AttributeBase::Set getDependencies () final
 

Protected Attributes

std::shared_ptr< T > mData
 

Detailed Description

template<class T>
class CPS::Attribute< T >

Main Attribute class. The template class T holds the attribute's type. This is used as the type for all attribute member variables.

Parameters
TThe type of this attribute

Definition at line 266 of file Attribute.h.

Member Function Documentation

◆ asRawPointer()

template<class T >
virtual std::shared_ptr<T> CPS::Attribute< T >::asRawPointer ( )
pure virtual

Exposing the underlying shared_ptr for this attribute's data. Used to create reference relations between two attributes.

Returns
The shared_ptr to this attribute's underlying data

Implemented in CPS::AttributeDynamic< T >, and CPS::AttributeStatic< T >.

◆ cloneValueOntoNewAttribute()

template<class T >
AttributeBase::Ptr CPS::Attribute< T >::cloneValueOntoNewAttribute ( )
inlineoverridevirtual

Generates a new attribute of the same type and copies the current value in the heap. Does not copy any dependency relations!

Returns
Pointer to the copied attribute

Implements CPS::AttributeBase.

Definition at line 353 of file Attribute.h.

◆ copyValue()

template<class T >
bool CPS::Attribute< T >::copyValue ( AttributeBase::Ptr  copyFrom)
inlineoverridevirtual

Copy the attribute value of copyFrom onto this attribute.

Returns
true if the copy operation was successful, false otherwise

Implements CPS::AttributeBase.

Definition at line 333 of file Attribute.h.

◆ derive()

template<class T >
template<class U >
Attribute<U>::Ptr CPS::Attribute< T >::derive ( typename AttributeUpdateTask< U, T >::Actor  getter = typename AttributeUpdateTask<U, T>::Actor(),
typename AttributeUpdateTask< U, T >::Actor  setter = typename AttributeUpdateTask<U, T>::Actor() 
)
inline

General method for deriving a new attribute from this attribute. Custom getter and setter functions have to be provided. The newly created attribute will only depend on this attribute in a 1:1 relationship.

Parameters
UThe type of the newly derived attribute
getterThe getter actor function to use for updating the derived attribute
setterThe setter actor function for updating this when the derived attribute is changed
Returns
a newly created attribute of type U which will calculate its value using the provided getter and update this on changes using the provided setter

Definition at line 368 of file Attribute.h.

◆ deriveCoeff()

template<class T >
template<class U , class V = T, std::enable_if_t< std::is_same_v< CPS::MatrixVar< U >, V >, bool > = true>
AttributePointer<Attribute<U> > CPS::Attribute< T >::deriveCoeff ( typename CPS::MatrixVar< U >::Index  row,
typename CPS::MatrixVar< U >::Index  column 
)
inline

Convenience method for deriving an attribute which covers one coefficient of this matrix

Parameters
UThe type of the coefficient (usally Real or Complex)
rowThe coefficients row coordinate
columnThe coefficients column coordinate
Returns
a new attribute whose value will always equal the value of the coefficient this(row, column)

Definition at line 516 of file Attribute.h.

◆ deriveImag()

template<class T >
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer<Attribute<Real> > CPS::Attribute< T >::deriveImag ( )
inline

Convenience method for deriving the imaginary part of a complex attribute

Returns
a new attribute whose value will always equal the imaginary part of this

Definition at line 420 of file Attribute.h.

◆ deriveMag()

template<class T >
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer<Attribute<Real> > CPS::Attribute< T >::deriveMag ( )
inline

Convenience method for deriving the magnitude of a complex attribute

Returns
a new attribute whose value will always equal the magnitude of this

Definition at line 444 of file Attribute.h.

◆ derivePhase()

template<class T >
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer<Attribute<Real> > CPS::Attribute< T >::derivePhase ( )
inline

Convenience method for deriving the phase of a complex attribute

Returns
a new attribute whose value will always equal the phase of this

Definition at line 467 of file Attribute.h.

◆ deriveReal()

template<class T >
template<typename U = T, std::enable_if_t< std::is_same_v< Complex, U >, bool > = true>
AttributePointer<Attribute<Real> > CPS::Attribute< T >::deriveReal ( )
inline

Convenience method for deriving the real part of a complex attribute

Returns
a new attribute whose value will always equal the real part of this

Definition at line 396 of file Attribute.h.

◆ deriveScaled()

template<class T >
template<typename U = T, std::enable_if_t< std::is_same_v< Real, U >||std::is_same_v< Complex, U >, bool > = true>
AttributePointer<Attribute<T> > CPS::Attribute< T >::deriveScaled ( scale)
inline

Convenience method for deriving an attribute whose value is always scaled by scale

Parameters
scaleThe scaling to apply to the attribute's value
Returns
a new attribute whose value will always equal the value of this but scaled by scale

Definition at line 492 of file Attribute.h.

◆ get()

template<class T >
virtual T& CPS::Attribute< T >::get ( )
pure virtual

Get a mutable reference to the attribute's underlying data. This method is also called when dereferencing an attribute using the * operator

Implemented in CPS::AttributeDynamic< T >, and CPS::AttributeStatic< T >.

◆ getType()

template<class T >
const std::type_info& CPS::Attribute< T >::getType ( )
inlineoverridevirtual

Get the type of this attribute.

Returns
std::type_info

Implements CPS::AttributeBase.

Definition at line 347 of file Attribute.h.

◆ operator const T &()

template<class T >
CPS::Attribute< T >::operator const T & ( )
inline

User-defined cast operator.

Allows attributes to be casted to their value type:

Real v = 1.2; auto a = Attribute<Real>(&v);

Real x = v;

Definition at line 322 of file Attribute.h.

◆ operator*()

template<class T >
T& CPS::Attribute< T >::operator* ( )
inline

User-defined dereference operator.

Allows easier access to the attribute's underlying data

Definition at line 327 of file Attribute.h.

◆ set()

template<class T >
virtual void CPS::Attribute< T >::set ( value)
pure virtual

Manually set the attribute to the given value. For dynamic attributes, this will trigger the UPDATE_ON_SET tasks for updating any dependency attributes.

Implemented in CPS::AttributeDynamic< T >, and CPS::AttributeStatic< T >.

◆ setReference()

template<class T >
virtual void CPS::Attribute< T >::setReference ( Attribute< T >::Ptr  reference)
pure virtual

Convenience method for setting this attribute to always equal another attribute. When this is dynamic, this will set up an UPDATE_ONCE task that sets this attribute's data pointer to equal the data pointer of the referenced attribute. If this is static, calling this method will result in a runtime error.

Parameters
referenceThe attribute which's value will be adapted

Implemented in CPS::AttributeDynamic< T >, and CPS::AttributeStatic< T >.

◆ toString() [1/3]

String CPS::Attribute< Real >::toString ( )
virtual

Display this attribute's value as a string

Implements CPS::AttributeBase.

◆ toString() [2/3]

String CPS::Attribute< Complex >::toString ( )
virtual

Display this attribute's value as a string

Implements CPS::AttributeBase.

◆ toString() [3/3]

String CPS::Attribute< String >::toString ( )
virtual

Display this attribute's value as a string

Implements CPS::AttributeBase.


The documentation for this class was generated from the following file: