Xmipp  v3.23.11-Nereus
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
VectorInt Class Reference

#include <VectorInt.h>

Collaboration diagram for VectorInt:
Collaboration graph
[legend]

Classes

struct  VectorIntDataTag
 

Public Types

typedef struct VectorInt::VectorIntDataTag VectorIntData
 

Public Member Functions

 VectorInt (int _n=0)
 
 VectorInt (int _n, int _ext)
 
 VectorInt (int _n, int *d)
 
VectorInt clone ()
 
void copyFrom (VectorInt r)
 
 VectorInt (const VectorInt &P)
 
VectorIntoperator= (const VectorInt &P)
 
void destroyCurrentBuffer ()
 
 ~VectorInt ()
 
void extend ()
 
void setSize (int _n)
 
void exactshape ()
 
void print ()
 
void prepareExtend (int new_extention)
 
int sz ()
 
int operator== (const VectorInt &P)
 
 operator int * () const
 
int equals (const VectorInt &Q)
 

Public Attributes

VectorIntDatad
 

Static Public Attributes

static VectorInt emptyVectorInt
 

Detailed Description

Definition at line 31 of file VectorInt.h.

Member Typedef Documentation

◆ VectorIntData

Constructor & Destructor Documentation

◆ VectorInt() [1/4]

VectorInt::VectorInt ( int  _n = 0)

Definition at line 46 of file VectorInt.cpp.

47 {
48  alloc(_n, _n);
49  memset(d->p,0,d->extention*sizeof(int));
50 }
VectorIntData * d
Definition: VectorInt.h:40

◆ VectorInt() [2/4]

VectorInt::VectorInt ( int  _n,
int  _ext 
)

Definition at line 52 of file VectorInt.cpp.

53 {
54  alloc(_n, _ext);
55  memset(d->p,0,d->extention*sizeof(int));
56 }
VectorIntData * d
Definition: VectorInt.h:40

◆ VectorInt() [3/4]

VectorInt::VectorInt ( int  _n,
int *  d 
)

Definition at line 58 of file VectorInt.cpp.

59 {
60  alloc(_n,_n);
61  if (_d) memcpy(d->p,_d,_n*sizeof(int));
62  else memset(d->p,0,d->extention*sizeof(int));
63 }
VectorIntData * d
Definition: VectorInt.h:40

◆ VectorInt() [4/4]

VectorInt::VectorInt ( const VectorInt P)

Definition at line 91 of file VectorInt.cpp.

92 {
93  // shallow copy
94  d=A.d;
95  (d->ref_count)++ ;
96 }
VectorIntData * d
Definition: VectorInt.h:40

◆ ~VectorInt()

VectorInt::~VectorInt ( )

Definition at line 75 of file VectorInt.cpp.

76 {
78 }
void destroyCurrentBuffer()
Definition: VectorInt.cpp:80

Member Function Documentation

◆ clone()

VectorInt VectorInt::clone ( )

Definition at line 110 of file VectorInt.cpp.

111 {
112  // a deep copy
113  VectorInt r(sz());
114  r.copyFrom(*this);
115  return r;
116 }
int sz()
Definition: VectorInt.h:63

◆ copyFrom()

void VectorInt::copyFrom ( VectorInt  r)

Definition at line 118 of file VectorInt.cpp.

119 {
120  unsigned n=r.sz();
121  if (n==0) return;
122  setSize(n);
123  memcpy(d->p,r.d->p,n*sizeof(double));
124 }
int sz()
Definition: VectorInt.h:63
void setSize(int _n)
Definition: VectorInt.cpp:126
VectorIntData * d
Definition: VectorInt.h:40
int * n

◆ destroyCurrentBuffer()

void VectorInt::destroyCurrentBuffer ( )

Definition at line 80 of file VectorInt.cpp.

81 {
82  if (!d) return;
83  (d->ref_count) --;
84  if (d->ref_count==0)
85  {
86  if (d->p) free(d->p);
87  free(d);
88  };
89 }
free((char *) ob)
VectorIntData * d
Definition: VectorInt.h:40

