Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 31, 2010, 3:37:40 AM (14 years ago)
Author:
landauf
Message:

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

Location:
code/trunk
Files:
10 edited
7 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/util/CMakeLists.txt

    r7226 r7284  
    3131  CRC32.cc
    3232  OutputHandler.cc
     33  ScopedSingletonManager.cc
     34  SharedPtr.cc
    3335  SignalHandler.cc
    3436  Sleep.cc
     37  SmallObjectAllocator.cc
    3538  SubString.cc
    3639COMPILATION_END
  • code/trunk/src/libraries/util/Convert.h

    r7266 r7284  
    109109        }
    110110    };
     111
     112    ////////////
     113    // upcast //
     114    ////////////
     115    namespace detail
     116    {
     117        // perform a static cast if ToType is a base of FromType
     118        template<class ToType, class FromType>
     119        FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<true>)
     120        {
     121            return static_cast<ToType>(input);
     122        }
     123
     124        // return zero if ToType is not a base of FromType
     125        template<class ToType, class FromType>
     126        FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<false>)
     127        {
     128            return 0;
     129        }
     130    }
     131
     132    // performs an upcast if ToType is a base of FromType, returns zero otherwise
     133    template <class ToType, class FromType>
     134    FORCEINLINE ToType upcast(FromType input)
     135    {
     136        enum { probe = ImplicitConversion<FromType, ToType>::exists };
     137        return detail::upcast<ToType, FromType>(input, Loki::Int2Type<probe>());
     138    }
    111139}
    112140
  • code/trunk/src/libraries/util/Math.cc

    r7184 r7284  
    234234    bool ConverterFallback<std::string, orxonox::Vector2>::convert(orxonox::Vector2* output, const std::string& input)
    235235    {
    236         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    237         if ((opening_parenthesis = input.find('(')) == std::string::npos)
     236        size_t opening_parenthesis, closing_parenthesis = input.find('}');
     237        if ((opening_parenthesis = input.find('{')) == std::string::npos)
    238238            opening_parenthesis = 0;
    239239        else
     
    257257    bool ConverterFallback<std::string, orxonox::Vector3>::convert(orxonox::Vector3* output, const std::string& input)
    258258    {
    259         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    260         if ((opening_parenthesis = input.find('(')) == std::string::npos)
     259        size_t opening_parenthesis, closing_parenthesis = input.find('}');
     260        if ((opening_parenthesis = input.find('{')) == std::string::npos)
    261261            opening_parenthesis = 0;
    262262        else
     
    282282    bool ConverterFallback<std::string, orxonox::Vector4>::convert(orxonox::Vector4* output, const std::string& input)
    283283    {
    284         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    285         if ((opening_parenthesis = input.find('(')) == std::string::npos)
     284        size_t opening_parenthesis, closing_parenthesis = input.find('}');
     285        if ((opening_parenthesis = input.find('{')) == std::string::npos)
    286286            opening_parenthesis = 0;
    287287        else
     
    309309    bool ConverterFallback<std::string, orxonox::Quaternion>::convert(orxonox::Quaternion* output, const std::string& input)
    310310    {
    311         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    312         if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     311        size_t opening_parenthesis, closing_parenthesis = input.find('}');
     312        if ((opening_parenthesis = input.find('{')) == std::string::npos)
     313            opening_parenthesis = 0;
     314        else
     315            opening_parenthesis++;
    313316
    314317        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
     
    332335    bool ConverterFallback<std::string, orxonox::ColourValue>::convert(orxonox::ColourValue* output, const std::string& input)
    333336    {
    334         size_t opening_parenthesis, closing_parenthesis = input.find(')');
    335         if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }
     337        size_t opening_parenthesis, closing_parenthesis = input.find('}');
     338        if ((opening_parenthesis = input.find('{')) == std::string::npos)
     339            opening_parenthesis = 0;
     340        else
     341            opening_parenthesis++;
    336342
    337343        SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');
  • code/trunk/src/libraries/util/MultiType.h

    r7268 r7284  
    7777#include <OgreColourValue.h>
    7878#include <loki/TypeTraits.h>
     79#include "mbool.h"
    7980
    8081namespace orxonox
     
    265266            inline MultiType(const orxonox::Radian& value)      : value_(0) { this->assignValue(value); }           /** @brief Constructor: Assigns the given value and sets the type. */
    266267            inline MultiType(const orxonox::Degree& value)      : value_(0) { this->assignValue(value); }           /** @brief Constructor: Assigns the given value and sets the type. */
     268            inline MultiType(const orxonox::mbool& value)       : value_(0) { this->assignValue((bool)value); }     /** @brief Constructor: Assigns the given mbool and converts it to bool. */
    267269            inline MultiType(const char* value)                 : value_(0) { this->setValue(std::string(value)); } /** @brief Constructor: Converts the char array to a std::string, assigns the value and sets the type. */
    268270            inline MultiType(const MultiType& other)            : value_(0) { this->setValue(other); }              /** @brief Copyconstructor: Assigns value and type of the other MultiType. */
     
    318320            inline void                       copy(const MultiType& other)    { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; }
    319321
    320             template <typename T> inline bool convert()                       { return this->setValue<T>((T)(*this));  } /** @brief Converts the current value to type T. */
     322            template <typename T> inline bool convert()                       { return this->setValue<T>((typename Loki::TypeTraits<T>::UnqualifiedReferredType)(*this));  } /** @brief Converts the current value to type T. */
    321323            inline bool                       convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */
    322324            bool                              convert(MT_Type::Value type);
     
    350352
    351353            /** @brief Checks whether the value is a default one. */
    352             bool                              hasDefaultValue()         const { return this->value_->hasDefaultValue(); }
     354            bool                              hasDefaultValue() const { return this->value_->hasDefaultValue(); }
     355
     356            /** @brief Checks if the MT contains no value. */
     357            bool                              null() const { return (!this->value_); }
    353358
    354359            operator char()                  const;
     
    487492    template <> inline bool MultiType::isType<orxonox::Degree>()      const { return (this->value_ && this->value_->type_ == MT_Type::Degree);           } /** @brief Returns true if the current type equals the given type. */
    488493
     494    template <> inline bool MultiType::convert<void>()                 { this->reset(); return true; } /** @brief Deletes the content, type becomes MT_Type::Null. */
     495
    489496    // Specialization to avoid ambiguities with the conversion operator
    490497    template <> inline bool MultiType::convert<std::string>()          { return this->setValue<std::string>         (this->operator std::string());          } /** @brief Converts the current value to the given type. */
  • code/trunk/src/libraries/util/OutputHandler.h

    r6105 r7284  
    104104
    105105            //! Writes to all output devices
    106             static inline const std::string& log(const std::string& text)
    107                 { OutputHandler::getOutStream(0).output(text) << std::endl; return text; }
     106            static inline void log(const std::string& text)
     107                { OutputHandler::getOutStream(0).output(text) << std::endl; }
    108108
    109109            //! Writes an error message to the output
    110             static inline const std::string& error(const std::string& text)
    111                 { OutputHandler::getOutStream(1).output(text) << std::endl; return text; }
     110            static inline void error(const std::string& text)
     111                { OutputHandler::getOutStream(1).output(text) << std::endl; }
    112112
    113113            //! Writes a warning message to the output
    114             static inline const std::string& warning(const std::string& text)
    115                 { OutputHandler::getOutStream(2).output(text) << std::endl; return text; }
     114            static inline void warning(const std::string& text)
     115                { OutputHandler::getOutStream(2).output(text) << std::endl; }
    116116
    117117            //! Writes an informational message to the output
    118             static inline const std::string& info(const std::string& text)
    119                 { OutputHandler::getOutStream(3).output(text) << std::endl; return text; }
     118            static inline void info(const std::string& text)
     119                { OutputHandler::getOutStream(3).output(text) << std::endl; }
    120120
    121121            //! Writes a debug message to the output
    122             static inline const std::string& debug(const std::string& text)
    123                 { OutputHandler::getOutStream(4).output(text) << std::endl; return text; }
     122            static inline void debug(const std::string& text)
     123                { OutputHandler::getOutStream(4).output(text) << std::endl; }
    124124
    125125            //! Registers an object that receives output via a provided std::ostream
  • code/trunk/src/libraries/util/StringUtils.cc

    r6424 r7284  
    3535
    3636#include <cctype>
     37#include <boost/scoped_array.hpp>
    3738#include "Convert.h"
    3839#include "Math.h"
     
    514515        @return Number of replacements
    515516    */
    516     _UtilExport size_t replaceCharacters(std::string& str, char target, char replacement)
     517    size_t replaceCharacters(std::string& str, char target, char replacement)
    517518    {
    518519        size_t j = 0;
     
    527528        return j;
    528529    }
     530
     531    /**
     532        @brief Calculates the Levenshtein distance between two strings.
     533
     534        The Levenshtein distance is defined by the number of transformations needed to convert str1
     535        into str2. Possible transformations are substituted, added, or removed characters.
     536    */
     537    unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2)
     538    {
     539        size_t cols = str1.size() + 1;
     540        size_t rows = str2.size() + 1;
     541        boost::scoped_array<int> matrix(new int[rows * cols]);
     542
     543        for (size_t r = 0; r < rows; ++r)
     544            for (size_t c = 0; c < cols; ++c)
     545                matrix[r*cols + c] = 0;
     546
     547        for (size_t i = 1; i < cols; ++i)
     548            matrix[0*cols + i] = i;
     549        for (size_t i = 1; i < rows; ++i)
     550            matrix[i*cols + 0] = i;
     551
     552        for (size_t r = 1; r < rows; ++r)
     553            for (size_t c = 1; c < cols; ++c)
     554                matrix[r*cols + c] = (str1[c-1] != str2[r-1]);
     555
     556        for (size_t r = 1; r < rows; ++r)
     557            for (size_t c = 1; c < cols; ++c)
     558                matrix[r*cols + c] = std::min(std::min(matrix[(r-1)*cols + c] + 1,
     559                                                       matrix[r*cols + c-1] + 1),
     560                                              matrix[(r-1)*cols + c-1] + (str1[c-1] != str2[r-1]));
     561
     562        return matrix[(rows-1)*cols + cols-1];
     563    }
    529564}
  • code/trunk/src/libraries/util/StringUtils.h

    r5738 r7284  
    4343    _UtilExport std::string getUniqueNumberString();
    4444
    45     _UtilExport void        strip(std::string* str);
    46     _UtilExport std::string getStripped(const std::string& str);
     45    _UtilExport void         strip(std::string* str);
     46    _UtilExport std::string  getStripped(const std::string& str);
    4747
    48     _UtilExport std::string removeTrailingWhitespaces(const std::string& str);
     48    _UtilExport std::string  removeTrailingWhitespaces(const std::string& str);
    4949
    50     _UtilExport size_t      getNextQuote(const std::string& str, size_t start);
    51     _UtilExport bool        isBetweenQuotes(const std::string& str, size_t pos);
     50    _UtilExport size_t       getNextQuote(const std::string& str, size_t start);
     51    _UtilExport bool         isBetweenQuotes(const std::string& str, size_t pos);
    5252
    53     _UtilExport bool        hasStringBetweenQuotes(const std::string& str);
    54     _UtilExport std::string getStringBetweenQuotes(const std::string& str);
     53    _UtilExport bool         hasStringBetweenQuotes(const std::string& str);
     54    _UtilExport std::string  getStringBetweenQuotes(const std::string& str);
    5555
    56     _UtilExport std::string stripEnclosingQuotes(const std::string& str);
    57     _UtilExport std::string stripEnclosingBraces(const std::string& str);
     56    _UtilExport std::string  stripEnclosingQuotes(const std::string& str);
     57    _UtilExport std::string  stripEnclosingBraces(const std::string& str);
    5858
    59     _UtilExport bool        isEmpty(const std::string& str);
    60     _UtilExport bool        isComment(const std::string& str);
    61     _UtilExport bool        isNumeric(const std::string& str);
     59    _UtilExport bool         isEmpty(const std::string& str);
     60    _UtilExport bool         isComment(const std::string& str);
     61    _UtilExport bool         isNumeric(const std::string& str);
    6262
    63     _UtilExport std::string addSlashes(const std::string& str);
    64     _UtilExport std::string removeSlashes(const std::string& str);
     63    _UtilExport std::string  addSlashes(const std::string& str);
     64    _UtilExport std::string  removeSlashes(const std::string& str);
    6565
    66     _UtilExport void        lowercase(std::string* str);
    67     _UtilExport std::string getLowercase(const std::string& str);
     66    _UtilExport void         lowercase(std::string* str);
     67    _UtilExport std::string  getLowercase(const std::string& str);
    6868
    69     _UtilExport void        uppercase(std::string* str);
    70     _UtilExport std::string getUppercase(const std::string& str);
     69    _UtilExport void         uppercase(std::string* str);
     70    _UtilExport std::string  getUppercase(const std::string& str);
    7171
    72     _UtilExport int         nocaseCmp(const std::string& s1, const std::string& s2);
    73     _UtilExport int         nocaseCmp(const std::string& s1, const std::string& s2, size_t len);
     72    _UtilExport int          nocaseCmp(const std::string& s1, const std::string& s2);
     73    _UtilExport int          nocaseCmp(const std::string& s1, const std::string& s2, size_t len);
    7474
    75     _UtilExport bool        hasComment(const std::string& str);
    76     _UtilExport std::string getComment(const std::string& str);
    77     _UtilExport size_t      getCommentPosition(const std::string& str);
    78     _UtilExport size_t      getNextCommentPosition(const std::string& str, size_t start = 0);
     75    _UtilExport bool         hasComment(const std::string& str);
     76    _UtilExport std::string  getComment(const std::string& str);
     77    _UtilExport size_t       getCommentPosition(const std::string& str);
     78    _UtilExport size_t       getNextCommentPosition(const std::string& str, size_t start = 0);
    7979
    80     _UtilExport size_t      replaceCharacters(std::string& str, char target, char replacement);
     80    _UtilExport size_t       replaceCharacters(std::string& str, char target, char replacement);
     81
     82    _UtilExport unsigned int getLevenshteinDistance(const std::string& str1, const std::string& str2);
    8183}
    8284
  • code/trunk/src/libraries/util/SubString.cc

    r7165 r7284  
    309309     * @param line the inputLine to split
    310310     * @param delimiters a String of Delimiters (here the input will be splitted)
    311      * @param delimiterNeighbours Naighbours to the Delimitter, that will be removed if they are to the left or the right of a Delimiter.
     311     * @param delimiterNeighbours Neighbours to the Delimiter, that will be removed if they are to the left or the right of a Delimiter.
    312312     * @param emptyEntries: if empty Strings are added to the List of Strings.
    313313     * @param escape_char: Escape carater (escapes splitters)
  • code/trunk/src/libraries/util/SubString.h

    r5738 r7284  
    8181            SL_SAFEESCAPE,        //!< In safe mode with the internal escape character, that escapes even the savemode character.
    8282            SL_COMMENT,           //!< In Comment mode.
    83             SL_PARENTHESES,       //!< Between parentheses (usually '(' and ')')
     83            SL_PARENTHESES,       //!< Between parentheses (usually '{' and '}')
    8484            SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing paranthesis character.
    8585        } SPLIT_LINE_STATE;
     
    9292                  const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false,
    9393                  char escapeChar ='\\', bool removeEscapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true,
    94                   char openparenthesis_char = '(', char closeparenthesis_char = ')',  bool removeParenthesisChars = true, char comment_char = '\0');
     94                  char openparenthesis_char = '{', char closeparenthesis_char = '}',  bool removeParenthesisChars = true, char comment_char = '\0');
    9595        SubString(unsigned int argc, const char** argv);
    9696        /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */
     
    116116                           const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false,
    117117                           char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true,
    118                            char openparenthesis_char = '(', char closeparenthesis_char = ')',  bool removeParenthesisChars = true, char comment_char = '\0');
     118                           char openparenthesis_char = '{', char closeparenthesis_char = '}',  bool removeParenthesisChars = true, char comment_char = '\0');
    119119        std::string join(const std::string& delimiter = " ") const;
    120120        ////////////////////////////////////////
     
    155155                                          char safemode_char = '"',
    156156                                          bool removeSafemodeChar = true,
    157                                           char openparenthesis_char = '(',
    158                                           char closeparenthesis_char = ')',
     157                                          char openparenthesis_char = '{',
     158                                          char closeparenthesis_char = '}',
    159159                                          bool removeParenthesisChars = true,
    160160                                          char comment_char = '\0',
Note: See TracChangeset for help on using the changeset viewer.