Sierra Toolkit  Version of the Day
FArray.cpp
1 #include <iostream>
2 #include <stdexcept>
3 #include <sstream>
4 
6 #include <stk_util/diag/StringUtil.hpp>
7 
8 namespace sierra {
9 
10 // Force inclusion of array_dimension_error by linker
11 FArrayBootstrap::~FArrayBootstrap()
12 {
13  static void (*array_dimension_error_bootstrap)(const std::type_info &typeinfo, unsigned dimension, unsigned value, unsigned upper) = array_dimension_error;
14 
15  (void) array_dimension_error_bootstrap; // suppress compiler warning for unused variable
16 }
17 
18 namespace {
19 
20 const char *ordinal[] = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eight"};
21 
22 } // namespace <unnamed>
23 
24 
25 void
26 array_dimension_error(
27  const std::type_info & type,
28  unsigned dimension,
29  unsigned value,
30  unsigned upper)
31 {
32  std::ostringstream os ;
33  os << demangle(type.name()) << " ";
34  if (dimension > sizeof(ordinal)/sizeof(ordinal[0]))
35  os << dimension;
36  else
37  os << ordinal[dimension];
38  os << " dimension value " << value
39  << " is out of bounds (0:" << upper - 1 << ")";
40 
41  throw std::range_error(os.str().c_str());
42 }
43 
44 } // namespace sierra
Definition: Env.cpp:53
const char * demangle(const char *symbol)
Function demangle returns the demangled C++ symbol from the mangled C++ symbol. The mangled named is ...
Definition: Platform.cpp:210