shared_ptr<Context> Context::create()
{
- return shared_ptr<Context>(new Context(), Context::Deleter());
+ return shared_ptr<Context>{new Context{}, default_delete<Context>{}};
}
Context::Context() :
shared_ptr<Session> Context::create_session()
{
- return shared_ptr<Session>(
- new Session(shared_from_this()), Session::Deleter());
+ return shared_ptr<Session>{new Session{shared_from_this()},
+ default_delete<Session>{}};
}
shared_ptr<UserDevice> Context::create_user_device(
string vendor, string model, string version)
{
- return shared_ptr<UserDevice>(
- new UserDevice(vendor, model, version), UserDevice::Deleter());
+ return shared_ptr<UserDevice>{
+ new UserDevice{move(vendor), move(model), move(version)},
+ default_delete<UserDevice>{}};
}
shared_ptr<Packet> Context::create_header_packet(Glib::TimeVal start_time)
auto packet = g_new(struct sr_datafeed_packet, 1);
packet->type = SR_DF_HEADER;
packet->payload = header;
- return shared_ptr<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+ return shared_ptr<Packet>{new Packet{nullptr, packet},
+ default_delete<Packet>{}};
}
shared_ptr<Packet> Context::create_meta_packet(
auto packet = g_new(struct sr_datafeed_packet, 1);
packet->type = SR_DF_META;
packet->payload = meta;
- return shared_ptr<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+ return shared_ptr<Packet>{new Packet{nullptr, packet},
+ default_delete<Packet>{}};
}
shared_ptr<Packet> Context::create_logic_packet(
auto packet = g_new(struct sr_datafeed_packet, 1);
packet->type = SR_DF_LOGIC;
packet->payload = logic;
- return shared_ptr<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+ return shared_ptr<Packet>{new Packet{nullptr, packet}, default_delete<Packet>{}};
}
shared_ptr<Packet> Context::create_analog_packet(
auto packet = g_new(struct sr_datafeed_packet, 1);
packet->type = SR_DF_ANALOG;
packet->payload = analog;
- return shared_ptr<Packet>(new Packet(nullptr, packet), Packet::Deleter());
+ return shared_ptr<Packet>{new Packet{nullptr, packet}, default_delete<Packet>{}};
}
shared_ptr<Session> Context::load_session(string filename)
{
- return shared_ptr<Session>(
- new Session(shared_from_this(), move(filename)), Session::Deleter());
+ return shared_ptr<Session>{
+ new Session{shared_from_this(), move(filename)},
+ default_delete<Session>{}};
}
shared_ptr<Trigger> Context::create_trigger(string name)
{
- return shared_ptr<Trigger>(
- new Trigger(shared_from_this(), move(name)), Trigger::Deleter());
+ return shared_ptr<Trigger>{
+ new Trigger{shared_from_this(), move(name)},
+ default_delete<Trigger>{}};
}
shared_ptr<Input> Context::open_file(string filename)
const struct sr_input *input;
check(sr_input_scan_file(filename.c_str(), &input));
- return shared_ptr<Input>(
- new Input(shared_from_this(), input), Input::Deleter());
+ return shared_ptr<Input>{
+ new Input{shared_from_this(), input},
+ default_delete<Input>{}};
}
shared_ptr<Input> Context::open_stream(string header)
auto ret = sr_input_scan_buffer(gstr, &input);
g_string_free(gstr, true);
check(ret);
- return shared_ptr<Input>(
- new Input(shared_from_this(), input), Input::Deleter());
+ return shared_ptr<Input>{
+ new Input{shared_from_this(), input},
+ default_delete<Input>{}};
}
map<string, string> Context::serials(shared_ptr<Driver> driver) const
for (GSList *device = device_list; device; device = device->next)
{
auto *const sdi = static_cast<struct sr_dev_inst *>(device->data);
- result.push_back(shared_ptr<HardwareDevice>(
- new HardwareDevice(shared_from_this(), sdi),
- HardwareDevice::Deleter()));
+ shared_ptr<HardwareDevice> hwdev {
+ new HardwareDevice{shared_from_this(), sdi},
+ default_delete<HardwareDevice>{}};
+ result.push_back(move(hwdev));
}
/* Free GSList returned from scan. */
const struct sr_datafeed_packet *pkt)
{
auto device = _session->get_device(sdi);
- auto packet = shared_ptr<Packet>(new Packet(device, pkt), Packet::Deleter());
+ shared_ptr<Packet> packet {new Packet{device, pkt}, default_delete<Packet>{}};
_callback(move(device), move(packet));
}
map<string, shared_ptr<Option>> InputFormat::options()
{
- const struct sr_option **options = sr_input_options_get(_structure);
map<string, shared_ptr<Option>> result;
- if (options)
+
+ if (const struct sr_option **options = sr_input_options_get(_structure))
{
- auto option_array = shared_ptr<const struct sr_option *>(
- options, sr_input_options_free);
- for (int i = 0; options[i]; i++)
- result[options[i]->id] = shared_ptr<Option>(
- new Option(options[i], option_array), Option::Deleter());
+ shared_ptr<const struct sr_option *> option_array
+ {options, &sr_input_options_free};
+ for (int i = 0; options[i]; i++) {
+ shared_ptr<Option> opt {
+ new Option{options[i], option_array},
+ default_delete<Option>{}};
+ result.emplace(opt->id(), move(opt));
+ }
}
return result;
}
auto input = sr_input_new(_structure, map_to_hash_variant(options));
if (!input)
throw Error(SR_ERR_ARG);
- return shared_ptr<Input>(new Input(_parent, input), Input::Deleter());
+ return shared_ptr<Input>{new Input{_parent, input}, default_delete<Input>{}};
}
Input::Input(shared_ptr<Context> context, const struct sr_input *structure) :
map<string, shared_ptr<Option>> OutputFormat::options()
{
- const struct sr_option **options = sr_output_options_get(_structure);
map<string, shared_ptr<Option>> result;
- if (options)
+
+ if (const struct sr_option **options = sr_output_options_get(_structure))
{
- auto option_array = shared_ptr<const struct sr_option *>(
- options, sr_output_options_free);
- for (int i = 0; options[i]; i++)
- result[options[i]->id] = shared_ptr<Option>(
- new Option(options[i], option_array), Option::Deleter());
+ shared_ptr<const struct sr_option *> option_array
+ {options, &sr_output_options_free};
+ for (int i = 0; options[i]; i++) {
+ shared_ptr<Option> opt {
+ new Option{options[i], option_array},
+ default_delete<Option>{}};
+ result.emplace(opt->id(), move(opt));
+ }
}
return result;
}
shared_ptr<Output> OutputFormat::create_output(
shared_ptr<Device> device, const map<string, Glib::VariantBase> &options)
{
- return shared_ptr<Output>(
- new Output(shared_from_this(), move(device), options),
- Output::Deleter());
+ return shared_ptr<Output>{
+ new Output{shared_from_this(), move(device), options},
+ default_delete<Output>{}};
}
shared_ptr<Output> OutputFormat::create_output(string filename,
shared_ptr<Device> device, const map<string, Glib::VariantBase> &options)
{
- return shared_ptr<Output>(
- new Output(move(filename), shared_from_this(), move(device), options),
- Output::Deleter());
+ return shared_ptr<Output>{
+ new Output{move(filename), shared_from_this(), move(device), options},
+ default_delete<Output>{}};
}
bool OutputFormat::test_flag(const OutputFlag *flag) const
throw Error(SR_ERR_BUG);
return shared;
}
-
- /* Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(Class *object) { delete object; }
- };
};
/** Type of log callback */
LogCallbackFunction _log_callback;
Context();
~Context();
- friend class Deleter;
friend class Session;
friend class Driver;
+ friend class std::default_delete<Context>;
};
enum Capability {
map<struct sr_channel *, unique_ptr<Channel> > _channels;
private:
map<string, unique_ptr<ChannelGroup> > _channel_groups;
- /** Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(Device *device) { delete device; }
- };
- friend class Deleter;
+
friend class Session;
friend class Channel;
friend class ChannelGroup;
friend class Output;
friend class Analog;
+ friend class std::default_delete<Device>;
};
/** A real hardware device, connected via a driver */
~HardwareDevice();
shared_ptr<Device> get_shared_from_this();
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;
+ friend class std::default_delete<HardwareDevice>;
};
/** A virtual device, created by the user */
UserDevice(string vendor, string model, string version);
~UserDevice();
shared_ptr<Device> get_shared_from_this();
- /** Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(UserDevice *device) { delete device; }
- };
+
friend class Context;
- friend class Deleter;
+ friend class std::default_delete<UserDevice>;
};
/** A channel on a device */
struct sr_trigger *_structure;
shared_ptr<Context> _context;
vector<unique_ptr<TriggerStage> > _stages;
- friend class Deleter;
friend class Context;
friend class Session;
+ friend class std::default_delete<Trigger>;
};
/** A stage in a trigger configuration */
explicit SessionDevice(struct sr_dev_inst *sdi);
~SessionDevice();
shared_ptr<Device> get_shared_from_this();
- /** Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(SessionDevice *device) { delete device; }
- };
- friend class Deleter;
+
friend class Session;
friend class std::default_delete<SessionDevice>;
};
SessionStoppedCallback _stopped_callback;
string _filename;
shared_ptr<Trigger> _trigger;
- friend class Deleter;
+
friend class Context;
friend class DatafeedCallbackData;
friend class SessionDevice;
+ friend class std::default_delete<Session>;
};
/** A packet on the session datafeed */
const struct sr_datafeed_packet *_structure;
shared_ptr<Device> _device;
unique_ptr<PacketPayload> _payload;
- friend class Deleter;
+
friend class Session;
friend class Output;
friend class DatafeedCallbackData;
friend class Logic;
friend class Analog;
friend class Context;
+ friend class std::default_delete<Packet>;
};
/** Abstract base class for datafeed packet payloads */
private:
virtual shared_ptr<PacketPayload> share_owned_by(shared_ptr<Packet> parent) = 0;
- /** Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(PacketPayload *payload) { delete payload; }
- };
- friend class Deleter;
friend class Packet;
friend class Output;
friend class std::default_delete<PacketPayload>;
const struct sr_input *_structure;
shared_ptr<Context> _context;
unique_ptr<InputDevice> _device;
- friend class Deleter;
+
friend class Context;
friend class InputFormat;
+ friend class std::default_delete<Input>;
};
/** A virtual device associated with an input */
~Option();
const struct sr_option *_structure;
shared_ptr<const struct sr_option *> _structure_array;
- friend class Deleter;
+
friend class InputFormat;
friend class OutputFormat;
+ friend class std::default_delete<Option>;
};
/** An output format supported by the library */
const shared_ptr<Device> _device;
const map<string, Glib::VariantBase> _options;
- friend class Deleter;
friend class OutputFormat;
+ friend class std::default_delete<Output>;
};
/** Base class for objects which wrap an enumeration value from libsigrok */