forked from shalevf6/AP-scriptRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoolArray.cpp
More file actions
61 lines (56 loc) · 1.39 KB
/
BoolArray.cpp
File metadata and controls
61 lines (56 loc) · 1.39 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
52
53
54
55
56
57
58
59
60
61
#include "BoolArray.h"
#include <iostream>
using namespace std;
/*
* constructor for new bool array using array variable constructor.
* boolArray - points to the beginning of the new array.
* size - the size of the array.
* name- the given name of the array
* type - the type of the array - set by default to be "BoolArray".
*
*/
BoolArray::BoolArray(bool* boolArray,int size, string name, string type) : ArrayVariable(size,name,type)
{
m_boolArray = (BoolVariable**) malloc(sizeof(BoolVariable) * size);
for (int i = 0; i < size;i++)
m_boolArray[i] = new BoolVariable(boolArray[i],"","bool");
}
/*
* destructor of the array.
*/
BoolArray::~BoolArray()
{
for (int i = 0; i < ArrayVariable::m_arraySize ; i++)
delete(m_boolArray[i]);
free(m_boolArray);
}
/*
* returns a pointer of an element in the array.
* index - the given index of the element.
*/
BoolVariable* BoolArray::getBoolElement(int index)
{
return m_boolArray[index];
}
/*
* A private function to print the array.
*/
ostream & BoolArray::Show(ostream & out)const
{
int i;
cout << *m_boolArray[0];
int length = ArrayVariable::m_arraySize;
for (i = 1; i < length; i++)
{
cout << ", ";
cout << *m_boolArray[i];
}
cout << "\n";
}
/*
* printing a given array with the right format.
*/
ostream & operator<<(ostream& out,const BoolArray & bA)
{
bA.Show(out);
}