Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
poorperl.h
00001 /**************************************************************************
00002  * Copyright (c) 2004-2011 T. M. Murali                                   *
00003  *                                                                        *
00004  * This file is part of Biorithm.                                         *
00005  *                                                                        *
00006  * Biorithm is free software: you can redistribute it and/or modify       *
00007  * it under the terms of the GNU General Public License as published by   *
00008  * the Free Software Foundation, either version 3 of the License, or      *
00009  * (at your option) any later version.                                    *
00010  *                                                                        *
00011  * Biorithm is distributed in the hope that it will be useful,            *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00014  * GNU General Public License for more details.                           *
00015  *                                                                        *
00016  * You should have received a copy of the GNU General Public License      *
00017  * along with Biorithm.  If not, see <http://www.gnu.org/licenses/>.      *
00018  *                                                                        *
00019  **************************************************************************/
00020 
00028 #ifndef _POORPERL_H
00029 #define _POORPERL_H
00030 
00031 #include <map>
00032 #include <string>
00033 #include <vector>
00034 
00035 using namespace std;
00036 
00037 // like Perl's exists() function to check if a key exists in a map. 
00038 // will work for a set too.
00039 template < class Container, class Item >
00040 bool exists(const Container &container, const Item &item)
00041 {
00042   return(container.end() != container.find(item));
00043 }
00044 
00045 
00046 // like Perl's exists() function to check if a key exists in a map. 
00047 // but also returns the value.
00048 template< class Key, class Value >
00049 bool exists(const map< Key, Value > &mymap, const Key &key, Value &value)
00050 {
00051   typename map< Key, Value >::const_iterator itr;
00052   itr = mymap.find(key);
00053   bool found = (mymap.end() != itr);
00054   if (found)
00055     value = (*itr).second;
00056   return(found);
00057 }
00058 
00059 
00060 
00061 char read_till_char(istream &istr, string &name, string limits,
00062                                 string ignore = "");
00063 // read a line from istr and store in line.
00064 inline void read_line(istream &istr, string &line)
00065 {
00066   read_till_char(istr, line, "\n");
00067 }
00068 
00069 
00070 // emulating perl_match(text, "m/\\S/"). used in gene.C and read.C,
00071 // for example.
00072 bool string_matches_non_space(const string &text);
00073 // emulating perl_match(text, "m/pattern/")
00074 bool string_matches(const string &text, const string &pattern);
00075 string::size_type string_split(const string &text, const string &splitters,
00076                                vector< string > &items);
00077 void string_substitute(string &text, const string &original,
00078                        const string &substitute);
00079 
00080 
00081 
00082 #endif // _POORPERL_H 
 All Classes Functions Variables Typedefs Friends