|
Sierra Toolkit
Version of the Day
|
00001 00002 #include <sstream> 00003 #include <iomanip> 00004 #include <map> 00005 00006 #include <stk_util/diag/Option.hpp> 00007 #include <stk_util/diag/Trace.hpp> 00008 #include <stk_util/diag/Writer_fwd.hpp> 00009 #include <iostream> 00010 00011 namespace stk_classic { 00012 namespace diag { 00013 00014 OptionMaskParser::Mask 00015 OptionMaskParser::parse( 00016 const char * mask) const 00017 { 00018 if (mask) { 00019 const std::string mask_string(mask); 00020 00021 m_status = true; 00022 00023 std::string::const_iterator it0 = mask_string.begin(); 00024 std::string::const_iterator it1; 00025 std::string::const_iterator it2; 00026 std::string::const_iterator it3; 00027 do { 00028 // Trim preceeding spaces 00029 while (it0 != mask_string.end() && *it0 == ' ') 00030 it0++; 00031 00032 if (it0 == mask_string.end()) 00033 break; 00034 00035 for (it1 = it0; it1 != mask_string.end(); ++it1) { 00036 if (*it1 == '(' || *it1 == ':' || *it1 == ',') 00037 break; 00038 } 00039 00040 // Trim trailing spaces 00041 it2 = it1; 00042 while (it2 != it0 && *(it2 - 1) == ' ') 00043 --it2; 00044 00045 std::string name(it0, it2); 00046 00047 // Get argument list 00048 if (*it1 == '(') { 00049 it2 = it1 + 1; 00050 00051 // Trim preceeding spaces 00052 while (it2 != mask_string.end() && *it2 == ' ') 00053 ++it2; 00054 00055 int paren_count = 0; 00056 00057 for (; it1 != mask_string.end(); ++it1) { 00058 if (*it1 == '(') 00059 ++paren_count; 00060 else if (*it1 == ')') { 00061 --paren_count; 00062 if (paren_count == 0) 00063 break; 00064 } 00065 } 00066 it3 = it1; 00067 00068 // Trim trailing spaces 00069 while (it3 != it2 && *(it3 - 1) == ' ') 00070 --it3; 00071 00072 // Find next argument start 00073 for (; it1 != mask_string.end(); ++it1) 00074 if (*it1 == ':' || *it1 == ',') 00075 break; 00076 } 00077 else 00078 it2 = it3 = it1; 00079 00080 const std::string arg(it2, it3); 00081 00082 parseArg(name, arg); 00083 00084 it0 = it1 + 1; 00085 } while (it1 != mask_string.end()); 00086 } 00087 00088 return m_optionMask; 00089 } 00090 00091 00092 void 00093 OptionMaskParser::parseArg( 00094 const std::string & name, 00095 const std::string & arg) const 00096 { 00097 OptionMaskNameMap::const_iterator mask_entry = m_optionMaskNameMap.find(name); 00098 00099 if (mask_entry != m_optionMaskNameMap.end()) m_optionMask |= (*mask_entry).second.m_mask; 00100 else { 00101 Mask mask_hex = 0; 00102 std::istringstream mask_hex_stream(name.c_str()); 00103 if (mask_hex_stream >> std::resetiosflags(std::ios::basefield) >> mask_hex) 00104 m_optionMask |= mask_hex; 00105 else 00106 m_status = false; 00107 } 00108 } 00109 00110 00111 std::ostream & 00112 OptionMaskParser::describe( 00113 std::ostream & os) const 00114 { 00115 os << "Specify a comma separated list of:" << std::endl; 00116 for (OptionMaskNameMap::const_iterator it = m_optionMaskNameMap.begin(); it != m_optionMaskNameMap.end(); ++it) 00117 (*it).second.describe(os); 00118 00119 return os; 00120 } 00121 00122 00123 std::ostream & 00124 OptionMaskName::describe( 00125 std::ostream & os) const 00126 { 00127 return os << " " << std::left << std::setw(20) << m_name << "\t" << m_description << std::endl; 00128 } 00129 00130 } // namespace diag 00131 } // namespace stk_classic