Bridges-C++ 3.5.0-dev2-1-ge3e57bf
Bridges(C++ API)
SymbolGroup.h
Go to the documentation of this file.
1#include <string>
2#include <unordered_map>
3#include <memory>
4
5using namespace std;
6
7#include <JSONutil.h>
8#include "DataStructure.h"
9#include "Symbol.h"
10
25#ifndef SYMBOL_GROUP_H
26
27#define SYMBOL_GROUP_H
28
29namespace bridges {
30 namespace datastructure {
39 class SymbolGroup : public Symbol {
40 private:
41
42 // symbols in this group
43 std::vector<std::shared_ptr<Symbol >> symbols;
44
45 public:
50 symbols.clear();
51 }
52
59 void addSymbolPtr(std::shared_ptr<Symbol> s) {
60 symbols.push_back(s);
61 }
62
63 template <typename T>
64 void addSymbol(T s) {
65 std::shared_ptr<T> pt = std::make_shared<T>(s);
66 addSymbolPtr ((std::shared_ptr<Symbol>)pt);
67 }
68
69 std::vector<std::shared_ptr<Symbol >> getAllSymbols() const {
70 return symbols;
71 }
72
85 virtual string getShapeType() const override {
86 return "group";
87 }
88
89 virtual const string getSymbolRepresentation() const override {
90
92
93 // first get the group's representation
94 string symbol_json = getSymbolAttributeRepresentation() + COMMA;
95
96 // process the symbols in the group
97 for (auto& entry : symbols) {
98 symbol_json +=
99 entry->getSymbolRepresentation();
100
101 // remove the close curly brace
102 if (symbol_json.size())
103 symbol_json.erase(symbol_json.size() - 1);
104
105 // add parent id
106 symbol_json += COMMA + QUOTE + "parentID" + QUOTE + COLON +
107 to_string(getIdentifier()) + CLOSE_CURLY + COMMA;
108 }
109 // remove last comma
110 if (symbols.size()) {
111 symbol_json.erase(symbol_json.size() - 1);
112 }
113
114 return symbol_json;
115 }
116 };
117 }
118} // namespace bridges
119
120#endif
the SymbolGroup represents a collection of symbols (shapes, polygons, and text) to visualize in Bridg...
Definition: SymbolGroup.h:39
std::vector< std::shared_ptr< Symbol > > getAllSymbols() const
Definition: SymbolGroup.h:69
virtual string getShapeType() const override
This method returns the JSON representation of the symbol group.
Definition: SymbolGroup.h:85
void addSymbol(T s)
Definition: SymbolGroup.h:64
void addSymbolPtr(std::shared_ptr< Symbol > s)
This method adds a symbol to the collection.
Definition: SymbolGroup.h:59
SymbolGroup()
Definition: SymbolGroup.h:49
virtual const string getSymbolRepresentation() const override
Virtual method to get the JSON representation of the symbol.
Definition: SymbolGroup.h:89
This is an abstract class for deriving a number of Symbol shape objects, for use in a SymbolCollectio...
Definition: Symbol.h:31
int getIdentifier() const
return the symbol identifier.
Definition: Symbol.h:217
const string getSymbolAttributeRepresentation() const
Get the JSON of the symbol representation.
Definition: Symbol.h:622
std::string JSONencode(const T &d)
Definition: JSONutil.h:38
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50