List having non-virtual destructor fixed (thanks to Thomas Jarosch) Proposed subset...
[libftdi] / ftdipp / ftdi.cpp
index 827bca1..0a22bd5 100644 (file)
@@ -5,15 +5,27 @@
     copyright            : (C) 2008 by Marek Vavruša
     email                : opensource@intra2net.com and marek@vavrusa.com
  ***************************************************************************/
+/*
+Copyright (C) 2008 by Marek Vavruša
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU Lesser General Public License           *
- *   version 2.1 as published by the Free Software Foundation;             *
- *                                                                         *
- ***************************************************************************/
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
 
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
 #include "ftdi.hpp"
 #include "ftdi.h"
 
@@ -389,30 +401,32 @@ int Eeprom::erase()
 class List::Private
 {
 public:
-    Private(struct ftdi_device_list* devlist)
-            : list(devlist)
+    Private(struct ftdi_device_list* _devlist)
+            : devlist(_devlist)
     {}
 
     ~Private()
     {
-        ftdi_list_free(&list);
+        if(devlist)
+            ftdi_list_free(&devlist);
     }
 
-    struct ftdi_device_list* list;
+    std::list<Context> list;
+    struct ftdi_device_list* devlist;
 };
 
 List::List(struct ftdi_device_list* devlist)
-        : ListBase(), d( new Private(devlist) )
+        : d( new Private(devlist) )
 {
     if (devlist != 0)
     {
         // Iterate list
-        for (d->list = devlist; d->list != 0; d->list = d->list->next)
+        for (; devlist != 0; devlist = devlist->next)
         {
             Context c;
-            c.set_usb_device(d->list->dev);
+            c.set_usb_device(devlist->dev);
             c.get_strings();
-            push_back(c);
+            d->list.push_back(c);
         }
     }
 }
@@ -421,6 +435,42 @@ List::~List()
 {
 }
 
+int List::size()
+{
+   return d->list.size();
+}
+
+void List::push_front(const Context& element)
+{
+   d->list.push_front(element);
+}
+
+
+void List::push_back(const Context& element)
+{
+   d->list.push_back(element);
+}
+
+void List::clear()
+{
+    d->list.clear();
+
+    // Free device list
+    ftdi_list_free(&d->devlist);
+    d->devlist = 0;
+}
+
+std::list<Context>::iterator List::begin()
+{
+   return d->list.begin();
+}
+
+std::list<Context>::iterator List::end()
+{
+   return d->list.end();
+}
+
+
 List* List::find_all(int vendor, int product)
 {
     struct ftdi_device_list* dlist = 0;