FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Prototype_pattern_exercise/Array.cpp at master · cablegui/Prototype_pattern_exercise · GitHub
cablegui
/
Prototype_pattern_exercise
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Prototype_pattern_exercise
/
Array.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
124 lines (91 loc) · 2.57 KB
Breadcrumbs
Prototype_pattern_exercise
/
Array.cpp
Copy path
File metadata and controls
124 lines (91 loc) · 2.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
Array.cpp
//
//
Array class. It uses an ArrayStructure for the actual storage.
//
This class acts like a kind of adapter since it defines a common interface
//
for different array structures like normal arrays and sparse arrays.
//
The array structure to use is given as template argument.
//
//
29 januari 1999 RD Started
//
2002-1-21 DD indexing starts at 1
//
2002-3-30 DD operator [] incorrectly implemented; corrected
//
2005-12-17 DD size_t --> I
//
//
(C) Datasim Component Technology 1999-2006
#
ifndef
DSArray_cpp
#
define
DSArray_cpp
#
include
"
Array.hpp
"
#
include
<
stddef.h
>
//
Constructors & destructor
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>::Array()
{
//
Default constructor
m_structure=
S
();
m_start=
1
;
}
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>::Array(I size)
{
//
Constructor with size. Start index=1.
m_structure=
S
(
size_t
(size));
m_start=
1
;
}
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>::Array(I size, I start)
{
//
Constructor with size & start index
m_structure=
S
(
size_t
(size));
m_start=start;
}
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>::Array(I size, I start,
const
V& value)
{
//
Constructor with size & start index
m_structure=
S
(
size_t
(size));
m_start=start;
//
Initialise array elements
for
(I i =
MinIndex
(); i <=
MaxIndex
(); i++) (*
this
)[i] = value;
}
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>::Array(
const
Array<V, I, S>& source)
{
//
Copy constructor
m_structure=source.
m_structure
;
m_start=source.
m_start
;
}
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>::
~Array
()
{
//
Destructor
}
//
Selectors
template
<
class
V
,
class
I
,
class
S
>
I Array<V, I, S>::MinIndex()
const
{
//
Return the minimum index
return
m_start;
}
template
<
class
V
,
class
I
,
class
S
>
I Array<V, I, S>::MaxIndex()
const
{
//
Return the maximum index
return
m_start+
Size
()-
1
;
}
template
<
class
V
,
class
I
,
class
S
>
I Array<V, I, S>::Size()
const
{
//
The size of the array
return
I
(m_structure.
Size
());
}
//
Operators
template
<
class
V
,
class
I
,
class
S
>
inline
V& Array<V, I, S>::
operator
[] (I index)
{
//
Subscripting operator
return
m_structure[index - m_start +
1
];
}
template
<
class
V
,
class
I
,
class
S
>
inline
const
V& Array<V, I, S>::
operator
[] (I index)
const
{
//
Subscripting operator
return
m_structure[index - m_start +
1
];
}
template
<
class
V
,
class
I
,
class
S
>
Array<V, I, S>& Array<V, I, S>::
operator
= (
const
Array<V, I, S>& source)
{
//
Assignment operator
//
Exit if same object
if
(
this
==&source)
return
*
this
;
m_structure=source.
m_structure
;
m_start=source.
m_start
;
return
*
this
;
}
#
endif
//
DSArray_cpp
Back
|
FazBrowse Home
|
New Git URL