00001 /*****************************************************************************/ 00002 /* */ 00003 /* XrdMonArgParserConvert.hh */ 00004 /* */ 00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */ 00006 /* All Rights Reserved */ 00007 /* Produced by Jacek Becla for Stanford University under contract */ 00008 /* DE-AC02-76SF00515 with the Department of Energy */ 00009 /*****************************************************************************/ 00010 00011 // $Id: XrdMonArgParserConvert.hh 24468 2008-06-22 16:47:03Z ganis $ 00012 00013 #include "XrdMon/XrdMonException.hh" 00014 #include "XrdMon/XrdMonErrors.hh" 00015 #include <stdlib.h> /* atoi */ 00016 #include <string.h> 00017 00018 namespace XrdMonArgParserConvert 00019 { 00020 struct Convert2String { 00021 static const char* convert(const char* s) { 00022 return s; 00023 } 00024 }; 00025 00026 struct Convert2Int { 00027 static int convert(const char* s) { 00028 return atoi(s); 00029 } 00030 }; 00031 00032 struct Convert2LL { 00033 static kXR_int64 convert(const char* s) { 00034 kXR_int64 x; 00035 sscanf(s, "%lld", &x); 00036 return x; 00037 } 00038 }; 00039 00040 struct ConvertOnOff { 00041 static bool convert(const char* s) { 00042 if ( 0 == strcasecmp(s, "on") ) { 00043 return true; 00044 } 00045 if ( 0 == strcasecmp(s, "off") ) { 00046 return false; 00047 } 00048 string ss("Expected 'on' or 'off', found "); ss += s; 00049 throw XrdMonException(ERR_INVALIDARG, ss); 00050 return false; 00051 } 00052 }; 00053 } 00054