Simbody  3.4 (development)
common.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMMATH_COMMON_H_
00002 #define SimTK_SIMMATH_COMMON_H_ 
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                        Simbody(tm): SimTKmath                              *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2006-12 Stanford University and the Authors.        *
00013  * Authors: Jack Middleton                                                    *
00014  * Contributors: Michael Sherman                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00032 #include "SimTKcommon.h"
00033 
00034 /* Shared libraries are messy in Visual Studio. We have to distinguish three
00035  * cases:
00036  *   (1) this header is being used to build the simmath shared library (dllexport)
00037  *   (2) this header is being used by a *client* of the simmath shared
00038  *       library (dllimport)
00039  *   (3) we are building the simmath static library, or the client is
00040  *       being compiled with the expectation of linking with the
00041  *       simmath static library (nothing special needed)
00042  * In the CMake script for building this library, we define one of the symbols
00043  *     SIMMATH_BUILDING_{SHARED|STATIC}_LIBRARY
00044  * Client code normally has no special symbol defined, in which case we'll
00045  * assume it wants to use the shared library. However, if the client defines
00046  * the symbol SimTK_USE_STATIC_LIBRARIES we'll suppress the dllimport so
00047  * that the client code can be linked with static libraries. Note that
00048  * the client symbol is not library dependent, while the library symbols
00049  * affect only the simmath library, meaning that other libraries can
00050  * be clients of this one. However, we are assuming all-static or all-shared.
00051 */
00052 
00053 #ifdef _WIN32
00054     #if defined(SimTK_SIMMATH_BUILDING_SHARED_LIBRARY)
00055         #define SimTK_SIMMATH_EXPORT __declspec(dllexport)
00056     #elif defined(SimTK_SIMMATH_BUILDING_STATIC_LIBRARY) || defined(SimTK_USE_STATIC_LIBRARIES)
00057         #define SimTK_SIMMATH_EXPORT
00058     #else
00059         /* i.e., a client of a shared library */
00060         #define SimTK_SIMMATH_EXPORT __declspec(dllimport)
00061     #endif
00062 #else
00063     /* Linux, Mac */
00064     #define SimTK_SIMMATH_EXPORT
00065 #endif
00066 
00067 
00068 // Every SimTK Core library must provide these two routines, with the library
00069 // name appearing after the "version_" and "about_".
00070 extern "C" {
00071     SimTK_SIMMATH_EXPORT void SimTK_version_simmath(int* major, int* minor, int* build);
00072     SimTK_SIMMATH_EXPORT void SimTK_about_simmath(const char* key, int maxlen, char* value);
00073 }
00074 
00075 
00076 
00077 const static double POSITIVE_INF =  2e19;
00078 const static double NEGATIVE_INF = -2e19;
00079 
00080 namespace SimTK {
00081 
00082 
00083 namespace Exception {
00084 
00085 class OptimizerFailed : public Base {
00086 public:
00087         OptimizerFailed( const char * fn, int ln, String msg) : Base(fn, ln)
00088         {
00089             setMessage("Optimizer failed: " + msg );
00090         }
00091 private:
00092 };
00093 
00094 class UnrecognizedParameter : public Base {
00095 public:
00096         UnrecognizedParameter( const char * fn, int ln, String msg) : Base(fn, ln)
00097         {
00098             setMessage("Unrecognized Parameter: " + msg );
00099         }
00100 private:
00101 };
00102 
00103 class IllegalLapackArg : public Base {
00104 public:
00105         IllegalLapackArg( const char *fn, int ln, const char *lapackRoutine, 
00106                   int info ) : Base(fn, ln)
00107         {
00108         char buf[1024];
00109 
00110         sprintf(buf, "SimTK internal error: %s called with an illegal value to"
00111             " argument #%d.\nPlease report this at SimTK.org.",
00112             lapackRoutine, -info );
00113         setMessage(String(buf));
00114 
00115         }
00116 private:
00117 };
00118 class IncorrectArrayLength : public Base {
00119 public:
00120         IncorrectArrayLength( const char *fn, int ln, const char *valueName, int length,  
00121                               const char *paramName, int paramValue, const char *where) : Base(fn, ln)
00122         {
00123         char buf[1024];
00124 
00125         sprintf(buf, "Incorrect array length in %s : %s is %d and must equal %s which is %d",
00126             where, valueName, length, paramName, paramValue );
00127         setMessage(String(buf));
00128 
00129         }
00130 private:
00131 };
00132 
00133 class SingularMatrix : public Base {
00134 public:
00135         SingularMatrix( const char *fn, int ln, int index,  
00136                                const char *where) : Base(fn, ln)
00137         {
00138         char buf[1024];
00139 
00140         sprintf(buf, "%s failed because index %d in matrix was singular and factorization failed",
00141             where, index );
00142         setMessage(String(buf));
00143 
00144         }
00145 private:
00146 };
00147 
00148 class ConvergedFailed : public Base {
00149 public:
00150         ConvergedFailed( const char *fn, int ln, const char *algorithm,  
00151                                const char *where) : Base(fn, ln)
00152         {
00153         char buf[1024];
00154 
00155         sprintf(buf, "%s failed because %s failed to converge", where, algorithm );
00156         setMessage(String(buf));
00157 
00158         }
00159 private:
00160 };
00161 
00162 class NotPositiveDefinite : public Base {
00163 public:
00164         NotPositiveDefinite( const char *fn, int ln, int index,  
00165                                const char *where) : Base(fn, ln)
00166         {
00167         char buf[1024];
00168 
00169         sprintf(buf, "%s failed because index %d in matrix was not positive definite and factorization failed ",
00170             where, index );
00171         setMessage(String(buf));
00172 
00173         }
00174 private:
00175 };
00176 } // namespace Exception
00177 
00178 } //  namespace SimTK
00179 
00180 #endif // SimTK_SIMMATH_COMMON_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines