1 /*-----------------------------------------------------------------------------
2 Name: PriorityEnum.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Allows you be called back after a given delay.
6 -----------------------------------------------------------------------------*/
7
8 #include <util/PriorityEnum.h>
9 #include <util/lexical_cast.h>
10 #include <iostream>
11
12 namespace org { namespace xmlBlaster { namespace util {
13
14 PriorityEnum int2Priority(int val)
15 {
16 if (val <= MIN_PRIORITY) return MIN_PRIORITY;
17 if (val >= MAX_PRIORITY) return MAX_PRIORITY;
18 switch(val) {
19 case MIN1_PRIORITY : return MIN1_PRIORITY;
20 case MIN2_PRIORITY : return MIN2_PRIORITY;
21 case LOW_PRIORITY : return LOW_PRIORITY;
22 case LOW4_PRIORITY : return LOW4_PRIORITY;
23 case NORM_PRIORITY : return NORM_PRIORITY;
24 case NORM6_PRIORITY : return NORM6_PRIORITY;
25 case HIGH_PRIORITY : return HIGH_PRIORITY;
26 }
27 return HIGH8_PRIORITY;
28 }
29
30 PriorityEnum str2Priority(const std::string& val)
31 {
32 if (val == "MIN") return MIN_PRIORITY;
33 if (val == "LOW") return LOW_PRIORITY;
34 if (val == "NORM") return NORM_PRIORITY;
35 if (val == "HIGH") return HIGH_PRIORITY;
36 if (val == "MAX") return MAX_PRIORITY;
37 try {
38 int prio = lexical_cast<int>(val);
39 return int2Priority(prio);
40 }
41 catch (...) { //bad_lexical_cast
42 std::cerr << "Don't know what to do with priority '" << val << "', returning NORM priority" << std::endl;
43 return NORM_PRIORITY;
44 }
45 /*
46 int prio;
47 int numConverted = sscanf(val.c_str(), "%d", &prio);
48 if (numConverted != 1) {
49 std::cerr << "Don't know what to to with priority '" << val << "', returning NORM priority" << std::endl;
50 return NORM_PRIORITY;
51 }
52 return int2Priority(prio);
53 */
54 }
55
56
57 }}} // namespaces
syntax highlighted by Code2HTML, v. 0.9.1