8 namespace datastructure {
65 MLelement(
const E& val = E(),
const string& lab =
string())
198 virtual const string getDataStructureRepresentation() const override final {
199 vector<const MLelement<E>*> nodes;
202 this->getListElements(
this, nodes);
209 unordered_map<const MLelement*, int> node_map { {
nullptr, -1} };
211 string nodes_JSON, links_JSON;
214 for (
const auto * e : nodes) {
215 if (node_map.emplace(e, i).second) {
218 nodes_JSON += e->getElementRepresentation() +
COMMA;
222 node_map.erase(
nullptr);
223 if (nodes_JSON.size()) {
224 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
228 for (
int k = 0;
k < nodes.size();
k++) {
229 if (nodes[k]->
next !=
nullptr) {
231 to_string(node_map[nodes[k]]),
236 if (nodes[k]->
sub_list !=
nullptr) {
238 nodes[k]->
links.at(nodes[k]->sub_list),
239 to_string(node_map[nodes[k]]),
246 if (links_JSON.size()) {
247 links_JSON = links_JSON.erase(links_JSON.size() - 1);
250 string ml_list_json =
268 void getListElements(
const MLelement<E> *list,
269 vector<
const MLelement<E>*>& nodes)
const {
272 while (it !=
nullptr) {
276 getListElements(it->sub_list, nodes);
279 it = (MLelement<E>*) it->next;
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:50
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:310
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:92
ElementVisualizer * getVisualizer()
Get the element visualizer object.
Definition: Element.h:141
void setShape(const Shape &shp)
Set the shape of the element.
Definition: ElementVisualizer.h:140
void setColor(const Color &col)
Set the color to "col".
Definition: ElementVisualizer.h:94
This class can be used to instantiate Multi-list Elements.
Definition: MLelement.h:46
void setNext(MLelement< E > *n)
Sets the element to point to the next MLelement.
Definition: MLelement.h:157
void setTag(bool t)
Sets the tag of the element.
Definition: MLelement.h:172
bool getTag()
Gets the tag of the element.
Definition: MLelement.h:181
MLelement< E > * getNext() override
Retrieves the element following this element.
Definition: MLelement.h:138
void setSubList(MLelement< E > *sl)
Sets the start of a new sublist to the MLelement "next".
Definition: MLelement.h:108
MLelement< E > * getNext() const override
Retrieves the element following this element - const version.
Definition: MLelement.h:148
virtual const string getDStype() const override
Return the string representaion of element.
Definition: MLelement.h:189
MLelement * getSubList()
Gets the sublist at this node, if it exists.
Definition: MLelement.h:128
MLelement(string label)
Creates an MLelement object.
Definition: MLelement.h:82
MLelement(E e, MLelement< E > *next)
Creates an MLelement object.
Definition: MLelement.h:97
bool tag
Definition: MLelement.h:50
MLelement(const E &val=E(), const string &lab=string())
constructor
Definition: MLelement.h:65
MLelement< E > * sub_list
Definition: MLelement.h:49
The singly linked list element, derived from Element.
Definition: SLelement.h:26
SLelement * next
Definition: SLelement.h:29
@ SQUARE
Definition: ElementVisualizer.h:10
Support for drawing Bar charts.
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50