/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/ers/ers-00-00-03/src/Core.cxx

Go to the documentation of this file.
00001 #include <ctype.h>
00002 #include <string.h>
00003 
00004 #include <iostream>
00005 #include <sstream>
00006 #include <string.h>
00007 #include "ers/Core.h"
00008 #include <cstdlib> 
00009 #include <assert.h>
00010 
00011 const char* const ers::Core::SEVERITY_NAMES[] = { "none", "debug_0", "debug_1", "debug_2", "debug_3", "information", "notification", "warning", "error", "fatal", "maximum (illegal)" } ;
00012 const char* const ers::Core::BOOLEAN_NAMES[] = { "false", "true" } ; 
00013 const char* const ers::Core::RESPONSIBILITY_NAMES[] = { "precondition", "internal", "subSystem" } ; 
00014 const std::string ers::Core::empty_string = "" ;
00015 
00022 const char *ers::Core::to_string(ers::severity_t s) throw() {
00023     const unsigned int index = (unsigned int) s ;
00024     assert(index<=severity_max); 
00025     return ers::Core::SEVERITY_NAMES[index] ; 
00026 } // getSeverityText
00027 
00033 ers::severity_t ers::Core::parse_severity(const char *s) throw() {
00034     for(int i=0;i<severity_max;i++) {
00035         if (strcmp(s,ers::Core::SEVERITY_NAMES[i])==0) return (ers::severity_t) i ; 
00036     }// for
00037     return severity_none ; 
00038 } // parse_severity
00039 
00045 ers::severity_t ers::Core::parse_severity(const std::string &s) throw() {
00046     return parse_severity(s.c_str());
00047 } // parse_severity
00048 
00054 const char* ers::Core::to_string(ers::responsibility_t  r) throw() {
00055     const unsigned int index = (unsigned int) r ;
00056     assert(index<=resp_max);
00057     return RESPONSIBILITY_NAMES[index] ;
00058 } // to_string
00059 
00065 ers::responsibility_t  ers::Core::parse_responsibility(const char *s) throw() {
00066     for(int i=0;i<resp_max;i++) {
00067         if (strcmp(s,RESPONSIBILITY_NAMES[i])==0) return (ers::responsibility_t) i ; 
00068     } // for 
00069     return resp_unknown ;
00070 } // parse_responsability
00071 
00077 ers::responsibility_t  ers::Core::parse_responsibility(const std::string &s) throw() {
00078     return parse_responsibility(s.c_str()) ; 
00079 } // parse_responsability
00080 
00088 int ers::Core::parse_boolean(const char* s) throw() {
00089     if (! s) return -1 ; 
00090     if (! *s) return -1 ; 
00091     if (strcasecmp(s,BOOLEAN_NAMES[1])==0) return 1 ;
00092     if (strcasecmp(s,BOOLEAN_NAMES[0])==0) return 0 ; 
00093     return -1 ; 
00094 } // parse_boolean
00095 
00101 const char* ers::Core::to_string(bool b) throw () {
00102     int index = b ? 1 : 0 ;
00103     return BOOLEAN_NAMES[index] ;
00104 } // to_string
00105 
00106 
00114 std::string ers::Core::parse_prefix_string(const char **ptr) throw() {
00115     if (ptr==0 || *ptr==0 || **ptr=='\0') return ers::Core::empty_string ; 
00116     int l = 0 ; 
00117     while(isdigit(**ptr)) { // we parse the integer 
00118         l*=10 ;
00119         l+=(**ptr)-'0' ; 
00120         (*ptr)++ ; 
00121     } // 
00122     std::string s(*ptr,l); // we create the string 
00123     (*ptr)+=l ; 
00124     return s ; 
00125 } // parse_gcc_string
00126 
00127 
00135 std::string ers::Core::umangle_gcc_class_name(const char* name) throw() {
00136     if (name==0 || strlen(name)==0) return ers::Core::empty_string ; 
00137     const char *ptr = name ; 
00138     std::ostringstream stream ; 
00139     while (*ptr=='P') { // pointers are denoted with P
00140         stream << "*" ;
00141         ptr++ ; 
00142     } // if
00143     while (*ptr=='N') { // namespace are denoted by N+string 
00144         ptr++ ; 
00145         stream << parse_prefix_string(&ptr) << "::" ; 
00146     } // 
00147     stream << parse_prefix_string(&ptr);
00148     return stream.str(); 
00149 } // umangle_gcc_class_name
00150 
00151 std::vector<std::string> ers::Core::tokenize(const std::string &text, const std::string &separators) {
00152     std::vector<std::string> result_vector ; 
00153     std::string::size_type start_p, end_p ; 
00154     start_p = text.find_first_not_of(separators) ; 
00155     while(start_p != std::string::npos) {
00156         end_p = text.find_first_of(separators,start_p) ;
00157         if (end_p == std::string::npos) {
00158             end_p = text.length(); 
00159         }
00160         const std::string sub_str = text.substr(start_p,end_p-start_p);
00161         result_vector.push_back(sub_str) ; 
00162         start_p = text.find_first_not_of(separators,end_p) ;
00163     } // while
00164     return result_vector ; 
00165 } // tokenize
00166 
00167 
00168 
00169 

Generated on Tue Nov 29 22:58:27 2016 for BOSS_7.0.2 by  doxygen 1.4.7