All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Valuable::AttributeFloatT< T > Class Template Reference

Template class for floating-point values. More...

#include <Valuable/AttributeFloat.hpp>

Inheritance diagram for Valuable::AttributeFloatT< T >:
Valuable::AttributeNumericT< T > Valuable::AttributeT< T > Valuable::Attribute Valuable::Serializable

Public Member Functions

 AttributeFloatT (Node *host, const QByteArray &name, T v=T(0), bool transit=false)
  More...
 
virtual void clearValue (Attribute::Layer layer=Attribute::USER)
 Unsets the value from a specific layer. More...
 
virtual void eventProcess (const QByteArray &, Radiant::BinaryData &data)
 Process a message. More...
 
AttributeFloatT< T > & operator*= (T i)
 Assignment by multiplication.
 
AttributeFloatT< T > & operator+= (T i)
 Assignment by addition.
 
AttributeFloatT< T > & operator-= (T i)
 Assignment by subtraction.
 
AttributeFloatT< T > & operator/= (T i)
 Assignment by division.
 
float percentage (Attribute::Layer layer) const
 
virtual bool set (int v, Attribute::Layer layer=Attribute::USER, Attribute::ValueUnit=Attribute::VU_UNKNOWN)
 Sets the numeric value.
 
virtual bool set (float v, Attribute::Layer layer=Attribute::USER, Attribute::ValueUnit unit=Attribute::VU_UNKNOWN)
 Sets the numeric value. More...
 
virtual void setAsDefaults ()
 Sets the current USER attribute value as the default value and clears the USER value. More...
 
void setPercentage (float factor, Attribute::Layer layer=Attribute::USER)
 
void setSrc (float src)
 
- Public Member Functions inherited from Valuable::AttributeNumericT< T >
virtual float asFloat (bool *const ok=nullptr, Attribute::Layer layer=Attribute::LAYER_CURRENT) const
 Converts the numeric value to float.
 
virtual int asInt (bool *const ok=nullptr, Attribute::Layer layer=Attribute::LAYER_CURRENT) const
 Converts the numeric value to integer.
 
virtual QString asString (bool *const ok=nullptr, Attribute::Layer layer=Attribute::LAYER_CURRENT) const
 Converts the numeric value to string.
 
 AttributeNumericT (Node *host, const QByteArray &name, T v, bool transit=false)
  More...
 
- Public Member Functions inherited from Valuable::AttributeT< T >
virtual QString asString (bool *const ok, Layer layer) const =0
 
 AttributeT (Node *host, const QByteArray &name, const T &v=T(), bool transit=false)
 Creates a new AttributeT and stores the default and current value as a separate variables. More...
 
virtual void clearValue (Layer layout=USER)
 Unsets the value from a specific layer. More...
 
Layer currentLayer () const
 
const T & defaultValue () const
 The default value (the value given in constructor) of the Attribute.
 
virtual bool deserialize (const ArchiveElement &element)
 Deserializes (reads) this object from serializer element. More...
 
virtual bool isChanged () const
 
virtual bool isValueDefinedOnLayer (Layer layer) const final
 
 operator const T & () const
 Typecast operator for the wrapped value.
 
const T & operator* () const
 Access the wrapped object with the dereference operator.
 
const T * operator-> () const
 Use the arrow operator to access fields inside the wrapped object.
 
AttributeT< T > & operator= (const T &t)
 Calls setValue with USER layer. More...
 
virtual ArchiveElement serialize (Archive &archive) const
 The object is serialized using its name as a tag name. More...
 
void setValue (const T &t, Layer layer=USER)
 Sets a new value for a specific layer. More...
 
const T & value (Layer layer) const
 
const T & value () const
 
- Public Member Functions inherited from Valuable::Attribute
long addListener (ListenerFunc func, int role=CHANGE_ROLE)
 Adds a listener that is invoked whenever the value is changed. More...
 
long addListener (Node *listener, ListenerFunc func, int role=CHANGE_ROLE)
 Adds a listener that is invoked whenever the value is changed. More...
 
long addListener (v8::Persistent< v8::Function > func, int role=CHANGE_ROLE)
 Adds a JavaScript listener that is invoked whenever the value is changed. More...
 
 Attribute (const Attribute &o)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
 Attribute (Node *host, const QByteArray &name, bool transit=false)
 Constructs a new value object and attaches it to its host. More...
 
virtual Attribute * attribute (const QByteArray &name) const
 Gets an Attribute with the given name. More...
 
virtual void emitChange ()
 Invokes the change valueChanged function of all listeners.
 
void eventProcessFloat (const char *id, float v)
 Utility function for sending a float message to the object.
 
void eventProcessInt (const char *id, int v)
 Utility function for sending an int message to the object.
 
void eventProcessString (const char *id, const QString &str)
 Utility function for sending string message to the object.
 
void eventProcessString (const char *id, const char *str)
 Utility function for sending string message to the object.
 
void eventProcessVector2 (const char *id, Nimble::Vector2)
 Utility function for sending a Nimble::Vector2f message to the object.
 
void eventProcessVector3 (const char *id, Nimble::Vector3)
 Utility function for sending a Vector3 message to the object.
 
void eventProcessVector4 (const char *id, Nimble::Vector4)
 Utility function for sending a Vector4 message to the object.
 
