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