|
Sierra Toolkit
Version of the Day
|
00001 #include <iostream> 00002 #include <stdexcept> 00003 #include <sstream> 00004 00005 #include <stk_util/diag/FArray.hpp> 00006 #include <stk_util/diag/StringUtil.hpp> 00007 00008 namespace sierra { 00009 00010 // Force inclusion of array_dimension_error by linker 00011 FArrayBootstrap::~FArrayBootstrap() 00012 { 00013 static void (*array_dimension_error_bootstrap)(const std::type_info &typeinfo, unsigned dimension, unsigned value, unsigned upper) = array_dimension_error; 00014 00015 (void) array_dimension_error_bootstrap; // suppress compiler warning for unused variable 00016 } 00017 00018 namespace { 00019 00020 const char *ordinal[] = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eight"}; 00021 00022 } // namespace <unnamed> 00023 00024 00025 void 00026 array_dimension_error( 00027 const std::type_info & type, 00028 unsigned dimension, 00029 unsigned value, 00030 unsigned upper) 00031 { 00032 std::ostringstream os ; 00033 os << demangle(type.name()) << " "; 00034 if (dimension > sizeof(ordinal)/sizeof(ordinal[0])) 00035 os << dimension; 00036 else 00037 os << ordinal[dimension]; 00038 os << " dimension value " << value 00039 << " is out of bounds (0:" << upper - 1 << ")"; 00040 00041 throw std::range_error(os.str().c_str()); 00042 } 00043 00044 } // namespace sierra