1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include "position.h"
#include <string.h>
#include <stdarg.h>
#include <exception>
Position::Position() :
iDims( 0 ),
aiValues( 0 )
{
}
Position::Position( int iDims ) :
iDims( iDims ),
aiValues( 0 )
{
aiValues = new int[iDims];
memset( aiValues, 0, sizeof(int)*iDims );
}
Position::Position( int iDims, int iX, ...) :
iDims( iDims ),
aiValues( 0 )
{
aiValues = new int[iDims];
memset( aiValues, 0, sizeof(int)*iDims );
aiValues[0] = iX;
va_list ap;
va_start( ap, iX );
for( int j = 1; j < iDims; j++ )
{
aiValues[j] = va_arg( ap, int );
}
va_end( ap );
}
Position::Position( const Position &rhs ) :
iDims( rhs.iDims ),
aiValues( 0 )
{
aiValues = new int[iDims];
memcpy( aiValues, rhs.aiValues, sizeof(int)*iDims );
}
Position::~Position()
{
delete[] aiValues;
}
int Position::operator[]( int iIdx ) const
{
if( iIdx < 0 )
throw std::exception();
else if( iIdx >= iDims )
throw std::exception();
return aiValues[iIdx];
}
int &Position::operator[]( int iIdx )
{
if( iIdx < 0 )
throw std::exception();
else if( iIdx >= iDims )
throw std::exception();
return aiValues[iIdx];
}
Position &Position::operator=( const Position &rhs )
{
delete[] aiValues;
iDims = rhs.iDims;
aiValues = new int[iDims];
memcpy( aiValues, rhs.aiValues, sizeof(int)*iDims );
return *this;
}
int Position::getDims() const
{
return iDims;
}
|