std_headers.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00033 #ifndef __std_headers__header__
00034 #define __std_headers__header__
00035 
00036 #ifdef __BORLANDC__
00037 #define __STD_ALGORITHM
00038 #endif
00039 
00040 #if defined(GCC_VISIBILITY)
00041 
00048 #   pragma GCC visibility push(default)
00049 #endif
00050 
00051 #include <cassert>
00052 #include <cstdio>
00053 #include <cstdlib>
00054 #include <ctime>
00055 #include <cstring>
00056 #include <cstdarg>
00057 #include <cmath>
00058 
00059 // STL containers
00060 #include <vector>
00061 #include <map>
00062 #include <string>
00063 #include <set>
00064 #include <list>
00065 #include <deque>
00066 #include <queue>
00067 #include <bitset>
00068 
00069 //STL exception
00070 #include <exception>
00071 
00072 // STL algorithms & functions
00073 #include <algorithm>
00074 #include <functional>
00075 #include <limits>
00076 
00077 // C++ Stream stuff
00078 #include <fstream>
00079 #include <iostream>
00080 #include <iomanip>
00081 #include <iterator>
00082 #include <sstream>
00083 
00084 #ifdef __BORLANDC__
00085 
00086 #endif
00087 
00088 extern "C" {
00089 
00090 #include <sys/types.h>
00091 #include <sys/stat.h>
00092 
00093 }
00094 
00095 #if PLATFORM == PLATFORM_WIN32
00096 #undef min
00097 #undef max
00098 #if defined( __MINGW32__ )
00099 #include <unistd.h>
00100 #endif
00101 #endif
00102 
00103 #if PLATFORM == PLATFORM_LINUX
00104 extern "C" {
00105 
00106 #include <unistd.h>
00107 #include <dlfcn.h>
00108 
00109 }
00110 #endif
00111 
00112 #if PLATFORM == PLATFORM_APPLE
00113 extern "C" {
00114 
00115 #include <unistd.h>
00116 #include <sys/param.h>
00117 #include <CoreFoundation/CoreFoundation.h>
00118 
00119 }
00120 #endif
00121 
00122 
00123 #if defined(GCC_VISIBILITY)
00124 #pragma GCC visibility pop
00125 #endif
00126 
00127 
00128 
00129 
00130 namespace gpucalc
00131 {
00132  template <typename T> inline bool addToContainer(const T & what, std::list<T> & Container)
00133  {
00134   typename std::list<T>::iterator i = std::find(Container.begin(), Container.end(), what);
00135   if (i != Container.end())
00136   {
00137    return false;
00138   }
00139   else
00140   {
00141    Container.push_back(what);
00142    return true;
00143   }
00144  }
00145 
00146 
00147  template <typename T> inline bool removeFromContainer(const T & what, std::list<T> & Container)
00148  {
00149   typename std::list<T>::iterator i = std::find(Container.begin(), Container.end(), what);
00150   if (i != Container.end())
00151   {
00152    Container.erase(i);
00153    return true;
00154   }
00155   else
00156   {
00157    return false;
00158   }
00159  }
00160 
00161  
00162  template <typename T> inline void clearContainer(std::list<T> & Container)
00163  {
00164   for (typename std::list<T>::iterator i = Container.begin(); i != Container.end(); ++i)
00165   {
00166    delete (*i);
00167   }
00168   Container.clear();
00169  }
00170  
00171 
00172  template <typename T> inline bool addToContainer(const T & what, std::vector<T> & Container)
00173  {
00174   typename std::vector<T>::iterator i = std::find(Container.begin(), Container.end(), what);
00175   if (i != Container.end())
00176   {
00177    return false;
00178   }
00179   else
00180   {
00181    Container.push_back(what);
00182    return true;
00183   }
00184  }
00185 
00186 
00187  template <typename T> inline bool removeFromContainer(const T & what, std::vector<T> & Container)
00188  {
00189   typename std::vector<T>::iterator i = std::find(Container.begin(), Container.end(), what);
00190   if (i != Container.end())
00191   {
00192    Container.erase(i);
00193    return true;
00194   }
00195   else
00196   {
00197    return false;
00198   }
00199  }
00200 
00201  
00202  template <typename T> inline void clearContainer(std::vector<T> & Container)
00203  {
00204   for (typename std::vector<T>::iterator i = Container.begin(); i != Container.end(); ++i)
00205   {
00206    delete (*i);
00207   }
00208   Container.clear();
00209  }
00210 
00211 
00212  template <typename T, typename Y> inline bool addToContainer(const T & what, const Y & where, std::map<Y, T> & Container)
00213  {
00214   typename std::map<Y, T>::iterator i = Container.find(where);
00215   if (i != Container.end())
00216   {
00217    return false;
00218   }
00219   else
00220   {
00221    Container.insert(std::make_pair(where, what));
00222    return true;
00223   }
00224  }
00225 
00226 
00227  template <typename T, typename Y> inline bool removeFromContainer(const Y & where, std::map<Y, T> & Container)
00228  {
00229   typename std::map<Y, T>::iterator i = Container.find(where);
00230   if (i != Container.end())
00231   {
00232    Container.erase(i);
00233    return true;
00234   }
00235   else
00236   {
00237    return false;
00238   }
00239  }
00240 
00241 
00242  template <typename T, typename Y> inline void clearContainer(std::map<Y, T> & Container)
00243  {
00244   for (typename std::map<Y, T>::iterator i = Container.begin(); i != Container.end(); ++i)
00245   {
00246    delete (i->second);
00247   }
00248   Container.clear();
00249  }
00250 
00251 
00252  
00253 }
00254 
00255 
00256 #endif

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6