Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9047


Ignore:
Timestamp:
Mar 18, 2012, 6:43:24 PM (12 years ago)
Author:
landauf
Message:

made SubString more standard compliant

Location:
code/branches/testing/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/testing/src/libraries/core/command/ConsoleCommand.h

    r8858 r9047  
    222222#include <stack>
    223223#include <vector>
    224 #include <boost/preprocessor/cat.hpp>
    225 #include <boost/preprocessor/facilities/expand.hpp>
    226224
    227225#include "util/VA_NARGS.h"
  • code/branches/testing/src/libraries/util/SubString.cc

    r8858 r9047  
    8787        @param other The other SubString
    8888        @param begin The beginning of the subset
    89 
    90         The subset ranges from the token with index @a begin to the end of the tokens.
    91         If @a begin is greater than the greatest index, the new SubString will be empty.
    92     */
    93     SubString::SubString(const SubString& other, unsigned int begin)
    94     {
    95         for (unsigned int i = begin; i < other.size(); ++i)
    96         {
    97             this->tokens_.push_back(other[i]);
    98             this->bTokenInSafemode_.push_back(other.isInSafemode(i));
    99         }
    100     }
    101 
    102     /**
    103         @brief creates a new SubString based on a subset of an other SubString.
    104         @param other The other SubString
    105         @param begin The beginning of the subset
    106         @param end The end of the subset
    107 
    108         The subset ranges from the token with index @a begin until (but not including) the token with index @a end.
    109         If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty.
    110     */
    111     SubString::SubString(const SubString& other, unsigned int begin, unsigned int end)
    112     {
    113         for (unsigned int i = begin; i < std::min(other.size(), end); ++i)
    114         {
    115             this->tokens_.push_back(other[i]);
    116             this->bTokenInSafemode_.push_back(other.isInSafemode(i));
     89        @param length The length of the subset
     90
     91        The subset ranges from the token with index @a begin and contains @a length elements.
     92    */
     93    SubString::SubString(const SubString& other, size_t begin, size_t length)
     94    {
     95        for (size_t i = 0; i < length; ++i)
     96        {
     97            if (begin + i >= other.size())
     98                break;
     99
     100            this->tokens_.push_back(other[begin + i]);
     101            this->bTokenInSafemode_.push_back(other.isInSafemode(begin + i));
    117102        }
    118103    }
     
    123108        @param argv An array of pointers to the arguments
    124109    */
    125     SubString::SubString(unsigned int argc, const char** argv)
    126     {
    127         for(unsigned int i = 0; i < argc; ++i)
     110    SubString::SubString(size_t argc, const char** argv)
     111    {
     112        for (size_t i = 0; i < argc; ++i)
    128113        {
    129114            this->tokens_.push_back(std::string(argv[i]));
     
    158143
    159144    /**
    160         @copydoc operator==
    161     */
    162     bool SubString::compare(const SubString& other) const
    163     {
    164         return (*this == other);
    165     }
    166 
    167     /**
    168145        @brief Compares this SubString to another SubString and returns true if the first @a length values match.
    169146        @param other The other SubString
    170147        @param length How many tokens to compare
    171148    */
    172     bool SubString::compare(const SubString& other, unsigned int length) const
    173     {
    174         if (length > this->size() || length > other.size())
     149    bool SubString::compare(const SubString& other, size_t length) const
     150    {
     151        if (std::min(length, this->size()) != std::min(length, other.size()))
    175152            return false;
    176153
    177         for (unsigned int i = 0; i < length; ++i)
     154        for (size_t i = 0; i < std::min(length, this->size()); ++i)
    178155            if ((this->tokens_[i] != other.tokens_[i]) || (this->bTokenInSafemode_[i] != other.bTokenInSafemode_[i]))
    179156                return false;
     157
    180158        return true;
    181159    }
     
    196174    SubString& SubString::operator+=(const SubString& other)
    197175    {
    198         for (unsigned int i = 0; i < other.size(); ++i)
     176        for (size_t i = 0; i < other.size(); ++i)
    199177        {
    200178            this->tokens_.push_back(other[i]);
     
    207185        @copydoc SubString(const std::string&,const std::string&,const std::string&,bool,char,bool,char,bool,char,char,bool,char)
    208186    */
    209     unsigned int SubString::split(const std::string& line,
    210                                   const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries,
    211                                   char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar,
    212                                   char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar)
     187    size_t SubString::split(const std::string& line,
     188                            const std::string& delimiters, const std::string& delimiterNeighbours, bool bAllowEmptyEntries,
     189                            char escapeChar, bool bRemoveEscapeChar, char safemodeChar, bool bRemoveSafemodeChar,
     190                            char openparenthesisChar, char closeparenthesisChar, bool bRemoveParenthesisChars, char commentChar)
    213191    {
    214192        this->tokens_.clear();
     
    228206        {
    229207            std::string retVal = this->tokens_[0];
    230             for (unsigned int i = 1; i < this->tokens_.size(); ++i)
     208            for (size_t i = 1; i < this->tokens_.size(); ++i)
    231209                retVal += delimiter + this->tokens_[i];
    232210            return retVal;
     
    239217        @brief Creates a subset of this SubString.
    240218        @param begin The beginning of the subset
     219        @param length The length of the subset
    241220        @return A new SubString containing the defined subset.
    242221
    243         The subset ranges from the token with index @a begin to the end of the tokens.
    244         If @a begin is greater than the greatest index, the new SubString will be empty.
     222        The subset ranges from the token with index @a begin and contains @a length elements.
    245223
    246224        This function is added for your convenience, and does the same as
    247         SubString::SubString(const SubString& other, unsigned int begin)
    248     */
    249     SubString SubString::subSet(unsigned int begin) const
    250     {
    251         return SubString(*this, begin);
    252     }
    253 
    254     /**
    255         @brief Creates a subset of this SubString.
    256         @param begin The beginning of the subset
    257         @param end The ending of the subset
    258         @return A new SubString containing the defined subset.
    259 
    260         The subset ranges from the token with index @a begin until (but not including) the token with index @a end.
    261         If @a begin or @a end are beyond the allowed index, the resulting SubString will be empty.
    262 
    263         This function is added for your convenience, and does the same as
    264         SubString::SubString(const SubString& other, unsigned int begin, unsigned int end)
    265     */
    266     SubString SubString::subSet(unsigned int begin, unsigned int end) const
    267     {
    268         return SubString(*this, begin, end);
     225        SubString::SubString(const SubString& other, size_t begin, size_t length)
     226    */
     227    SubString SubString::subSet(size_t begin, size_t length) const
     228    {
     229        return SubString(*this, begin, length);
    269230    }
    270231
     
    298259    {
    299260        SPLIT_LINE_STATE state = start_state;
    300         unsigned int i = 0;
    301         unsigned int fallBackNeighbours = 0;
     261        size_t i = 0;
     262        size_t fallBackNeighbours = 0;
    302263
    303264        std::string token;
     
    514475    {
    515476        orxout(debug_output) << "Substring-information::count=" << this->tokens_.size() << " ::";
    516         for (unsigned int i = 0; i < this->tokens_.size(); ++i)
     477        for (size_t i = 0; i < this->tokens_.size(); ++i)
    517478            orxout(debug_output) << "s" << i << "='" << this->tokens_[i].c_str() << "'::";
    518479        orxout(debug_output) << endl;
  • code/branches/testing/src/libraries/util/SubString.h

    r8858 r9047  
    5858    SubString tokens(text, SubString::WhiteSpaces, "", false, '\\', true, '"', true, '{', '}', true, '\0');
    5959
    60     for (unsigned int i = 0; i < tokens.size(); ++i)
     60    for (size_t i = 0; i < tokens.size(); ++i)
    6161        orxout() << i << ": " << tokens[i] << endl;
    6262    @endcode
     
    127127                  bool bRemoveParenthesisChars = true,
    128128                  char commentChar = '\0');
    129         SubString(unsigned int argc, const char** argv);
    130         SubString(const SubString& other, unsigned int begin);
    131         SubString(const SubString& other, unsigned int begin, unsigned int end);
     129        SubString(size_t argc, const char** argv);
     130        SubString(const SubString& other, size_t begin, size_t length = std::string::npos);
    132131        ~SubString();
    133132
     
    135134        SubString& operator=(const SubString& other);
    136135        bool operator==(const SubString& other) const;
    137         bool compare(const SubString& other) const;
    138         bool compare(const SubString& other, unsigned int length) const;
     136        bool compare(const SubString& other, size_t length = std::string::npos) const;
    139137        SubString operator+(const SubString& other) const;
    140138        SubString& operator+=(const SubString& other);
     
    144142        /////////////////////////////////////////
    145143        // Split and Join the any String. ///////
    146         unsigned int split(const std::string& line,
    147                            const std::string& delimiters = SubString::WhiteSpaces,
    148                            const std::string& delimiterNeighbours = "",
    149                            bool bAllowEmptyEntries = false,
    150                            char escapeChar ='\\',
    151                            bool bRemoveEscapeChar = true,
    152                            char safemodeChar = '"',
    153                            bool bRemoveSafemodeChar = true,
    154                            char openparenthesisChar = '{',
    155                            char closeparenthesisChar = '}',
    156                            bool bRemoveParenthesisChars = true,
    157                            char commentChar = '\0');
     144        size_t split(const std::string& line,
     145                     const std::string& delimiters = SubString::WhiteSpaces,
     146                     const std::string& delimiterNeighbours = "",
     147                     bool bAllowEmptyEntries = false,
     148                     char escapeChar ='\\',
     149                     bool bRemoveEscapeChar = true,
     150                     char safemodeChar = '"',
     151                     bool bRemoveSafemodeChar = true,
     152                     char openparenthesisChar = '{',
     153                     char closeparenthesisChar = '}',
     154                     bool bRemoveParenthesisChars = true,
     155                     char commentChar = '\0');
    158156
    159157        std::string join(const std::string& delimiter = " ") const;
     
    161159
    162160        // retrieve a SubSet from the String
    163         SubString subSet(unsigned int begin) const;
    164         SubString subSet(unsigned int begin, unsigned int end) const;
     161        SubString subSet(size_t begin, size_t length = std::string::npos) const;
    165162
    166163        // retrieve Information from within
     
    168165        inline bool empty() const { return this->tokens_.empty(); }
    169166        /// Returns the number of tokens stored in this SubString
    170         inline unsigned int size() const { return this->tokens_.size(); }
     167        inline size_t size() const { return this->tokens_.size(); }
    171168        /// Returns the i'th token from the subset of strings @param index The index of the requested token
    172         inline const std::string& operator[](unsigned int index) const { return this->tokens_[index]; }
     169        inline const std::string& operator[](size_t index) const { return this->tokens_[index]; }
    173170        /// Returns the i'th token from the subset of strings @param index The index of the requested token
    174         inline const std::string& getString(unsigned int index) const { return (*this)[index]; }
     171        inline const std::string& getString(size_t index) const { return (*this)[index]; }
    175172        /// Returns all tokens as std::vector
    176173        inline const std::vector<std::string>& getAllStrings() const { return this->tokens_; }
    177174        /// Returns true if the token is in safemode. @param index The index of the token
    178         inline bool isInSafemode(unsigned int index) const { return this->bTokenInSafemode_[index]; }
     175        inline bool isInSafemode(size_t index) const { return this->bTokenInSafemode_[index]; }
    179176        /// Returns the front of the list of tokens.
    180177        inline const std::string& front() const { return this->tokens_.front(); }
  • code/branches/testing/src/libraries/util/VA_NARGS.h

    r7401 r9047  
    3636    type aware, but for different numbers of arguments is still very powerful).
    3737
     38    Important: The macro can not be overloaded for 0 arguments: ORXONOX_VA_NARGS() returns 1!
     39
    3840    Example: A macro to call functions
    3941    @code
     
    6466*/
    6567
     68#include <boost/preprocessor/cat.hpp>
    6669#include <boost/preprocessor/facilities/expand.hpp>
    6770
  • code/branches/testing/src/modules/notifications/dispatchers/CommandNotification.cc

    r7489 r9047  
    117117    const std::string& CommandNotification::bindingNiceifyer(const std::string& binding)
    118118    {
    119         SubString string = SubString(binding, ".");
     119        SubString substring = SubString(binding, ".");
    120120        std::string name;
    121121        std::string group;
    122         switch(string.size())
     122        switch(substring.size())
    123123        {
    124124            case 0:
     
    127127                return binding;
    128128            case 2:
    129                 group = string[0];
     129                group = substring[0];
    130130            default:
    131                 name = string.subSet(1, string.size()).join(".");
     131                name = substring.subSet(1).join(".");
    132132        }
    133133
     
    148148        return *(new std::string(stream.str()));
    149149    }
    150    
     150
    151151}
Note: See TracChangeset for help on using the changeset viewer.