xrootd
XrdMonArgParserConvert.hh
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* */
3 /* XrdMonArgParserConvert.hh */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Jacek Becla for Stanford University under contract */
8 /* DE-AC02-76SF00515 with the Department of Energy */
9 /*****************************************************************************/
10 
11 // $Id$
12 
14 #include "XrdMon/XrdMonErrors.hh"
15 #include <stdlib.h> /* atoi */
16 #include <string.h>
17 
18 namespace XrdMonArgParserConvert
19 {
20  struct Convert2String {
21  static const char* convert(const char* s) {
22  return s;
23  }
24  };
25 
26  struct Convert2Int {
27  static int convert(const char* s) {
28  return atoi(s);
29  }
30  };
31 
32  struct Convert2LL {
33  static kXR_int64 convert(const char* s) {
34  kXR_int64 x;
35  sscanf(s, "%lld", &x);
36  return x;
37  }
38  };
39 
40  struct ConvertOnOff {
41  static bool convert(const char* s) {
42  if ( 0 == strcasecmp(s, "on") ) {
43  return true;
44  }
45  if ( 0 == strcasecmp(s, "off") ) {
46  return false;
47  }
48  string ss("Expected 'on' or 'off', found "); ss += s;
50  return false;
51  }
52  };
53 }
54