-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.h
More file actions
51 lines (48 loc) · 1.86 KB
/
Copy pathArray.h
File metadata and controls
51 lines (48 loc) · 1.86 KB
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
// This code was written by Michael Warren, on April 10, 2014. If you have any questions, concerns, or suggestions, please e-mail him at mwarren04011990@gmail.com
#ifndef ARRAY_H
#define ARRAY_H
#include <iostream>
#include <string>
/* This class will allow for a better way to store data in a container of constant size (without using a vector). In order to be
any good, it will need to be templated. */
template <typename Object>
class Array
{
public:
Array();
Array(unsigned arraySize);
Array(const Array&);
~Array();
Array& operator=(const Array&);
unsigned getLength() const;
//for detecting the type of this Array
std::string getArrayType() const;
//a setter
void setElementAt(unsigned, const Object&);
// a way to swap elements
void swapElements(unsigned, unsigned);
//operators that an Array should have
Object& operator[](unsigned);
const Object& operator[](unsigned) const;
bool operator==(const Array<Object>&) const;
bool operator!=(const Array<Object>&) const;
friend std::ostream& operator<<(std::ostream& outputStream, const Array<Object>& theArray)
{
outputStream << "{ ";
for (unsigned j = 0; j < theArray.getLength(); j++)
{
outputStream << theArray[j];
if (j < theArray.getLength() - 1)
outputStream << ", ";
}
return (outputStream << " }");
}
private:
static const unsigned capacity; // the size of any Array should not exceed this many elements
unsigned length;
Object * internalDataStorage;
//helper function for parsing int to string
static const std::string intToString(int);
};
//#include "Array.cpp"
#endif // ARRAY_H