2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef UTILITIES_H
|
|
|
|
#define UTILITIES_H
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_gfxPrimitives.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <ext/hash_map>
|
|
|
|
|
|
|
|
using __gnu_cxx::hash_map;
|
|
|
|
using __gnu_cxx::hash;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace __gnu_cxx {
|
|
|
|
template<> struct hash< std::string > {
|
|
|
|
size_t operator()( const std::string& x ) const {
|
|
|
|
return hash< const char* >()( x.c_str() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
struct eqstr {
|
|
|
|
bool operator()(const char* s1, const char* s2) const {
|
|
|
|
return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class case_less {
|
|
|
|
public:
|
2010-05-02 15:29:09 +03:00
|
|
|
bool operator()(const string &left, const string &right) const;
|
2010-02-04 13:33:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
string trim(const string& s);
|
2010-05-02 15:29:09 +03:00
|
|
|
string strreplace (string orig, const string &search, const string &replace);
|
2010-02-04 13:33:47 +02:00
|
|
|
string cmdclean (string cmdline);
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
char *string_copy(const string &);
|
|
|
|
void string_copy(const string &, char **);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
bool fileExists(const string &file);
|
2010-02-04 13:33:47 +02:00
|
|
|
bool rmtree(string path);
|
|
|
|
|
|
|
|
int max (int a, int b);
|
|
|
|
int min (int a, int b);
|
|
|
|
int constrain (int x, int imin, int imax);
|
|
|
|
|
|
|
|
int evalIntConf (int val, int def, int imin, int imax);
|
|
|
|
int evalIntConf (int *val, int def, int imin, int imax);
|
2010-05-02 15:29:09 +03:00
|
|
|
const string &evalStrConf (const string &val, const string &def);
|
|
|
|
const string &evalStrConf (string *val, const string &def);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
|
|
|
bool split (vector<string> &vec, const string &str, const string &delim, bool destructive=true);
|
|
|
|
|
|
|
|
int intTransition(int from, int to, long int tickStart, long duration=500, long tickNow=-1);
|
|
|
|
|
|
|
|
#endif
|