Simbody  3.6
SimTKmath/include/simmath/internal/common.h
Go to the documentation of this file.
1 #ifndef SimTK_SIMMATH_COMMON_H_
2 #define SimTK_SIMMATH_COMMON_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKmath *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2006-12 Stanford University and the Authors. *
13  * Authors: Jack Middleton *
14  * Contributors: Michael Sherman *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
32 #include "SimTKcommon.h"
33 
34 /* Shared libraries are messy in Visual Studio. We have to distinguish three
35  * cases:
36  * (1) this header is being used to build the simmath shared library (dllexport)
37  * (2) this header is being used by a *client* of the simmath shared
38  * library (dllimport)
39  * (3) we are building the simmath static library, or the client is
40  * being compiled with the expectation of linking with the
41  * simmath static library (nothing special needed)
42  * In the CMake script for building this library, we define one of the symbols
43  * SIMMATH_BUILDING_{SHARED|STATIC}_LIBRARY
44  * Client code normally has no special symbol defined, in which case we'll
45  * assume it wants to use the shared library. However, if the client defines
46  * the symbol SimTK_USE_STATIC_LIBRARIES we'll suppress the dllimport so
47  * that the client code can be linked with static libraries. Note that
48  * the client symbol is not library dependent, while the library symbols
49  * affect only the simmath library, meaning that other libraries can
50  * be clients of this one. However, we are assuming all-static or all-shared.
51 */
52 
53 #if defined(_WIN32) && defined(_MSC_VER)
54  #if defined(SimTK_SIMMATH_BUILDING_SHARED_LIBRARY)
55  #define SimTK_SIMMATH_EXPORT __declspec(dllexport)
56  #elif defined(SimTK_SIMMATH_BUILDING_STATIC_LIBRARY) || defined(SimTK_USE_STATIC_LIBRARIES)
57  #define SimTK_SIMMATH_EXPORT
58  #else
59  /* i.e., a client of a shared library */
60  #define SimTK_SIMMATH_EXPORT __declspec(dllimport)
61  #endif
62 #else
63  /* Linux, Mac, MinGW */
64  #define SimTK_SIMMATH_EXPORT
65 #endif
66 
67 
68 // Every SimTK Core library must provide these two routines, with the library
69 // name appearing after the "version_" and "about_".
70 extern "C" {
71  SimTK_SIMMATH_EXPORT void SimTK_version_simmath(int* major, int* minor, int* build);
72  SimTK_SIMMATH_EXPORT void SimTK_about_simmath(const char* key, int maxlen, char* value);
73 }
74 
75 
76 
77 const static double POSITIVE_INF = 2e19;
78 const static double NEGATIVE_INF = -2e19;
79 
80 namespace SimTK {
81 
82 namespace Exception {
83 
84 #ifdef _MSC_VER
85 #pragma warning(push)
86 #pragma warning(disable:4996) // don't warn about sprintf, etc.
87 #endif
88 
89 class OptimizerFailed : public Base {
90 public:
91  OptimizerFailed( const char * fn, int ln, String msg) : Base(fn, ln)
92  {
93  setMessage("Optimizer failed: " + msg );
94  }
95 private:
96 };
97 
98 class UnrecognizedParameter : public Base {
99 public:
100  UnrecognizedParameter( const char * fn, int ln, String msg) : Base(fn, ln)
101  {
102  setMessage("Unrecognized Parameter: " + msg );
103  }
104 private:
105 };
106 
107 class IllegalLapackArg : public Base {
108 public:
109  IllegalLapackArg( const char *fn, int ln, const char *lapackRoutine,
110  int info ) : Base(fn, ln)
111  {
112  char buf[1024];
113 
114  sprintf(buf, "SimTK internal error: %s called with an illegal value to"
115  " argument #%d.\nPlease report this at SimTK.org.",
116  lapackRoutine, -info );
117  setMessage(String(buf));
118 
119  }
120 private:
121 };
122 class IncorrectArrayLength : public Base {
123 public:
124  IncorrectArrayLength( const char *fn, int ln, const char *valueName, int length,
125  const char *paramName, int paramValue, const char *where) : Base(fn, ln)
126  {
127  char buf[1024];
128 
129  sprintf(buf, "Incorrect array length in %s : %s is %d and must equal %s which is %d",
130  where, valueName, length, paramName, paramValue );
131  setMessage(String(buf));
132 
133  }
134 private:
135 };
136 
137 class SingularMatrix : public Base {
138 public:
139  SingularMatrix( const char *fn, int ln, int index,
140  const char *where) : Base(fn, ln)
141  {
142  char buf[1024];
143 
144  sprintf(buf, "%s failed because index %d in matrix was singular and factorization failed",
145  where, index );
146  setMessage(String(buf));
147 
148  }
149 private:
150 };
151 
152 class ConvergedFailed : public Base {
153 public:
154  ConvergedFailed( const char *fn, int ln, const char *algorithm,
155  const char *where) : Base(fn, ln)
156  {
157  char buf[1024];
158 
159  sprintf(buf, "%s failed because %s failed to converge", where, algorithm );
160  setMessage(String(buf));
161 
162  }
163 private:
164 };
165 
166 class NotPositiveDefinite : public Base {
167 public:
168  NotPositiveDefinite( const char *fn, int ln, int index,
169  const char *where) : Base(fn, ln)
170  {
171  char buf[1024];
172 
173  sprintf(buf, "%s failed because index %d in matrix was not positive definite and factorization failed ",
174  where, index );
175  setMessage(String(buf));
176 
177  }
178 private:
179 };
180 
181 #ifdef _MSC_VER
182 #pragma warning(pop)
183 #endif
184 
185 } // namespace Exception
186 
187 } // namespace SimTK
188 
189 #endif // SimTK_SIMMATH_COMMON_H_
Definition: SimTKmath/include/simmath/internal/common.h:98
Definition: SimTKmath/include/simmath/internal/common.h:152
ConvergedFailed(const char *fn, int ln, const char *algorithm, const char *where)
Definition: SimTKmath/include/simmath/internal/common.h:154
static const double POSITIVE_INF
Definition: SimTKmath/include/simmath/internal/common.h:77
void setMessage(const std::string &msgin)
Definition: Exception.h:57
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
NotPositiveDefinite(const char *fn, int ln, int index, const char *where)
Definition: SimTKmath/include/simmath/internal/common.h:168
Definition: SimTKmath/include/simmath/internal/common.h:122
Definition: SimTKmath/include/simmath/internal/common.h:166
static const double NEGATIVE_INF
Definition: SimTKmath/include/simmath/internal/common.h:78
Includes internal headers providing declarations for the basic SimTK Core classes, including Simmatrix.
UnrecognizedParameter(const char *fn, int ln, String msg)
Definition: SimTKmath/include/simmath/internal/common.h:100
Definition: Exception.h:46
void SimTK_version_simmath(int *major, int *minor, int *build)
void SimTK_about_simmath(const char *key, int maxlen, char *value)
SimTK::String is a plug-compatible std::string replacement (plus some additional functionality) inten...
Definition: String.h:62
Definition: SimTKmath/include/simmath/internal/common.h:89
SingularMatrix(const char *fn, int ln, int index, const char *where)
Definition: SimTKmath/include/simmath/internal/common.h:139
IncorrectArrayLength(const char *fn, int ln, const char *valueName, int length, const char *paramName, int paramValue, const char *where)
Definition: SimTKmath/include/simmath/internal/common.h:124
OptimizerFailed(const char *fn, int ln, String msg)
Definition: SimTKmath/include/simmath/internal/common.h:91
Definition: SimTKmath/include/simmath/internal/common.h:107
Definition: SimTKmath/include/simmath/internal/common.h:137
#define SimTK_SIMMATH_EXPORT
Definition: SimTKmath/include/simmath/internal/common.h:64
IllegalLapackArg(const char *fn, int ln, const char *lapackRoutine, int info)
Definition: SimTKmath/include/simmath/internal/common.h:109