~reviczky/luatex/texlive-bin-git

« back to all changes in this revision

Viewing changes to texk/dvisvgm/dvisvgm-1.8.1/src/Message.h

  • Committer: Adam Reviczky
  • Date: 2015-04-26 22:40:47 UTC
  • Revision ID: adam.reviczky@kclalumni.net-20150426224047-i2p26n3wqphupq6z
TeX Live 2015 import (rev. 37052)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************************************
2
 
** Message.h                                                            **
3
 
**                                                                      **
4
 
** This file is part of dvisvgm -- the DVI to SVG converter             **
5
 
** Copyright (C) 2005-2014 Martin Gieseking <martin.gieseking@uos.de>   **
6
 
**                                                                      **
7
 
** This program is free software; you can redistribute it and/or        **
8
 
** modify it under the terms of the GNU General Public License as       **
9
 
** published by the Free Software Foundation; either version 3 of       **
10
 
** the License, or (at your option) any later version.                  **
11
 
**                                                                      **
12
 
** This program is distributed in the hope that it will be useful, but  **
13
 
** WITHOUT ANY WARRANTY; without even the implied warranty of           **
14
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         **
15
 
** GNU General Public License for more details.                         **
16
 
**                                                                      **
17
 
** You should have received a copy of the GNU General Public License    **
18
 
** along with this program; if not, see <http://www.gnu.org/licenses/>. **
19
 
*************************************************************************/
20
 
 
21
 
#ifndef DVISVGM_MESSAGE_H
22
 
#define DVISVGM_MESSAGE_H
23
 
 
24
 
#include <algorithm>
25
 
#include <string>
26
 
#include <ostream>
27
 
#include <sstream>
28
 
#include "Terminal.h"
29
 
#include "types.h"
30
 
 
31
 
 
32
 
class Message;
33
 
 
34
 
class MessageStream
35
 
{
36
 
        friend class Message;
37
 
 
38
 
        public:
39
 
                MessageStream ();
40
 
                MessageStream (std::ostream &os);
41
 
                ~MessageStream ();
42
 
 
43
 
                template <typename T>
44
 
                MessageStream& operator << (const T &obj) {
45
 
                        std::ostringstream oss;
46
 
                        oss << obj;
47
 
                        (*this) << oss.str();
48
 
                        return *this;
49
 
                }
50
 
 
51
 
                MessageStream& operator << (const char *str);
52
 
                MessageStream& operator << (const char &c);
53
 
                MessageStream& operator << (const std::string &str) {return (*this) << str.c_str();}
54
 
 
55
 
                void indent (int level)        {_indent = std::max(0, level*2);}
56
 
                void indent (bool reset=false);
57
 
                void outdent (bool all=false);
58
 
                void clearline ();
59
 
 
60
 
        protected:
61
 
                void putChar (const char c, std::ostream &os);
62
 
                std::ostream* os () {return _os;}
63
 
 
64
 
        private:
65
 
                std::ostream *_os;
66
 
                bool _nl;     ///< true if previous character was a newline
67
 
                int _col;     ///< current terminal column
68
 
                int _indent;  ///< indentation width (number of columns/characters)
69
 
};
70
 
 
71
 
 
72
 
class Message
73
 
{
74
 
        struct Color {
75
 
                Color () : foreground(-1), background(-1) {}
76
 
                Color (Int8 fgcolor) : foreground(fgcolor), background(-1) {}
77
 
                Color (Int8 fgcolor, bool light) : foreground(fgcolor + (light ? 8 : 0)), background(-1) {}
78
 
                Color (Int8 fgcolor, Int8 bgcolor) : foreground(fgcolor), background(bgcolor) {}
79
 
                Int8 foreground;
80
 
                Int8 background;
81
 
        };
82
 
 
83
 
        public:
84
 
                enum MessageClass {
85
 
                        MC_ERROR,
86
 
                        MC_WARNING,
87
 
                        MC_MESSAGE,
88
 
                        MC_PAGE_NUMBER,
89
 
                        MC_PAGE_SIZE,
90
 
                        MC_PAGE_WRITTEN,
91
 
                        MC_STATE,
92
 
                        MC_TRACING,
93
 
                        MC_PROGRESS,
94
 
                };
95
 
 
96
 
        public:
97
 
                static MessageStream& mstream (bool prefix=false, MessageClass mclass=MC_MESSAGE);
98
 
                static MessageStream& estream (bool prefix=false);
99
 
                static MessageStream& wstream (bool prefix=false);
100
 
 
101
 
                enum {ERRORS=1, WARNINGS=2, MESSAGES=4};
102
 
                static int LEVEL;
103
 
                static bool COLORIZE;
104
 
 
105
 
        protected:
106
 
                static void init ();
107
 
 
108
 
 
109
 
        private:
110
 
                static Color _classColors[];
111
 
                static bool _initialized;
112
 
};
113
 
 
114
 
#endif