AttributePointer< type > Class Template Reference

AttributePointer< type > Class Template Reference

#include <node.h>

Class Description

template<typename type>
class mudbox::AttributePointer< type >

This class can be used instead of standard pointers, when the pointer target class is derived from the Node class.

This object has the following advantages over a plain pointer:

  • The pointer value will be zero by default, you don't have to initialize it.
  • If the target of the pointer is destroyed, the pointer value becomes zero automatically.
  • The owner of the pointer (the class which declares the pointer object as a member variable) will be able to catch events about the target of the pointer, like when its content is changed, or it's destructed.
  • The pointer value will be serializable. If the pointer has a valid target, the target will be included in the mud file also. See AttributePointer::Serialize() for more details.

Definition at line 601 of file node.h.

+ Inheritance diagram for AttributePointer< type >:

Public Member Functions

 AttributePointer (Node *pOwner=NULL, const QString &sID="")
 
 AttributePointer (Node *pOwner, const QString &sID, bool bInstall)
 
 AttributePointer (const AttributePointer< type > &cOther)
 
QString AsString (bool) const
 Returns the value of the attribute as a string. More...
 
void SetFromString (const QString &, bool=true, bool=false)
 Sets the value of the attribute as a string. More...
 
void SetValidator (validator *pValidator)
 Register a function as the validator for this pointer. More...
 
void SetPointerValue (Node *pNode, bool bLink=true)
 This is valid only for pointer attributes (See AttributePointer). More...
 
virtual void SetValue (type *cValue, bool bInternal=false)
 Set the value of the attribute to cValue. More...
 
void AddTarget (Attribute &cTarget)
 
void DeleteTarget (void)
 Deletes the object what is referred in this pointer. More...
 
void Serialize (Stream &s)
 Serializes the pointer value to a stream. More...
 
void StartEvent (NodeEventType cType) const
 
Attribute::AttributeType Type (void) const
 Returns the type of the attribute. More...
 
 PTROPERATORS (type)
 
- Public Member Functions inherited from AttributeInstance< type * >
 AttributeInstance (Node *pOwner, const QString &sID)
 Standard constructor. You have to specify the name of the attribute which will be used in the user interface. More...
 
 AttributeInstance (Node *pOwner, const QString &sID, const type * &cValue)
 Using this constructor you can also specify the initial value of the attribute with its name. More...
 
 AttributeInstance (const AttributeInstance< type * > &o)
 
virtual ~AttributeInstance (void)
 
const type * & Value (void) const
 Returns the value of the attribute. More...
 
void UpdateTargets (void)
 
void Serialize (Stream &s)
 Serialize the value of the attribute into a stream. More...
 
void AddTarget (Attribute &cTarget, bool bInternal=false)
 Connection management. More...
 
Attribute::AttributeType Type (void) const
 Returns the type of the attribute. More...
 
 OPERATORS (type *)
 
- Public Member Functions inherited from Attribute
unsigned int TargetCount (void) const
 Returns the number of attributes currently linked to this attribute as target. More...
 
AttributeTarget (unsigned int iIndex) const
 Returns the target with the given index. If iIndex is greater than the number of targets, returns 0;. More...
 
AttributeSource (void) const
 Returns the source attribute, or 0 if there is no source. More...
 
bool operator== (const Attribute &cAttribute) const
 This is a special operator, it does NOT compare the value of the attribute. See Node::OnNodeEvent for details. More...
 
bool operator!= (const Attribute &cAttribute) const
 This is a special operator, it does NOT compare the value of the attribute. See Node::OnNodeEvent for details. More...
 
QString ID (void) const
 Returns the unique ID (within this node) of the attribute. More...
 
QString Name (void) const
 Returns the name of the attribute. More...
 
void SetName (const QString &sName)
 Sets the name of the attribute. More...
 
QString Category (void) const
 Returns the category of the attribute. More...
 
