check_range.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_RANGE_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_RANGE_HPP
3 
7 #include <sstream>
8 #include <string>
9 
10 namespace stan {
11 namespace math {
12 
13 /**
14  * Check if specified index is within range.
15  *
16  * This check is 1-indexed by default. This behavior can be
17  * changed by setting <code>stan::error_index::value</code>.
18  *
19  * @param function Function name (for error messages)
20  * @param name Variable name (for error messages)
21  * @param max Maximum size of the variable
22  * @param index Index to check
23  * @param nested_level Nested level (for error messages)
24  * @param error_msg Additional error message (for error messages)
25  *
26  * @throw <code>std::out_of_range</code> if the index is not in range
27  */
28 inline void check_range(const char* function, const char* name, int max,
29  int index, int nested_level, const char* error_msg) {
30  if ((index >= stan::error_index::value)
31  && (index < max + stan::error_index::value))
32  return;
33 
34  std::stringstream msg;
35  msg << "; index position = " << nested_level;
36  std::string msg_str(msg.str());
37 
38  out_of_range(function, max, index, msg_str.c_str(), error_msg);
39 }
40 
41 /**
42  * Check if specified index is within range.
43  *
44  * This check is 1-indexed by default. This behavior can be
45  * changed by setting <code>stan::error_index::value</code>.
46  *
47  * @param function Function name (for error messages)
48  * @param name Variable name (for error messages)
49  * @param max Maximum size of the variable
50  * @param index Index to check
51  * @param error_msg Additional error message (for error messages)
52  *
53  * @throw <code>std::out_of_range</code> if the index is not in range
54  */
55 inline void check_range(const char* function, const char* name, int max,
56  int index, const char* error_msg) {
57  if ((index >= stan::error_index::value)
58  && (index < max + stan::error_index::value))
59  return;
60 
61  out_of_range(function, max, index, error_msg);
62 }
63 
64 /**
65  * Check if specified index is within range.
66  *
67  * This check is 1-indexed by default. This behavior can be
68  * changed by setting <code>stan::error_index::value</code>.
69  *
70  * @param function Function name (for error messages)
71  * @param name Variable name (for error messages)
72  * @param max Maximum size of the variable
73  * @param index Index to check
74  *
75  * @throw <code>std::out_of_range</code> if the index is not in range
76  */
77 inline void check_range(const char* function, const char* name, int max,
78  int index) {
79  if ((index >= stan::error_index::value)
80  && (index < max + stan::error_index::value))
81  return;
82 
83  out_of_range(function, max, index);
84 }
85 
86 } // namespace math
87 } // namespace stan
88 #endif
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
void out_of_range(const char *function, int max, int index, const char *msg1="", const char *msg2="")
int max(const std::vector< int > &x)
Definition: max.hpp:22
enum BeamMode string