www.quadsoftware.com
FAQ  FAQ   Search  Search   Memberlist  Memberlist   Usergroups  Usergroups
Register  ::  Log in Log in to check your private messages


Post new topic  Reply to topic
 GetPropValue usage « View previous topic :: View next topic » 
Author Message
mkolb
PostPosted: Thu Aug 23, 2007 7:09 am    Post subject: GetPropValue usage Reply with quote



Joined: 21 Aug 2007
Posts: 12

Hi,

I want to retrieve the user properties in the SDK for a custom exporter plug-in. However I can't manage to create the appropriate variable to save the value in it.

This is what I've got so far:

Code:

t_char** Ogremesh = new t_char*[128];

   iPropertyTableOwner *prop_owner = (iPropertyTableOwner*)inst->OpenSubinterface(
      g_sdk_root->GetTypeId(iPropertyTableOwner::TypeString()));
   prop_owner->GetPropertyTable(0)->GetPropValue(0,0,(void*&)Ogremesh);


I am a bit weak with pointer-to-pointers(or how you might name **), so could please someone give me a short hint on how to initialise the variable for a string property?

Regards
Back to top
View user's profile Send private message
ALicu
PostPosted: Thu Aug 23, 2007 11:23 am    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

Hi,

Yes, there is small bug in the SDK that don't let you get a string. Please download the today patch (1.10.01) that fixes this problem.

The SDK is using pointer to pointer so it doesn't have to allocate the string or for you to have it previously allocated (without knowing the string size).

Now, as stated in the function documentation, the GetPropValue will accept a pointer to a pointer of t_char and fill it with the pointer to the internal string kept by the engine. So the code may look like this:

Code:

t_char* OgremeshPointer;

iPropertyTableOwner *prop_owner = (iPropertyTableOwner*)inst->OpenSubinterface(
      g_sdk_root->GetTypeId(iPropertyTableOwner::TypeString()));
   prop_owner->GetPropertyTable(0)->GetPropValue(0,0, &OgremeshPointer);

// Now we have our pointer filled, is time to copy it into one of our strings.
if(OgremeshPointer)
{
   t_char* Ogremesh = new char((gStrLen(OgremeshPointer)+1)*sizeof(t_char));

   gStrCpy(Ogremesh, OgremeshPointer);

   // Do something with Ogremesh string.
   // ...

   delete(Ogremesh);
}


You can also use OgremeshPointer directly as long as you don't modify the string (because it is pointing to the internally allocated one). You can modify it with SetPropValue.

To be noted that if you add this as a resource property and have storage format plugin for ogre meshes for example (to read ogre meshes directly) you can access the ogres meshes directly through the property, not only its name.

Regards,
Back to top
View user's profile Send private message
mkolb
PostPosted: Thu Aug 23, 2007 11:43 am    Post subject: Reply with quote



Joined: 21 Aug 2007
Posts: 12

Thank you for your reply,

for the sake of correctness and others possibly others having the same problem I have to point out that the line
Code:

t_char* Ogremesh = new char((gStrLen(OgremeshPointer)+1)*sizeof(t_char));

should be
Code:

t_char* Ogremesh = new t_char((gStrLen(OgremeshPointer)+1)*sizeof(t_char));
Back to top
View user's profile Send private message
ALicu
PostPosted: Thu Aug 23, 2007 11:47 am    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

Ah, you are right, actually it should be

Code:

new t_char[gStrLen(OgremeshPointer)+1];


or

Code:

(t_char*)malloc((gStrLen(OgremeshPointer)+1)*sizeof(t_char)];



Thanks for pointing that out.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Based on a template by Dustin Baccetti
Powered by phpBB © 2001, 2005 phpBB Group