00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include "./Utility.h"
00060
00061 #include <iostream>
00062
00063 using std::cout;
00064 using std::cerr;
00065 using std::endl;
00066
00067
00068
00069 namespace CIMPL
00070 {
00071
00072
00073
00074 Utility::Utility(void)
00075 {
00076 }
00077
00078
00079 Utility::~Utility(void)
00080 {
00081 }
00082
00083
00084 void Utility::RunTimeError(char *message)
00085 {
00086 cerr << "Run Time Error!" << endl;
00087 cerr << message << endl;
00088 cerr << "Exiting now..." << endl << endl;
00089 exit(1);
00090 }
00091
00092
00093 void Utility::Warning(char *message)
00094 {
00095 cout << "Warning!" << endl;
00096 cout << message << endl << endl ;
00097 }
00098
00099
00100 void Utility::CheckPointer(void *p)
00101 {
00102 if(p == 0)
00103 {
00104 cerr << "Memory Allocation Error. May be out of memory!" << endl;
00105 cerr << "Exiting now..." << endl << endl;
00106 exit(1);
00107 }
00108 }
00109
00110 vector<string> Utility::Split(const string& str, const string& delimiters)
00111 {
00112 std::vector<string> tokens;
00113 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00114 string::size_type pos = str.find_first_of(delimiters, lastPos);
00115 while (string::npos != pos || string::npos != lastPos)
00116 {
00117 tokens.push_back(str.substr(lastPos, pos - lastPos));
00118 lastPos = str.find_first_not_of(delimiters, pos);
00119 pos = str.find_first_of(delimiters, lastPos);
00120 }
00121 return tokens;
00122 }
00123
00124 string Utility::Join(vector<string>& tokens, const string delim)
00125 {
00126 string temp = "";
00127
00128 vector<string>::const_iterator constIterator;
00129 int i = 0;
00130 for(constIterator = tokens.begin(); constIterator != tokens.end(); constIterator++)
00131 {
00132 if(i != 0)
00133 {
00134 temp += delim;
00135 }
00136 temp += *constIterator;
00137 i++;
00138 }
00139
00140 return temp;
00141 }
00142
00143
00144 int Utility::ToInt(string &s)
00145 {
00146 int temp;
00147 std::stringstream ss(s);
00148 ss >> temp;
00149 return temp;
00150 }
00151
00152
00153 double Utility::ToDouble(string &s)
00154 {
00155 double temp;
00156 std::stringstream ss(s);
00157 ss >> temp;
00158 return temp;
00159 }
00160
00161
00162
00163
00164
00165
00166 };
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178