Rudiments: /home/dmuse/src/rudiments/include/rudiments/private/staticarrayinlines.h Source File

Rudiments

- Main Page
- Classes

staticarrayinlines.h
1 // Copyright (c) 2015 David Muse
2 // See the COPYING file for more information.
3
4 #include <rudiments/private/rudimentsinlines.h>
5 #include <rudiments/private/new.h>
6
7 template< class valuetype, uint64_t length >
8 RUDIMENTS_TEMPLATE_INLINE
9 staticarray<valuetype,length>::staticarray() {
10 len=length;
11 data=new valuetype[len];
12 }
13
14 template< class valuetype, uint64_t length >
15 RUDIMENTS_TEMPLATE_INLINE
16 staticarray<valuetype,length>::staticarray(
17 const staticarray<valuetype,length> &v) {
18 len=v.len;
19 data=new valuetype[len];
20 for (uint64_t i=0; i<len; i++) {
21
22 // Why not just:
23 // *data[i]=*v.data[i];
24 //
25 // Some compilers get confused and think that
26 // *data[i]=*v.data[i]
27 // means
28 // *((data[i])->operator=(*v.data[i]))
29 // and no carefully placed parentheses help.
30 //
31 // This silliness sorts out the problem.
32 valuetype *a=&(data[i]);
33 valuetype *b=&(v.data[i]);
34 *a=*b;
35 }
36 }
37
38 template< class valuetype, uint64_t length >
39 RUDIMENTS_TEMPLATE_INLINE
40 staticarray<valuetype,length> &staticarray<valuetype,length>::operator=(
41 const staticarray<valuetype,length> &v) {
42 if (this!=&v) {
43 len=v.len;
44 data=new valuetype[len];
45 for (uint64_t i=0; i<len; i++) {
46
47 // Why not just:
48 // *data[i]=*v.data[i];
49 //
50 // Some compilers get confused and think that
51 // *data[i]=*v.data[i]
52 // means
53 // *((data[i])->operator=(*v.data[i]))
54 // and no carefully placed parentheses help.
55 //
56 // This silliness sorts out the problem.
57 valuetype *a=&(data[i]);
58 valuetype *b=&(v.data[i]);
59 *a=*b;
60 }
61 }
62 return *this;
63 }
64
65 template< class valuetype, uint64_t length >
66 RUDIMENTS_TEMPLATE_INLINE
67 staticarray<valuetype,length>::~staticarray() {
68 delete[] data;
69 }
70
71 template< class valuetype, uint64_t length >
72 RUDIMENTS_TEMPLATE_INLINE
73 valuetype &staticarray<valuetype,length>::operator[](uint64_t index) {
74 return data[index];
75 }
76
77 template< class valuetype, uint64_t length >
78 RUDIMENTS_TEMPLATE_INLINE
79 uint64_t staticarray<valuetype,length>::getLength() const {
80 return len;
81 }
82
83 template< class valuetype, uint64_t length >
84 RUDIMENTS_TEMPLATE_INLINE
85 void staticarray<valuetype,length>::clear() {
86 for (uint64_t i=0; i<len; i++) {
87 ((valuetype *)&data[i])->~valuetype();
88 new(&data[i]) valuetype;
89 }
90 }
staticarray::clear
void clear()
Definition: staticarrayinlines.h:85
staticarray::operator[]
valuetype & operator[](uint64_t index)
Definition: staticarrayinlines.h:73
staticarray::getLength
uint64_t getLength() const
Definition: staticarrayinlines.h:79
staticarray::staticarray
staticarray()
Definition: staticarrayinlines.h:9
staticarray::~staticarray
~staticarray()
Definition: staticarrayinlines.h:67
staticarray
Definition: staticarray.h:37
staticarray::operator=
staticarray< valuetype, length > & operator=(const staticarray< valuetype, length > &v)
Definition: staticarrayinlines.h:40