zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Error.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
34 #ifndef ZENI_ERROR_H
35 #define ZENI_ERROR_H
36 
37 #include <Zeni/String.h>
38 
39 #include <cassert>
40 #include <stdexcept>
41 
42 #if defined(_MACOSX)
43 #include <Zeni/macosx_zeni.h>
44 #elif defined(_WINDOWS)
45 #include <Windows.h>
46 #elif defined(ANDROID)
47 #include <android/log.h>
48 #endif
49 
50 namespace Zeni {
51 
52  struct ZENI_DLL Error : public std::exception {
53  Error(const String &msg_) : msg(msg_) {}
54 
55  ~Error() throw() {}
56 
58  };
59 
60  inline void message_box(const char * const &msg) {
61 #if defined(_MACOSX)
62  mac_message_box(msg);
63 #elif defined(_WINDOWS)
64  MessageBoxA(0, msg, 0, MB_OK);
65 #elif defined(ANDROID)
66  __android_log_print(ANDROID_LOG_VERBOSE, "zenilib", "%s", msg);
67 #else
68  String cmd("xmessage -center '");
69  for(const char * cc = msg; *cc; ++cc) {
70  if(*cc != '\'')
71  cmd += *cc;
72  else
73  cmd += "'\"'\"'";
74  }
75  cmd += '\'';
76  system(cmd.c_str());
77 #endif
78  }
79 
80  inline void message_box(const String &msg) {
81  message_box(msg.c_str());
82  }
83 
84 }
85 
86 #endif
Error(const String &msg_)
Definition: Error.h:53
void mac_message_box(const char *const msg)
Definition: macosx_zeni.mm:22
const char * c_str() const
Definition: String.cpp:467
~Error()
Definition: Error.h:55
void message_box(const char *const &msg)
Definition: Error.h:60
The Error Class.
Definition: Error.h:52
String msg
Definition: Error.h:57