Rudiments
staticarrayinlines.h
1// Copyright (c) 1999-2018 David Muse
2// See the COPYING file for more information.
3
4#include <rudiments/private/new.h>
5#include <rudiments/private/nodeinlines.h>
6#include <rudiments/bytestring.h>
7
8template< class valuetype, uint64_t count >
9inline
13
14template< class valuetype, uint64_t count >
15inline
22
23template< class valuetype, uint64_t count >
24inline
31
32template< class valuetype, uint64_t count >
33inline
36 if (this!=&v) {
37 clear();
39 clone(v);
40 }
41 return *this;
42}
43
44template< class valuetype, uint64_t count >
45inline
48 if (this!=&v) {
49 clear();
51 clone(v);
52 }
53 return *this;
54}
55
56template< class valuetype, uint64_t count >
57inline
59 bool managevalues=this->getManageValues();
60 bool managearrayvalues=this->getManageArrayValues();
61 for (uint64_t i=0; i<count && i<v.getCount(); i++) {
62 data[i]=node_duplicate_value(&(v[i]),
63 managevalues,managearrayvalues);
64 }
65}
66
67template< class valuetype, uint64_t count >
68inline
70 deleteManagedValues();
71 delete[] data;
72}
73
74template< class valuetype, uint64_t count >
75inline
77 set(0,0,count);
78}
79
80template< class valuetype, uint64_t count >
81inline
83 set(0,0,zerocount);
84}
85
86template< class valuetype, uint64_t count >
87inline
88void staticarray<valuetype,count>::zero(uint64_t start, uint64_t zerocount) {
89 set(0,start,zerocount);
90}
91
92template< class valuetype, uint64_t count >
93inline
95 set(value,0,count);
96}
97
98template< class valuetype, uint64_t count >
99inline
100void staticarray<valuetype,count>::set(byte_t value, uint64_t setcount) {
101 set(value,0,setcount);
102}
103
104template< class valuetype, uint64_t count >
105inline
107 uint64_t start, uint64_t setcount) {
108 bytestring::set(data,value+start,sizeof(valuetype)*setcount);
109}
110
111template< class valuetype, uint64_t count >
112inline
114 // I once had (semi-clever) bounds-checking code here like:
115 //
116 // if (index>=count) {
117 // return *((valuetype *)NULL);
118 // }
119 //
120 // which would successfully return a NULL/0 if valuetype was a pointer,
121 // but would throw warnings on some platforms if valuetype isn't a
122 // pointer, and would probably crash on those platforms if it managed
123 // to run.
124 //
125 // It's (apparently) conventional for the operator[] not to do any
126 // bounds checking, not even throw any exceptions, and and just attempt
127 // to access and return the requested index, possibly crashing in the
128 // process. When a program accesses via the [] opertator it's telling
129 // the compiler "trust me, I know what I'm doing".
130 //
131 // So, for now, I removed that code above and we'll just let whatever
132 // happens, happen.
133 return data[index];
134}
135
136template< class valuetype, uint64_t count >
137inline
139 return count;
140}
141
142template< class valuetype, uint64_t count >
143inline
145 deleteManagedValues();
146 for (uint64_t i=0; i<count; i++) {
147 ((valuetype *)&data[i])->~valuetype();
148 new(&data[i]) valuetype;
149 }
150 return true;
151}
152
153template< class valuetype, uint64_t count >
154inline
156 bool managevalues=this->getManageValues();
157 bool managearrayvalues=this->getManageArrayValues();
158 if (managevalues || managearrayvalues) {
159 for (uint64_t i=0; i<count; i++) {
160 node_delete_value(&(data[i]),
161 managevalues,managearrayvalues);
162 node_zero_value(&(data[i]));
163 }
164 }
165}
Definition arraycollection.h:13
Definition avltree.h:11
avltreenode(valuetype value)
Definition avltreeinlines.h:555
static void * set(void *dest, byte_t character, size_t size)
collection & operator=(collection &c)
Definition collectioninlines.h:30
Definition staticarray.h:48
uint64_t getCount()
Definition staticarrayinlines.h:138
~staticarray()
Definition staticarrayinlines.h:69
staticarray()
Definition staticarrayinlines.h:10
bool clear()
Definition staticarrayinlines.h:144
void set(byte_t value)
Definition staticarrayinlines.h:94
staticarray< valuetype, count > & operator=(staticarray< valuetype, count > &v)
Definition staticarrayinlines.h:34
void zero()
Definition staticarrayinlines.h:76
valuetype & operator[](uint64_t index)
Definition staticarrayinlines.h:113