Main MRPT website > C++ reference
MRPT logo
CTypeSelector.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CTypeSelector_H
29 #define CTypeSelector_H
30 
32 
33 namespace mrpt
34 {
35 namespace utils
36 {
37  // This must be added to any CSerializable derived class:
39 
40  /** This class represents a std::string derived class which is also CSerializable
41  * \sa CSerializable
42  * \ingroup mrpt_base_grp
43  */
44  class BASE_IMPEXP CTypeSelector : public mrpt::utils::CSerializable
45  {
46  // This must be added to any CSerializable derived class:
48  protected:
49  /** The possibilities
50  */
51  std::vector<std::string> possibleTypes;
52 
53  /** The selected one:
54  */
55  unsigned int selection;
56 
57  public:
58  /** Default constructor.
59  * \param posibilitiesList The list of options, as a comma-separated-string, for example: "type 1,other type 2,type_3"
60  * \param defaultType Default type value
61  */
62  CTypeSelector(std::string posibilitiesList = "", std::string defaultType = "");
63 
64  /** Destructor
65  */
66  virtual ~CTypeSelector();
67 
68  /** Returns the set of posibilities in the "type" represented by this class.
69  */
70  void getTypePosibilities( std::vector<std::string> &outPosibilities)const;
71 
72  /** Gets the currently selected type, from the set of posibilities.
73  * \sa setType,getTypePosibilities
74  * \exception std::exception If currently there is not a valid selection.
75  */
76  std::string getType() const;
77 
78  /** Fast check for a given type, returns true if the selection is exactly the specified type name.
79  */
80  bool isType(const char *type) const;
81 
82  /** Fast check for a given type, returns true if the selection is exactly the specified type name.
83  */
84  bool isType(const std::string &type) const;
85 
86  /** Sets the currently selected type.
87  * \sa getType,getTypePosibilities
88  * \exception std::exception On trying to select a type not in the list of posible values.
89  */
90  void setType(const std::string &type);
91 
92  /** Returns the index of a given type within the list of all possible types, or -1 if the given string is not a valid type.
93  */
94  int checkTypeIndex(const std::string &type) const;
95 
96  }; // End of class def.
97 
98  } // End of namespace
99 } // End of namespace
100 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013