Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

QCollection.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_Pattern_QCollection_h
00002 #define Impala_Core_Array_Pattern_QCollection_h
00003 
00004 #include <iostream>
00005 #include <string>
00006 #include <set> 
00007 #include <queue> 
00008 #include <stack> 
00009 #include <map>
00010 
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace Array
00016 {
00017 namespace Pattern
00018 {
00019 
00020 
00021 template <class T> 
00022 class Qset {
00023 private:
00024     typedef std::set<T> Container;
00025     Container container;
00026     Qset(const Qset &);
00027     Qset& operator= (const Qset &);
00028 public:
00029     //typedef Container::size_type size_type;
00030     typedef typename Container::iterator iterator;
00031     //typedef Container::const_iterator const_iterator;
00032     Qset() {}
00033     ~Qset() {}
00034     bool empty() const { return container.empty(); }
00035     typename Container::size_type size() const { return container.size(); }
00036     void clear() { container.clear(); }
00037     void push(const T &val) { container.insert(val); }
00038     void erase(iterator iter) { container.erase(iter); }
00039     iterator after_upper_bound(const T &val) { 
00040         iterator iter=container.upper_bound(val); 
00041         if (iter!=container.end()) iter++; 
00042         return iter; 
00043     }
00044     iterator lower_bound(const T &val) { return container.lower_bound(val); }
00045     void pop() { container.erase(container.begin()); }
00046     //T & top() { return *container.begin(); }
00047     typedef typename Container::const_reference const_reference;
00048     const_reference top() { return *container.begin(); }
00049 };
00050 
00051 class Int {
00052 private:
00053     int val;
00054 public:
00055     Int() : val(0) {}
00056     void operator ++ (int) { val++; } // Postfix increment operator
00057     operator int() const { return val; }
00058 };
00059 
00060 class Bugs {
00061 private:
00062     std::map<int,Int> m;
00063     //Bugs();
00064     Bugs(const Bugs &);
00065     Bugs & operator = (const Bugs &);
00066     std::string fn;
00067 public:
00068     Bugs(const char *cc=__FILE__) : fn(cc) {}
00069     void plusplus(int i) { m[i]++; }
00070     ~Bugs() { 
00071         if (!m.empty()) {
00072             std::cout << m.size() << "Bugs founds in file " << fn << std::endl;
00073         }
00074         for (std::map<int,Int>::const_iterator iter=m.begin(); iter!=m.end();
00075              iter++) {
00076             std::cout << "error in line " << iter->first <<", #=" << iter->second 
00077                       << std::endl;
00078         }
00079     }
00080 };
00081 
00082 template <class T>
00083 class Qpriority_queue {
00084 private:
00085     typedef std::priority_queue<T> Container;
00086     Container container;
00087     Qpriority_queue(const Qpriority_queue &);
00088     Qpriority_queue & operator = (const Qpriority_queue &);
00089     Bugs bugs;
00090 public:
00091     Qpriority_queue() {}
00092     ~Qpriority_queue() {}
00093     bool empty() const { return container.empty(); }
00094     typename Container::size_type size() const { return container.size(); }
00095     void push(const T &val) { container.push(val); }
00096     void pop() { container.pop(); }
00097     T & top() { return container.top(); }
00098     // stuff below is not valid !!
00099     typedef T *iterator;
00100     void clear() { bugs.plusplus(__LINE__); }
00101     void erase(iterator iter) { bugs.plusplus(__LINE__); }
00102     iterator lower_bound(const T &val) { bugs.plusplus(__LINE__); return NULL; }
00103     iterator after_upper_bound(const T &val) { bugs.plusplus(__LINE__); return NULL; }
00104 };
00105 
00106 /*
00107 BUG: the MS VC file <queue> doesnt implement std::queue::top()
00108 and I'd like to have clear()
00109 This bug is probably fixed in VS2005 and beyond, workaround breaks NVCC2.3win
00110 */
00111 template<class Ty, class  C> 
00112 class msvcqueue : public std::queue<Ty, C> {
00113 };
00114 
00115 
00116 template <class T>
00117 class Qqueue {
00118 private:
00119     //typedef std::queue<T> Container;
00120     //typedef msvcqueue<T, std::vector<T> > Container; //damn container.pop() --> c.pop_front() which is not a member of std::vector<T>
00121     typedef msvcqueue<T, std::deque<T> > Container; 
00122     Container container;
00123     Qqueue(const Qqueue &);
00124     Qqueue & operator = (const Qqueue &);
00125     Bugs bugs;
00126 public:
00127     Qqueue() {}
00128     ~Qqueue() {}
00129     bool empty() const { return container.empty(); }
00130     typename Container::size_type size() const { return container.size(); }
00131     void push(const T &val) { container.push(val); }
00132     void pop() { container.pop(); }
00133     T & top() { return container.top(); }
00134     // stuff below is not valid !!
00135     typedef T *iterator;
00136     void clear() { bugs.plusplus(__LINE__); }
00137     //void clear() { container.clear(); }
00138     void erase(iterator iter) { bugs.plusplus(__LINE__); }
00139     iterator lower_bound(const T &val) { bugs.plusplus(__LINE__); return NULL; }
00140     iterator after_upper_bound(const T &val) { bugs.plusplus(__LINE__); return NULL; }
00141 };
00142 
00143 /*
00144 I'd like to have clear()
00145 */
00146 template<class Ty, class C>
00147 class msvcstack : public std::stack<Ty, C> {
00148 public:
00149     //void clear() { c.clear(); } // untested
00150 };
00151 
00152 
00153 template <class T>
00154 class Qstack {
00155 private:
00156     //typedef std::stack<T> Container;
00157     //typedef msvcstack<T, std::deque<T> > Container;
00158     typedef msvcstack<T, std::vector<T> > Container;
00159     Container container;
00160     Qstack(const Qstack &);
00161     Qstack & operator = (const Qstack &);
00162     Bugs bugs;
00163 public:
00164     Qstack() {}
00165     ~Qstack() {}
00166     bool empty() const { return container.empty(); }
00167     typename Container::size_type size() const { return container.size(); }
00168     void push(const T &val) { container.push(val); }
00169     void pop() { container.pop(); }
00170     T & top() { return container.top(); }
00171     // stuff below is not valid !!
00172     typedef T* iterator;
00173     void clear() { bugs.plusplus(__LINE__); }
00174     //void clear() { container.clear(); }
00175     void erase(iterator iter) { bugs.plusplus(__LINE__); }
00176     iterator lower_bound(const T &val) { bugs.plusplus(__LINE__); return NULL; }
00177     iterator after_upper_bound(const T &val) { bugs.plusplus(__LINE__); return NULL; }
00178 };
00179 
00180 } // namespace Pattern
00181 } // namespace Array
00182 } // namespace Core
00183 } // namespace Impala
00184 
00185 #endif

Generated on Fri Mar 19 09:30:52 2010 for ImpalaSrc by  doxygen 1.5.1