1 #ifndef __JEEP__JEEPTOOLKIT__
2 #define __JEEP__JEEPTOOLKIT__
22 namespace JPP {
using namespace JEEP; }
30 static const char*
const PATH =
"PATH";
31 static const char*
const SHELL =
"SHELL";
47 inline std::string
strip(
const std::string& file_name)
51 string::const_iterator p = file_name. begin();
52 string::const_reverse_iterator q = file_name.rbegin();
54 for ( ; p != file_name.end() && q != file_name.rend() && isspace(*p); ++p) {}
55 for ( ; p != file_name.end() && q != file_name.rend() && isspace(*q); ++q) {}
57 return string(p,q.base());
73 if (pos != string::npos)
74 return file_name.substr(pos + 1);
90 const string buffer =
strip(file_name);
93 if (pos != string::npos)
94 return buffer.substr(pos + 1);
106 inline std::string
getPath(
const std::string& file_name)
110 const string buffer =
strip(file_name);
113 if (pos != string::npos)
114 return buffer.substr(0, pos + 1);
130 const string buffer =
strip(path);
150 inline std::string
getFilename(
const std::string& path,
const std::string& file_name)
157 return strip(file_name);
159 return buffer +
strip(file_name);
174 inline std::string
getPath(
const std::string& variable,
const std::string& file_name)
182 const string buffer(getenv(variable.c_str()));
184 if (!buffer.empty()) {
191 path = buffer.substr(pos,len);
193 }
while (!ifstream(
getFilename(path, file_name).c_str()).good() && len != string::npos && (pos += len + 1) != buffer.length());
197 if (ifstream(
getFilename(path, file_name).c_str()).good())
211 inline std::string
getFullFilename(
const std::string& variable,
const std::string& file_name)
229 if (pos != string::npos)
230 return type_name.substr(0, pos);
248 if (pos != string::npos)
249 return type_name.substr(pos + 2);
267 if (pos != string::npos)
268 return file_name.substr(0, pos);
292 inline T*
open(
const std::string& file_name);
302 inline std::istream*
open(
const std::string& file_name)
310 return new ifstream (file_name.c_str());
323 inline std::ostream*
open(
const std::string& file_name)
331 return new ofstream (file_name.c_str());
347 if (dynamic_cast<ifstream*> (pf) != NULL) { dynamic_cast<ifstream*> (pf)->close();
return; }
348 if (dynamic_cast<igzstream*>(pf) != NULL) { dynamic_cast<igzstream*>(pf)->close();
return; }
362 if (dynamic_cast<ofstream*> (pf) != NULL) { dynamic_cast<ofstream*> (pf)->close();
return; }
363 if (dynamic_cast<ogzstream*>(pf) != NULL) { dynamic_cast<ogzstream*>(pf)->close();
return; }