virtual bool handleShorthand (const Valuable::StyleValue &value, Radiant::ArrayMap< Valuable::Attribute *, Valuable::StyleValue > &expanded)
 If attribute supports shorthand properties, this should be used to parse those. More...
 
Node * host () const
 The host object of the value object (is any). More...
 
virtual bool isValueDefinedOnLayer (Layer layer) const
 Check if the given layer defines a value. More...
 
bool layerForSerialization (SerializationOptions flags, Layer &layer) const
 
const QByteArray & name () const
 Returns the name of the object.
 
const Attribute & operator= (const Attribute &)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
Attribute * ownerShorthand () const
 
QByteArray path () const
 Returns the path (separated by '/'s) from the root.
 
void removeHost ()
 Sets the host pointer to zero and removes this object from the host. More...
 
bool removeListener (Node *listener, int role=ALL_ROLES)
 Removes a listener from the listener list. More...
 
bool removeListener (long id)
 Removes a listener from the listener list. More...
 
void removeListeners (int role=ALL_ROLES)
 Removes listeners from the listener list.
 
virtual bool set (const QString &v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector2f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector3f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const Nimble::Vector4f &v, Layer layer=USER, QList< ValueUnit > units=QList< ValueUnit >())
 Sets the value of the object.
 
virtual bool set (const StyleValue &value, Layer layer=USER)
 Sets the value of the object.
 
void setName (const QByteArray &s)
 Sets the name of the object.
 
void setOwnerShorthand (Attribute *owner)
 
virtual QByteArray type () const
 Get the type id of the attribute. More...
 
- Public Member Functions inherited from Valuable::Serializable
virtual bool deserializeXML (const DOMElement &element)
 Deserializes (reads) this object from an XML element. More...
 
bool isSerializable () const
 
void setSerializable (bool v)
 

Additional Inherited Members

- Public Types inherited from Valuable::Attribute
enum  Layer {
  DEFAULT = 0, STYLE, USER, STYLE_IMPORTANT,
  LAYER_COUNT, LAYER_CURRENT
}
 Attribute has multiple independent attribute values on LAYER_COUNT different layers. More...
 
typedef std::function< void()> ListenerFunc
 Callback function type in the listener API.
 
enum  ListenerRole { DELETE_ROLE = 1 << 0, CHANGE_ROLE = 1 << 1, ALL_ROLES = (CHANGE_ROLE << 1) -1 }
 Different listener roles, used when adding a new listener.
 
enum  ValueUnit {
  VU_UNKNOWN, VU_PXS, VU_PERCENTAGE, VU_EMS,
  VU_EXS
}
 Units of a value. More...
 
- Protected Member Functions inherited from Valuable::Attribute
virtual void emitDelete ()
 Invokes the change valueDeleted function of all listeners.
 
- Protected Attributes inherited from Valuable::AttributeT< T >
Layer m_current
 
T m_values [LAYER_COUNT]
 
bool m_valueSet [LAYER_COUNT]
 

Detailed Description

template<class T>
class Valuable::AttributeFloatT< T >

Template class for floating-point values.

The actual value objects are created by using AttributeFloatT<float> etc.

See Also
AttributeFloat.
Examples:
AdvancedRenderingExample.cpp, CustomRenderWidgetExample.cpp, ImageMovieExample.cpp, MixedJavaScriptExample.js, PostProcessingExample.cpp, and Widget3DExample.cpp.

Constructor & Destructor Documentation

template<class T >
Valuable::AttributeFloatT< T >::AttributeFloatT ( Node *  host,
const QByteArray &  name,
T  v = T(0),
bool  transit = false 
)
inline

Member Function Documentation

template<class T >
virtual void Valuable::AttributeFloatT< T >::clearValue ( Attribute::Layer  layer = Attribute::USER)
inlinevirtual

Unsets the value from a specific layer.

Parameters
layerlayer to clear, must not be DEFAULT, since DEFAULT layer should always be set

Reimplemented from Valuable::Attribute.

template<class T >
virtual void Valuable::AttributeFloatT< T >::eventProcess ( const QByteArray &  id,
Radiant::BinaryData &  data 
)
inlinevirtual

Process a message.

This method is a key element in the event-passing system. It is used to deliver information between objects. The information contains two parts:

  1. Identifier: A character string that gives the address for the adjustment
  2. Data: A binary blob that contains information for the message

This function is overridden in number of classes that need to receive and process events. In a typical case, when overriding this function, you should either process the message, or call the function of the parent class.

void MyClass::eventProcess(const QByteArray & type, Radiant::BinaryData & data)
{
if(type == "jump")
doJump();
else if(type == "crawl") {
bool ok;
int speed = data.readInt32(&ok);
if(ok)
doCrawl(speed);
}
else
Parent::eventProcess(type, data);
}
Parameters
idThe indentifier for the message. Typically this is quite human-readable
dataBinary blob that contains the argument data in easily parseable format.

Reimplemented from Valuable::Attribute.

template<class T >
virtual bool Valuable::AttributeFloatT< T >::set ( float  v,
Attribute::Layer  layer = Attribute::USER,
Attribute::ValueUnit  unit = Attribute::VU_UNKNOWN 
)
inlinevirtual

Sets the numeric value.

Reimplemented from Valuable::Attribute.

template<class T >
virtual void Valuable::AttributeFloatT< T >::setAsDefaults ( )
inlinevirtual

Sets the current USER attribute value as the default value and clears the USER value.

Reimplemented from Valuable::AttributeT< T >.