Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/StringCollection.h
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 ///@cond DOXYGEN_HIDDEN
00020 
00021 #ifndef STRINGCOLLECTION_H
00022 #define STRINGCOLLECTION_H
00023 
00024 #include <string>
00025 #include <vector>
00026 
00027 #include <tulip/tulipconf.h>
00028 
00029 namespace tlp {
00030 
00031 /**
00032  * This class represents a list of selectable string entries that can be used as plugin parameter.
00033  * The list will appear as a combo box in the Plugin Parameter Dialog from the Tulip GUI.
00034  */
00035 class TLP_SCOPE StringCollection {
00036 
00037   std::vector<std::string> _data;
00038   size_t current;
00039 
00040 public:
00041 
00042   /**
00043    * Initializes an empty string collection.
00044    */
00045   StringCollection();
00046 
00047   /**
00048    * Initializes a string collection with strings stored in a vector.
00049    *
00050    * @param vectorParam a vector of strings entries for the string collection
00051    */
00052   explicit StringCollection(const std::vector<std::string> &vectorParam);
00053 
00054   /**
00055    * Initializes a string collection from a semicolon separated values string.
00056    *
00057    * @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 : \; .
00058    */
00059   explicit StringCollection(const std::string &param);
00060 
00061   /**
00062    * Initializes a string collection with strings stored in a vector.
00063    *
00064    * @param vectorParam a vector of strings entries for the string collection
00065    * @param currentParam the index of the current selected string in the vector
00066    */
00067   StringCollection(const std::vector<std::string>&  vectorParam, const int currentParam);
00068 
00069   /**
00070    * Initializes a string collection with strings stored in a vector.
00071    *
00072    * @param vectorParam a vector of strings entries for the string collection
00073    * @param currentString the current selected string value from the vector
00074    */
00075   StringCollection(const std::vector<std::string>& vectorParam, const std::string &currentString);
00076 
00077   /**
00078   * Returns all the selectable string entries.
00079   **/
00080   const std::vector<std::string>& getValues()const;
00081 
00082   /**
00083    * Returns the current selected string value.
00084    */
00085   const std::string& getCurrentString() const;
00086 
00087   /**
00088    * Sets the current selected string index.
00089    * Returns true if the provided index is valid.
00090    *
00091    * @param param a valid index in the string collection
00092    */
00093   bool setCurrent(const unsigned int param);
00094 
00095   /**
00096    * Sets the current selected string value.
00097    * Returns true if the string value exists in the collection.
00098    *
00099    * @param param a string value from the collection
00100    */
00101   bool setCurrent(const std::string param);
00102 
00103   /**
00104    * Returns the index of the current selected string.
00105    */
00106   int getCurrent() const;
00107 
00108   /**
00109    * Adds a string value to this string collection.
00110    *
00111    * @param element the string to add to the collection
00112    */
00113   void push_back(const std::string& element) {
00114     _data.push_back(element);
00115   }
00116 
00117   /**
00118    * Returns true if the collection is empty.
00119    */
00120   inline bool empty() const {
00121     return _data.empty();
00122   }
00123 
00124   /**
00125    * Returns the string element at a certain index in the collection.
00126    *
00127    * @param index a valid index in the collection
00128    */
00129   inline std::string at(const size_t index) const {
00130     return _data.at(index);
00131   }
00132 
00133   /**
00134    * Returns the number of strings in the collection.
00135    */
00136   inline size_t size() const {
00137     return _data.size();
00138   }
00139 
00140   inline std::string operator[](const unsigned int i) const {
00141     return _data[i];
00142   }
00143   inline std::string& operator[](const unsigned int i) {
00144     return _data[i];
00145   }
00146 };
00147 
00148 }
00149 #endif
00150 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties