as2js: /home/snapwebsites/snapcpp/contrib/as2js/include/as2js/message.h Source File

message.h
Go to the documentation of this file.
1 #ifndef AS2JS_MESSAGE_H
2 #define AS2JS_MESSAGE_H
3 /* include/as2js/message.h
4 
5 Copyright (c) 2005-2019 Made to Order Software Corp. All Rights Reserved
6 
8 
9 Permission is hereby granted, free of charge, to any
10 person obtaining a copy of this software and
11 associated documentation files (the "Software"), to
12 deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify,
14 merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom
16 the Software is furnished to do so, subject to the
17 following conditions:
18 
19 The above copyright notice and this permission notice
20 shall be included in all copies or substantial
21 portions of the Software.
22 
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
24 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
25 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
27 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
29 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
30 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
31 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 SOFTWARE.
33 
34 */
35 
36 #include "position.h"
37 #include "int64.h"
38 #include "float64.h"
39 
40 #include <sstream>
41 
42 
43 namespace as2js
44 {
45 
46 
47 enum class message_level_t
48 {
56 };
57 
58 
59 enum class err_code_t
60 {
61  AS_ERR_NONE = 0,
62 
145 
146  AS_ERR_max
147 };
148 
149 
151 {
152 public:
153  virtual ~MessageCallback() {}
154 
155  virtual void output(message_level_t message_level, err_code_t error_code, Position const& pos, std::string const& message) = 0;
156 };
157 
158 
159 // Note: avoid copies because with such you'd get the Message two or more times
160 class Message : public std::stringstream
161 {
162 public:
163  Message(message_level_t message_level, err_code_t error_code, Position const& pos);
164  Message(message_level_t message_level, err_code_t error_code);
165  Message(Message const& rhs) = delete;
166  ~Message();
167 
168  Message& operator = (Message const& rhs) = delete;
169 
170  template<typename T>
171  Message& operator << (T const& data)
172  {
173  static_cast<std::stringstream&>(*this) << data;
174  return *this;
175  }
176 
177  // internal types; you can add your own types with
178  // Message& operator << (Message& os, <my-type>);
179  Message& operator << (char const *s);
180  Message& operator << (wchar_t const *s);
181  Message& operator << (std::string const& s);
182  Message& operator << (std::wstring const& s);
183  Message& operator << (String const& s);
184  Message& operator << (char const v);
185  Message& operator << (signed char const v);
186  Message& operator << (unsigned char const v);
187  Message& operator << (signed short const v);
188  Message& operator << (unsigned short const v);
189  Message& operator << (signed int const v);
190  Message& operator << (unsigned int const v);
191  Message& operator << (signed long const v);
192  Message& operator << (unsigned long const v);
193  Message& operator << (signed long long const v);
194  Message& operator << (unsigned long long const v);
195  Message& operator << (Int64 const v);
196  Message& operator << (float const v);
197  Message& operator << (double const v);
198  Message& operator << (Float64 const v);
199  Message& operator << (bool const v);
200 
201  static void set_message_callback(MessageCallback *callback);
202  static void set_message_level(message_level_t min_level);
203  static int warning_count();
204  static int error_count();
205 
206 private:
209  Position f_position = Position();
210 };
211 
212 
213 
214 }
215 // namespace as2js
216 #endif
217 //#ifndef AS2JS_MESSAGE_H
218 
219 // vim: ts=4 sw=4 et
virtual ~MessageCallback()
Definition: message.h:153
std::ostream & operator<<(std::ostream &out, Node const &node)
Send a node to the specified output stream.
err_code_t
Definition: message.h:59
message_level_t
Definition: message.h:47
The AlexScript to JavaScript namespace.
Definition: compiler.cpp:37

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly