Changeset 691 for cpp


Ignore:
Timestamp:
09/04/17 03:24:01 (7 years ago)
Author:
Maciej Komosinski
Message:

Support for reading/parsing and writing 64-bit integer values

Location:
cpp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/Convert.h

    r286 r691  
    1515typedef XY<double> Pt2D;
    1616
     17#ifdef LINUX
     18#define UINT64_FORMAT "%llu" //we want to avoid this and ambiguous "long long", but gcc does not seem to support I64u (yet?)
     19#else
     20#define UINT64_FORMAT "%I64u"
     21#endif
    1722
    1823struct Convert
  • cpp/frams/util/sstringutils.cpp

    r529 r691  
    77#include <common/log.h>
    88#include <common/nonstd.h>
     9#include <common/Convert.h>
    910
    1011int loadSString(const char* filename, SString& s, const char* framsgmodule, const char* error, bool remove_cr)
     
    1920        }
    2021        else if (framsgmodule)
    21                 logPrintf(framsgmodule, "loadSString", LOG_WARN, error ? error : "can't open file \"%s\"", filename);
     22                logPrintf(framsgmodule, "loadSString", LOG_WARN, error ? error : "Can't open file \"%s\"", filename);
    2223        return ret;
    2324}
     
    323324}
    324325
     326SString getUIDString(uint64_t uid, char prefix)
     327{
     328        return SString::sprintf("%c" UINT64_FORMAT, prefix, uid);
     329}
     330
     331bool parseUIDString(const char* str, char prefix, uint64_t &uid, bool err)
     332{
     333        if ((str[0] == prefix) && (isdigit(str[1])))
     334        {
     335                char* end;
     336                uid = strtoull(str + 1, &end, 10);
     337                if (end == (str + 1 + strlen(str + 1)))
     338                        return true;
     339        }
     340        if (err)
     341                logPrintf("SString", "parseUIDString", LOG_ERROR, "Invalid uid: '%s'", str);
     342        return false;
     343}
  • cpp/frams/util/sstringutils.h

    r529 r691  
    1010
    1111/// return: 1=ok 0=error
    12 int loadSString(const char* filename, SString& s, const char* framsgmodule = 0, const char* error = 0, bool remove_cr=true);
    13 void loadSString(VirtFILE *f, SString& s, bool remove_cr=true);
     12int loadSString(const char* filename, SString& s, const char* framsgmodule = 0, const char* error = 0, bool remove_cr = true);
     13void loadSString(VirtFILE *f, SString& s, bool remove_cr = true);
    1414bool loadSStringLine(VirtFILE* f, SString &s);
    1515
     
    3030bool matchWildcard(const SString& word, const SString& pattern);///< '*' in pattern matches any substring
    3131bool matchWildcardList(const SString& word, const SString& patterns);///< patterns is a list of patterns (separated by ',')
     32SString getUIDString(uint64_t uid, char prefix);
     33bool parseUIDString(const char* str, char prefix, uint64_t &uid, bool err);
    3234
    3335#endif
Note: See TracChangeset for help on using the changeset viewer.