Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
myperl.h
00001 /**************************************************************************
00002  * Copyright (c) 2002-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 
00021 // Purpose: to define a global variable that points to a perl interpreter.
00022 
00023 #ifndef _MYPERL_H
00024 #define _MYPERL_H
00025 
00026 #include <string>
00027 #include <vector>
00028 
00029 using namespace std;
00030 
00031 // see p. 540 of the second edition of the camel book.
00032 #include <EXTERN.h>
00033 #include <perl.h>
00034 
00035 static PerlInterpreter *my_perl = NULL;
00036 
00037 
00038 // functions in perlmatch.C
00039 // SV* my_eval_sv(SV *sv, I32 croak_on_error);
00040 bool perl_match(string text, string pattern);
00041 I32 perl_match(SV *string, const char *pattern);
00042 int perl_substitute(string& text, string pattern);
00043 I32 perl_substitute(SV **string, const char *pattern);
00044 I32 perl_matches(SV *string, const char *pattern, AV **match_list);
00045 int perl_split(string text, string pattern, vector< string >& item_list);
00046 I32 perl_split(SV *string, const char *pattern, AV **item_list);
00047 
00048 
00049 inline void perlInit(int argc, char **argv)
00050 {
00051   char *embedding[] = { "", "-e", "0" };
00052   my_perl = perl_alloc();
00053   perl_construct(my_perl);
00054   // the 3 below refers to the number of args i am passing to perl in
00055   // embedding. see the perlembed manpage.
00056   perl_parse(my_perl, NULL, 3, embedding, (char **) NULL);
00057 }
00058 
00059 
00060 inline void perlKill()
00061 {
00062   perl_destruct(my_perl);
00063   perl_free(my_perl);
00064 }
00065 
00066 
00067 
00068 #endif // _MYPERL_H 
 All Classes Functions Variables Typedefs Friends