bool   sgCObject::SetUserDynamicData(const SG_USER_DYNAMIC_DATA* u_d_d)

 

Description:

Assigns a user-defined block of data to an object.

 

Arguments:

u_d_d - an index to the user-defined block of data. The object of the user data block should have the same class type that  the inherited one from SG_USER_DYNAMIC_DATA – the memory release function must be defined.

 

Returned value:

If succeed the function returns true, otherwise false.

 

Note:

The user-defined block of data isn't saved in the same file with the object. The user must save it manually.

 

Example:

 

class MyData : public SG_USER_DYNAMIC_DATA

{

public:

 int* m_data;

public:

 MyData()

 {

         m_data=new int[10];

 }

 ~MyData()

 {

         delete[] m_data;

 };

 virtual void Finalize()

 {

         if (m_data)

         {

                 delete[] m_data;

                 m_data = NULL;

                 delete this;

         }

 }

};

 

sgCPoint* pnt = sgCreatePoint(i-15, j-15, pZ);

sgGetScene()->AttachObject(pnt);

 

MyData*  usDat = new MyData();

pnt->SetUserDynamicData(usDat);

MyData*  uuu = reinterpret_cast<MyData*>(pnt->GetUserDymanicData());

uuu->m_data[5] = 999;

ASSERT(usDat->m_data[5]==999);

 

See also:

GetUserDynamicData SG_USER_DYNAMIC_DATA