Private()
: ftdi(0), dev(0), open(false)
{
+ ftdi = ftdi_new();
+ }
+
+ ~Private()
+ {
+ if(open)
+ ftdi_usb_close(ftdi);
+
+ ftdi_free(ftdi);
}
bool open;
Context::Context()
: d( new Private() )
{
- d->ftdi = ftdi_new();
}
/*! \brief Destructor.
*/
Context::~Context()
{
- if (d->open)
- close();
-
- ftdi_free(d->ftdi);
- delete d;
}
bool Context::is_open()
Eeprom::~Eeprom()
{
- delete d;
}
void Eeprom::init_defaults()
class List::Private
{
public:
- Private()
- : list(0)
+ Private(struct ftdi_device_list* devlist)
+ : list(devlist)
{}
+ ~Private()
+ {
+ ftdi_list_free(&list);
+ }
+
struct ftdi_device_list* list;
};
List::List(struct ftdi_device_list* devlist)
- : ListBase(), d( new Private() )
+ : ListBase(), d( new Private(devlist) )
{
if (devlist != 0)
{
// Iterate list
- Context* c = 0;
for (d->list = devlist; d->list != 0; d->list = d->list->next)
{
- c = new Context();
- c->set_usb_device(d->list->dev);
+ Context c;
+ c.set_usb_device(d->list->dev);
+ c.get_strings();
push_back(c);
}
-
- // Store pointer
- d->list = devlist;
}
}
List::~List()
{
- // Deallocate instances
- for (iterator it = begin(); it != end(); it++)
- delete *it;
-
- // Clear list
- clear();
- ftdi_list_free(&d->list);
-
- // Delete d-ptr
- delete d;
}
List* List::find_all(int vendor, int product)
#include <list>
#include <string>
+#include <boost/shared_ptr.hpp>
#include "ftdi.h"
namespace Ftdi
private:
class Private;
- Private *d;
-
- /* Disable copy constructor */
- Context(const Context &) {}
- Context& operator=(const Context &) {}
+ boost::shared_ptr<Private> d;
};
/*! \brief Device EEPROM.
private:
class Private;
- Private *d;
+ boost::shared_ptr<Private> d;
};
-typedef std::list<Context*> ListBase;
+typedef std::list<Context> ListBase;
/*! \brief Device list.
*/
private:
class Private;
- Private *d;
+ boost::shared_ptr<Private> d;
};
}