Current Version: 1.0.20
Project Name: csspp
error.h
Go to the documentation of this file.
1 #ifndef CSSPP_ERROR_H
2 #define CSSPP_ERROR_H
3 // CSS Preprocessor
4 // Copyright (c) 2015-2018 Made to Order Software Corp. All Rights Reserved
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #include "csspp/position.h"
21 
22 #include <istream>
23 #include <sstream>
24 
25 namespace csspp
26 {
27 
28 enum class error_mode_t
29 {
31  ERROR_DEC,
34  ERROR_HEX,
35  ERROR_INFO,
37 };
38 
39 typedef uint32_t error_count_t;
40 
41 // the bare pointer is problematic with effective c++
42 #pragma GCC diagnostic push
43 #pragma GCC diagnostic ignored "-Weffc++"
44 class error
45 {
46 public:
47  error();
48 
49  static error & instance();
50  std::ostream & get_error_stream() const;
51  void set_error_stream(std::ostream & err_stream);
52 
53  void set_count_warnings_as_errors(bool warnings_as_errors);
54 
55  error_count_t get_error_count() const;
56  void set_error_count(error_count_t count);
57  error_count_t get_warning_count() const;
58  void set_warning_count(error_count_t count);
59 
60  void set_hide_all(bool show_debug);
61  void set_show_debug(bool show_debug);
62 
63  void set_verbose(bool status);
64 
65  error & operator << (position const & pos);
67  error & operator << (std::string const & msg);
68  error & operator << (char const * msg);
69  error & operator << (int32_t value);
70  error & operator << (int64_t value);
71  error & operator << (double value);
72 
73 private:
74  void reset();
75 
77  std::stringstream f_message = std::stringstream();
78  std::ostream * f_error = nullptr;
79  error_count_t f_error_count = 0;
80  error_count_t f_warning_count = 0;
81  bool f_warnings_as_errors = false;
82  bool f_hide_all = false;
83  bool f_show_debug = false;
84  bool f_verbose = false;
85 };
86 #pragma GCC diagnostic pop
87 
89 {
90 public:
91  safe_error_t();
92  ~safe_error_t();
93 
94 private:
95  error_count_t f_error_count = 0;
96  error_count_t f_warning_count = 0;
97 };
98 
99 
101 {
102 public:
103  safe_error_stream_t(std::ostream & err_stream);
104  safe_error_stream_t(safe_error_stream_t const & rhs) = delete;
106 
107  safe_error_stream_t & operator = (safe_error_stream_t const & rhs) = delete;
108 
109 private:
110  std::ostream * f_error = nullptr;
111 };
112 
113 
115 {
116 public:
118 
119  bool error_happened() const;
120  bool warning_happened() const;
121 
122 private:
123  error_count_t f_error_count = 0;
124  error_count_t f_warning_count = 0;
125 };
126 
127 } // namespace csspp
128 
129 std::ostream & operator << (std::ostream & out, csspp::error_mode_t const type);
130 
131 #endif
132 // #ifndef CSSPP_LEXER_H
133 
134 // Local Variables:
135 // mode: cpp
136 // indent-tabs-mode: nil
137 // c-basic-offset: 4
138 // tab-width: 4
139 // End:
140 
141 // vim: ts=4 sw=4 et
uint32_t error_count_t
Definition: error.h:39
The namespace of all the classes in the CSS Preprocessor.
Definition: assembler.cpp:40
std::ostream & operator<<(std::ostream &out, csspp::error_mode_t const type)
Definition: error.cpp:297
error_mode_t
Definition: error.h:28
position f_position
Definition: error.h:76

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.