]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
C++: Add UserOwned base template for objects with resources owned by user.
[libsigrok.git] / bindings / cxx / classes.cpp
index 0aade4b1b2043fccc475a441df5fac33c0a653f3..525e046ddcc168fad28e599345bef3c9e7d53ac7 100644 (file)
@@ -71,9 +71,11 @@ shared_ptr<Context> Context::create()
 }
 
 Context::Context() :
+       UserOwned(structure),
        session(NULL)
 {
        check(sr_init(&structure));
+
        struct sr_dev_driver **driver_list = sr_driver_list();
        if (driver_list)
                for (int i = 0; driver_list[i]; i++)
@@ -245,7 +247,7 @@ shared_ptr<Input> Context::open_stream(string header)
 }
 
 Driver::Driver(struct sr_dev_driver *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        initialized(false)
 {
 }
@@ -446,7 +448,7 @@ void Device::close()
 }
 
 HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        Device(structure),
        driver(driver)
 {
@@ -467,7 +469,7 @@ shared_ptr<Driver> HardwareDevice::get_driver()
 }
 
 Channel::Channel(struct sr_channel *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        type(ChannelType::get(structure->type))
 {
 }
@@ -508,7 +510,7 @@ unsigned int Channel::get_index()
 
 ChannelGroup::ChannelGroup(Device *device,
                struct sr_channel_group *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        Configurable(device->structure->driver, device->structure, structure)
 {
        for (GSList *entry = structure->channels; entry; entry = entry->next)
@@ -533,7 +535,8 @@ vector<shared_ptr<Channel>> ChannelGroup::get_channels()
 }
 
 Trigger::Trigger(shared_ptr<Context> context, string name) : 
-       structure(sr_trigger_new(name.c_str())), context(context)
+       UserOwned(sr_trigger_new(name.c_str())),
+       context(context)
 {
        for (auto stage = structure->stages; stage; stage = stage->next)
                stages.push_back(new TriggerStage((struct sr_trigger_stage *) stage->data));
@@ -568,7 +571,7 @@ shared_ptr<TriggerStage> Trigger::add_stage()
 }
 
 TriggerStage::TriggerStage(struct sr_trigger_stage *structure) : 
-       StructureWrapper(structure)
+       ParentOwned(structure)
 {
 }
 
@@ -604,7 +607,7 @@ void TriggerStage::add_match(shared_ptr<Channel> channel, const TriggerMatchType
 }
 
 TriggerMatch::TriggerMatch(struct sr_trigger_match *structure, shared_ptr<Channel> channel) :
-       StructureWrapper(structure), channel(channel)
+       ParentOwned(structure), channel(channel)
 {
 }
 
@@ -690,6 +693,7 @@ EventSource::~EventSource()
 }
 
 Session::Session(shared_ptr<Context> context) :
+       UserOwned(structure),
        context(context), saving(false)
 {
        check(sr_session_new(&structure));
@@ -697,6 +701,7 @@ Session::Session(shared_ptr<Context> context) :
 }
 
 Session::Session(shared_ptr<Context> context, string filename) :
+       UserOwned(structure),
        context(context), saving(false)
 {
        check(sr_session_load(filename.c_str(), &structure));
@@ -936,7 +941,7 @@ void Session::set_trigger(shared_ptr<Trigger> trigger)
 
 Packet::Packet(shared_ptr<Device> device,
        const struct sr_datafeed_packet *structure) :
-       structure(structure),
+       UserOwned(structure),
        device(device)
 {
        switch (structure->type)
@@ -995,7 +1000,7 @@ PacketPayload::~PacketPayload()
 }
 
 Header::Header(const struct sr_datafeed_header *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        PacketPayload()
 {
 }
@@ -1022,7 +1027,7 @@ Glib::TimeVal Header::get_start_time()
 }
 
 Meta::Meta(const struct sr_datafeed_meta *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        PacketPayload()
 {
 }
@@ -1048,7 +1053,7 @@ map<const ConfigKey *, Glib::VariantBase> Meta::get_config()
 }
 
 Logic::Logic(const struct sr_datafeed_logic *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        PacketPayload()
 {
 }
@@ -1078,7 +1083,7 @@ unsigned int Logic::get_unit_size()
 }
 
 Analog::Analog(const struct sr_datafeed_analog *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        PacketPayload()
 {
 }
@@ -1127,7 +1132,7 @@ vector<const QuantityFlag *> Analog::get_mq_flags()
 }
 
 InputFormat::InputFormat(const struct sr_input_module *structure) :
-       StructureWrapper(structure)
+       ParentOwned(structure)
 {
 }
 
@@ -1168,7 +1173,7 @@ shared_ptr<Input> InputFormat::create_input(
 }
 
 Input::Input(shared_ptr<Context> context, const struct sr_input *structure) :
-       structure(structure),
+       UserOwned(structure),
        context(context),
        device(nullptr)
 {
@@ -1204,7 +1209,7 @@ Input::~Input()
 
 InputDevice::InputDevice(shared_ptr<Input> input,
                struct sr_dev_inst *structure) :
-       StructureWrapper(structure),
+       ParentOwned(structure),
        Device(structure),
        input(input)
 {
@@ -1221,7 +1226,7 @@ shared_ptr<Device> InputDevice::get_shared_from_this()
 
 Option::Option(const struct sr_option *structure,
                shared_ptr<const struct sr_option *> structure_array) :
-       structure(structure),
+       UserOwned(structure),
        structure_array(structure_array)
 {
 }
@@ -1259,7 +1264,7 @@ vector<Glib::VariantBase> Option::get_values()
 }
 
 OutputFormat::OutputFormat(const struct sr_output_module *structure) :
-       StructureWrapper(structure)
+       ParentOwned(structure)
 {
 }
 
@@ -1299,7 +1304,7 @@ shared_ptr<Output> OutputFormat::create_output(
 
 Output::Output(shared_ptr<OutputFormat> format,
                shared_ptr<Device> device, map<string, Glib::VariantBase> options) :
-       structure(sr_output_new(format->structure,
+       UserOwned(sr_output_new(format->structure,
                map_to_hash_variant(options), device->structure)),
        format(format), device(device), options(options)
 {