36#ifndef _CHOMP_SYSTEM_TEXTFILE_H_
37#define _CHOMP_SYSTEM_TEXTFILE_H_
68 bool _show =
true,
bool _flush =
false);
75 void logfile (
const char *filename);
141 bool _flush): out (_out)
168 logstream =
new std::ofstream (filename);
173 out <<
"WARNING: Can't create '" << filename <<
174 "'. Logging to a file has been turned off." <<
226template<
typename type>
232 out. out <<
object << std::flush;
233 if (out. log && out. getlogstream ())
234 (*(out. getlogstream ())) <<
object << std::flush;
240 if (out. log && out. getlogstream ())
241 (*(out. getlogstream ())) << object;
253 out. out <<
object << std::flush;
254 if (out. log && out. getlogstream ())
255 (*(out. getlogstream ())) <<
object << std::flush;
261 if (out. log && out. getlogstream ())
262 (*(out. getlogstream ())) << object;
270 std::ostream& (*
object)(std::ostream&))
275 out. out <<
object << std::flush;
276 if (out. log && out. getlogstream ())
277 (*(out. getlogstream ())) <<
object << std::flush;
283 if (out. log && out. getlogstream ())
284 (*(out. getlogstream ())) << object;
299extern outputstream
sout;
303extern outputstream
scon;
306extern outputstream
serr;
311extern outputstream
slog;
315extern outputstream
sbug;
319extern outputstream
sseq;
349 if (tab [0] == tab [1])
351 else if (tab [0] > tab [1])
355 for (
int i = 0; i < n - 1; ++ i)
357 for (
int j = i + 1; j < n; ++ j)
358 if (tab [i] > tab [j])
362 if (tab [i] == tab [i + 1])
365 for (
int j = i + 1; j < n; ++ j)
366 tab [j] = tab [j + 1];
378 in. ignore (0x7FFFFFFFl,
'\n');
387 int ch = in. peek ();
444 for (
int i = 0; i < argc; ++ i)
458 return std::asctime (std::localtime (&t));
467template <
class settype>
469 const char *filename,
const char *name)
478 str = std::string (prefix) + std::string (filename);
481 const char *s = str. c_str ();
484 std::ofstream out (s);
487 sout <<
"WARNING: Cannot save the file '" << s <<
"'.\n";
492 sout <<
"Saving " << name <<
" to '" << s <<
"'... ";
493 out <<
"; This is " << name <<
".\n";
521#define ERRORMSG {std::ostringstream error_msg_string; error_msg_string
525#define THROW ""; throw error_msg_string. str (). c_str (); }
532inline void fileerror (
const char *filename,
const char *what =
"open")
534 ERRORMSG <<
"Cannot " << what <<
" the file '" <<
535 filename <<
"'." <<
THROW
546#define MAXTEXTLENGTH 200
568 int open (
const char *filename);
579 long readnumber (
long defaultnumber = 0,
int ignorecolons = 0);
This class defines an output stream for replacing the standard 'cout'.
int precision() const
Returns the precision of the main output stream.
bool copied
This variable is set to true if this log file pointer was copied from another output stream,...
void keepforever(void)
Makes this stream keep the allocated file open for ever, and not close it even in the destructor.
bool flush
If this variable is set to true then both the output stream 'cout' and the log file are flushed after...
bool show
If this variable is set to true then everything that is written to this stream is also written to 'co...
std::ostream & out
A reference to the main output stream bound with this stream.
std::ofstream * getlogstream(void)
Returns a pointer to the stream which is working as a log file.
~outputstream()
The destructor.
std::ofstream * logstream
A pointer to the log file stream.
bool log
If this variable is set to true then everything that is written to this stream is also written to the...
outputstream(std::ostream &_out=std::cout, bool _show=true, bool _flush=false)
The default constructor.
void logfile(const char *filename)
Turns on logging to a file.
A class for reading text data from a text file.
void ignorespaces()
Ignores white characters and fills in the variable 'ch' with the first non-white character.
long linenumber()
Returns the current line number.
std::ifstream * fs
The true file if it was opened.
int readphrase(const char *phrase)
Reads a strongly expected phrase from the file.
std::istream * s
A pointer to an input stream (usually equal to 'fs').
long line
The current line number.
int open(const char *filename)
Opens a file with the given name.
void ignoreline()
Ignore the current line from the current position to the end of line, including the end of line chara...
int readword(char *buf, int maxlength)
Reads one word from the file and returns its actual length.
int ch
The character already read and waiting to be interpreted.
long readnumber(long defaultnumber=0, int ignorecolons=0)
Read an integer number from the input file.
void close()
Closes the file.
~textfile()
The destructor.
int checkchar()
Returns the first non-white character waiting to be read.
int readchar()
Read one non-white character from the file.
textfile(std::istream &in)
A constructor for an opened file.
textfile()
The default constructor.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
outputstream sseq
An auxiliary stream which captures sequences of processed data.
void ignoreline(std::istream &in)
Ignores the input characters until the end of a line, including this end of the line.
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
void swapelements(type &x, type &y)
A simple template for swapping two elements with the use of a temporary variable of the same type and...
int closingparenthesis(int ch)
Returns the matching closing parenthesis for the given opening one or EOF if none.
outputstream serr
A wrapper for the standard error stream.
std::string commandline(int argc, char *argv[])
Returns the entire command line as a single string.
void fileerror(const char *filename, const char *what="open")
Throws a message about the inability to do something with a file.
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
outputstream sbug
An output stream for writing additional debug messages.
int readparenthesis(std::istream &in)
Reads an opening parenthesis from the input file.
void savetheset(const char *name, const settype &s, const char *pluralname, const char *what, const char *filecomment=0)
Saves a given set to a file and shows appropriate messages.
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...
const char * currenttime(void)
Retrieves the current time as a pointer to a C-style string.
void ignorecomments(std::istream &in)
Ignores white characters (spaces, tabulators, CRs and LFs), as well as comments from the input text f...
int sortelements(type *tab, int n)
A simple template that sorts an array using the bubble sort method, removes repeated elements and ret...
outputstream slog
The output stream to which one can send messages for logging only.
This namespace contains the entire CHomP library interface.
Local mute of the stream.
mute(outputstream &_stream)
#define ERRORMSG
The first macro in a pair of macrodefinitions for throwing an error message.
#define THROW
The second macro in a pair of macrodefinitions for throwing an error message.