12 #ifndef HELIB_PTRVECTOR_H
13 #define HELIB_PTRVECTOR_H
22 #include <NTL/vector.h>
24 #include <helib/assertions.h>
25 #include <helib/apiAttributes.h>
35 virtual long size()
const = 0;
39 if (
size() != newSize)
40 throw LogicError(
"Cannot resize a generic PtrVector");
46 if (i < 0 || i >=
size())
48 return ((*
this)[i] !=
nullptr);
52 virtual long numNonNull(
long first = 0,
long last = LONG_MAX)
const
59 for (
long i = first; i < last; i++)
60 if ((*
this)[i] !=
nullptr)
69 for (
long i = 0; i <
size(); i++) {
99 void resize(PtrVector<T>& v,
long newSize,
const T& val);
101 template <
typename T>
104 resize<T>(v, newSize, *val);
110 template <
typename V1,
typename V2>
111 void vecCopy(V1& v1,
const V2& v2,
long sizeLimit = 0)
114 if (sizeLimit > 0 && sizeLimit < n)
120 for (
int i = 0; i < n; i++)
126 template <
typename V,
typename T>
130 if (sizeLimit > 0 && sizeLimit < n)
136 for (
int i = 0; i < n; i++)
140 template <
typename V,
typename T>
144 if (sizeLimit > 0 && sizeLimit < n)
150 for (
int i = 0; i < n; i++)
154 template <
typename T>
158 if (sizeLimit > 0 && sizeLimit < n)
164 for (
int i = 0; i < n; i++)
174 template <
typename T>
180 long size()
const override {
return v.length(); }
185 v.SetLength(newSize,
nullptr);
190 template <
typename T>
196 long size()
const override {
return long(
v.size()); }
201 v.resize(newSize,
nullptr);
206 template <
typename T>
212 long size()
const override {
return v.length(); }
220 if (another ==
nullptr)
223 assertNotNull(pt,
"another->ptr2nonNull() returned a null ptr");
224 v.SetLength(newSize, *pt);
228 long numNonNull(
long first = 0,
long last = LONG_MAX)
const override
232 if (last >
v.length())
238 return ((
v.length() > 0) ? &(
v[0]) :
nullptr);
243 template <
typename T>
249 long size()
const override {
return long(
v.size()); }
257 if (another ==
nullptr)
260 assertNotNull(pt,
"another->ptr2nonNull() returned a null ptr");
261 v.resize(newSize, *pt);
264 long numNonNull(
long first = 0,
long last = LONG_MAX)
const override
268 if (last >
long(
v.size()))
269 last = long(
v.size());
275 template <
typename T>
286 if (_sz == 0 || from >= slice.
size()) {
294 if (_sz < 0 || from + _sz > slice.
size())
295 _sz = slice.
size() - from;
310 long size()
const override {
return sz; }
312 long numNonNull(
long first = 0,
long last = LONG_MAX)
const override
320 template <
typename T>
325 T*
operator[](
long i)
const override {
return (i == 0) ? ((T*)
v) :
nullptr; }
326 long size()
const override {
return 1L; }
329 template <
typename T>
338 #endif // ifndef HELIB_PTRVECTOR_H
long start
Definition: PtrVector.h:279
long lsize(const std::vector< T > &v)
Size of STL vector as a long (rather than unsigned long)
Definition: NumbTh.h:702
PtrVector_slice(const PtrVector_slice< T > &slice, long from, long _sz=-1)
Definition: PtrVector.h:281
PtrVector_VecPt(NTL::Vec< T * > &_v)
Definition: PtrVector.h:178
const T * v
Definition: PtrVector.h:323
long size() const override
Definition: PtrVector.h:326
T * operator[](long i) const override
Definition: PtrVector.h:195
long numNonNull(long first=0, long last=LONG_MAX) const override
Definition: PtrVector.h:264
virtual T * operator[](long) const =0
void resize(long newSize, const PtrVector< T > *another) override
Definition: PtrVector.h:251
PtrVector_VecT(NTL::Vec< T > &_v)
Definition: PtrVector.h:210
Inherits from Exception and std::logic_error.
Definition: exceptions.h:68
PtrVector_vectorPt(std::vector< T * > &_v)
Definition: PtrVector.h:194
long size() const override
Definition: PtrVector.h:212
long numNonNull(long first=0, long last=LONG_MAX) const override
Definition: PtrVector.h:312
long size() const override
Definition: PtrVector.h:249
T * operator[](long i) const override
Definition: PtrVector.h:325
std::vector< T > & v
Definition: PtrVector.h:246
T * operator[](long i) const override
Definition: PtrVector.h:179
long size() const override
Definition: PtrVector.h:196
const T * ptr2nonNull() const override
Definition: PtrVector.h:236
long numNonNull(long first=0, long last=LONG_MAX) const override
Definition: PtrVector.h:228
An implementation of PtrVector using Vec<T>
Definition: PtrVector.h:208
const T * ptr2nonNull() const override
Definition: PtrVector.h:316
virtual ~PtrVector()
Definition: PtrVector.h:42
void resize(long newSize, UNUSED const PtrVector< T > *another=nullptr) override
Definition: PtrVector.h:182
void assertNotNull(const T &p, const std::string &message)
Definition: assertions.h:156
void setLengthZero(std::vector< T > &vec)
Definition: NumbTh.h:724
An implementation of PtrVector using vector<T*>
Definition: PtrVector.h:192
void resize(NTL::Vec< T > &v, long sz, const T &val)
Definition: NumbTh.h:744
PtrVector_vectorT(std::vector< T > &_v)
Definition: PtrVector.h:247
virtual long size() const =0
void resize(long newSize, UNUSED const PtrVector< T > *another=nullptr) override
Definition: PtrVector.h:198
long size() const override
Definition: PtrVector.h:310
virtual long numNonNull(long first=0, long last=LONG_MAX) const
Definition: PtrVector.h:52
Abstract class for an array of objects.
Definition: PtrVector.h:32
Definition: apiAttributes.h:21
virtual void resize(long newSize, UNUSED const PtrVector *another=nullptr)
Definition: PtrVector.h:37
void resize(long newSize, const PtrVector< T > *another) override
Definition: PtrVector.h:214
NTL::Vec< T * > & v
Definition: PtrVector.h:177
bool isSet(long i) const
Definition: PtrVector.h:44
void vecCopy(V1 &v1, const V2 &v2, long sizeLimit=0)
Definition: PtrVector.h:111
An implementation of PtrVector as a slice of another PtrVector.
Definition: PtrVector.h:277
T * operator[](long i) const override
Definition: PtrVector.h:211
An implementation of PtrVector using vector<T>
Definition: PtrVector.h:245
An implementation of PtrVector using Vec<T*>
Definition: PtrVector.h:176
std::vector< T * > & v
Definition: PtrVector.h:193
PtrVector_Singleton(const T *_v)
Definition: PtrVector.h:324
An implementation of PtrVector from a single T object.
Definition: PtrVector.h:322
long sz
Definition: PtrVector.h:279
T * operator[](long i) const override
Definition: PtrVector.h:309
NTL::Vec< T > & v
Definition: PtrVector.h:209
PtrVector_slice(const PtrVector< T > &_orig, long from, long _sz=-1)
Definition: PtrVector.h:299
T * operator[](long i) const override
Definition: PtrVector.h:248
const PtrVector< T > & orig
Definition: PtrVector.h:278
virtual const T * ptr2nonNull() const
Definition: PtrVector.h:67
long size() const override
Definition: PtrVector.h:180