as2js: /home/snapwebsites/snapcpp/contrib/as2js/lib/message.cpp Source File

as2js  0.1.14
AlexScript to JavaScript
message.cpp
Go to the documentation of this file.
1 /* lib/message.cpp
2 
3 Copyright (c) 2005-2019 Made to Order Software Corp. All Rights Reserved
4 
6 
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16 
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31 
32 */
33 
34 #include "as2js/message.h"
35 
36 
37 namespace as2js
38 {
39 
40 namespace
41 {
44  int g_warning_count = 0;
45  int g_error_count = 0;
46 }
47 // no name namespace
48 
49 
65 Message::Message(message_level_t message_level, err_code_t error_code, Position const& pos)
66  //: stringstream() -- auto-init
67  : f_message_level(message_level)
68  , f_error_code(error_code)
69  , f_position(pos)
70 {
71 }
72 
73 
83 Message::Message(message_level_t message_level, err_code_t error_code)
84  //: stringstream() -- auto-init
85  : f_message_level(message_level)
86  , f_error_code(error_code)
87  //, f_position()
88 {
89 }
90 
91 
105 {
106  // actually emit the message
107  if(g_message_callback // there is a callback?
109  && f_message_level <= g_maximum_message_level // level is large enough?
110  && rdbuf()->in_avail() != 0) // there is a message?
111  {
112  if(f_position.get_filename().empty())
113  {
114  f_position.set_filename("unknown-file");
115  }
116  if(f_position.get_function().empty())
117  {
118  f_position.set_function("unknown-func");
119  }
120 
121  switch(f_message_level)
122  {
125  ++g_error_count;
126  break;
127 
129  ++g_warning_count;
130  break;
131 
132  // others are not currently counted
133  default:
134  break;
135 
136  }
137 
139  }
140 }
141 
142 
152 {
153  // we assume UTF-8 because in our Snap environment most everything is
154  static_cast<std::stringstream&>(*this) << s;
155  return *this;
156 }
157 
158 
167 Message& Message::operator << (wchar_t const *s)
168 {
169  String string;
170  string.from_wchar(s);
171  static_cast<std::stringstream&>(*this) << string.to_utf8();
172  return *this;
173 }
174 
175 
184 Message& Message::operator << (std::string const& s)
185 {
186  static_cast<std::stringstream&>(*this) << s;
187  return *this;
188 }
189 
190 
199 Message& Message::operator << (std::wstring const& s)
200 {
201  String string;
202  string.from_wchar(s.c_str(), s.length());
203  static_cast<std::stringstream&>(*this) << string.to_utf8();
204  return *this;
205 }
206 
207 
217 {
218  static_cast<std::stringstream&>(*this) << s.to_utf8();
219  return *this;
220 }
221 
222 
232 {
233  static_cast<std::stringstream&>(*this) << v;
234  return *this;
235 }
236 
237 
246 Message& Message::operator << (signed char const v)
247 {
248  static_cast<std::stringstream&>(*this) << static_cast<int>(v);
249  return *this;
250 }
251 
252 
261 Message& Message::operator << (unsigned char const v)
262 {
263  static_cast<std::stringstream&>(*this) << static_cast<int>(v);
264  return *this;
265 }
266 
267 
276 Message& Message::operator << (signed short const v)
277 {
278  static_cast<std::stringstream&>(*this) << static_cast<int>(v);
279  return *this;
280 }
281 
282 
291 Message& Message::operator << (unsigned short const v)
292 {
293  static_cast<std::stringstream&>(*this) << static_cast<int>(v);
294  return *this;
295 }
296 
297 
306 Message& Message::operator << (signed int const v)
307 {
308  static_cast<std::stringstream&>(*this) << v;
309  return *this;
310 }
311 
312 
321 Message& Message::operator << (unsigned int const v)
322 {
323  static_cast<std::stringstream&>(*this) << v;
324  return *this;
325 }
326 
327 
336 Message& Message::operator << (signed long const v)
337 {
338  static_cast<std::stringstream&>(*this) << v;
339  return *this;
340 }
341 
342 
351 Message& Message::operator << (unsigned long const v)
352 {
353  static_cast<std::stringstream&>(*this) << v;
354  return *this;
355 }
356 
357 
366 Message& Message::operator << (signed long long const v)
367 {
368  static_cast<std::stringstream&>(*this) << v;
369  return *this;
370 }
371 
372 
380 {
381  static_cast<std::stringstream&>(*this) << v.get();
382  return *this;
383 }
384 
385 
394 Message& Message::operator << (unsigned long long const v)
395 {
396  static_cast<std::stringstream&>(*this) << v;
397  return *this;
398 }
399 
400 
410 {
411  static_cast<std::stringstream&>(*this) << v;
412  return *this;
413 }
414 
415 
425 {
426  static_cast<std::stringstream&>(*this) << v;
427  return *this;
428 }
429 
430 
438 {
439  static_cast<std::stringstream&>(*this) << v.get();
440  return *this;
441 }
442 
443 
453 {
454  static_cast<std::stringstream&>(*this) << static_cast<int>(v);;
455  return *this;
456 }
457 
458 
468 {
469  g_message_callback = callback;
470 }
471 
472 
486 {
489  : max_level;
490 }
491 
492 
503 {
504  return g_warning_count;
505 }
506 
507 
518 {
519  return g_error_count;
520 }
521 
522 
523 
524 
525 }
526 // namespace as2js
527 
528 // vim: ts=4 sw=4 et
err_code_t f_error_code
Definition: message.h:208
Position f_position
Definition: message.h:209
float64_type get() const
Definition: float64.h:71
std::string to_utf8() const
Convert a string to UTF-8 and return the result.
Definition: string.cpp:1343
Message(message_level_t message_level, err_code_t error_code, Position const &pos)
Create a message object with the specified information.
Definition: message.cpp:65
Message & operator<<(T const &data)
Definition: message.h:171
message_level_t f_message_level
Definition: message.h:207
static void set_message_level(message_level_t min_level)
Define the maximum level a message can be to be displayed.
Definition: message.cpp:485
static int error_count()
The number of errors that were found so far.
Definition: message.cpp:517
~Message()
Output the message created with the << operators.
Definition: message.cpp:104
virtual void output(message_level_t message_level, err_code_t error_code, Position const &pos, std::string const &message)=0
int64_type get() const
Definition: int64.h:69
void set_function(String const &function)
Set the function being read.
Definition: position.cpp:68
static int warning_count()
The number of warnings that were found so far.
Definition: message.cpp:502
err_code_t
Definition: message.h:59
message_level_t
Definition: message.h:47
conversion_result_t from_wchar(wchar_t const *str, int len=-1)
Copy a wchar_t string to this String.
Definition: string.cpp:638
String get_filename() const
Retrieve the filename.
Definition: position.cpp:143
The AlexScript to JavaScript namespace.
Definition: compiler.cpp:37
String get_function() const
Retrieve the function name.
Definition: position.cpp:158
static void set_message_callback(MessageCallback *callback)
Setup the callback so tools can receive error messages.
Definition: message.cpp:467
void set_filename(String const &filename)
Set the filename being read.
Definition: position.cpp:52

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