[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program 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. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[7401] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @ingroup Command ArgumentCompletion |
---|
| 32 | @brief Definition of ArgumentCompletionList, which is used in @ref ArgumentCompletionFunctions.h "argument completion functions", and its element. |
---|
| 33 | */ |
---|
| 34 | |
---|
[1505] | 35 | #ifndef _ArgumentCompletionListElement_H__ |
---|
| 36 | #define _ArgumentCompletionListElement_H__ |
---|
| 37 | |
---|
[7203] | 38 | #include "core/CorePrereqs.h" |
---|
[1505] | 39 | |
---|
[3196] | 40 | #include <list> |
---|
[1505] | 41 | #include <string> |
---|
| 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[7401] | 45 | const int ACL_MODE_NORMAL = 1; ///< A flag, used if there's a normal string |
---|
| 46 | const int ACL_MODE_COMPARABLE = 2; ///< A flag, used if there's a different string used to compare |
---|
| 47 | const int ACL_MODE_DISPLAY = 4; ///< A flag, used if there's a different string used to be displayed |
---|
[1784] | 48 | |
---|
[1505] | 49 | typedef std::list<ArgumentCompletionListElement> ArgumentCompletionList; |
---|
| 50 | |
---|
[7401] | 51 | /** |
---|
| 52 | @brief This class is used in argument completion lists and contains up to three different strings, used in different situations. |
---|
| 53 | |
---|
| 54 | A list containing elements of type ArgumentCompletionListElement is returned by |
---|
| 55 | an @ref ArgumentCompletionFunctions.h "argument completion function". These elements |
---|
| 56 | are composed of up to three strings with different usage: |
---|
| 57 | - normal: What is used as the actual argument |
---|
| 58 | - comparable: What is used to compere the argument to the input of the user (usually lowercase, except for case-sensitive arguments) |
---|
| 59 | - display: This is displayed in the list of possible arguments - can differ from what is actually used for better readability |
---|
| 60 | |
---|
| 61 | @remarks An element with an empty ("") 'comparable' string will be ignored by the argument |
---|
| 62 | completion algorithms, but it's 'display' string will still be printed in the list. This |
---|
| 63 | can be used to add additional information, whitespaces, linebreaks or whatever is needed |
---|
| 64 | to format the output. |
---|
| 65 | */ |
---|
[1505] | 66 | class _CoreExport ArgumentCompletionListElement |
---|
| 67 | { |
---|
| 68 | public: |
---|
[7401] | 69 | /// Constructor: Normal, comparable, and display string are all the same. |
---|
[7228] | 70 | ArgumentCompletionListElement(const std::string& normalcase) : mode_(ACL_MODE_NORMAL), normal_(normalcase) {} |
---|
[7401] | 71 | /// Constructor: Normal and display string are the same, a different (usually lowercase) string is used for comparison. |
---|
[7228] | 72 | ArgumentCompletionListElement(const std::string& normalcase, const std::string& lowercase) : mode_(ACL_MODE_NORMAL | ACL_MODE_COMPARABLE), normal_(normalcase), comparable_(lowercase) {} |
---|
[7401] | 73 | /// Constructor: Normal, comparable, and display are all different strings. |
---|
[7228] | 74 | ArgumentCompletionListElement(const std::string& normalcase, const std::string& lowercase, const std::string& display) : mode_(ACL_MODE_NORMAL | ACL_MODE_COMPARABLE | ACL_MODE_DISPLAY), normal_(normalcase), comparable_(lowercase), display_(display) {} |
---|
[1505] | 75 | |
---|
[7401] | 76 | /// Returns the normal string which is used as the actual argument. |
---|
[1505] | 77 | const std::string& getString() const |
---|
[7228] | 78 | { return this->normal_; } |
---|
[7401] | 79 | /// Returns the comparable string which is used to compare arguments and user input |
---|
[1505] | 80 | const std::string& getComparable() const |
---|
[7228] | 81 | { return (this->mode_ & ACL_MODE_COMPARABLE) ? this->comparable_ : this->normal_; } |
---|
[7401] | 82 | /// Returns the display string which is used in the displayed list of possible arguments |
---|
[1505] | 83 | const std::string& getDisplay() const |
---|
[7228] | 84 | { return (this->mode_ & ACL_MODE_DISPLAY) ? this->display_ : this->normal_; } |
---|
[1505] | 85 | |
---|
[7401] | 86 | /// Returns true if there's a different string for comparison. |
---|
[7228] | 87 | bool hasComparable() const |
---|
| 88 | { return (this->mode_ & ACL_MODE_COMPARABLE); } |
---|
[7401] | 89 | /// Returns true if there's a different string to display. |
---|
[7228] | 90 | bool hasDisplay() const |
---|
| 91 | { return (this->mode_ & ACL_MODE_DISPLAY); } |
---|
[1505] | 92 | |
---|
[7401] | 93 | /// Overloaded operator for usage in maps and sets. |
---|
[1505] | 94 | bool operator<(const ArgumentCompletionListElement& other) const |
---|
| 95 | { return (this->getComparable() < other.getComparable()); } |
---|
| 96 | |
---|
| 97 | private: |
---|
[7401] | 98 | unsigned char mode_; ///< The flags |
---|
| 99 | std::string normal_; ///< The normal string |
---|
| 100 | std::string comparable_; ///< The comparable (usually lowercase) string |
---|
| 101 | std::string display_; ///< The string to display |
---|
[1505] | 102 | }; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | #endif /* _ArgumentCompletionListElement_H__ */ |
---|