- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/ListManipulator.cpp

    00001 //==============================================================================
    00002 // Copyright (c) 2001           Model-based Embedded and Robotic Systems Group
    00003 // All Rights Reserved          Massachusetts Institute of Technology
    00004 //
    00005 // This software is provided as is. Model-based Embedded and Robotic Systems
    00006 // (MERS) group does not assume any responsibility.
    00007 //==============================================================================
    00008
    00009 #include "ListManipulator.h"
    00010
    00011 //#include <functional>
    00012 #include <cassert>
    00013
    00014 using namespace std;
    00015
    00016 /*#
    00017 template<typename CT>
    00018 class less
    00019 {
    00020         public:
    00021                 typedef bool (*comp_func)(CT, CT);
    00022                 comp_func const   comparison;
    00023
    00024                 less(comp_func cf)
    00025                 {
    00026                         comparison = cf;
    00027                 };
    00028
    00029                 bool operator()(CT left, CT right) const
    00030                 {
    00031                         return (comparison(left, right));
    00032                 };
    00033 };
    00034 */
    00035
    00036 /*#
    00037 //template<typename T>
    00038 //ListManipulator<T>::ListManipulator<T>()
    00039 //{
    00040 //}
    00041 */
    00042
    00043 /*#
    00044 template<typename T>
    00045 void
    00046 ListManipulator<T>::sort(list<T> &lst, comp_func comp) const
    00047 {
    00049         list<T> tmp = lst;
    00050         lst.clear();
    00051
    00052         typename list<T>::iterator tmpIter;
    00053         for (tmpIter = tmp.begin(); tmpIter != tmp.end(); tmpIter++)
    00054         {
    00055                 merge(lst, *tmpIter, comp);
    00056         }
    00057 }
    00058 */
    00059
    00060 /*#
    00061 template<typename T>
    00062 void
    00063 ListManipulator<T>::merge(list<T> &lst1, list<T> const &lst2, comp_func comp) const
    00064 {
    00065         typename list<T>::iterator listIter;
    00066         typename list<T>::const_iterator otherIter;
    00067
    00068         bool finishedOrigList = false;
    00069         for (otherIter = lst2.begin(), listIter = lst1.begin();
    00070              otherIter != lst2.end(); otherIter++)
    00071         {
    00072                 if (finishedOrigList || listIter == lst1.end())
    00073                 {
    00074                         finishedOrigList = true;
    00075                         lst1.push_back((*otherIter));
    00076                 } else
    00077                 {
    00078                         while ( listIter != lst1.end() && comp(*listIter, *otherIter) )
    00079                         {
    00080                                 listIter++;
    00081                         }
    00082                         if (listIter == lst1.end())
    00083                         {
    00084                                 finishedOrigList = true;
    00085                                 lst1.push_back((*otherIter));
    00086                         } else
    00087                         {
    00088                                 lst1.insert(listIter, *otherIter);
    00089                         }
    00090                 }
    00091         }
    00092 }
    00093 */
    00094
    00095 /*#
    00096 template<typename T>
    00097 void
    00098 ListManipulator<T>::merge(list<T> &lst1, T item, comp_func comp) const
    00099 {
    00100         typename list<T>::const_iterator iter;
    00101
    00102         for (iter = lst1.begin(); iter != lst1.end(); iter++)
    00103         {
    00104                 if (!(comp(*iter, item)))
    00105                 {
    00106                         lst1.insert(iter, item);
    00107                         return;
    00108                 }
    00109         }
    00110         lst1.push_back(item);
    00111 }
    00112 */
    00113
    00114
    00115 /*#
    00116 template<typename T>
    00117 list<T>
    00118 ListManipulator<T>::merge_out(list<T> const &lst1, list<T> const &lst2, comp_func comp) const
    00119 {
    00120         list<T> res;
    00121         typename list<T>::const_iterator firstIter;
    00122         typename list<T>::const_iterator secondIter;
    00123
    00124         for (firstIter = lst1.begin(), secondIter = lst2.begin();
    00125              firstIter != lst1.end() || secondIter != lst2.end();
    00126             )
    00127         {
    00128                 if (firstIter == lst1.end())
    00129                 {
    00130                         res.push_back((*secondIter));
    00131                 } else
    00132                 if (secondIter == lst2.end())
    00133                 {
    00134                         res.push_back((*firstIter));
    00135                 } else
    00136                 {
    00137                         if (comp(*firstIter, *secondIter))
    00138                         {
    00139                                 res.push_back(*firstIter);
    00140                                 firstIter++;
    00141                         } else
    00142                         {
    00143                                 res.push_back(*secondIter);
    00144                                 secondIter++;
    00145                         }
    00146                 }
    00147         }
    00148
    00149         return res;
    00150 }
    00151 */
    00152