1 #ifndef XRD_CLIIDXVEC_H 2 #define XRD_CLIIDXVEC_H 46 #define IDXVEC_MINCAPACITY 128 75 inline void Init(
int cap = -1) {
76 if (rawdata) free(rawdata);
81 rawdata =
static_cast<char *
>(malloc(mincap * sizeof_t));
83 index =
static_cast<myindex *
>(malloc(mincap *
sizeof(myindex)));
85 if (!rawdata || !
index) {
86 std::cerr <<
"XrdClientIdxVector::Init .... out of memory. sizeof_t=" << sizeof_t <<
87 " sizeof(myindex)=" <<
sizeof(myindex) <<
" capacity=" << mincap << std::endl;
92 memset(
index, 0, mincap *
sizeof(myindex));
97 maxsize = capacity =
mincap;
104 reinterpret_cast<T*
>(rawdata+el->offs)->~T();
108 void put(T& item,
long pos) {
112 if (size+holecount >= capacity) {
113 std::cerr <<
"XrdClientIdxVector::put .... internal error." << std::endl;
127 p =
new(rawdata +
offs) T(item);
134 std::cerr <<
"XrdClientIdxVector::put .... out of memory." << std::endl;
145 for (
long i = 0; i <
size; i++)
152 sizeof_t(0), rawdata(0),
index(0)
155 sizeof_t = (
sizeof(T) + 3) >> 2 << 2;
160 rawdata(0),
index(0) {
162 sizeof_t = (
sizeof(T) + 3) >> 2 << 2;
167 for (
int i = 0; i < v.
size; i++)
172 for (
long i = 0; i <
size; i++)
175 if (rawdata) free(rawdata);
182 if (newsize > oldsize) {
186 for (
long i = oldsize; i < newsize; i++) {
192 for (
long i = oldsize; i > newsize; i--)
235 memmove(&
index[pos+1], &
index[pos], (size-pos) *
sizeof(myindex));
238 memmove(&
index[pos+1], &
index[pos], (size-pos) *
sizeof(myindex));
266 void Erase(
unsigned int pos,
bool dontrealloc=
true) {
270 struct myindex tmpi =
index[pos];
273 memmove(&
index[pos], &
index[pos+1], (size-pos-1) *
sizeof(myindex));
304 inline T &
At(
int pos) {
305 if ((pos < 0) || (static_cast<unsigned long>(pos) >=
306 static_cast<unsigned long>(size))) abort();
308 return *(
reinterpret_cast<T*
>(rawdata +
index[pos].
offs));
359 std::cerr <<
"XrdClientIdxVector::BufRealloc .... out of memory." << std::endl;
377 std::cerr <<
"XrdClientIdxVector::BufRealloc .... out of memory." << std::endl;
long capacity
Definition: XrdClientVector.hh:68
XrdClientVector(XrdClientVector &v)
Definition: XrdClientVector.hh:159
~XrdClientVector()
Definition: XrdClientVector.hh:171
long maxsize
Definition: XrdClientVector.hh:68
void Resize(int newsize)
Definition: XrdClientVector.hh:179
void Clear()
Definition: XrdClientVector.hh:144
long mincap
Definition: XrdClientVector.hh:67
long size
Definition: XrdClientVector.hh:67
bool notempty
Definition: XrdClientVector.hh:60
void DestroyElem(myindex *el)
Definition: XrdClientVector.hh:103
Definition: XrdClientVector.hh:58
T Pop_front()
Definition: XrdClientVector.hh:294
int BufRealloc(int newsize)
Definition: XrdClientVector.hh:321
int GetSize() const
Definition: XrdClientVector.hh:142
int sizeof_t
Definition: XrdClientVector.hh:54
XrdClientVector(int cap=-1)
Definition: XrdClientVector.hh:151
T & At(int pos)
Definition: XrdClientVector.hh:304
#define IDXVEC_MINCAPACITY
Definition: XrdClientVector.hh:46
char * rawdata
Definition: XrdClientVector.hh:56
void Erase(unsigned int pos, bool dontrealloc=true)
Definition: XrdClientVector.hh:266
void Insert(T &item, int pos)
Definition: XrdClientVector.hh:224
Definition: XrdClientVector.hh:49
T & operator[](int pos)
Definition: XrdClientVector.hh:311
int holecount
Definition: XrdClientVector.hh:65
T Pop_back()
Definition: XrdClientVector.hh:282
void Push_back(T &item)
Definition: XrdClientVector.hh:197
long offs
Definition: XrdClientVector.hh:59
void Init(int cap=-1)
Definition: XrdClientVector.hh:75
struct XrdClientVector::myindex * index
void put(T &item, long pos)
Definition: XrdClientVector.hh:108