// Utils.H -*- C++ -*- // Copyright (c) 1997, 1998 Etienne BERNARD // Copyright (c) 2002,2005,2008 Clinton Ebadi // 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 // 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., 51 Franklin Street, Fifth Floor, Boston, MA // 02110-1301, USA. #ifndef UTILS_H #define UTILS_H #ifndef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include class Bot; #ifdef USESCRIPTS #include #endif namespace Utils { std::string get_nick (std::string); std::string get_userhost (std::string); std::string get_key(); int get_level (Bot *, std::string); int get_level (Bot *, std::string, std::string); std::string make_wildcard (std::string); // predicates bool channel_p (std::string); bool wildcard_p (std::string); bool valid_channel_name_p (std::string); bool valid_nickname_p (const Bot *, std::string); bool IP_p (std::string); std::string level2str (int); std::string prot2str (int); std::string bool2str (bool); std::string long2str (long); std::time_t str2time(std::string); // string case conversion std::string to_lower (std::string); std::string to_upper (std::string); std::string trim_str (std::string); #ifdef USESCRIPTS std::string scm2str (SCM); SCM str2scm (std::string); #endif // Class to compare *i1 / *i2 in heaps etc. template class IndirectPred { C compare; public: bool operator() (const T * i1, const T * i2) const { return compare (*i1, *i2); } typedef T* first_argument_type; typedef T* second_argument_type; typedef bool result_type; }; template void push_sorted (std::list & storage, T item, C compare) { storage.insert (std::find_if (storage.begin (), storage.end (), std::bind1st (compare, item)), item); } } #endif