Rcpp Version 1.0.9
exceptions.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // exceptions.h: Rcpp R/C++ interface class library -- exceptions
4 //
5 // Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
6 // Copyright (C) 2017 Dirk Eddelbuettel, Romain Francois, and James J Balamuta
7 //
8 // This file is part of Rcpp.
9 //
10 // Rcpp is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // Rcpp is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef Rcpp__exceptionscpp98__h
24 #define Rcpp__exceptionscpp98__h
25 
26 namespace Rcpp {
27 
28 #define RCPP_ADVANCED_EXCEPTION_CLASS(__CLASS__, __WHAT__) \
29 class __CLASS__ : public std::exception{ \
30  public: \
31  __CLASS__( ) throw() : message( std::string(__WHAT__) + "." ){} \
32  __CLASS__( const std::string& message ) throw() : message( std::string(__WHAT__) + ": " + message + "." ){} \
33  template <typename T1> \
34  __CLASS__(const char* fmt, const T1& arg1) throw() : \
35  message( tfm::format(fmt, arg1 ) ){} \
36  template <typename T1, typename T2> \
37  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2) throw() : \
38  message( tfm::format(fmt, arg1, arg2 ) ){} \
39  template <typename T1, typename T2, typename T3> \
40  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3) throw() : \
41  message( tfm::format(fmt, arg1, arg2, arg3 ) ){} \
42  template <typename T1, typename T2, typename T3, typename T4> \
43  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) throw() : \
44  message( tfm::format(fmt, arg1, arg2, arg3, arg4 ) ){} \
45  template <typename T1, typename T2, typename T3, typename T4, typename T5> \
46  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5) throw() : \
47  message( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5 ) ){} \
48  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6> \
49  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6) throw() : \
50  message( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6 ) ){} \
51  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
52  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7) throw() : \
53  message( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ) ){} \
54  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
55  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8) throw() : \
56  message( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ) ){} \
57  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9> \
58  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9) throw() : \
59  message( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) ){} \
60  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10> \
61  __CLASS__(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9, const T10& arg10) throw() : \
62  message( tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 ) ){} \
63  virtual ~__CLASS__() throw(){} \
64  virtual const char* what() const throw() { return message.c_str() ; } \
65  private: \
66  std::string message ; \
67 } ; \
68 
69 // -- Start Rcpp::warning declaration
70 
71 template <typename T1>
72 inline void warning(const char* fmt, const T1& arg1) {
73  Rf_warning("%s", tfm::format(fmt, arg1).c_str());
74 }
75 
76 template <typename T1, typename T2>
77 inline void warning(const char* fmt, const T1& arg1, const T2& arg2) {
78  Rf_warning("%s", tfm::format(fmt, arg1, arg2).c_str());
79 }
80 
81 template <typename T1, typename T2, typename T3>
82 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3) {
83  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3).c_str());
84 }
85 
86 template <typename T1, typename T2, typename T3, typename T4>
87 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
88  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4).c_str());
89 }
90 
91 template <typename T1, typename T2, typename T3, typename T4, typename T5>
92 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5) {
93  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4, arg5).c_str());
94 }
95 
96 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
97 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6) {
98  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6).c_str());
99 }
100 
101 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
102 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7) {
103  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7).c_str());
104 }
105 
106 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
107 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8) {
108  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).c_str());
109 }
110 
111 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
112 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9) {
113  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).c_str());
114 }
115 
116 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
117 inline void warning(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9, const T10& arg10) {
118  Rf_warning("%s", tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10).c_str());
119 }
120 
121 // -- End Rcpp::warning declaration
122 
123 // -- Start Rcpp::stop declaration
124 
125 template <typename T1>
126 inline void NORET stop(const char* fmt, const T1& arg1) {
127  throw Rcpp::exception(tfm::format(fmt, arg1).c_str());
128 }
129 
130 template <typename T1, typename T2>
131 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2) {
132  throw Rcpp::exception(tfm::format(fmt, arg1, arg2).c_str());
133 }
134 
135 template <typename T1, typename T2, typename T3>
136 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3) {
137  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3).c_str());
138 }
139 
140 template <typename T1, typename T2, typename T3, typename T4>
141 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4) {
142  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4).c_str());
143 }
144 
145 template <typename T1, typename T2, typename T3, typename T4, typename T5>
146 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5) {
147  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4, arg5).c_str());
148 }
149 
150 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
151 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6) {
152  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6).c_str());
153 }
154 
155 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
156 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7) {
157  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7).c_str());
158 }
159 
160 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
161 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8) {
162  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8).c_str());
163 }
164 
165 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
166 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9) {
167  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9).c_str());
168 }
169 
170 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
171 inline void NORET stop(const char* fmt, const T1& arg1, const T2& arg2, const T3& arg3, const T4& arg4, const T5& arg5, const T6& arg6, const T7& arg7, const T8& arg8, const T9& arg9, const T10& arg10) {
172  throw Rcpp::exception(tfm::format(fmt, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10).c_str());
173 }
174 
175 // -- End Rcpp::stop declaration
176 } // namespace Rcpp
177 #endif
#define NORET
Definition: headers.h:78
Rcpp API.
Definition: algo.h:28
void warning(const char *fmt, Args &&... args)
Definition: exceptions.h:46
void NORET stop(const char *fmt, Args &&... args)
Definition: exceptions.h:51
void format(std::ostream &out, const char *fmt)
Definition: tinyformat.h:996