Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces 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 #include <vector>
26 
27 #include <tulip/tulipconf.h>
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 class TLP_SCOPE StringCollection {
36 
37  std::vector<std::string> _data;
38  size_t current;
39 
40 public:
41 
42  /**
43  * Initializes an empty string collection.
44  */
45  StringCollection();
46 
47  /**
48  * Initializes a string collection with strings stored in a vector.
49  *
50  * @param vectorParam a vector of strings entries for the string collection
51  */
52  explicit StringCollection(const std::vector<std::string> &vectorParam);
53 
54  /**
55  * Initializes a string collection from a semicolon separated values string.
56  *
57  * @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 : \; .
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  std::vector<std::string> getValues()const;
81 
82  /**
83  * Returns the current selected string value.
84  */
85  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  * Returns true if the collection is empty.
119  */
120  inline bool empty() const {
121  return _data.empty();
122  }
123 
124  /**
125  * Returns the string element at a certain index in the collection.
126  *
127  * @param index a valid index in the collection
128  */
129  inline std::string at(const size_t index) const {
130  return _data.at(index);
131  }
132 
133  /**
134  * Returns the number of strings in the collection.
135  */
136  inline size_t size() const {
137  return _data.size();
138  }
139 
140  inline std::string operator[](const unsigned int i) const {
141  return _data[i];
142  }
143  inline std::string& operator[](const unsigned int i) {
144  return _data[i];
145  }
146 };
147 
148 }
149 #endif
150 ///@endcond