|
Sierra Toolkit Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #include <stk_util/environment/ReportHandler.hpp> 00010 00011 #include <iostream> 00012 #include <stdexcept> 00013 00014 namespace stk { 00015 00016 void 00017 default_report_handler( 00018 const char * message, 00019 int type) 00020 { 00021 std::cout << "Message type " << type << ": " << message << std::endl; 00022 } 00023 00024 REH 00025 s_reportHandler = &default_report_handler; 00026 00027 00028 void 00029 report( 00030 const char * message, 00031 int type) 00032 { 00033 (*s_reportHandler)(message, type); 00034 } 00035 00036 00037 REH 00038 set_report_handler( 00039 REH reh) 00040 { 00041 /* %TRACE[ON]% */ /* %TRACE% */ 00042 if (!reh) 00043 throw std::runtime_error("Cannot set report handler to NULL"); 00044 00045 REH prev_reh = s_reportHandler; 00046 s_reportHandler = reh; 00047 00048 return prev_reh; 00049 } 00050 00051 00052 std::string 00053 source_relative_path( 00054 const std::string & path) 00055 { 00056 static const char *prefix[] = {"/src/", "/include/", "/Apps_", "/stk_"}; 00057 00058 for (unsigned int i = 0; i < sizeof(prefix)/sizeof(prefix[0]); ++i) { 00059 std::string::size_type j = path.rfind(prefix[i], path.length()); 00060 if (j != std::string::npos) { 00061 j = path.rfind("/", j - 1); 00062 if (j != std::string::npos) 00063 return path.substr(j + 1, path.length()); 00064 else 00065 return path; 00066 } 00067 } 00068 return path; 00069 } 00070 00071 } // namespace stk