00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024 #include <string.h>
00025 #include <stdio.h>
00026 #include "LeakChecker/Lea.h"
00027 #include "Navigation/NavKey.h"
00028 #include "MessageService/MsgService.h"
00029
00030 ClassImp(NavKey)
00031
00032
00033
00034
00035 CVSID("$Id: NavKey.cxx,v 1.6 2001/08/29 07:49:32 west Exp $");
00036
00037 char NavKey::fValueStr[15];
00038
00039
00040
00041
00042
00043
00044
00045 Int_t NavKey::CompareValue(NavKey that) const {
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 if ( ! CompareType(that) ) {
00072
00073 MSG("Nav", Msg::kWarning) << "Cannot compare NavKeys:-" << endl
00074 << " this:" << GetType() << " " << GetValue() << endl
00075 << " that:" << that.GetType() << " " << that.GetValue() << endl;
00076
00077 return 999;
00078 }
00079
00080 switch (fTag) {
00081 case kInt:
00082 return ( fInt > that.fInt ) ? 1 : ( fInt < that.fInt ) ? -1 : 0;
00083 case kFloat:
00084 return ( fFloat > that.fFloat ) ? 1 :
00085 ( fFloat < that.fFloat) ? -1 : 0;
00086 default:
00087 Int_t test = strcmp(fString, that.fString);
00088 return ( test > 0 ) ? 1 : ( test < 0 ) ? -1 : 0;
00089 }
00090
00091 }
00092
00093
00094
00095 string NavKey::GetType() const {
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 switch (fTag) {
00117 case kInt: return "Int";
00118 case kFloat: return "Float";
00119 default: return "String";
00120 }
00121
00122 }
00123
00124
00125
00126 string NavKey::GetValue() const {
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 switch (fTag) {
00148 case kInt:
00149 sprintf( fValueStr, "%ld", fInt);
00150 break;
00151 case kFloat:
00152 sprintf( fValueStr, "%g", fFloat );
00153 break;
00154 default:
00155 sprintf( fValueStr, "%s", fString);
00156 break;
00157 }
00158
00159 return fValueStr;
00160
00161 }
00162
00163
00164
00165 NavKey::NavKey(const char* string) {
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 LEA_CTOR
00189
00190 strncpy( fString, string, kMaxStringSize );
00191 fString[kMaxStringSize-1] = '\0';
00192 fTag = kString;
00193
00194 if ( strlen( string ) >= kMaxStringSize ) {
00195 MSG("Nav", Msg::kError) << "String " << string
00196 << " too long, truncated to " << fString << endl;
00197 }
00198 }
00199