Open Babel  3.0
tokenst.h
Go to the documentation of this file.
1 /**********************************************************************
2 tokenst.h - Tokenize and trim strings; Open data files
3 
4 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
5 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
6 
7 This file is part of the Open Babel project.
8 For more information, see <http://openbabel.org/>
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation version 2 of the License.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 ***********************************************************************/
19 
20 #ifndef OB_TOKENST_H
21 #define OB_TOKENST_H
22 
23 #include <openbabel/babelconfig.h>
24 
25 #include <vector>
26 #include <sstream>
27 #include <string>
28 #include <fstream>
29 
30 namespace OpenBabel
31 {
32  // Utility function prototypes
33  OBERROR bool tokenize(std::vector<std::string>&, const char *buf, const char *delimstr=" \t\n\r");
34  OBERROR bool tokenize(std::vector<std::string>&, std::string&, const char *delimstr=" \t\n\r", int limit=-1);
36  OBERROR std::string& Trim(std::string& txt);
37 
38  // \return a string representation of a variable
39  template<typename T>
40  std::string toString(T val)
41  {
42  std::ostringstream s;
43  s << val;
44  return s.str();
45  }
46 
48  struct DeleteObject
49  {
50  template<typename T>
51  void operator()(const T* ptr)const { delete ptr; }
52  };
53 
55  OBERROR std::istream& ignore(std::istream& ifs, const std::string& txt);
56 
58  // full documentation in tokenst.cpp
59  OBERROR std::string OpenDatafile(std::ifstream& fs,
60  const std::string& filename,
61  const std::string& envvar = "BABEL_DATADIR");
62 
63  // Used by other code for reading files
64 #ifdef WIN32
65  #define FILE_SEP_CHAR "\\"
66 #else
67 #define FILE_SEP_CHAR "/"
68 #endif
69 
70 
71 }//namespace
72 #endif
73 
Definition: residue.h:336
std::istream & ignore(std::istream &ifs, const std::string &txt)
Read and discard all characters from input stream up to, and including, a string. ...
Definition: tokenst.cpp:155
std::string OpenDatafile(std::ifstream &fs, const std::string &filename, const std::string &envvar="BABEL_DATADIR")
Opens a datafile in a directory where OpenBabel expects to find it.
Definition: tokenst.cpp:191
Functor for deleting containers of pointers. Scott Meyers, Effective STL, Item 7. ...
Definition: tokenst.h:48
bool tokenize(std::vector< std::string > &, const char *buf, const char *delimstr=" \\)
Definition: tokenst.cpp:36
std::string & Trim(std::string &txt)
Remove leading and trailing whitespace from a string (docs in tokenst.cpp)
Definition: tokenst.cpp:135
void operator()(const T *ptr) const
Definition: tokenst.h:51
std::string toString(T val)
Definition: tokenst.h:40
Global namespace for all Open Babel code.
Definition: alias.h:22