Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NavKey.cxx

Go to the documentation of this file.
00001 
00002 // $Id: NavKey.cxx,v 1.6 2001/08/29 07:49:32 west Exp $
00003 //
00004 // NavKey
00005 //
00006 // Package: Nav (Navigational Model).
00007 
00008 // Begin_Html<img src="../../pedestrians.gif" align=center>
00009 // <a href="../source_warning.html">Warning for beginners</a>.<br>
00010 // Also see <a href="../../root_crib/index.html">The ROOT Crib</a> and
00011 // <a href="../index.html">The MINOS Class User Guide</a>End_Html
00012 //
00013 // N. West 03/20000
00014 //
00015 // Concept:  Associated Key Value.                                    
00016 //                                                                    
00017 // Purpose:  A NavKey value can be associated with the objects of a   
00018 //           NavSet allowing sorting, slicing and searching by value  
00019 //           See Stroustrup: discriminating union.                    
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 //   Definition of static data members
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 // Definition of member functions (alphabetical order)
00040 // ***************************************************
00041 
00042 
00043 //.....................................................................
00044 
00045 Int_t NavKey::CompareValue(NavKey that) const {
00046 //
00047 //
00048 //  Purpose:  Compare this NavKey with that NavKey
00049 //
00050 //  Arguments: 
00051 //    that         in    The NavKey to be compared with.
00052 //
00053 //  Return:  this - that:-
00054 //             =  1   this > that
00055 //             =  0   this = that
00056 //             = -1   this < that
00057 //             = 999  that NavKey is not of same type.
00058 //
00059 //  Contact:   N. West
00060 //
00061 //  Specification:-
00062 //  =============
00063 //
00064 //  o Compare two NavKeys.
00065 
00066 //  Program Notes:-
00067 //  =============
00068 
00069 //  None.
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 //  Purpose:  Return NavKey type as string.
00099 //
00100 //  Arguments: None.
00101 //
00102 //  Return:  NavKey type as string.  
00103 //
00104 //  Contact:   N. West
00105 //
00106 //  Specification:-
00107 //  =============
00108 //
00109 //  o Return NavKey type as string.
00110 
00111 //  Program Notes:-
00112 //  =============
00113 
00114 //  None.
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 //  Purpose:  Return NavKey value as string.
00130 //
00131 //  Arguments: None.
00132 //
00133 //  Return:  NavKey value as string.  
00134 //
00135 //  Contact:   N. West
00136 //
00137 //  Specification:-
00138 //  =============
00139 //
00140 //  o Return NavKey value as string.
00141 
00142 //  Program Notes:-
00143 //  =============
00144 
00145 //  None.
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 //  Purpose: Constructor for character string value.
00169 //
00170 //  Arguments: 
00171 //    string       in    Initialising char string
00172 //
00173 //  Return:    n/a
00174 //
00175 //  Contact:   N. West
00176 //
00177 //  Specification:-
00178 //  =============
00179 //
00180 //  o Construct NavKey from character string value.  If string too
00181 //    long truncate it.
00182 
00183 //  Program Notes:-
00184 //  =============
00185 
00186 //  None.
00187 
00188   LEA_CTOR   //Leak Checking
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 

Generated on Mon Feb 15 11:07:02 2010 for loon by  doxygen 1.3.9.1