Changeset 955 for cpp/frams/util


Ignore:
Timestamp:
06/25/20 00:34:29 (4 years ago)
Author:
Maciej Komosinski
Message:

Genetic format ID becomes a string (no longer limited to a single character)

Location:
cpp/frams/util
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/sstring-simple.cpp

    r897 r955  
    2222}
    2323
    24 SString::SString(int x)
    25 {
    26         initEmpty();
    27         if (x)
    28                 ensureSize(x + 1);
    29 }
    30 
    3124SString::SString(const char *t, int t_len)
    3225{
     
    4639        txt = from.txt; size = from.size; used = from.used;
    4740        from.txt = NULL; from.size = 0; from.used = 0;
     41}
     42
     43SString::SString(char in)
     44{
     45        initEmpty();
     46        append(&in, 1);
    4847}
    4948
     
    117116SString SString::operator+(const SString& s) const
    118117{
    119         SString ret(len() + s.len());
     118        SString ret;
     119        ret.reserve(len() + s.len());
    120120        ret = *this;
    121121        ret += s;
  • cpp/frams/util/sstring-simple.h

    r793 r955  
    2727        SString(); ///< make an empty string
    2828        SString(const char*t, int t_len = -1); ///< make a string from char*
    29         SString(int x); ///< string with initial buffer allocated for x characters
     29        SString(int x) = delete; ///< disallow the former 'int' constructor (so the new 'char' version is not used through implicit conversion)
    3030        SString(const SString& from); ///< duplicate string
    3131        SString(SString&& from);///< move
     32        SString(char in);
    3233        ~SString();
    3334
    3435        void copyFrom(const char* ch, int chlen = -1); ///< copy string, length of -1 == unknown
    35 
     36       
    3637        void* operator new(size_t s, void* mem){ return mem; }
    3738#ifdef _MSC_VER
     
    4344        int len() const { return used; } ///< get string length
    4445        void shrink(); ///< free unnecessary buffer
     46        void reserve(int needed) { ensureSize(needed); } ///< like in std::string
    4547
    4648        /// after this call, you can modify sstring directly.
  • cpp/frams/util/sstring.cpp

    r897 r955  
    127127}
    128128
    129 SString::SString(int x)
    130 {
    131         buf = new SBuf(x);
    132 }
    133 
    134129SString::SString(const char *t, int t_len)
    135130{
     
    157152                REF_UNLOCK;
    158153        }
     154}
     155
     156SString::SString(char in)
     157{
     158        initEmpty();
     159        copyFrom(&in, 1);
    159160}
    160161
  • cpp/frams/util/sstring.h

    r889 r955  
    7070        SString(); ///< make an empty string
    7171        SString(const char*t, int t_len = -1); ///< make a string from char*
    72         SString(int x); ///< string with initial buffer size
     72        SString(int x) = delete; ///< disallow the former 'int' constructor (so the new 'char' version is not used through implicit conversion)
    7373        SString(const SString& from); ///< duplicate string
    7474        SString(SString&& from); ///< move
     75        SString(char in);
    7576        ~SString();
    7677
     
    8687        int len() const { return buf->used; } ///< get string length
    8788        void shrink(); ///< free unnecessary buffer
     89        void reserve(int needed) { ensureSize(needed); } ///< like in std::string
    8890
    8991        /// after this call, you can modify sstring directly.
Note: See TracChangeset for help on using the changeset viewer.