From: Martin Ling Date: Tue, 2 Sep 2014 20:31:11 +0000 (+0100) Subject: C++: Implement Deleter pattern in UserOwned template. X-Git-Tag: libsigrok-0.4.0~1045 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b4ed33a7765a3e08756c18695bcd885b330bc83a;p=libsigrok.git C++: Implement Deleter pattern in UserOwned template. --- diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index e25c1d54..4005c04a 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -211,6 +211,13 @@ protected: structure(structure) { } + + /* Deleter needed to allow shared_ptr use with protected destructor. */ + class Deleter + { + public: + void operator()(Class *object) { delete object; } + }; }; /** Type of log callback */ @@ -269,12 +276,6 @@ protected: LogCallbackFunction log_callback; Context(); ~Context(); - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Context *context) { delete context; } - }; friend class Deleter; friend class Session; friend class Driver; @@ -448,12 +449,7 @@ protected: ~Trigger(); shared_ptr context; vector stages; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Trigger *trigger) { delete trigger; } - }; + friend class Deleter; friend class Context; friend class Session; }; @@ -638,12 +634,6 @@ protected: string save_filename; uint64_t save_samplerate; shared_ptr trigger; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Session *session) { delete session; } - }; friend class Deleter; friend class Context; friend class DatafeedCallbackData; @@ -663,12 +653,6 @@ protected: ~Packet(); shared_ptr device; PacketPayload *payload; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Packet *packet) { delete packet; } - }; friend class Deleter; friend class Session; friend class Output; @@ -809,12 +793,6 @@ protected: ~Input(); shared_ptr context; InputDevice *device; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Input *input) { delete input; } - }; friend class Deleter; friend class Context; friend class InputFormat; @@ -830,13 +808,6 @@ protected: ~InputDevice(); shared_ptr get_shared_from_this(); shared_ptr input; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(InputDevice *device) { delete device; } - }; - friend class Deleter; friend class Input; }; @@ -859,12 +830,6 @@ protected: shared_ptr structure_array); ~Option(); shared_ptr structure_array; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Option *option) { delete option; } - }; friend class Deleter; friend class InputFormat; friend class OutputFormat; @@ -908,12 +873,6 @@ protected: const shared_ptr format; const shared_ptr device; const map options; - /** Deleter needed to allow shared_ptr use with protected destructor. */ - class Deleter - { - public: - void operator()(Output *output) { delete output; } - }; friend class Deleter; friend class OutputFormat; };