Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/SuperOrxoBros_HS18/src/libraries/core/command/ArgumentCompletionListElement.h @ 12175

Last change on this file since 12175 was 12175, checked in by siramesh, 5 years ago

Super Orxo Bros (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 5.2 KB
Line 
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
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
35#ifndef _ArgumentCompletionListElement_H__
36#define _ArgumentCompletionListElement_H__
37
38#include "core/CorePrereqs.h"
39
40#include <list>
41#include <string>
42
43namespace orxonox
44{
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
48
49    typedef std::list<ArgumentCompletionListElement> ArgumentCompletionList;
50
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    */
66    class _CoreExport ArgumentCompletionListElement
67    {
68        public:
69            /// Constructor: Normal, comparable, and display string are all the same.
70            ArgumentCompletionListElement(const std::string& normalcase) : mode_(ACL_MODE_NORMAL), normal_(normalcase) {}
71            /// Constructor: Normal and display string are the same, a different (usually lowercase) string is used for comparison.
72            ArgumentCompletionListElement(const std::string& normalcase, const std::string& lowercase) : mode_(ACL_MODE_NORMAL | ACL_MODE_COMPARABLE), normal_(normalcase), comparable_(lowercase) {}
73            /// Constructor: Normal, comparable, and display are all different strings.
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) {}
75
76            /// Returns the normal string which is used as the actual argument.
77            const std::string& getString() const
78                { return this->normal_; }
79            /// Returns the comparable string which is used to compare arguments and user input
80            const std::string& getComparable() const
81                { return (this->mode_ & ACL_MODE_COMPARABLE) ? this->comparable_ : this->normal_; }
82            /// Returns the display string which is used in the displayed list of possible arguments
83            const std::string& getDisplay() const
84                { return (this->mode_ & ACL_MODE_DISPLAY) ? this->display_ : this->normal_; }
85
86            /// Returns true if there's a different string for comparison.
87            bool hasComparable() const
88                { return (this->mode_ & ACL_MODE_COMPARABLE); }
89            /// Returns true if there's a different string to display.
90            bool hasDisplay() const
91                { return (this->mode_ & ACL_MODE_DISPLAY); }
92
93            /// Overloaded operator for usage in maps and sets.
94            bool operator<(const ArgumentCompletionListElement& other) const
95                { return (this->getComparable() < other.getComparable()); }
96
97        private:
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
102    };
103}
104
105#endif /* _ArgumentCompletionListElement_H__ */
Note: See TracBrowser for help on using the repository browser.