File: txlogger.h

package info (click to toggle)
tralics 2.14.4-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 17,152 kB
  • ctags: 8,260
  • sloc: cpp: 49,403; xml: 18,145; sh: 140; makefile: 118
file content (129 lines) | stat: -rw-r--r-- 5,390 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// -*- C++ -*-
// $Id: txlogger.h,v 2.19 2008/04/14 06:33:50 grimm Exp $
// TRALICS, copyright (C) INRIA/apics (Jose' Grimm) 2003,  2007, 2008

// This software is governed by the CeCILL license under French law and
// abiding by the rules of distribution of free software.  You can  use, 
// modify and/ or redistribute the software under the terms of the CeCILL
// license as circulated by CEA, CNRS and INRIA at the following URL
// "http://www.cecill.info". 
// (See the file COPYING in the main directory for details)

// This include file holds some declarations for printing objects
// and the classes that allow us to print either on the tty, the log file 
// or both.

extern ostream& operator<< (ostream&fp, const Glue&x);
extern ostream& operator<< (ostream&fp, const Istring&x);
extern ostream& operator<< (ostream&fp, const Macro&x);
extern ostream& operator<< (ostream&fp, const TokenList& L);
extern ostream& operator<< (ostream&fp, const FontInfo& L);
extern ostream& operator<< (ostream&fp, const SthInternal&x);
extern ostream& operator<< (ostream&fp, Token x);
extern ostream& operator<< (ostream&fp, Xid);
extern ostream& operator<< (ostream&fp, const Utf8Char&);
extern ostream& operator<< (ostream&fp, const Xml*);
extern ostream& operator<< (ostream&fp, const ScaledInt&x);
extern ostream& operator<< (ostream&fp, const boundary_type&x);

inline ostream& operator<<(ostream&fp, const Buffer& L)
{ 
  return fp << L.c_str(); 
}

class Logger;
typedef void logger_fn(Logger&);


class Logger{
  bool finished; // if false, we are printing a character sequence and
                 // a newline is required 
  string filename; // the name of the log file
 public:
  fstream* fp; // the stream to which we print
  void finish_seq();
  void out_single_char(Utf8Char c);
  void dump (String s);
  void dump0 (String s);
  void set_finished() { finished = true; }
  void set_file_name(string x) { filename = x; }
  void abort();
  string get_filename() const { return filename; }
  Logger& operator<<(logger_fn f) { f(*this); return *this; }
  // some trivial functions
  Logger& operator<<(String s) { (*fp) << s; return *this; }
  Logger& operator<<(const Buffer& s) { (*fp) << s; return *this;}
  Logger& operator<<(int s) { (*fp)<< s; return *this;}
  Logger& operator<<(Istring s) { (*fp)<< s; return *this;}
  Logger& operator<<(char c)  { *(fp)<< c; return *this;}
  Logger& operator<<(unsigned char c)  { *(fp)<< c; return *this;}
  Logger& operator<<(const string& s)   { *(fp)<< s; return *this;}
  Logger& operator<<(const TokenList& s)   { *(fp)<< s; return *this;}
  Logger& operator<<(const boundary_type& s)   { *(fp)<< s; return *this;}
  Logger& operator<<(const Xml* s)   { *(fp)<< s; return *this;}
};

class FullLogger {
 public:
  Logger L;
  void abort() { L.abort(); }
  FullLogger& operator<<(logger_fn f) { f(L); return *this; }
  void finish(int);
  void init(string);
  void unexpected_char(String s, int k);
};

class HalfLogger
{
 public:
  Logger L;
  bool verbose;
  HalfLogger& operator <<(logger_fn f) { f(L); return *this; }
  HalfLogger() { verbose = true; }
};

// if X is of type logger, then X << lg_start; is the same as
// lg_start(X); and hence as  X.finish_seq();
// if Y is of type FullLogger, Y<< lg_start; is the same as
// lg_start(Y.L), hence Y.L.finish_seq();


inline void lg_flush(Logger& L) { (*(L.fp)).flush(); }
inline void lg_start(Logger& L) { L.finish_seq(); }
inline void lg_startstack(Logger& L) { L.finish_seq(); *(L.fp) << "+stack: "; }
inline void lg_startbrace(Logger& L) { L.finish_seq(); *(L.fp) << "{"; }
inline void lg_startcond(Logger& L) { L.finish_seq(); *(L.fp) << "+"; }
inline void lg_startif(Logger& L) { L.finish_seq(); *(L.fp) << "{ifthenelse "; }
inline void lg_startcalc(Logger& L) { L.finish_seq(); *(L.fp) << "{calc "; }
inline void lg_startbracebs(Logger& L) { L.finish_seq(); *(L.fp) << "{\\"; }
void lg_end(Logger& L);
inline void lg_endsentence(Logger& L) { *(L.fp) << ".\n"; }
inline void lg_endbrace(Logger& L) { *(L.fp) << "}\n"; }
inline void lg_arrow(Logger&L) { *(L.fp) << "->"; }
inline void lg_fatal(Logger&L) { L.abort(); }


Logger& operator <<(Logger& X,  const ScaledInt&x);
Logger& operator <<(Logger& X,  const Glue&x);
Logger& operator <<(Logger& X,  const Macro&x);
Logger& operator <<(Logger& X,  const SthInternal&x);
Logger& operator <<(Logger& X,  const FontInfo&x);
Logger& operator <<(Logger& X,  Token x);
Logger& operator <<(Logger& X,  const Utf8Char& x);
FullLogger& operator <<(FullLogger& X,  const Utf8Char& x);
FullLogger& operator <<(FullLogger& X, Token x);
FullLogger& operator <<(FullLogger& X, const Macro& x);
FullLogger& operator <<(FullLogger& X, const ScaledInt&x);
FullLogger& operator <<(FullLogger& X, String s);
FullLogger& operator <<(FullLogger& X, Istring s);
FullLogger& operator <<(FullLogger& X, int s);
FullLogger& operator <<(FullLogger& X, const string& s);
FullLogger& operator <<(FullLogger& X, char s);
FullLogger& operator <<(FullLogger& X, unsigned char s);
FullLogger& operator <<(FullLogger& X, const Buffer& s);
FullLogger& operator <<(FullLogger& X, const TokenList& s);
FullLogger& operator <<(FullLogger& X, const Xml* s);
HalfLogger& operator <<(HalfLogger& X, String s);
HalfLogger& operator <<(HalfLogger& X, Istring s);
HalfLogger& operator <<(HalfLogger& X, int s);
HalfLogger& operator <<(HalfLogger& X, const string& s);