Changeset 1005


Ignore:
Timestamp:
07/14/20 15:54:43 (3 weeks ago)
Author:
Maciej Komosinski
Message:

Higher conformance with C++17, but gave up after missing M_PI, M_PI_2, strdup() and more; other cosmetic improvements

Location:
cpp
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/Convert.cpp

    r400 r1005  
    44
    55#include "Convert.h"
    6 
    76#include <sstream>
    87
     
    9190        struct tm ret;
    9291#if defined LINUX // || android?
    93         return *::localtime_r(&timep,&ret);
     92        return *::localtime_r(&timep, &ret);
    9493#elif defined _WIN32 && !defined __BORLANDC__
    9594        ::localtime_s(&ret, &timep);
     
    9796#else //borland?
    9897        pthread_mutex_lock(&fix_unsafe_mutex);
    99         ret=*::localtime(&timep);
     98        ret = *::localtime(&timep);
    10099        pthread_mutex_unlock(&fix_unsafe_mutex);
    101100        return ret;
     
    110109#ifndef MULTITHREADED
    111110
    112         ret=::asctime(&tm);
     111        ret = ::asctime(&tm);
    113112
    114113#else //MULTITHREADED
     
    116115        char buf[26];
    117116#if defined LINUX // || android?
    118         ret=::asctime_r(&tm,buf);
     117        ret = ::asctime_r(&tm, buf);
    119118#elif defined _WIN32 && !defined __BORLANDC__
    120119        asctime_s(buf, sizeof(buf), &tm);
     
    122121#else //borland?
    123122        pthread_mutex_lock(&fix_unsafe_mutex);
    124         strcpy(buf,::asctime(&tm));
    125         ret=buf;
     123        strcpy(buf, ::asctime(&tm));
     124        ret = buf;
    126125        pthread_mutex_unlock(&fix_unsafe_mutex);
    127126#endif
  • cpp/common/Convert.h

    r913 r1005  
    1111#include "2d.h"
    1212#include <stdint.h>
     13#include <cmath>
    1314
    1415
     
    3940        static uint32_t hexToInt(const string& col);
    4041
    41         static double toRadians(double angle) { return angle*M_PI / 180; }
     42        static double toRadians(double angle) { return angle * M_PI / 180; }
    4243        static double toDegrees(double angle) { return angle / M_PI * 180; }
    4344        static double atan_2(double y, double x) { if (x == 0 && y == 0) return 0; else return atan2(y, x); } //needed by borland 5/6 only?
     
    4647        {
    4748                double dx = x2 - x1, dy = y2 - y1;
    48                 return dx*dx + dy*dy;
     49                return dx * dx + dy * dy;
    4950        }
    5051        static double odleglosc_sq(const Pt2D& p1, const Pt2D& p2) //odleglosc do kwadratu
     
    5354        }
    5455
    55         static double odleglosc(double x1, double y1, double x2, double y2)     { return sqrt(odleglosc_sq(x1, y1, x2, y2)); }
     56        static double odleglosc(double x1, double y1, double x2, double y2) { return sqrt(odleglosc_sq(x1, y1, x2, y2)); }
    5657        static double odleglosc(const Pt2D& p1, const Pt2D& p2)
    5758        {
  • cpp/common/random.h

    r896 r1005  
    66
    77#ifdef _MSC_VER
    8  #define NOMINMAX //we don't want Windows headers (minwindef.h) to define min() and max() as macros
    9  #undef min //for some reason, NOMINMAX did not work so we have to #undef anyway
    10  #undef max
     8#define NOMINMAX //we don't want Windows headers (minwindef.h) to define min() and max() as macros
     9#undef min //for some reason, NOMINMAX did not work so we have to #undef anyway
     10#undef max
    1111#endif
    1212
     
    1414#include <stdint.h> //uintptr_t
    1515#ifdef MULTITHREADED
    16  #include "threads.h"
     16#include "threads.h"
    1717#endif
    1818#ifdef LINUX
    19  #include <unistd.h>
    20  #include <sys/stat.h>
    21  #include <fcntl.h>
     19#include <unistd.h>
     20#include <sys/stat.h>
     21#include <fcntl.h>
    2222#endif
    2323#ifdef _WIN32
    24  #define _WINSOCKAPI_ //http://stackoverflow.com/questions/1372480/c-redefinition-header-files
    25  #include <rpc.h> //UUID
    26  #pragma comment(lib, "Rpcrt4.lib")
     24#define _WINSOCKAPI_ //http://stackoverflow.com/questions/1372480/c-redefinition-header-files
     25#include <rpc.h> //UUID
     26#pragma comment(lib, "Rpcrt4.lib")
    2727#endif
    2828
     
    6363                mt[0] = seed;
    6464                for (unsigned int i = 1; i < length; i++)
    65                         mt[i] = (1812433253 * (mt[i - 1] ^ (mt[i - 1] >> 30)) + i)&bitMask_32;
     65                        mt[i] = (1812433253 * (mt[i - 1] ^ (mt[i - 1] >> 30)) + i) & bitMask_32;
    6666#ifdef MULTITHREADED
    6767                pthread_mutex_unlock(&lock);
     
    7474                //for ms visual, could use http://msdn.microsoft.com/en-us/library/sxtz2fa8.aspx
    7575#ifdef LINUX
    76                 int fd=open("/dev/urandom",O_RDONLY);
    77                 if (fd>=0)
     76                int fd = open("/dev/urandom", O_RDONLY);
     77                if (fd >= 0)
    7878                {
    79                         read(fd,&seed,sizeof(seed));
     79                        read(fd, &seed, sizeof(seed));
    8080                        close(fd);
    8181                }
     
    8484                {
    8585                        counter++;
    86                         seed = (unsigned int)time(NULL);                         //time (seconds); could use hi-res timer but then we would depend on common/timer.h
     86                        seed = (unsigned int)time(NULL);           //time (seconds); could use hi-res timer but then we would depend on common/timer.h
    8787                        seed ^= counter;                           //incremented value, possibly randomly initialized
    8888                        seed ^= (unsigned int)(uintptr_t)&counter; //memory address
     
    9191                UUID uuid;
    9292                ::UuidCreate(&uuid);
    93                 seed ^= uuid.Data1^uuid.Data2^uuid.Data3^uuid.Data4[0];
     93                seed ^= uuid.Data1 ^ uuid.Data2 ^ uuid.Data3 ^ uuid.Data4[0];
    9494#endif
    9595                setSeed(seed);
     
    117117        //UniformRandomBitGenerator
    118118        typedef unsigned int result_type;
    119         static constexpr unsigned int min() {return 0;}
    120         static constexpr unsigned int max() {return MAXVALUE;}
    121         inline unsigned int operator()() {return getUint32();}
     119        static constexpr unsigned int min() { return 0; }
     120        static constexpr unsigned int max() { return MAXVALUE; }
     121        inline unsigned int operator()() { return getUint32(); }
    122122
    123123        inline double getDouble() // [0,1)
  • cpp/frams/_demos/simil_test.cpp

    r1004 r1005  
    1919{
    2020        LoggerToStdout messages_to_stdout(LoggerBase::Enable);
    21         typedef double *pDouble;
    2221        int iCurrParam = 0; // index of the currently processed parameter
    2322        char *szCurrParam = NULL;
     
    172171        double **aaSimil = NULL; // array of similarities
    173172
    174         // create the empty array of similarities
    175         aaSimil = new pDouble[pvGenos.size()];
     173        // create an empty array of similarities
     174        aaSimil = new double*[pvGenos.size()];
    176175        for (unsigned int k = 0; k < pvGenos.size(); k++)
    177176        {
     
    181180        }
    182181
    183         // compute and remember similarities
     182        // compute and store similarities
    184183        for (unsigned int i = 0; i < pvGenos.size(); i++)
    185184        {
     
    193192        if (bPrintNames)
    194193        {
    195                 // if "-names" switch was given, print the number of genotypes and their names
     194                // if the "-names" switch was given, print the number of genotypes and their names
    196195                printf("%li\n", pvGenos.size());
    197196                for (unsigned int iGen = 0; iGen < pvNames.size(); iGen++)
  • cpp/frams/genetics/f9/f9_oper.cpp

    r974 r1005  
    66#include "f9_conv.h"
    77#include <common/nonstd.h> //rndUint, rndDouble
     8#include <string.h>
    89
    910
  • cpp/frams/param/paramobj.cpp

    r792 r1005  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#include <frams/util/extvalue.h>
    77#include <common/nonstd_stl.h>
    8 
     8       
    99static const char* maybedup(bool dup, const char* src)
    1010{
  • cpp/frams/util/extvalue.cpp

    r973 r1005  
    705705                fpExceptDisable();
    706706                double tmp = getDouble() / a;
    707                 if (!finite(tmp))
     707                if (!std::isfinite(tmp))
    708708                {
    709709                        logPrintf("ExtValue", "divide", LOG_ERROR, "Overflow %s/%g", getString().c_str(), a); setInvalid();
Note: See TracChangeset for help on using the changeset viewer.