SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
canNewArray.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Scientific Computation Research Center
3  *
4  * This work is open source software, licensed under the terms of the
5  * BSD license as described in the LICENSE file in the top-level directory.
6  */
7 
8 #ifndef CAN_NEW_ARRAY_H
9 #define CAN_NEW_ARRAY_H
10 
14 #include <cstddef>
15 #include "canArray.h"
16 
17 namespace can {
18 
26 template <class T>
27 class NewArray : public Array<T,0>
28 {
29  public:
31  NewArray() {}
33  NewArray(std::size_t n) : Array<T,0>(n) {}
35  ~NewArray() {}
37  bool allocated() const {return this->elems;}
39  void deallocate()
40  {
41  delete [] this->elems;
42  this->sz = 0;
43  this->elems=0;
44  }
48  void allocate(std::size_t n) {this->resize(n);}
49  private:
50  NewArray(NewArray<T> const& other);
51  NewArray<T>& operator=(const NewArray<T>& other);
52 };
53 
54 } //namespace apf
55 
56 #endif
bool allocated() const
return true if memory has been allocated
Definition: canNewArray.h:37
~NewArray()
Array destructor frees memory.
Definition: canNewArray.h:35
void allocate(std::size_t n)
user-callable allocation helper
Definition: canNewArray.h:48
compile-time size array
wrapper over operator new/delete []
Definition: canNewArray.h:27
compile-time (static) array of size N
Definition: canArray.h:23
void deallocate()
user-callable deallocation helper
Definition: canNewArray.h:39
void resize(unsigned n)
resize the array
Definition: canArray.h:80
NewArray()
default initialize pointer to zero
Definition: canNewArray.h:31
NewArray(std::size_t n)
construct with (n) elements
Definition: canNewArray.h:33