00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef SCV_SPARSE_ARRAY_H
00044 #define SCV_SPARSE_ARRAY_H
00045
00046 #include <systemc.h>
00047 #include <limits.h>
00048 #include "scv/scv_config.h"
00049 #include "scv/_scv_associative_array.h"
00050 #include "scv/scv_report.h"
00051
00052 #include <math.h>
00053 #include <map>
00054
00055
00056
00057 template <class Key, class T>
00058 class scv_sparse_array : public _scv_associative_array<Key, T, map<Key, T, less<Key> > > {
00059 T _dummy;
00060 Key _indexLB;
00061 Key _indexUB;
00062 public:
00063
00064 typedef map<Key, T, less<Key> > container_type;
00065
00066
00067 scv_sparse_array(const char *nameP, const T& defaultValue,
00068 const Key& indexLB=0 , const Key& indexUB=INT_MAX ):
00069
00070 _scv_associative_array<Key, T, container_type>(nameP, defaultValue),
00071 _dummy(defaultValue),
00072 _indexLB(indexLB),
00073 _indexUB(indexUB)
00074 { };
00075
00076
00077
00078
00079 scv_sparse_array(const scv_sparse_array& other, const char *nameP="<anonymous>")
00080 : _scv_associative_array<Key, T, container_type>(other, nameP),
00081 _dummy(other._dummy),
00082 _indexLB(other._indexLB), _indexUB(other._indexUB){}
00083
00084
00085
00086
00087 virtual ~scv_sparse_array() {}
00088
00089 virtual const char* kind() const
00090 { static const char name[]="scv_sparse_array"; return name; }
00091
00092
00093
00094
00095 const Key& indexLB() const { return _indexLB; };
00096 const Key& indexUB() const { return _indexUB; };
00097
00098 const Key& lower_bound() const { return _indexLB; };
00099 const Key& upper_bound() const { return _indexUB; };
00100
00101
00102
00103
00104
00105
00106
00107
00108 T& operator[](const Key& i) {
00109 if ((i >= _indexLB) && (i <= _indexUB))
00110 return _scv_associative_array<Key, T, container_type>::operator[](i);
00111 else {
00112
00113
00114
00115 scv_out << "*** SCV_ERROR: SPARSE_ARRAY_ILLEGAL_INDEX: " << i << endl ;
00116 scv_out << "In scv_sparse_array '" << this->nameP() << "'." << endl;
00117 scv_out << "The valid range is lower = " << _indexLB ;
00118 scv_out << ", upper = " << _indexUB << endl;
00119
00120
00121 return _dummy;
00122 }
00123 }
00124 const T& operator[](const Key& i) const {
00125 if (!((i >= _indexLB) && (i <= _indexUB))) {
00126
00127
00128 scv_out << "*** SCV_ERROR: SPARSE_ARRAY_ILLEGAL_INDEX: " << i << endl ;
00129 scv_out << "In scv_sparse_array '" << this->nameP() << "'." << endl;
00130 scv_out << "The valid range is lower = " << _indexLB ;
00131 scv_out << ", upper = " << _indexUB << endl;
00132 return _dummy;
00133 } else
00134 return _scv_associative_array<Key, T, container_type>::operator[](i);
00135 }
00136
00137
00138
00139
00140 scv_sparse_array& operator=(const scv_sparse_array<Key, T>& other) {
00141 if (this != &other) {
00142 *((_scv_associative_array<Key, T, container_type> *) this) =
00143 (_scv_associative_array<Key, T, container_type> ) other;
00144 _indexUB = other._indexUB;
00145 _indexLB = other._indexLB;
00146 }
00147 return *this;
00148 }
00149
00150 virtual void print(ostream& os=scv_out, int details=0, int indent=0) const {
00151
00152
00153 _scv_associative_array<Key, T,container_type>::print(os,details,indent);
00154 }
00155
00156 virtual void show(int details=0, int indent=0) const {
00157 print(scv_out, details, indent);
00158 }
00159
00160 };
00161
00162 #endif // SCV_SPARSE_ARRAY_H