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

Every Attribute is some kind of AttributeT<T> object. More...

#include <Valuable/Attribute.hpp>

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

Public Member Functions

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...
 
virtual void setAsDefaults ()
 Sets the current USER attribute value as the default value and clears the USER value. 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...
 
virtual float asFloat (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object in a floating point number. More...
 
virtual int asInt (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object in an integer. More...
 
virtual QString asString (bool *const ok=0, Layer layer=LAYER_CURRENT) const
 Converts the value object to a string. 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 Attributeattribute (const QByteArray &name) const
 Gets an Attribute with the given name. More...
 
virtual void clearValue (Layer layer)
 Unsets the value from a specific layer. More...
 
virtual void emitChange ()
 Invokes the change valueChanged function of all listeners.
 
virtual void eventProcess (const QByteArray &id, Radiant::BinaryData &data)
 Process a message. More...
 
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...
 
Nodehost () 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 Attributeoperator= (const Attribute &)
 Create a copy of the given Attribute WITHOUT the link to host, listeners, or the attribute name. More...
 
AttributeownerShorthand () 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 (float v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
virtual bool set (int v, Layer layer=USER, ValueUnit unit=VU_UNKNOWN)
 Sets the value of the object.
 
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)
 

Protected Attributes

Layer m_current
 
m_values [LAYER_COUNT]
 
bool m_valueSet [LAYER_COUNT]
 

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.
 

Detailed Description

template<typename T>
class Valuable::AttributeT< T >

Every Attribute is some kind of AttributeT<T> object.

Common functionality should be in either here or in Attribute

Constructor & Destructor Documentation

template<typename T>
Valuable::AttributeT< T >::AttributeT ( Node host,
const QByteArray &  name,
const T &  v = T(),
bool  transit = false 
)
inline

Creates a new AttributeT and stores the default and current value as a separate variables.

Parameters
hosthost object
namename of the value
vthe default value of the object
transitignored

Member Function Documentation

template<typename T>
virtual void Valuable::AttributeT< T >::clearValue ( Layer  layout = 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 in Valuable::AttributeLocation2f.

template<typename T>
Layer Valuable::AttributeT< T >::currentLayer ( ) const
inline
Returns
the active layer that has the highest priority
template<typename T>
virtual bool Valuable::AttributeT< T >::deserialize ( const ArchiveElement element)
inlinevirtual

Deserializes (reads) this object from serializer element.

Parameters
elementSerialized element that holds the data that should be deserialized.
Returns
Returns true if the read process worked correctly, and false otherwise.

Implements Valuable::Serializable.

template<typename T>
virtual bool Valuable::AttributeT< T >::isChanged ( ) const
inlinevirtual
Returns
true if the current value of the object is different from the default value. Default implementation always returns true

Reimplemented from Valuable::Attribute.

template<typename T>
virtual bool Valuable::AttributeT< T >::isValueDefinedOnLayer ( Layer  layer) const
inlinefinalvirtual
Parameters
layerlayer to check
Returns
true if layer is active
template<typename T>
AttributeT<T>& Valuable::AttributeT< T >::operator= ( const T &  t)
inline

Calls setValue with USER layer.

Parameters
tnew value for the attribute
Returns
reference to this
template<typename T>
virtual ArchiveElement Valuable::AttributeT< T >::serialize ( Archive archive) const
inlinevirtual

The object is serialized using its name as a tag name.

Parameters
archiveSerialization archive that is used to create new elements.
Returns
Serialized object as an ArchiveElement

Reimplemented from Valuable::Attribute.

template<typename T>
virtual void Valuable::AttributeT< T >::setAsDefaults ( )
inlinevirtual

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

Reimplemented from Valuable::Attribute.

Reimplemented in Valuable::AttributeLocation2f, and Valuable::AttributeFloatT< T >.

template<typename T>
void Valuable::AttributeT< T >::setValue ( const T &  t,
Layer  layer = USER 
)
inline

Sets a new value for a specific layer.

If currentLayer() is more important than the layer given as a parameter, the active value of the attribute won't change. Otherwise, if the value does change, this function will trigger all listeners callbacks.

Parameters
tnew value for the attribute
layervalue will be set to this layer
template<typename T>
const T& Valuable::AttributeT< T >::value ( Layer  layer) const
inline
Parameters
layerlayer to use
Returns
attribute value on given layer
template<typename T>
const T& Valuable::AttributeT< T >::value ( ) const
inline
Returns
attribute active value