Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
StringCollection.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 
26 #include "tulipconf.h"
27 #include <vector>
28 
29 namespace 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  */
35 struct TLP_SCOPE StringCollection {
36 
37 private:
38  size_t current;
39  std::vector<std::string> _data;
40 
41 public:
42 
43  /**
44  * Initializes an empty string collection.
45  */
46  StringCollection();
47 
48  /**
49  * Initializes a string collection with strings stored in a vector.
50  *
51  * @param vectorParam a vector of strings entries for the string collection
52  */
53  explicit StringCollection(const std::vector<std::string> &vectorParam);
54 
55  /**
56  * Initializes a string collection from a semicolon separated values string.
57  *
58  * @param param a semicolon separated values string ("entry1;...;entryN"). If an entry need to contain a semicolon, you have to escape it the following way : \; .
59  */
60  StringCollection(const std::string param);
61 
62  /**
63  * Initializes a string collection with strings stored in a vector.
64  *
65  * @param vectorParam a vector of strings entries for the string collection
66  * @param currentParam the index of the current selected string in the vector
67  */
68  StringCollection(const std::vector<std::string>& vectorParam, int currentParam);
69 
70  /**
71  * Initializes a string collection with strings stored in a vector.
72  *
73  * @param vectorParam a vector of strings entries for the string collection
74  * @param currentString the current selected string value from the vector
75  */
76  StringCollection(const std::vector<std::string>& vectorParam, std::string currentString);
77 
78  /**
79  * Returns all the selectable string entries.
80  **/
81  std::vector<std::string> getValues()const;
82 
83  /**
84  * Returns the current selected string value.
85  */
86  std::string getCurrentString();
87 
88  /**
89  * Sets the current selected string index.
90  * Returns true if the provided index is valid.
91  *
92  * @param param a valid index in the string collection
93  */
94  bool setCurrent(unsigned int param);
95 
96  /**
97  * Sets the current selected string value.
98  * Returns true if the string value exists in the collection.
99  *
100  * @param param a string value from the collection
101  */
102  bool setCurrent(std::string param);
103 
104  /**
105  * Returns the index of the current selected string.
106  */
107  int getCurrent();
108 
109  /**
110  * Adds a string value to this string collection.
111  *
112  * @param element the string to add to the collection
113  */
114  void push_back(const std::string& element) {
115  _data.push_back(element);
116  }
117 
118  /**
119  * Returns true if the collection is empty.
120  */
121  inline bool empty() {
122  return _data.empty();
123  }
124 
125  /**
126  * Returns the string element at a certain index in the collection.
127  *
128  * @param index a valid index in the collection
129  */
130  inline std::string at(size_t index) {
131  return _data.at(index);
132  }
133 
134  /**
135  * Returns the number of strings in the collection.
136  */
137  inline size_t size() {
138  return _data.size();
139  }
140 
141  inline std::string operator[](const unsigned int i) const {
142  return _data[i];
143  }
144  inline std::string& operator[](const unsigned int i) {
145  return _data[i];
146  }
147 };
148 
149 }
150 #endif
151 ///@endcond