A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Array.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #include "Object.h"
20 #include "PDBTemplateBase.h"
21 #include "Handle.h"
22 
23 #ifndef ARRAY_H
24 #define ARRAY_H
25 
26 #include <cstddef>
27 #include <iostream>
28 #include <iterator>
29 #include <cstring>
30 
31 // PRELOAD %Array <Nothing>%
32 
33 namespace pdb {
34 
35 
36 // The Array type is the one type that we allow to be variable length. This is accomplished
37 // the the data[] array at the end of the class. When an Array object is alllocated, it is
38 // always allocated with some extra space at the end of the class to allow this array to
39 // be used.
40 //
41 // Since the array class can be variable length, it is used as the key building block for
42 // both the Vector and String classes.
43 
44 template <class TypeContained>
45 class Array : public Object {
46 
47 public:
48  // constructor/sdestructor
49  Array();
50  Array(uint32_t numSlots);
51  Array(const Array& copyFromMe);
52  ~Array();
53 
54  // this constructor pre-allocates the given number of slots, and initializes the specified
55  // number,
56  // so that the number of used slots is equal to the secod parameter
57  Array(uint32_t numSlots, uint32_t numUsedSlots);
58 
59  // normally these would be defined by the ENABLE_DEEP_COPY macro, but because
60  // Array is the one variable-sized type that we allow, we need to manually override
61  // these methods
62  void setUpAndCopyFrom(void* target, void* source) const;
63  void deleteObject(void* deleteMe);
64  size_t getSize(void* forMe);
65 
66 private:
67  // and this gives us our info about TypeContained
69 
70  // the number of slots actually used
71  uint32_t usedSlots;
72 
73  // the number of slots
74  uint32_t numSlots;
75 
76  // the array of data
78 
79 public:
80  // create a new Array object of size howMany, and copy our contents into it
81  Handle<Array<TypeContained>> resize(uint32_t howMany);
82 
83  // get a pointer to the data
84  TypeContained* c_ptr();
85 
86  // access a particular object in the array, by index
87  TypeContained& getObj(uint32_t which);
88 
89  // assign a particular item in the array
90  void assign(uint32_t which, const TypeContained& val);
91 
92  // add to the end
93  void push_back(const TypeContained& val);
94 
95  // add an empty item at the end
96  void push_back();
97 
98  // remove from the end and shrink the number of used slots
99  void pop_back();
100 
101  // return a new array that is twice the size, containing the same contents
103 
104  // check if the array is full
105  bool isFull();
106 
107  // return/set the number of used slots
108  uint32_t numUsedSlots();
109  void setUsed(uint32_t toMe);
110 
111  // beause the communicator needs to see inside to do efficient sends
112  friend class PDBCommunicator;
113 };
114 }
115 
116 #include "Array.cc"
117 
118 #endif
void push_back()
Definition: Array.cc:233
Handle< Array< TypeContained > > doubleSize()
Definition: Array.cc:128
PDBTemplateBase typeInfo
Definition: Array.h:68
uint32_t numSlots
Definition: Array.h:74
uint32_t numUsedSlots()
Definition: Array.cc:255
void setUpAndCopyFrom(void *target, void *source) const
Definition: Array.cc:41
TypeContained * c_ptr()
Definition: Array.cc:242
TypeContained & getObj(uint32_t which)
Definition: Array.cc:210
bool isFull()
Definition: Array.cc:133
Handle< Array< TypeContained > > resize(uint32_t howMany)
Definition: Array.cc:171
void assign(uint32_t which, const TypeContained &val)
Definition: Array.cc:215
~Array()
Definition: Array.cc:148
Nothing data[0]
Definition: Array.h:77
uint32_t usedSlots
Definition: Array.h:71
size_t getSize(void *forMe)
Definition: Array.cc:270
void setUsed(uint32_t toMe)
Definition: Array.cc:260
void deleteObject(void *deleteMe)
Definition: Array.cc:265
void pop_back()
Definition: Array.cc:247