ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
admb_messages.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  *
7  * ADModelbuilder and associated libraries and documentations are
8  * provided under the general terms of the "BSD" license.
9  *
10  * License:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * 3. Neither the name of the University of California, Otter Research,
24  * nor the ADMB Foundation nor the names of its contributors may be used
25  * to endorse or promote products derived from this software without
26  * specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
41 #ifndef __ADMB_MESSAGES_H__
42 #define __ADMB_MESSAGES_H__
43 #include <iostream>
44 #include <fvar.hpp>
45 
46 #define ADMB_ERROR(x) admb::messages::error(x);
47 #define ADMB_ARRAY_BOUNDS_ERROR(message,function,lower_bounds,upper_bounds,\
48 index) admb::messages::array_bounds_error(message,function,lower_bounds,\
49 upper_bounds,index);
50 
51 namespace admb
52 {
53 const int ARRAY_BOUNDS_ERROR = 42;
54 
58 class messages
59 {
60 public:
64  messages() {;}
68  messages(const messages&);
72  virtual ~messages() {;}
73 
74 public:
78  static
79  void error(const adstring& message)
80  {
81  error(message, 1);
82  }
86  static
87  void error(const int error_code)
88  {
89  adstring message = "Error: ";
90  switch (error_code)
91  {
92  case 1:
93  message += "allocating memory in dmatrix contructor";
94  break;
95  case 2:
96  message +=
97  "attempting to access non-allocated ivector in ivector::operator()";
98  break;
99  default:
100  break;
101  };
102  error(message, error_code);
103  }
107  static
108  void error(const adstring& message, const adstring& function_name,
109  const int error_code)
110  {
111  adstring m = message;
112  if (function_name.size() > 0)
113  {
114  m += " in " + function_name;
115  }
116  error(m, error_code);
117  }
121  static
122  void array_bounds_error(const adstring& message,
123  const adstring& function,
124  const int lower_bounds,
125  const int upper_bounds,
126  const int index)
127  {
128  //tools99/string1.cpp
129  //cerr << "First index out of bounds in adstring::operator () (int,int)\n"
130  //<< "Index value was " << i << " The size of this adstring is "
131  //<< shape->size() << "\n";
132  //cerr << "Index out of bounds in adstring::operator () (const int)\n"
133  //<< "Index value was " << i << " The size of this adstring is "
134  //<< shape->size() << "\n";
135  //tools99/string5.cpp
136  //cerr << "Error index too low in adstring& operator [] (int i)" << endl;
137  //cerr << "value was " << i << " minimum valid index is "
138  /*
139  adstring m = message + " in \"" + function + "\"\n"
140  + adstring("Index value was ")
141  + str(index)
142  + " The size of this adstring is "
143  + str(upper_bounds);
144  */
145  adstring m = adstring("Error: Invalid index ")
146  + str(index)
147  + " used for array range ["
148  + str(lower_bounds)
149  + ", "
150  + str(upper_bounds)
151  + "] in \"" + function + "\".\n"
152  + message + "\n";
154  }
158  static
159  void error(const adstring& message, const int error_code)
160  {
161  cerr << message << '\n';
162  ad_exit(error_code);
163  }
164 };
165 }
166 #endif
size_t size() const
Definition: string.cpp:58
static void error(const int error_code)
Definition: admb_messages.h:87
static void error(const adstring &message, const int error_code)
exitptr ad_exit
Definition: gradstrc.cpp:53
static void array_bounds_error(const adstring &message, const adstring &function, const int lower_bounds, const int upper_bounds, const int index)
static void error(const adstring &message)
Definition: admb_messages.h:79
const int ARRAY_BOUNDS_ERROR
Definition: admb_messages.h:53
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
virtual ~messages()
Definition: admb_messages.h:72
adstring str(double x, int minwidth=17, int decplaces=-1)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
static void error(const adstring &message, const adstring &function_name, const int error_code)