×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Is it an Object or a pointer to an Objects??

  • Posts: 94
  • Thank you received: 8
I'm still looking for answers to my previous question (Getting all the Telescopes and Cameras), but perhaps this is related to things not working.

This may be related to my relative unfamiliarity to C++, but I am finding that instances of BaseDevice seems function as both an object and as a pointer to an object.

I am using Xcode on macOS for development and find that both these pieces of code compile just fine:
void IndiClient::newDevice(INDI::BaseDevice baseDevice)
{         
   IDLog("New Device: %s\n", baseDevice.getDeviceName());
   auto interface = baseDevice.getDriverInterface();
   if (interface & BaseDevice::TELESCOPE_INTERFACE)
   {
       IDLog("New Telescope: %s\n", baseDevice.getDeviceName());
   }
}

and
void IndiClient::newDevice(INDI::BaseDevice baseDevice)
{         
   IDLog("New Device: %s\n", baseDevice->getDeviceName());
   auto interface = baseDevice->getDriverInterface();
   if (interface & BaseDevice::TELESCOPE_INTERFACE)
   {
       IDLog("New Telescope: %s\n", baseDevice->getDeviceName());
   }
}

In the first case I'm referencing baseDevice as if it were an object and in the second case I'm using pointer dereferencing. They both compile without errors and both work. What's going on here??

Is this somehow related to the d-pointer pattern that INDI is using? Or is it some glitch in Xcode and maybe I need to have some setting different so this compiles poperlt?

Thanks for you looking at this.
Bill
1 year 4 months ago #88995

Please Log in or Create an account to join the conversation.

  • Posts: 28
  • Thank you received: 17
In the past, some functions returned a pointer to an object, which could later refer to a nonexistent object.
Currently, BaseDevice has a built-in shared pointer that eliminates this problem.
To maintain backward compatibility, BaseDevice has the operator-> which is used by various code snippets. BaseDevice and Property/PropertyXXX should be passed as values, not as pointers.
The "->" operator will be marked as deprecated in future versions of the library.

The example below follows the latest trends.
void IndiClient::newDevice(INDI::BaseDevice baseDevice)
{         
   IDLog("New Device: %s\n", baseDevice.getDeviceName());
   auto interface = baseDevice.getDriverInterface();
   if (interface & BaseDevice::TELESCOPE_INTERFACE)
   {
       IDLog("New Telescope: %s\n", baseDevice.getDeviceName());
   }
}
1 year 4 months ago #89025

Please Log in or Create an account to join the conversation.

  • Posts: 94
  • Thank you received: 8
Very sneaky. Thanks for the explanation.
1 year 4 months ago #89038

Please Log in or Create an account to join the conversation.

Time to create page: 0.686 seconds