void SetCategory (const QString &sCategory, bool bSeparator=false)
 Sets the category of the attribute. This value will be used in the user interface to determine which attribute group to be used. More...
 
bool Separator (void) const
 Returns the separator state of the widget. More...
 
void SetSeparator (bool bSeparator)
 Call this with true to display a separator line below this widget. More...
 
bool Const (void) const
 Gets the constant status of the attribute. Default value is false. If this is set to true the attribute will not be editable by the user on the interface. More...
 
void SetConst (bool bConst)
 Sets the constant status of the attribute. Default value is false. If this is set to true the attribute will not be editable by the user on the interface. More...
 
bool InstantEdit (void) const
 Returns true, if the attribute edition should be instant, i.e. the attribute should change every time the user makes any changes to the widget. Default is false. More...
 
void SetInstantEdit (bool bOn)
 If bOn is true, editing the attribute on the UI will be instant, i.e. More...
 
bool Visible (void) const
 Returns true if the property is visible. More...
 
void SetVisible (bool bVisible)
 Sets the visible status of the property. More...
 
QString ToolTip (void) const
 Gets the tooltip text to be used on the user interface, this is optional. More...
 
void SetToolTip (const QString &sToolTip)
 Sets the tooltip text to be used on the user interface, this is optional. More...
 
unsigned int Size (void) const
 Returns the size of the attribute value in bytes. More...
 
float LabelWidth (void) const
 Returns the width of label relative to the full width of the line. More...
 
void SetLabelWidth (float fLabelWidth)
 Set the width of label. More...
 
int Index (void) const
 Returns the attribute index;. More...
 
void SetIndex (int iIndex)
 Sets the attribute index;. More...
 
NodeOwner (void) const
 Gets the address of the Node which contains this attribute. More...
 
virtual ~Attribute (void)
 
void SetOwner (Node *pOwner)
 This function sets the owner of the attribute. More...
 
void LogTargets (void)
 
void LogSource (void)
 
void CheckValidity (void)
 
void ClearTargets (void)
 Removes all outgoing connections from the attribute. More...
 
void ClearSource (void)
 Removes the incoming connection for this attribute. More...
 
void Connect (Attribute &cSource, bool bInternal=false)
 Connect this attribute to another one. More...
 
virtual unsigned int ParameterCount (void) const
 
virtual QString ParameterName (unsigned int iIndex) const
 Returns the name of a parameter with a given index. More...
 
virtual QString ParameterValue (unsigned int iIndex) const
 Returns the value of parameter with a given index. More...
 
virtual void SetParameterValue (const QString &sName, const QString &sValue)
 Set the value of a parameter. More...
 

Public Attributes

QString m_sNullString
 
bool m_bAllowNull
 
- Public Attributes inherited from AttributeInstance< type * >
typem_cValue
 

Friends

class Node
 
class AttributeThisPointer
 
struct Attribute
 

Additional Inherited Members

- Public Types inherited from Attribute
enum  AttributeType {
  typeUnknown, typeInt, typeFloat, typeBool,
  typeString, typePointer, typeColor, typeVector,
  typeEnum, typeWatch
}
 Type of the attribute. More...
 
- Protected Member Functions inherited from AttributeInstance< type * >
 AttributeInstance (Node *pOwner, const QString &sName, bool bInstall)
 Protected constructor, do not use it. You have to specify the name of the attribute which will be used in the user interface. More...
 
- Protected Member Functions inherited from Attribute
 Attribute (Node *pOwner, const QString &sID)
 
 Attribute (Node *pOwner, bool bInstall)
 
void Uninstall (void)
 
- Protected Attributes inherited from Attribute
int m_iSize
 
Attributem_pSource
 
Attributem_pNext
 
Store< Attribute * > m_aTargets
 
Nodem_pNode
 
QString m_sName
 
bool m_bSeparator
 
QString m_sCategory
 
QString m_sToolTip
 
