Free Electron
Array.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __core_Array_h__
8 #define __core_Array_h__
9 
10 namespace fe
11 {
12 
13 /**************************************************************************//**
14  @brief Wrapper for std::vector
15 
16  @ingroup core
17 
18  Allows bounds-checking just for debug builds.
19 *//***************************************************************************/
20 template<typename T>
21 class FE_DL_EXPORT Array: public std::vector<T>
22 {
23  public:
24 
25 explicit Array(void) {}
26 
27 explicit Array(U32 a_size):
28  std::vector<T>(a_size) {}
29 
30 explicit Array(U32 a_size,const T& a_value):
31  std::vector<T>(a_size,a_value) {}
32 
33  Array(const Array& a_other):
34  std::vector<T>(a_other) {}
35 
36  Array(const std::vector<T>& a_other):
37  std::vector<T>(a_other) {}
38 
39  Array& operator=(const Array& a_other)
40  { return (Array&)std::vector<T>::operator=(a_other); }
41 
42 #if FE_CODEGEN<=FE_DEBUG
43 const T& operator[](I32 index) const
44  {
45  try
46  {
47  return std::vector<T>::at(index);
48  }
49  catch(const std::exception& std_e)
50  {
51  String location;
52  location.sPrintf("Array<%s>::operator[%d] const",
53  FE_TYPESTRING(T).c_str(),index);
54  feX(location.c_str(),std_e.what());
55  }
56  catch(...)
57  {
58  feX("Array::operator[] const","unrecognized exception");
59  }
60  //* NOTE should never get this far
61  return std::vector<T>::at(index);
62  }
63 
64  T& operator[](I32 index)
65  {
66  try
67  {
68  return std::vector<T>::at(index);
69  }
70  catch(const std::exception& std_e)
71  {
72  String location;
73  location.sPrintf("Array<%s>::operator[%d]",
74  FE_TYPESTRING(T).c_str(),index);
75  feX(location.c_str(),std_e.what());
76  }
77  catch(...)
78  {
79  feX("Array::operator[]","unrecognized exception");
80  }
81  //* NOTE should never get this far
82  return std::vector<T>::at(index);
83  }
84 #endif
85 
86 };
87 
88 } // namespace
89 
90 #endif // __core_Array_h__
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
kernel
Definition: namespace.dox:3
String & sPrintf(const char *fmt,...)
Populate the string in the manner of sprintf().
Definition: String.cc:529
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21