]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/include/libsigrok/libsigrok.hpp
C++: Make hardware device instances user owned.
[libsigrok.git] / bindings / cxx / include / libsigrok / libsigrok.hpp
index 15509c9c5803ac805956a8f7f648fe98502e95a1..972bde883d523fccec8f7324a9dc05dea06f6972 100644 (file)
@@ -323,7 +323,8 @@ public:
        /** Scan for devices and return a list of devices found.
         * @param options Mapping of (ConfigKey, value) pairs. */
        vector<shared_ptr<HardwareDevice> > scan(
-               map<const ConfigKey *, Glib::VariantBase> options = {});
+               map<const ConfigKey *, Glib::VariantBase> options =
+                       map<const ConfigKey *, Glib::VariantBase>());
 protected:
        bool _initialized;
        vector<HardwareDevice *> _devices;
@@ -378,17 +379,24 @@ protected:
 
 /** A real hardware device, connected via a driver */
 class SR_API HardwareDevice :
-       public ParentOwned<HardwareDevice, Context, struct sr_dev_inst>,
+       public UserOwned<HardwareDevice, struct sr_dev_inst>,
        public Device
 {
 public:
        /** Driver providing this device. */
        shared_ptr<Driver> driver();
 protected:
-       HardwareDevice(Driver *driver, struct sr_dev_inst *structure);
+       HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
        ~HardwareDevice();
        shared_ptr<Device> get_shared_from_this();
-       Driver *_driver;
+       shared_ptr<Driver> _driver;
+       /** Deleter needed to allow shared_ptr use with protected destructor. */
+       class Deleter
+       {
+       public:
+               void operator()(HardwareDevice *device) { delete device; }
+       };
+       friend class Deleter;
        friend class Driver;
        friend class ChannelGroup;
 };
@@ -795,7 +803,8 @@ public:
        map<string, shared_ptr<Option> > options();
        /** Create an input using this input format.
         * @param options Mapping of (option name, value) pairs. */
-       shared_ptr<Input> create_input(map<string, Glib::VariantBase> options = {});
+       shared_ptr<Input> create_input(map<string, Glib::VariantBase> options =
+               map<string, Glib::VariantBase>());
 protected:
        InputFormat(const struct sr_input_module *structure);
        ~InputFormat();
@@ -874,7 +883,8 @@ public:
         * @param device Device to output for.
         * @param options Mapping of (option name, value) pairs. */
        shared_ptr<Output> create_output(shared_ptr<Device> device,
-               map<string, Glib::VariantBase> options = {});
+               map<string, Glib::VariantBase> options =
+                       map<string, Glib::VariantBase>());
 protected:
        OutputFormat(const struct sr_output_module *structure);
        ~OutputFormat();