AttributePointer< type > Class Template Reference


Detailed 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 558 of file node.h.

#include <node.h>

Inheritance diagram for AttributePointer< type >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

  AttributePointer (Node *pOwner=NULL, const QString &sID="")
  AttributePointer (Node *pOwner, const QString &sID, bool bInstall)
QString  AsString (unsigned int) const
  Returns the value of the attribute as a string. See also SetFromString.
void  SetFromString (const QString &, unsigned int=Attribute::asStringInternal)
  Sets the value of the attribute as a string. See also AsString.
void  SetValidator (validator *pValidator)
  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.
void  SetPointerValue (Node *pNode, bool bLink=true)
  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.
virtual void  SetValue (type *cValue, unsigned int options=0)
  Set the value of the attribute to cValue.
void  AddTarget (Attribute &cTarget)
  Adds a new outgoing connection for this node to pTarget.
void  DeleteTarget (void)
  Deletes the object what is referred in this pointer.
void  Serialize (Stream &s)
  Serializes the pointer value to a stream.
void  StartEvent (NodeEventType cType) const
Attribute::AttributeType  Type (void) const
  Returns the type of the attribute.
  PTROPERATORS (type)

Public Attributes

QString  m_sNullString
bool  m_bAllowNull

Friends

class  Node
class  AttributeThisPointer
struct  Attribute

Constructor & Destructor Documentation

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

Definition at line 579 of file node.h.

:
    AttributePointer( Node *pOwner=NULL, const QString &sID = "") : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
AttributePointer ( Node pOwner,
const QString &  sID,
bool  bInstall 
) [inline]

Definition at line 580 of file node.h.

:
    AttributePointer( Node *pOwner=NULL, const QString &sID = "") : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };

Member Function Documentation

QString AsString ( unsigned  options ) const [inline, virtual]

Returns the value of the attribute as a string. See also SetFromString.

Reimplemented from AttributeInstance< type * >.

Definition at line 581 of file node.h.

:
    AttributePointer( Node *pOwner=NULL, const QString &sID = "") : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
void SetFromString ( const QString &  sValue,
unsigned  options = Attribute::asStringInternal 
) [inline, virtual]

Sets the value of the attribute as a string. See also AsString.

Reimplemented from AttributeInstance< type * >.

Definition at line 582 of file node.h.

:
    AttributePointer( Node *pOwner=NULL, const QString &sID = "") : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
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 584 of file node.h.

: AttributeInstance<type *>( pOwner, sID, bInstall ) { SetValue( 0, Attribute::asStringInternal ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };
void SetPointerValue ( Node pValue,
bool  bLink = true 
) [inline, virtual]

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 585 of file node.h.

                                             { if ( PointerValue() ) return PointerValue()->Name(); else return m_sNullString; };
    void SetFromString( const QString & /*sValue*/, unsigned int /*options*/ = Attribute::asStringInternal ) { SetPointerValue( 0 ); };
    inline void SetValidator( validator *pValidator ) { m_pValidator = pValidator; };
    void SetPointerValue( Node *pNode, bool bLink = true ) 
    {
        // always accept 0 pointer, the target may be destroyed
        if ( pNode && m_pValidator && !m_pValidator( dynamic_cast<type *>( pNode ) ) )
            return;
        if ( bLink )
virtual void SetValue ( type *  cValue,
unsigned int  options = 0 
) [inline, virtual]

Set the value of the attribute to cValue.

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

Reimplemented from AttributeInstance< type * >.

Definition at line 595 of file node.h.

    {
        if ( cValue == AttributePointer<type>::Value() )
            return;
        AttributeInstance<type *>::SetValue( cValue, options );
        if ( cValue )
void AddTarget ( Attribute cTarget ) [inline, virtual]

Adds a new outgoing connection for this node to pTarget.

Reimplemented from AttributeInstance< type * >.

Definition at line 605 of file node.h.

    {
        Attribute::AddTarget( cTarget );
        if ( cTarget.Size() )
        {
void DeleteTarget ( void  ) [inline]

Deletes the object what is referred in this pointer.

Definition at line 615 of file node.h.

    {
void Serialize ( Stream s ) [inline, virtual]

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 AttributeInstance< type * >.

Definition at line 304 of file stream.h.

{
    if ( s.IsStoring() )
        s.WritePointer( AttributeInstance<type *>::Value() );
    else
        SetValue( dynamic_cast<type *>( s.ReadPointer() ) );
};
void StartEvent ( NodeEventType  cType ) const [inline, virtual]

Reimplemented from Attribute.

Definition at line 635 of file node.h.

Attribute::AttributeType Type ( void  ) const [inline, virtual]

Returns the type of the attribute.

Reimplemented from AttributeInstance< type * >.

Definition at line 642 of file node.h.

PTROPERATORS ( type  )

Friends And Related Function Documentation

friend class Node [friend]

Reimplemented from Attribute.

Definition at line 662 of file node.h.

friend class AttributeThisPointer [friend]

Definition at line 663 of file node.h.

friend struct Attribute [friend]

Definition at line 664 of file node.h.


Member Data Documentation

Definition at line 659 of file node.h.

Definition at line 660 of file node.h.


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