MCPcopy Create free account
hub / github.com/coin-or/CppAD / MyVector

Class MyVector

example/utility/check_simple_vector.cpp:52–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50// example simple vector class
51template <class Scalar>
52class MyVector {
53private:
54 size_t length;
55 Scalar * data;
56public:
57
58# if CppADMyVectorOmit != 1
59 // type of the elements in the vector
60 typedef Scalar value_type;
61# endif
62# if CppADMyVectorOmit != 2
63 // default constructor
64 MyVector(void) : length(0) , data(0)
65 { }
66# endif
67# if CppADMyVectorOmit != 3
68 // constructor with a specified size
69 MyVector(size_t n) : length(n)
70 { if( length == 0 )
71 data = 0;
72 else
73 data = new Scalar[length];
74 }
75# endif
76# if CppADMyVectorOmit != 4
77 // copy constructor
78 MyVector(const MyVector &x) : length(x.length)
79 { size_t i;
80 if( length == 0 )
81 data = 0;
82 else
83 data = new Scalar[length];
84
85 for(i = 0; i < length; i++)
86 data[i] = x.data[i];
87 }
88# endif
89# if CppADMyVectorOmit != 4
90# if CppADMyVectorOmit != 7
91 // destructor (it is not safe to delete the pointer in cases 4 and 7)
92 ~MyVector(void)
93 { delete [] data; }
94# endif
95# endif
96# if CppADMyVectorOmit != 5
97 // size function
98 size_t size(void) const
99 { return length; }
100# endif
101# if CppADMyVectorOmit != 6
102 // resize function
103 void resize(size_t n)
104 { if( length > 0 )
105 delete [] data;
106 length = n;
107 if( length > 0 )
108 data = new Scalar[length];
109 else

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected