Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
StringCollection.h
1/*
2 *
3 * This file is part of Tulip (https://tulip.labri.fr)
4 *
5 * Authors: David Auber and the Tulip development Team
6 * from LaBRI, University of Bordeaux
7 *
8 * Tulip is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * Tulip is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 */
19///@cond DOXYGEN_HIDDEN
20
21#ifndef STRINGCOLLECTION_H
22#define STRINGCOLLECTION_H
23
24#include <string>
25#include <vector>
26
27#include <tulip/tulipconf.h>
28
29namespace tlp {
30
31/**
32 * This class represents a list of selectable string entries that can be used as plugin parameter.
33 * The list will appear as a combo box in the Plugin Parameter Dialog from the Tulip GUI.
34 */
35class TLP_SCOPE StringCollection {
36
37 std::vector<std::string> _data;
38 size_t current;
39
40public:
41 /**
42 * Initializes an empty string collection.
43 */
44 StringCollection();
45
46 /**
47 * Initializes a string collection with strings stored in a vector.
48 *
49 * @param vectorParam a vector of strings entries for the string collection
50 */
51 explicit StringCollection(const std::vector<std::string> &vectorParam);
52
53 /**
54 * Initializes a string collection from a semicolon separated values string.
55 *
56 * @param param a semicolon separated values string ("entry1;...;entryN"). If an entry need to
57 * contain a semicolon, you have to escape it the following way : \; .
58 */
59 explicit StringCollection(const std::string &param);
60
61 /**
62 * Initializes a string collection with strings stored in a vector.
63 *
64 * @param vectorParam a vector of strings entries for the string collection
65 * @param currentParam the index of the current selected string in the vector
66 */
67 StringCollection(const std::vector<std::string> &vectorParam, const int currentParam);
68
69 /**
70 * Initializes a string collection with strings stored in a vector.
71 *
72 * @param vectorParam a vector of strings entries for the string collection
73 * @param currentString the current selected string value from the vector
74 */
75 StringCollection(const std::vector<std::string> &vectorParam, const std::string &currentString);
76
77 /**
78 * Returns all the selectable string entries.
79 **/
80 const std::vector<std::string> &getValues() const;
81
82 /**
83 * Returns the current selected string value.
84 */
85 const std::string &getCurrentString() const;
86
87 /**
88 * Sets the current selected string index.
89 * Returns true if the provided index is valid.
90 *
91 * @param param a valid index in the string collection
92 */
93 bool setCurrent(const unsigned int param);
94
95 /**
96 * Sets the current selected string value.
97 * Returns true if the string value exists in the collection.
98 *
99 * @param param a string value from the collection
100 */
101 bool setCurrent(const std::string &param);
102
103 /**
104 * Returns the index of the current selected string.
105 */
106 int getCurrent() const;
107
108 /**
109 * Adds a string value to this string collection.
110 *
111 * @param element the string to add to the collection
112 */
113 void push_back(const std::string &element) {
114 _data.push_back(element);
115 }
116
117 /**
118 * Concatenete a string collection to the current collection
119 *
120 */
121 inline void insert(const tlp::StringCollection &str) {
122 _data.insert(_data.end(), str._data.begin(), str._data.end());
123 }
124
125 /**
126 * Returns true if the collection is empty.
127 */
128 inline bool empty() const {
129 return _data.empty();
130 }
131 /**
132 * @brief clear the content of the collection.
133 */
134 void clear() {
135 _data.clear();
136 }
137
138 /**
139 * Returns the string element at a certain index in the collection.
140 *
141 * @param index a valid index in the collection
142 */
143 inline std::string at(const size_t index) const {
144 return _data.at(index);
145 }
146
147 /**
148 * Returns the number of strings in the collection.
149 */
150 inline size_t size() const {
151 return _data.size();
152 }
153
154 inline std::string operator[](const unsigned int i) const {
155 return _data[i];
156 }
157 inline std::string &operator[](const unsigned int i) {
158 return _data[i];
159 }
160};
161} // namespace tlp
162#endif
163///@endcond