1 /* -------------------------------------------------------------------------- *
2 * OpenSim: About.cpp *
3 * -------------------------------------------------------------------------- *
4 * The OpenSim API is a toolkit for musculoskeletal modeling and simulation. *
5 * See http://opensim.stanford.edu and the NOTICE file for more information. *
6 * OpenSim is developed at Stanford University and supported by the US *
7 * National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
8 * through the Warrior Web program. *
9 * *
10 * Copyright (c) 2005-2017 Stanford University and the Authors *
11 * Author(s): Ayman Habib *
12 * *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may *
14 * not use this file except in compliance with the License. You may obtain a *
15 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
16 * *
17 * Unless required by applicable law or agreed to in writing, software *
18 * distributed under the License is distributed on an "AS IS" BASIS, *
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
20 * See the License for the specific language governing permissions and *
21 * limitations under the License. *
22 * -------------------------------------------------------------------------- */
23
24 /**
25 * Define the standard SimTK compliant "version" and "about" routines.
26 */
27
28
29 #include "osimActuatorsDLL.h"
30
31 #include <string>
32 #include <cstring>
33 #include <cctype>
34
35
36 #define STR(var) #var
37 #define MAKE_VERSION_STRING(maj,min,build) STR(maj.min.build)
38 #define MAKE_COPYRIGHT_STRING(y,a) \
39 "Copyright (c) " STR(y) " Stanford University, " STR(a)
40 #define MAKE_STRING(a) STR(a)
41
42 #define GET_VERSION_STRING \
43 MAKE_VERSION_STRING(OPENSIM_ACTUATORS_MAJOR_VERSION, \
44 OPENSIM_ACTUATORS_MINOR_VERSION, \
45 OPENSIM_ACTUATORS_BUILD_VERSION)
46
47 #define GET_COPYRIGHT_STRING \
48 MAKE_COPYRIGHT_STRING(OPENSIM_ACTUATORS_COPYRIGHT_YEARS, \
49 OPENSIM_ACTUATORS_AUTHORS)
50
51 #define GET_AUTHORS_STRING \
52 MAKE_STRING(OPENSIM_ACTUATORS_AUTHORS)
53
54 #define GET_LIBRARY_STRING \
55 MAKE_STRING(OPENSIM_ACTUATORS_LIBRARY_NAME)
56
57 #define GET_TYPE_STRING \
58 MAKE_STRING(OPENSIM_ACTUATORS_TYPE)
59
60 #ifndef NDEBUG
61 #define GET_DEBUG_STRING "debug"
62 #else
63 #define GET_DEBUG_STRING "release"
64 #endif
65
66
67 using namespace std;
68
69
70 extern "C" {
71
opensim_version_actuators(int * major,int * minor,int * build)72 void opensim_version_actuators(int* major, int* minor, int* build) {
73 static const char* l = "OPENSIM library=" GET_LIBRARY_STRING;
74 static const char* t = "OPENSIM type=" GET_TYPE_STRING;
75 static const char* d = "OPENSIM debug=" GET_DEBUG_STRING;
76 static const char* v = "OPENSIM version=" GET_VERSION_STRING;
77 static const char* c = "OPENSIM copyright=" GET_COPYRIGHT_STRING;
78
79 if (major) *major = OPENSIM_ACTUATORS_MAJOR_VERSION;
80 if (minor) *minor = OPENSIM_ACTUATORS_MINOR_VERSION;
81 if (build) *build = OPENSIM_ACTUATORS_BUILD_VERSION;
82
83 // Force statics to be present in the binary (Release mode otherwise
84 // optimizes them away).
85 volatile int i=0;
86 if (i) { // never true, but compiler doesn't know ...
87 *major = *l + *t + *d + *v + *c;
88 }
89 }
90
opensim_about_actuators(const char * key,int maxlen,char * value)91 void opensim_about_actuators(const char* key, int maxlen, char* value) {
92 if (maxlen <= 0 || value==0) return;
93 value[0] = '\0'; // in case we don't find a match
94 if (key==0) return;
95
96 // downshift the key
97 std::string skey(key);
98 for (size_t i=0; i<skey.size(); ++i)
99 skey[i] = tolower(skey[i]);
100
101 const char* v = 0;
102 if (skey == "version") v = GET_VERSION_STRING;
103 else if (skey == "library") v = GET_LIBRARY_STRING;
104 else if (skey == "type") v = GET_TYPE_STRING;
105 else if (skey == "copyright") v = GET_COPYRIGHT_STRING;
106 else if (skey == "authors") v = GET_AUTHORS_STRING;
107 else if (skey == "debug") v = GET_DEBUG_STRING;
108
109 if (v) {
110 strncpy(value,v,maxlen-1);
111 value[maxlen-1] = '\0'; // in case we ran out of room
112 }
113 }
114
115 }
116