00001 /*----------------------------------------------------------------------------- 00002 Name: PriorityEnum.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Allows you be called back after a given delay. 00006 -----------------------------------------------------------------------------*/ 00007 00008 #include <util/PriorityEnum.h> 00009 #include <util/lexical_cast.h> 00010 #include <iostream> 00011 00012 namespace org { namespace xmlBlaster { namespace util { 00013 00014 PriorityEnum int2Priority(int val) 00015 { 00016 if (val <= MIN_PRIORITY) return MIN_PRIORITY; 00017 if (val >= MAX_PRIORITY) return MAX_PRIORITY; 00018 switch(val) { 00019 case MIN1_PRIORITY : return MIN1_PRIORITY; 00020 case MIN2_PRIORITY : return MIN2_PRIORITY; 00021 case LOW_PRIORITY : return LOW_PRIORITY; 00022 case LOW4_PRIORITY : return LOW4_PRIORITY; 00023 case NORM_PRIORITY : return NORM_PRIORITY; 00024 case NORM6_PRIORITY : return NORM6_PRIORITY; 00025 case HIGH_PRIORITY : return HIGH_PRIORITY; 00026 } 00027 return HIGH8_PRIORITY; 00028 } 00029 00030 PriorityEnum str2Priority(const std::string& val) 00031 { 00032 if (val == "MIN") return MIN_PRIORITY; 00033 if (val == "LOW") return LOW_PRIORITY; 00034 if (val == "NORM") return NORM_PRIORITY; 00035 if (val == "HIGH") return HIGH_PRIORITY; 00036 if (val == "MAX") return MAX_PRIORITY; 00037 try { 00038 int prio = lexical_cast<int>(val); 00039 return int2Priority(prio); 00040 } 00041 catch (...) { //bad_lexical_cast 00042 std::cerr << "Don't know what to do with priority '" << val << "', returning NORM priority" << std::endl; 00043 return NORM_PRIORITY; 00044 } 00045 /* 00046 int prio; 00047 int numConverted = sscanf(val.c_str(), "%d", &prio); 00048 if (numConverted != 1) { 00049 std::cerr << "Don't know what to to with priority '" << val << "', returning NORM priority" << std::endl; 00050 return NORM_PRIORITY; 00051 } 00052 return int2Priority(prio); 00053 */ 00054 } 00055 00056 00057 }}} // namespaces 00058 00059 00060