9 namespace datastructure {
32 : array_data(nullptr), num_dims(0), dims{0, 0, 0}, size(0) {
36 if (array_data !=
nullptr)
46 : array_data(nullptr) {
47 int dim[] = {1, 1, sz};
58 if (dim[0] <= 0 || dim[1] <= 0 || dim[2] <= 0) {
59 cout <<
"Dimensions of array must be positive!" << endl
60 <<
"\tProvided dimensions: " << dim[0]
61 <<
"," << dim[1] <<
"," << dim[2] << endl;
68 size = dim[0] * dim[1] * dim[2];
71 if (array_data !=
nullptr)
109 return array_data[index];
120 return array_data[index];
130 array_data[ind] = el;
145 vector<const Element<E>*> nodes;
147 for (
int k = 0; k < size; k++) {
148 nodes.push_back(&array_data[k]);
161 generateJSON(nodes) +
172 const string generateJSON(
const vector<
const Element<E>*>& nodes)
const {
175 throw "Max allowed elements(for visualization) exceeded.. " +
176 to_string(nodes.size()) +
" Must be less than " +
182 unordered_map<const Element<E>*,
int> map{{
nullptr, -1}};
187 for (
const auto* e : nodes) {
188 if (map.emplace(e, i).second && ++i) {
191 nodes_JSON += e->getElementRepresentation() +
COMMA;
195 if (nodes_JSON.size()) {
196 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
int const * getDimensions() const
Definition: Array.h:97
This is the fundamental building block for all data structures in BRIDGES.
Definition: Element.h:52
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 size
Definition: Array.h:45
virtual const string getDStype() const override
Definition: Array.h:138
const string COLON
Definition: DataStructure.h:51
virtual const string getDataStructureRepresentation() const override final
Definition: Array.h:142
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:129
const string CLOSE_CURLY
Definition: DataStructure.h:53
void getDimensions(int *dim)
Get the dimensions of the array.
Definition: Array.h:80
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:57
const string CLOSE_BOX
Definition: DataStructure.h:55
Element< E > & getElement(int index)
Definition: Array.h:108
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:119
const string QUOTE
Definition: DataStructure.h:49
std::string JSONencode(const T &d)
Definition: JSONutil.h:37