9 namespace datastructure {
32 : array_data(nullptr), num_dims(0), dims{0, 0, 0}, size(0) {
36 if (array_data !=
nullptr)
44 : array_data(nullptr) {
45 int dim[] = {1, 1, sz};
56 if (dim[0] <= 0 || dim[1] <= 0 || dim[2] <= 0) {
57 cout <<
"Dimensions of array must be positive!" << endl
58 <<
"\tProvided dimensions: " << dim[0]
59 <<
"," << dim[1] <<
"," << dim[2] << endl;
66 size = dim[0] * dim[1] * dim[2];
69 if (array_data !=
nullptr)
107 return array_data[index];
118 return array_data[index];
128 array_data[ind] = el;
143 vector<const Element<E>*> nodes;
145 for (
int k = 0; k < size; k++) {
146 nodes.push_back(&array_data[k]);
159 generateJSON(nodes) +
170 const string generateJSON(
const vector<
const Element<E>*>& nodes)
const {
173 throw "Max allowed elements(for visualization) exceeded.. " +
174 to_string(nodes.size()) +
" Must be less than " +
180 unordered_map<const Element<E>*,
int> map{{
nullptr, -1}};
185 for (
const auto* e : nodes) {
186 if (map.emplace(e, i).second && ++i) {
189 nodes_JSON += e->getElementRepresentation() +
COMMA;
193 if (nodes_JSON.size()) {
194 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
int const * getDimensions() const
Definition: Array.h:95
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:44
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:61
Array(int sz)
builds an array given the dimensions
Definition: Array.h:43
virtual const string getDStype() const override
Definition: Array.h:136
const string COLON
Definition: DataStructure.h:51
virtual const string getDataStructureRepresentation() const override final
Definition: Array.h:140
The foundation of BRIDGES array types. It is not meant to be used directly by students.
Definition: Array.h:21
const string OPEN_BOX
Definition: DataStructure.h:54
void setElement(int ind, Element< E > el)
Set the Element at index ind - 1D array.
Definition: Array.h:127
const string CLOSE_CURLY
Definition: DataStructure.h:53
void getDimensions(int *dim)
Get the dimensions of the array.
Definition: Array.h:78
virtual ~Array()
Definition: Array.h:35
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
void setSize(int nd, int *dim)
Set the size of the array.
Definition: Array.h:55
const string CLOSE_BOX
Definition: DataStructure.h:55
Element< E > & getElement(int index)
Definition: Array.h:106
Array()
Definition: Array.h:31
Array & operator=(const Array &)=delete
const string COMMA
Definition: DataStructure.h:50
Element< E > const & getElement(int index) const
Get the object at index index - 1D array.
Definition: Array.h:117
const string QUOTE
Definition: DataStructure.h:49
std::string JSONencode(const T &d)
Definition: JSONutil.h:37