Sierra Toolkit Version of the Day
WriterParser.cpp
00001 
00002 #include <sstream>
00003 #include <iomanip>
00004 #include <map>
00005 
00006 #include <stk_util/diag/WriterParser.hpp>
00007 #include <stk_util/diag/Trace.hpp>
00008 #include <stk_util/diag/Writer_fwd.hpp>
00009 #include <iostream>
00010 
00011 namespace stk {
00012 namespace diag {
00013 
00014 WriterParser::WriterParser()
00015   : OptionMaskParser()
00016 {
00017   mask("coverage", 0, "Collect and display traceable function usage coverage");
00018   mask("members", LOG_MEMBERS, "Display data structure members messages");
00019   mask("trace", LOG_TRACE, "Display execution trace");
00020   mask("trace-stats", LOG_TRACE_STATS, "Display execution time and memory usage during trace");
00021   mask("trace-down", LOG_TRACE_SUB_CALLS, "Display subsequent calls after tracing is enabled");
00022 }
00023 
00024 
00025 OptionMaskParser::Mask
00026 WriterParser::parse(
00027   const char *          mask_string) const
00028 {
00029   m_optionMask = LOG_MEMBERS;
00030   return OptionMaskParser::parse(mask_string);
00031 }
00032 
00033 
00034 void
00035 WriterParser::parseArg(
00036   const std::string &  name,
00037   const std::string &  arg) const
00038 {
00039   if (name == "trace") {
00040     m_optionMask |= LOG_TRACE;
00041     if (!arg.empty()) {
00042       std::string::const_iterator it0 = arg.begin();
00043       std::string::const_iterator it1;
00044       std::string::const_iterator it2;
00045       do {
00046         // Trim preceeding spaces
00047         while (it0 != arg.end() && *it0 == ' ')
00048           it0++;
00049 
00050         if (it0 == arg.end())
00051           break;
00052 
00053         int paren_count = 0;
00054         for (it1 = it0; it1 != arg.end(); ++it1) {
00055           if (*it1 == '(')
00056             ++paren_count;
00057           else if (*it1 == ')')
00058             --paren_count;
00059           else if (*it1 == ',' && paren_count == 0)
00060             break;
00061         }
00062 
00063 
00064         // Trim trailing spaces
00065         it2 = it1;
00066         while (it2 != it0 && *(it2 - 1) == ' ')
00067           --it2;
00068 
00069         std::string function(it0, it2);
00070 
00071         Trace::addTraceFunction(function);
00072 
00073         it0 = it1 + 1;
00074       } while (it1 != arg.end());
00075     }
00076     else
00077       m_optionMask |= LOG_TRACE_SUB_CALLS;
00078   }
00079 
00080   else if (name == "coverage") {
00081     Trace::enableCoverage();
00082   }
00083 
00084   else {
00085     OptionMaskNameMap::const_iterator mask_entry = m_optionMaskNameMap.find(name.c_str());
00086 
00087     if (mask_entry != m_optionMaskNameMap.end())
00088       m_optionMask |= (*mask_entry).second.m_mask;
00089     else {
00090       Mask  mask_hex = 0;
00091       std::istringstream mask_hex_stream(name.c_str());
00092       if (mask_hex_stream >> std::resetiosflags(std::ios::basefield) >> mask_hex)
00093         m_optionMask |= mask_hex;
00094       else
00095         m_status = false;
00096     }
00097   }
00098 }
00099 
00100 } // namespace diag
00101 } // namespace stk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines