Skip to content

Commit 769c1cb

Browse files
committed
Use delegated constructors from C++ in PTPUSB
1 parent e837d4b commit 769c1cb

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

lib/PTPUSB.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ namespace EasyPTP {
2828

2929
int PTPUSB::inst_count = 0;
3030

31-
PTPUSB::PTPUSB() {
32-
this->init();
33-
}
31+
PTPUSB::PTPUSB() : PTPUSB(NULL) { }
3432

35-
PTPUSB::PTPUSB(libusb_device * dev) {
36-
this->init();
37-
this->open(dev);
33+
PTPUSB::PTPUSB(libusb_device * dev) : handle(NULL), usb_error(0), intf(NULL),
34+
ep_in(0), ep_out(0)
35+
{
36+
// Increment our instance count, and initialize libusb if this is our first
37+
// instance
38+
if(PTPUSB::inst_count++ == 0)
39+
{
40+
libusb_init(NULL);
41+
}
42+
43+
// If we were passsed a device, open it!
44+
if(dev != NULL)
45+
{
46+
this->open(dev);
47+
}
3848
}
3949

4050
PTPUSB::~PTPUSB() {
@@ -47,19 +57,6 @@ PTPUSB::~PTPUSB() {
4757
}
4858
}
4959

50-
void PTPUSB::init() {
51-
if(PTPUSB::inst_count == 0) {
52-
libusb_init(NULL); // Make sure to initialize libusb first!
53-
}
54-
55-
PTPUSB::inst_count++;
56-
this->handle = NULL;
57-
this->usb_error = 0;
58-
this->intf = NULL;
59-
this->ep_in = 0;
60-
this->ep_out = 0;
61-
}
62-
6360
void PTPUSB::connect_to_first() {
6461
// Find the first camera
6562
libusb_device * dev = this->find_first_camera();

0 commit comments

Comments
 (0)