float m_fLabelWidth
 
bool m_bConst
 
bool m_bVisible
 
int m_iIndex
 
bool m_bInstantEdit
 
QString m_sID
 

Constructor & Destructor Documentation

AttributePointer ( Node pOwner = NULL,
const QString sID = "" 
)
inline

Definition at line 622 of file node.h.

622  : AttributeInstance<type *>( pOwner, sID )
623  { SetValue( 0, true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
virtual void SetValue(type *cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:649
QString m_sNullString
Definition: node.h:713
AttributePointer ( Node pOwner,
const QString sID,
bool  bInstall 
)
inline

Definition at line 625 of file node.h.

625  : AttributeInstance<type *>( pOwner, sID, bInstall )
626  { SetValue( 0, true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
virtual void SetValue(type *cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:649
QString m_sNullString
Definition: node.h:713
AttributePointer ( const AttributePointer< type > &  cOther)
inline

Definition at line 628 of file node.h.

628  : AttributeInstance<type *>( 0, "" )
629  { SetValue( cOther.Value(), true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
virtual void SetValue(type *cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:649
QString m_sNullString
Definition: node.h:713

Member Function Documentation

QString AsString ( bool  bLocalized) const
inlinevirtual

Returns the value of the attribute as a string.

See also SetFromString.

Parameters
bLocalizedif this is true the string representation of the value is assumed to be localized (translated)

Reimplemented from AttributeInstance< type * >.

Definition at line 631 of file node.h.

631 { if ( PointerValue() ) return PointerValue()->Name(); else return m_sNullString; };
QString m_sNullString
Definition: node.h:713
virtual QString Name(const ClassDesc *pClass=0) const
Deprecated.
void SetFromString ( const QString sValue,
bool  bInternal = true,
bool  = false 
)
inlinevirtual

Sets the value of the attribute as a string.

See also AsString.

Parameters
bInternalif this is false the owner node will receive an event about the value change (See NodeEventType::etValueChanged).
bLocalizedif this is true the string representation of the value is assumed to be localized (translated)

Reimplemented from AttributeInstance< type * >.

Definition at line 633 of file node.h.

633 { SetPointerValue( 0 ); };
void SetPointerValue(Node *pNode, bool bLink=true)
This is valid only for pointer attributes (See AttributePointer).
Definition: node.h:639
void SetValidator ( validator *  pValidator)
inline

Register a function as the validator for this pointer.

This function will be called each time a new value has to be assigned to the pointer. If this function returns false the value wont be assigned to the pointer.

Definition at line 637 of file node.h.

637 { m_pValidator = pValidator; };
void SetPointerValue ( Node pValue,
bool  bLink = true 
)
inlinevirtual

This is valid only for pointer attributes (See AttributePointer).

Sets the value of the pointer. This function is used only if you dont know exactly the type of the attribute. Use AttributePointer::SetValue otherwise.

Reimplemented from Attribute.

Definition at line 639 of file node.h.

640  {
641  // always accept 0 pointer, the target may be destroyed
642  if ( pNode && m_pValidator && !m_pValidator( dynamic_cast<type *>( pNode ) ) )
643  return;
644  if ( bLink )
645  SetValue( dynamic_cast<type *>( pNode ) );
646  else
647  AttributeInstance<type *>::SetValue( dynamic_cast<type *>( pNode ) );
648  };
virtual void SetValue(type *cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:649
virtual void SetValue(type cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:409
virtual void SetValue ( type cValue,
bool  bInternal = false 
)
inlinevirtual

Set the value of the attribute to cValue.

Parameters
bInternalif this is false the owner node will receive an event about the value change (See NodeEventType::etValueChanged).

Reimplemented from AttributeInstance< type * >.

Definition at line 649 of file node.h.

650  {
651  if ( cValue == AttributePointer<type>::Value() )
652  return;
653  AttributeInstance<type *>::SetValue( cValue, bInternal );
654  if ( cValue )
655  cValue->m_pThis.AddTarget( *this );
656  else
658  };
void ClearSource(void)
Removes the incoming connection for this attribute.
virtual void SetValue(type cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:409
void AddTarget ( Attribute cTarget)
inline

Definition at line 659 of file node.h.

660  {
661  Attribute::AddTarget( cTarget );
662  if ( cTarget.Size() )
663  {
664  if ( cTarget.PointerValue() != PointerValue() )
665  cTarget.SetPointerValue( PointerValue() );
666  };
667  };
virtual void AddTarget(Attribute &cTarget, bool bInternal=false)
Adds a new outgoing connection for this node to pTarget.
void DeleteTarget ( void  )
inline

Deletes the object what is referred in this pointer.

Definition at line 669 of file node.h.

670  {
672  };
const type * & Value(void) const
Returns the value of the attribute.
Definition: node.h:406
void Serialize ( Stream s)
inlinevirtual

Serializes the pointer value to a stream.

The following two lines are doing the same:

s == m_pMyPointer;
m_pMyPointer.Serialize( s );

The stream has an internal list of the nodes it contains. This list is empty when the stream is opened, and keeps growing as more and more nodes are serialized. If the stream is writing data to a file and a pointers Serialize function is called, the stream checks the list if the target of the pointer is there or not. If its there, it will only write the index of the node into the stream. Otherwise it will serialize the target node and append it to the end of the list. You don't have to know about this mechanism, but be carefull because if you serialize pointers in your nodes then it might lead to a huge stream file containing lots of nodes. For example if you have a pointer to a mesh object, and you serialize that pointer, then the whole scene graph will be serialized to the file, since the mesh node will also serialize some pointers and so on.

Reimplemented from Attribute.

Definition at line 321 of file stream.h.

322 {
323  if ( s.IsStoring() )
324  s.WritePointer( AttributeInstance<type *>::Value() );
325  else
326  SetValue( dynamic_cast<type *>( s.ReadPointer() ), true );
327 };
virtual void SetValue(type *cValue, bool bInternal=false)
Set the value of the attribute to cValue.
Definition: node.h:649
const type * & Value(void) const
Returns the value of the attribute.
Definition: node.h:406
GLdouble s
Definition: GLee.h:1173
void StartEvent ( NodeEventType  cType) const
inlinevirtual

Reimplemented from Attribute.

Definition at line 689 of file node.h.

690  {
692  if ( cType == etPointerContentChanged || cType == etPointerTargetDestroyed || cType == etPointerTargetUIChanged || cType == etRefreshDialogUI )
693  for ( unsigned int i = 0; i < AttributeInstance<type *>::TargetCount(); i++ )
695  };
Causes entire dialog to refresh its UI.
Definition: node.h:168
Attribute * Target(unsigned int iIndex) const
Returns the target with the given index. If iIndex is greater than the number of targets, returns 0;.
This is valid only for pointer type attributes (See AttributePointer). This is posted when the target...
Definition: node.h:157
virtual void StartEvent(NodeEventType cType) const
UI data in attributes are changed.
Definition: node.h:163
This is valid only for pointer type attributes (See AttributePointer). The target node of the pointer...
Definition: node.h:159
Attribute::AttributeType Type ( void  ) const
inlinevirtual

Returns the type of the attribute.

Reimplemented from Attribute.

Definition at line 696 of file node.h.

Pointer attribute, see AttributePointer.
Definition: node.h:197
PTROPERATORS ( type  )

Friends And Related Function Documentation

friend class Node
friend

Definition at line 716 of file node.h.

friend class AttributeThisPointer
friend

Definition at line 717 of file node.h.

friend struct Attribute
friend

Definition at line 718 of file node.h.

Member Data Documentation

QString m_sNullString

Definition at line 713 of file node.h.

bool m_bAllowNull

Definition at line 714 of file node.h.


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