SyFi  0.3
utilities.cpp
Go to the documentation of this file.
00001 // Copyright (C) 2006-2009 Kent-Andre Mardal and Simula Research Laboratory
00002 //
00003 // This file is part of SyFi.
00004 //
00005 // SyFi 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 // SyFi 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 SyFi. If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #include "utilities.h"
00019 #include "syfi_version.h"
00020 
00021 #include <sstream>
00022 #include <math.h>
00023 
00024 using namespace std;
00025 
00026 namespace SyFi
00027 {
00028 
00029         /* Version information buried into the library */
00030         const int version_major = SYFILIB_MAJOR_VERSION;
00031         const int version_minor = SYFILIB_MINOR_VERSION;
00032         const char* version_micro = SYFILIB_MICRO_VERSION;
00033 
00034         int dirac(unsigned int i, unsigned int j)
00035         {
00036                 if (i==j) return 1;
00037                 else return 0;
00038         }
00039 
00040         string int2string(int i)
00041         {
00042                 ostringstream os;
00043                 os << i;
00044                 return os.str();
00045         }
00046 
00047         string istr(const string & a, int b)
00048         {
00049                 ostringstream s;
00050                 s << a << b;
00051                 return s.str();
00052         }
00053 
00054         string istr(const string & a, int b, int c)
00055         {
00056                 ostringstream s;
00057                 s << a << b << "_" <<c;
00058                 return s.str();
00059         }
00060 
00061         string lst2string(GiNaC::lst& l)
00062         {
00063 
00064                 ostringstream s;
00065                 GiNaC::lst::const_iterator i = l.begin();
00066                 s <<"("<<*i;
00067                 ++i;
00068 
00069                 for (; i != l.end() ; ++i)
00070                 {
00071                         s<< ","<< *i;
00072                 }
00073                 s <<");"<<endl;
00074                 return s.str();
00075         }
00076 
00077         string exvector2string(GiNaC::exvector& v)
00078         {
00079                 ostringstream s;
00080                 s <<"[";
00081                 for (unsigned int i=0; i< v.size()-1; i++)
00082                 {
00083                         s <<v[i]<<",";
00084                 }
00085                 s<<v[v.size()-1]<< "]";
00086                 return s.str();
00087         }
00088 
00089         void print(GiNaC::lst& l)
00090         {
00091                 //  for (GiNaC::lst::const_iterator i = l.begin(); i != l.end(); ++i)
00092                 //    cout << *i << endl;
00093                 //
00094                 GiNaC::lst::const_iterator i = l.begin();
00095                 cout <<"GiNaC::lst("<<*i;
00096                 ++i;
00097 
00098                 for (; i != l.end() ; ++i)
00099                 {
00100                         cout << ","<< *i;
00101                 }
00102                 cout <<");"<<endl;
00103         }
00104 
00105         void print(GiNaC::exvector& v)
00106         {
00107                 cout <<"v=[";
00108                 for (unsigned int i=0; i< v.size()-1; i++)
00109                 {
00110                         cout <<v[i]<<"," <<endl;
00111                 }
00112                 cout <<v[v.size()-1]<< "]"<<endl;
00113         }
00114 
00115         void print(std::map<std::pair<unsigned int,unsigned int>, GiNaC::ex>& A)
00116         {
00117                 map<std::pair<unsigned int,unsigned int>,GiNaC::ex>::iterator iter;
00118                 for (iter = A.begin(); iter != A.end() ; iter++)
00119                 {
00120                         cout <<"A["<<(*iter).first.first<<","<<(*iter).first.second<<"]="<<(*iter).second<<endl;
00121                 }
00122         }
00123 
00124         void print(ex_int_map map)
00125         {
00126                 GiNaC::ex b;
00127                 int c=0;
00128                 ex_int_map::iterator iter;
00129                 iter = map.begin();
00130                 cout <<"{";
00131                 for (iter = map.begin(); iter != map.end(); iter++)
00132                 {
00133                         b = (*iter).first; c = map[b];
00134                         cout <<", "<<b<<":"<<c;
00135                 }
00136                 cout <<"}"<<endl;
00137         }
00138 
00139         void print(GiNaC::exmap map)
00140         {
00141                 GiNaC::ex b;
00142                 GiNaC::ex c;
00143                 GiNaC::exmap::iterator iter;
00144                 cout <<"{" <<b<<":"<<c;
00145                 for (iter = map.begin(); iter != map.end(); iter++)
00146                 {
00147                         b = (*iter).first; c = map[b];
00148                         cout <<", "<<b<<":"<<c;
00149                 }
00150                 cout <<"}"<<endl;
00151         }
00152 
00153 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator