- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Friends

# AttributePointer< type > Class Template Reference

Search for all occurrences

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

`#include <node.h>`

Inheritance diagram for AttributePointer< type >:
[legend]

List of all members.

## 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.
void | SetFromString (const QString &, bool=true, bool=false)
| Sets the value of the attribute as a string.
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, bool bInternal=false)
| 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 582 of file node.h.

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

AttributePointer | ( | Node * | pOwner,
|  | const QString & | sID,
|  | bool | bInstall
| ) |  | `[inline]`

Definition at line 583 of file node.h.

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

AttributePointer | ( | const AttributePointer< type > & | cOther | ) | `[inline]`

Definition at line 584 of file node.h.

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

## Member Function Documentation

QString AsString | ( | bool | bLocalized | ) | const `[inline, virtual]`

Search for all occurrences

Returns the value of the attribute as a string.

See also SetFromString.

Parameters:

  bLocalized | if this is true the string representation of the value is assumed to be localized (translated)

Reimplemented from AttributeInstance< type * >.

Definition at line 585 of file node.h.

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

void SetFromString | ( | const QString & | sValue,
|  | bool | bInternal = `true`,
|  | bool | bLocalized = `false`
| ) |  | `[inline, virtual]`

Search for all occurrences

Sets the value of the attribute as a string.

See also AsString.

Parameters:

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

Reimplemented from AttributeInstance< type * >.

Definition at line 586 of file node.h.

    : AttributeInstance<type *>( pOwner, sID ) { SetValue( 0, true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };

void SetValidator | ( | validator * | pValidator | ) | `[inline]`

Search for all occurrences

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

    : AttributeInstance<type *>( 0, "" ) { SetValue( cOther.Value(), true ); m_pValidator = 0; m_sNullString = "NULL"; m_bAllowNull = true; };

void SetPointerValue | ( | Node * | pValue,
|  | bool | bLink = `true`
| ) |  | `[inline, virtual]`

Search for all occurrences

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

                                         { if ( PointerValue() ) return PointerValue()->Name(); else return m_sNullString; };
        void SetFromString( const QString & /*sValue*/, bool /*bInternal*/ = true, bool /*bLocalized*/ = false ) { 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,
|  | bool | bInternal = `false`
| ) |  | `[inline, virtual]`

Search for all occurrences

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

        {
            if ( cValue == AttributePointer<type>::Value() )
                return;
            AttributeInstance<type *>::SetValue( cValue, bInternal );
            if ( cValue )

void AddTarget | ( | Attribute & | cTarget | ) | `[inline, virtual]`

Search for all occurrences

Adds a new outgoing connection for this node to pTarget.

Reimplemented from AttributeInstance< type * >.

Definition at line 609 of file node.h.

        {
            Attribute::AddTarget( cTarget );
            if ( cTarget.Size() )
            {

void DeleteTarget | ( | void |  | ) | `[inline]`

Search for all occurrences

Deletes the object what is referred in this pointer.

Definition at line 619 of file node.h.

        {

void Serialize | ( | Stream & | s | ) | `[inline, virtual]`

Search for all occurrences

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 308 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]`

Search for all occurrences

Reimplemented from Attribute.

Definition at line 639 of file node.h.

        {
            AttributeInstance<type *>::StartEvent( cType );

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

Search for all occurrences

Returns the type of the attribute.

Reimplemented from AttributeInstance< type * >.

Definition at line 646 of file node.h.

PTROPERATORS | ( | type |  | ) |

Search for all occurrences

## Friends And Related Function Documentation

friend class Node `[friend]`

Search for all occurrences

Reimplemented from Attribute.

Definition at line 666 of file node.h.

friend class AttributeThisPointer `[friend]`

Search for all occurrences

Definition at line 667 of file node.h.

friend struct Attribute `[friend]`

Search for all occurrences

Definition at line 668 of file node.h.

## Member Data Documentation

QString m_sNullString

Search for all occurrences

Definition at line 663 of file node.h.

bool m_bAllowNull

Search for all occurrences

Definition at line 664 of file node.h.

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

- Mudbox/node.h
- Mudbox/stream.h