◆ equals()

int VectorInt::equals ( const VectorInt Q)

Definition at line 148 of file VectorInt.cpp.

149 {
150  if (d->n != Q.d->n) return 0;
151 
152  int *cP = d->p, *cQ = Q.d->p;
153  int i = d->n;
154 
155  while( i-- )
156  {
157  if (*cP!=*cQ) return 0;
158  cP++; cQ++;
159  }
160 
161  return 1;
162 }
#define i
VectorIntData * d
Definition: VectorInt.h:40

◆ exactshape()

void VectorInt::exactshape ( )

Definition at line 139 of file VectorInt.cpp.

140 {
141  if (d->extention!=d->n)
142  {
143  d->p=(int*)realloc(d->p,d->n*sizeof(int));
144  d->extention=d->n;
145  };
146 }
VectorIntData * d
Definition: VectorInt.h:40

◆ extend()

void VectorInt::extend ( )

Definition at line 133 of file VectorInt.cpp.

134 {
135  d->n++;
136  if (d->n>d->extention) prepareExtend(d->extention+100);
137 }
void prepareExtend(int new_extention)
Definition: VectorInt.cpp:65
VectorIntData * d
Definition: VectorInt.h:40

◆ operator int *()

VectorInt::operator int * ( ) const
inline

Definition at line 65 of file VectorInt.h.

65 { return d->p; };
VectorIntData * d
Definition: VectorInt.h:40

◆ operator=()

VectorInt & VectorInt::operator= ( const VectorInt P)

Definition at line 98 of file VectorInt.cpp.

99 {
100  // shallow copy
101  if (this != &A)
102  {
104  d=A.d;
105  (d->ref_count) ++ ;
106  }
107  return *this;
108 }
void destroyCurrentBuffer()
Definition: VectorInt.cpp:80
VectorIntData * d
Definition: VectorInt.h:40

◆ operator==()

int VectorInt::operator== ( const VectorInt P)
inline

Definition at line 64 of file VectorInt.h.

64 {return (d==P.d);}
VectorIntData * d
Definition: VectorInt.h:40

◆ prepareExtend()

void VectorInt::prepareExtend ( int  new_extention)

Definition at line 65 of file VectorInt.cpp.

66 {
67  if (d->extention<new_extention)
68  {
69  d->p=(int*)realloc(d->p,new_extention*sizeof(int));
70  memset(d->p+d->extention,0,(new_extention-d->extention)*sizeof(int));
71  d->extention=new_extention;
72  };
73 }
VectorIntData * d
Definition: VectorInt.h:40

◆ print()

void VectorInt::print ( )

Definition at line 165 of file VectorInt.cpp.

166 {
167  printf("[");
168  if (!d->n || !d->p) { printf("]\n"); return; }
169 
170  int N=d->n,*up=d->p;
171  while (--N) printf("%i,",*(up++));
172  printf("%i]\n",*up);
173 }
VectorIntData * d
Definition: VectorInt.h:40

◆ setSize()

void VectorInt::setSize ( int  _n)

Definition at line 126 of file VectorInt.cpp.

127 {
128  d->n=_n;
129  if (_n==0) { free(d->p); d->p=NULL; d->extention=0; return; }
130  prepareExtend(_n);
131 }
free((char *) ob)
void prepareExtend(int new_extention)
Definition: VectorInt.cpp:65
VectorIntData * d
Definition: VectorInt.h:40

◆ sz()

int VectorInt::sz ( )
inline

Definition at line 63 of file VectorInt.h.

63 {return d->n;};
VectorIntData * d
Definition: VectorInt.h:40

Member Data Documentation

◆ d

VectorIntData* VectorInt::d

Definition at line 40 of file VectorInt.h.

◆ emptyVectorInt

VectorInt VectorInt::emptyVectorInt
static

Definition at line 70 of file VectorInt.h.


The documentation for this class was generated from the following files: