NCBI C++ ToolKit
njn_ioutil.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_IOUTIL
2 #define ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_IOUTIL
3 
4 /* $Id: njn_ioutil.hpp 44808 2010-02-18 16:10:58Z boratyng $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's offical duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================*/
28 
29 /*****************************************************************************
30 
31 File name: njn_ioutil.hpp
32 
33 Author: John Spouge
34 
35 Contents:
36 
37 ******************************************************************************/
38 
39 #include <corelib/ncbistl.hpp>
40 #include <sstream>
41 
43 BEGIN_SCOPE(blast)
44 
45 BEGIN_SCOPE(Njn)
46 BEGIN_SCOPE(IoUtil)
47 
48  char getTerminator (); // gets the terminator character; default '!'
49  void setTerminator (char t_); // sets the terminator character
50  char clearTerminator (); // resets the terminator character to and returns default
51 
52  enum Format {HUMAN, MACHINE, FORMAT}; // format type
53 
54  Format getFormat (); // gets the format type
55  void setFormat (Format format_); // sets the format type
56  Format clearFormat (); // resets the format type to and returns default
57 
58  void abort (); // abort
59  void abort (const std::string &s_);
60  inline void abort (const char *s_);
61 
62  std::istream &getLine (
63  std::istream &in_, // input filestream
64  std::string &str_, // string before '!' from next line
65  const char t_ = getTerminator ()); // termination character (could be '\n'; default '!')
66  // behaves like std::getline (in_, str_) but throws away the string after first character t_ && skips lines of white space
67 
68  template <typename T>
69  std::istream &getString (
70  std::istream &in_, // input filestream
71  T &value_, // string before '!' from next line
72  std::string &line_, // string before '!' from next line
73  const char t_ = getTerminator ()); // termination character (could be '\n'; default '!')
74  // extracts the first non-white-space string from the result of getLine (in_, str_, t_) and throws everything else away
75 
76  std::istream &getLine (
77  std::istream &in_, // input filestream
78  std::stringstream &sstr_, // string before '!' from next line
79  const char t_ = getTerminator ()); // termination character (could be '\n'; default '!')
80  // behaves like std::getline (in_, str_) but throws away the string after first character t_ && skips lines of white space
81 
82  std::istream &in (
83  std::istream &in_,
84  double &x_);
85 
86 END_SCOPE(IoUtil)
87 END_SCOPE(Njn)
88 
89 inline std::ostream &operator << (std::ostream &ostr_, Njn::IoUtil::Format format_);
90 inline std::istream &operator >> (std::istream &istr_, Njn::IoUtil::Format format_);
91 
92 //
93 // There are no more declarations beyond this point.
94 //
95 
96 BEGIN_SCOPE(Njn)
97 BEGIN_SCOPE(IoUtil)
98 
99  void abort (const char *s_)
100  {
101  abort (static_cast <const std::string> (s_));
102  }
103 
104  template <typename T>
105  std::istream &getString (
106  std::istream &in_, // input filestream
107  T &value_, // string before '!' from next line
108  std::string &line_, // string before '!' from next line
109  const char t_) // termination character (could be '\n')
110  { // behaves like getline (in_, str_) but throws away the string after first character t_ && skips lines of white space
111 
112  std::string line;
113  std::stringstream sstream;
115 
116  getLine (in_, line_, t_);
117  sstream << line_;
118  sstream >> std::skipws >> str;
119  sstream.str (str);
120  sstream.clear ();
121  sstream >> value_;
122 
123  return in_;
124  }
125 
126 END_SCOPE(IoUtil)
127 END_SCOPE(Njn)
128 
129 
130 std::ostream &operator << (std::ostream &ostr_, Njn::IoUtil::Format format_)
131 {
132  Njn::IoUtil::setFormat (format_);
133  return ostr_;
134 }
135 
136 std::istream &operator >> (std::istream &istr_, Njn::IoUtil::Format format_)
137 {
138  Njn::IoUtil::setFormat (format_);
139  return istr_;
140 }
141 
142 
143 END_SCOPE(blast)
145 
146 #endif //! ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_IOUTIL
#define T(s)
Definition: common.h:230
static const char * str(char *buf, int n)
Definition: stats.c:84
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
The NCBI C++/STL use hints.
char getTerminator()
Definition: njn_ioutil.cpp:74
std::istream & operator>>(std::istream &istr_, Njn::IoUtil::Format format_)
Definition: njn_ioutil.hpp:136
std::istream & getString(std::istream &in_, T &value_, std::string &line_, const char t_=getTerminator())
Definition: njn_ioutil.hpp:105
void setFormat(Format format_)
Definition: njn_ioutil.cpp:64
char clearTerminator()
Definition: njn_ioutil.cpp:84
Format clearFormat()
Definition: njn_ioutil.cpp:69
std::istream & in(std::istream &in_, double &x_)
std::istream & getLine(std::istream &in_, std::string &str_, const char t_=getTerminator())
std::ostream & operator<<(std::ostream &ostr_, Njn::IoUtil::Format format_)
Definition: njn_ioutil.hpp:130
Format
Definition: njn_ioutil.hpp:52
@ FORMAT
Definition: njn_ioutil.hpp:52
@ HUMAN
Definition: njn_ioutil.hpp:52
@ MACHINE
Definition: njn_ioutil.hpp:52
void setTerminator(char t_)
Definition: njn_ioutil.cpp:79
void abort()
Format getFormat()
Definition: njn_ioutil.cpp:59
#define const
Definition: zconf.h:232
Modified on Wed May 01 14:24:49 2024 by modify_doxy.py rev. 669887