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
00035 #ifndef _RTA_MANAGER_H_
00036 #define _RTA_MANAGER_H_
00037
00038 #include <stdio.h>
00039
00040
00041 template <class T>
00042 class Rta_Rnd_Iter {
00043 private:
00044 friend class Rta_Manager;
00045
00046 T * _base;
00047 INT _index;
00048 INT _size;
00049
00050 Rta_Rnd_Iter(T * base, INT size, INT index = 0) : _base(base), _index(index), _size(size) { }
00051 public:
00052 Rta_Rnd_Iter(const Rta_Rnd_Iter &iter)
00053 : _base(iter._base), _index(iter._index), _size(iter._size) { }
00054 Rta_Rnd_Iter & operator=(const Rta_Rnd_Iter &iter) {
00055 _base = iter._base;
00056 _index = iter._index;
00057 }
00058
00059 T & operator*() const {
00060 FmtAssert(_index < _size, ("Dereferencing iterator that points beyond the last element."));
00061 return _base[_index];
00062 }
00063 Rta_Rnd_Iter & operator++() {
00064 FmtAssert(_index < _size, ("Iterator moves out of bound."));
00065 ++_index;
00066 return *this;
00067 }
00068 Rta_Rnd_Iter operator++(INT) {
00069 FmtAssert(_index < _size, ("Iterator moves out of bound."));
00070 Rta_Rnd_Iter iter(*this);
00071 ++_index;
00072 return iter;
00073 }
00074 Rta_Rnd_Iter & operator--() {
00075 FmtAssert(_index > 0, ("Iterator moves out of bound."));
00076 --_index;
00077 return *this;
00078 }
00079 Rta_Rnd_Iter operator--(INT) {
00080 FmtAssert(_index > 0, ("Iterator moves out of bound."));
00081 Rta_Rnd_Iter iter(*this);
00082 --_index;
00083 return iter;
00084 }
00085 Rta_Rnd_Iter & operator+=(INT offset) {
00086 _index += offset;
00087 FmtAssert(_index > 0 && _index <= _size, ("Iterator moves out of bound."));
00088 return *this;
00089 }
00090 Rta_Rnd_Iter & operator-=(INT offset) {
00091 return *this += (-offset);
00092 }
00093 Rta_Rnd_Iter operator+(INT offset) const {
00094 Rta_Rnd_Iter iter(*this);
00095 iter._index += offset;
00096 FmtAssert(iter._index > 0 && iter._index <= _size, ("Iterator moves out of bound."));
00097 return iter;
00098 }
00099 Rta_Rnd_Iter operator-(INT offset) const {
00100 return *this + (-offset);
00101 }
00102
00103 BOOL operator==(const Rta_Rnd_Iter &iter) const {
00104 return _base == iter._base && _index == iter._index;
00105 }
00106 BOOL operator!=(const Rta_Rnd_Iter &iter) const {
00107 return !(*this == iter);
00108 }
00109 };
00110
00119 class Rta_Manager {
00120 public:
00121
00122 typedef Rta_Rnd_Iter<Rta_Pu> Pu_Iter;
00123 typedef Rta_Rnd_Iter<Rta_Bb> Bb_Iter;
00124 typedef Rta_Rnd_Iter<Rta_Op> Op_Iter;
00125
00126 Rta_Manager(void * start) : _start(start) { }
00127
00128 Rta_Hdr & Hdr() const { return *(Rta_Hdr *)_start; }
00129
00130
00131 INT num() const { return Rta_hdr_pu_num(&Hdr()); }
00132 Pu_Iter begin() const { return Pu_Iter(ary(), num()); }
00133 Pu_Iter end() const { return Pu_Iter(ary(), num(), num());}
00134 Rta_Pu & Pu(INT index) const {
00135 FmtAssert((index != 0), ("Index 0 is reserved. PUs are indexed from 1."));
00136 FmtAssert((index > 0) && (index <= num())
00137 , ("Index (%d) in PU header table is out of bound [%d, %d]"
00138 , index, 1, num()));
00139 return ary()[index-1];
00140 }
00141
00142
00143 INT num(const Pu_Iter & pi) const {
00144 return Rta_pu_bb_num(&*pi);
00145 }
00146 Bb_Iter begin(const Pu_Iter & pi) const {
00147 return Bb_Iter(ary(pi), num(pi));
00148 }
00149 Bb_Iter end(const Pu_Iter & pi) const {
00150 return Bb_Iter(ary(pi), num(pi), num(pi));
00151 }
00152 Rta_Bb & Bb(const Pu_Iter & pi, INT index) const {
00153 FmtAssert((index != 0), ("Index 0 is reserved. BBs are indexed from 1."));
00154 FmtAssert((index >= Rta_pu_bb_begin(&*pi))
00155 && (index < Rta_pu_bb_begin(&*pi) + num(pi))
00156 , ("Index (%d) in BB header table is out of bound [%d, %d]"
00157 , index, Rta_pu_bb_begin(&*pi), Rta_pu_bb_begin(&*pi) + num(pi) - 1));
00158 return ary(pi)[index - Rta_pu_bb_begin(&*pi)];
00159 }
00160
00161
00162 INT num(const Bb_Iter & bi) const {
00163 return Rta_bb_op_num(&*bi);
00164 }
00165 Op_Iter begin(const Bb_Iter & bi) const {
00166 return Op_Iter(ary(bi), num(bi));
00167 }
00168 Op_Iter end(const Bb_Iter & bi) const {
00169 return Op_Iter(ary(bi), num(bi), num(bi));
00170 }
00171 Rta_Op & Op(const Bb_Iter & bi, INT index) const {
00172 FmtAssert((index != 0), ("Index 0 is reserved. OPs are indexed from 1."));
00173 FmtAssert((index > 0), ("OP index (%d) is negative."));
00174 return ary(bi)[index - 1];
00175 }
00176 private:
00177 void * _start;
00178
00179 Rta_Pu * ary() const {
00180 return (Rta_Pu *)((char *)_start + Rta_hdr_pu_off(&Hdr()));
00181 }
00182 Rta_Bb * ary(const Pu_Iter & pi) const {
00183 return (Rta_Bb *)((char *)&*pi + Rta_pu_bb_off(&*pi));
00184 }
00185 Rta_Op * ary(const Bb_Iter & bi) const {
00186 return (Rta_Op *)((char *)&*bi + Rta_bb_op_off(&*bi));
00187 }
00188 };
00189
00190 #endif // _RTA_MANAGER_H_