simmath/internal/common.h

Go to the documentation of this file.
00001 #ifndef SIMMATH_COMMON_H_
00002 #define SIMMATH_COMMON_H_ 
00003 
00004 /* Portions copyright (c) 2006 Stanford University and Jack Middleton.
00005  * Contributors:
00006  * 
00007  * Permission is hereby granted, free of charge, to any person obtaining
00008  * a copy of this software and associated documentation files (the
00009  * "Software"), to deal in the Software without restriction, including 
00010  * without limitation the rights to use, copy, modify, merge, publish, 
00011  * distribute, sublicense, and/or sell copies of the Software, and to
00012  * permit persons to whom the Software is furnished to do so, subject
00013  * to the following conditions:
00014  * 
00015  * The above copyright notice and this permission notice shall be included 
00016  * in all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00021  * IN NO EVENT SHALL THE AUTHORS, COPYRIGHT HOLDERS, OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00023  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00024  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 argNum ) : Base(fn, ln)
00107         {
00108         char buf[1024];
00109 
00110         sprintf(buf, "SimTK internal error: %s called with an illegal value to arguement #%d \n Please report this to SimTK",
00111             lapackRoutine, argNum );
00112         setMessage(String(buf));
00113 
00114         }
00115 private:
00116 };
00117 class IncorrectArrayLength : public Base {
00118 public:
00119         IncorrectArrayLength( const char *fn, int ln, const char *valueName, int length,  
00120                               const char *paramName, int paramValue, const char *where) : Base(fn, ln)
00121         {
00122         char buf[1024];
00123 
00124         sprintf(buf, "Incorrect array length in %s : %s is %d and must equal %s which is %d",
00125             where, valueName, length, paramName, paramValue );
00126         setMessage(String(buf));
00127 
00128         }
00129 private:
00130 };
00131 
00132 class SingularMatrix : public Base {
00133 public:
00134         SingularMatrix( const char *fn, int ln, int index,  
00135                                const char *where) : Base(fn, ln)
00136         {
00137         char buf[1024];
00138 
00139         sprintf(buf, "%s failed because index %d in matrix was singular and factorization failed",
00140             where, index );
00141         setMessage(String(buf));
00142 
00143         }
00144 private:
00145 };
00146 
00147 class ConvergedFailed : public Base {
00148 public:
00149         ConvergedFailed( const char *fn, int ln, const char *algorithm,  
00150                                const char *where) : Base(fn, ln)
00151         {
00152         char buf[1024];
00153 
00154         sprintf(buf, "%s failed because %s failed to converge", where, algorithm );
00155         setMessage(String(buf));
00156 
00157         }
00158 private:
00159 };
00160 
00161 class NotPositiveDefinite : public Base {
00162 public:
00163         NotPositiveDefinite( const char *fn, int ln, int index,  
00164                                const char *where) : Base(fn, ln)
00165         {
00166         char buf[1024];
00167 
00168         sprintf(buf, "%s failed because index %d in matrix was not positive definite and factorization failed ",
00169             where, index );
00170         setMessage(String(buf));
00171 
00172         }
00173 private:
00174 };
00175 } // namespace Exception
00176 
00177 } //  namespace SimTK
00178 
00179 #endif // SIMMATH_COMMON_H_

Generated on Thu Aug 12 16:37:05 2010 for SimTKcore by  doxygen 1.6.1