Changeset 375 for cpp/frams/util


Ignore:
Timestamp:
04/26/15 00:59:09 (9 years ago)
Author:
Maciej Komosinski
Message:

Renamed logging functions to more intuitive and simple names

Location:
cpp/frams/util
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/3d.cpp

    r372 r375  
    44
    55#include <common/nonstd_math.h>
    6 #include <common/hmessage.h>
     6#include <common/log.h>
    77#include "3d.h"
    88
     
    1717{
    1818        double q = x*x + y*y + z*z;
    19         if (q < 0) { if (report_errors) Hprintf("Pt3D", "operator()", HMLV_ERROR, "sqrt(%g): domain error", q); return 0; }
     19        if (q < 0) { if (report_errors) logPrintf("Pt3D", "operator()", LOG_ERROR, "sqrt(%g): domain error", q); return 0; }
    2020        return sqrt(q);
    2121}
     
    2424{
    2525        double len = length();
    26         if (fabs(len) < 1e-50) { if (report_errors) Hprintf("Pt3D", "normalize()", HMLV_WARN, "vector[%g,%g,%g] too small", x, y, z); x = 1; y = 0; z = 0; return false; }
     26        if (fabs(len) < 1e-50) { if (report_errors) logPrintf("Pt3D", "normalize()", LOG_WARN, "vector[%g,%g,%g] too small", x, y, z); x = 1; y = 0; z = 0; return false; }
    2727        operator/=(len);
    2828        return true;
     
    6464        if (dx == 0 && dy == 0)
    6565        {
    66                 if (report_errors) Hprintf("Pt3D", "getAngle()", HMLV_WARN, "atan2(%g,%g)", dy, dx);
     66                if (report_errors) logPrintf("Pt3D", "getAngle()", LOG_WARN, "atan2(%g,%g)", dy, dx);
    6767                return 0; // incorrect result, but there is no correct one
    6868        }
     
    147147{
    148148        double q = x*x + y*y;
    149         if (q < 0) { if (Pt3D::report_errors) Hprintf("", "d2()", HMLV_ERROR, "sqrt(%g): domain error", q); return 0; }
     149        if (q < 0) { if (Pt3D::report_errors) logPrintf("", "d2()", LOG_ERROR, "sqrt(%g): domain error", q); return 0; }
    150150        return sqrt(q);
    151151}
  • cpp/frams/util/extvalue.cpp

    r372 r375  
    9898        if (warn)
    9999        {
    100                 Hprintf("ExtValue", "getObjectTarget", HMLV_WARN, "%s object expected, %s found", classname, interfaceName());
     100                logPrintf("ExtValue", "getObjectTarget", LOG_WARN, "%s object expected, %s found", classname, interfaceName());
    101101        }
    102102
     
    269269                        if (tmp.len() > 30) tmp = tmp.substr(0, 30) + "...";
    270270                        if (type == TString) tmp = SString("\"") + tmp + SString("\"");
    271                         Hprintf("ExtValue", "getObjectTarget", HMLV_WARN, "%s object expected, %s found", classname, tmp.c_str());
     271                        logPrintf("ExtValue", "getObjectTarget", LOG_WARN, "%s object expected, %s found", classname, tmp.c_str());
    272272                }
    273273                return NULL;
     
    419419                                context->v2->typeAndValue().c_str());
    420420                }
    421                 Hprintf("ExtValue", "interpretCompare", HMLV_ERROR, "%s", msg.c_str());
     421                logPrintf("ExtValue", "interpretCompare", LOG_ERROR, "%s", msg.c_str());
    422422                ret = -1;
    423423        }
     
    448448                {
    449449                case TDouble:
    450                         Hprintf("ExtValue", "add", HMLV_WARN, "Adding %s to %s", src.typeAndValue().c_str(), typeAndValue().c_str());
     450                        logPrintf("ExtValue", "add", LOG_WARN, "Adding %s to %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    451451                        setDouble(double(getInt()) + src.getDouble());
    452452                        return;
     
    487487        default:;
    488488        }
    489         Hprintf("ExtValue", "add", HMLV_ERROR, "Can't add %s to %s", src.typeAndValue().c_str(), typeAndValue().c_str());
     489        logPrintf("ExtValue", "add", LOG_ERROR, "Can't add %s to %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    490490}
    491491
     
    502502                        return;
    503503                case TDouble:
    504                         Hprintf("ExtValue", "subtract", HMLV_WARN, "Subtracting %s from %s", src.typeAndValue().c_str(), typeAndValue().c_str());
     504                        logPrintf("ExtValue", "subtract", LOG_WARN, "Subtracting %s from %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    505505                        setDouble(double(getInt()) - src.getDouble());
    506506                        return;
     
    520520        default:;
    521521        }
    522         Hprintf("ExtValue", "subtract", HMLV_ERROR, "Can't subtract %s from %s", src.typeAndValue().c_str(), typeAndValue().c_str());
     522        logPrintf("ExtValue", "subtract", LOG_ERROR, "Can't subtract %s from %s", src.typeAndValue().c_str(), typeAndValue().c_str());
    523523}
    524524
     
    535535                        return;
    536536                case TDouble:
    537                         Hprintf("ExtValue", "multiply", HMLV_WARN, "Multiplying %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
     537                        logPrintf("ExtValue", "multiply", LOG_WARN, "Multiplying %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    538538                        setDouble(double(getInt())*src.getDouble());
    539539                        return;
     
    591591        default:;
    592592        }
    593         Hprintf("ExtValue", "multiply", HMLV_WARN, "Can't multiply %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
     593        logPrintf("ExtValue", "multiply", LOG_WARN, "Can't multiply %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    594594}
    595595
     
    611611        else
    612612        {
    613                 Hprintf("ExtValue", "divide", HMLV_CRITICAL, "Division by zero: %d/0", idata());
     613                logPrintf("ExtValue", "divide", LOG_CRITICAL, "Division by zero: %d/0", idata());
    614614                setInvalid();
    615615        }
     
    620620        if (a == 0.0)
    621621        {
    622                 Hprintf("ExtValue", "divide", HMLV_CRITICAL, "Division by zero: %s/0.0", getString().c_str());
     622                logPrintf("ExtValue", "divide", LOG_CRITICAL, "Division by zero: %s/0.0", getString().c_str());
    623623                setInvalid();
    624624        }
     
    629629                if (!finite(tmp))
    630630                {
    631                         Hprintf("ExtValue", "divide", HMLV_CRITICAL, "Overflow %s/%g", getString().c_str(), a); setInvalid();
     631                        logPrintf("ExtValue", "divide", LOG_CRITICAL, "Overflow %s/%g", getString().c_str(), a); setInvalid();
    632632                }
    633633                else
     
    635635                // niby dobrze ale lepiej byloby to robic bardziej systematycznie a nie tylko w dzieleniu?
    636636                //if (isnan(ddata())) //http://www.digitalmars.com/d/archives/c++/Traping_divide_by_zero_5728.html
    637                 //        { Hprintf("ExtValue","divide",HMLV_ERROR,"not-a-number",(const char*)getString()); setInvalid(); }
     637                //        { logPrintf("ExtValue","divide",LOG_ERROR,"not-a-number",(const char*)getString()); setInvalid(); }
    638638                fpExceptEnable();
    639639        }
     
    651651                        return;
    652652                case TDouble:
    653                         Hprintf("ExtValue", "divide", HMLV_WARN, "Dividing %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
     653                        logPrintf("ExtValue", "divide", LOG_WARN, "Dividing %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    654654                        divDouble(src.ddata());
    655655                        return;
     
    673673        default:;
    674674        }
    675         Hprintf("ExtValue", "divide", HMLV_ERROR, "Can't divide %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
     675        logPrintf("ExtValue", "divide", LOG_ERROR, "Can't divide %s by %s", typeAndValue().c_str(), src.typeAndValue().c_str());
    676676}
    677677
     
    778778
    779779        case TObj: case TUnknown: case TInvalid:
    780                 Hprintf("ExtValue", "modulo", HMLV_WARN, "Can't apply modulo to %s", typeDescription().c_str());
     780                logPrintf("ExtValue", "modulo", LOG_WARN, "Can't apply modulo to %s", typeDescription().c_str());
    781781
    782782        default:;
     
    791791        {
    792792                if (error)
    793                         Hprintf("ExtValue", "parseInt", HMLV_ERROR, "Could not parse '%s'%s", s, strict ? " (strict)" : "");
     793                        logPrintf("ExtValue", "parseInt", LOG_ERROR, "Could not parse '%s'%s", s, strict ? " (strict)" : "");
    794794                return false;
    795795        }
     
    805805        {
    806806                if (error)
    807                         Hprintf("ExtValue", "parseDouble", HMLV_ERROR, "Could not parse '%s'", s);
     807                        logPrintf("ExtValue", "parseDouble", LOG_ERROR, "Could not parse '%s'", s);
    808808                return false;
    809809        }
     
    836836        case TString: return getInt(sdata().c_str());
    837837        case TObj:
    838                 Hprintf("ExtValue", "getInt", HMLV_WARN, "Getting integer value from object reference (%s)", getString().c_str());
     838                logPrintf("ExtValue", "getInt", LOG_WARN, "Getting integer value from object reference (%s)", getString().c_str());
    839839                return (paInt)(intptr_t)odata().param;
    840840        default:;
     
    851851        case TString: return getDouble(sdata().c_str());
    852852        case TObj:
    853                 Hprintf("ExtValue", "getDouble", HMLV_WARN, "Getting floating point value from object reference (%s)", getString().c_str());
     853                logPrintf("ExtValue", "getDouble", LOG_WARN, "Getting floating point value from object reference (%s)", getString().c_str());
    854854                return (double)(intptr_t)odata().param;
    855855        default:;
     
    989989                else
    990990                {
    991                         Hprintf("ExtValue", "deserialize", HMLV_ERROR, "Missing '\"' in string: '%s'", ret);
     991                        logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing '\"' in string: '%s'", ret);
    992992                        return NULL;
    993993                }
     
    10111011                                else if (*p != ']')
    10121012                                {
    1013                                         Hprintf("ExtValue", "deserialize", HMLV_ERROR, "Missing ',' in Vector: '%s'", p);
     1013                                        logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ',' in Vector: '%s'", p);
    10141014                                        return NULL;
    10151015                                }
     
    10371037                        if ((!ret) || (args[1].getType() != TString)) { p = NULL; break; }
    10381038                        p = ret;
    1039                         if (*p != ':') { Hprintf("ExtValue", "deserialize", HMLV_ERROR, "Missing ':' in Dictionary: '%s'", p); p = NULL; break; }
     1039                        if (*p != ':') { logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ':' in Dictionary: '%s'", p); p = NULL; break; }
    10401040                        p++;
    10411041                        ret = args[0].deserialize(p);
     
    10461046                        else if (*p != '}')
    10471047                        {
    1048                                 Hprintf("ExtValue", "deserialize", HMLV_ERROR, "Missing ',' in Dictionary: '%s'", p);
     1048                                logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing ',' in Dictionary: '%s'", p);
    10491049                                return NULL;
    10501050                        }
     
    10861086                        }
    10871087                }
    1088                 Hprintf("ExtValue", "deserialize", HMLV_ERROR, "Invalid reference: '%s'", in - 1);
     1088                logPrintf("ExtValue", "deserialize", LOG_ERROR, "Invalid reference: '%s'", in - 1);
    10891089                return NULL;
    10901090        }
     
    11331133                }
    11341134                setEmpty();
    1135                 Hprintf("ExtValue", "deserialize", HMLV_WARN, "object of class \"%s\" could not be deserialized", clsname.c_str());
     1135                logPrintf("ExtValue", "deserialize", LOG_WARN, "object of class \"%s\" could not be deserialized", clsname.c_str());
    11361136                return ret;
    11371137        }
    1138         Hprintf("ExtValue", "deserialize", HMLV_ERROR, "Bad syntax: '%s'", in);
     1138        logPrintf("ExtValue", "deserialize", LOG_ERROR, "Bad syntax: '%s'", in);
    11391139        setEmpty();
    11401140        return NULL;
  • cpp/frams/util/sstringutils.cpp

    r372 r375  
    55#include "sstringutils.h"
    66#include <frams/virtfile/virtfile.h>
    7 #include <common/hmessage.h>
     7#include <common/log.h>
    88#include <common/nonstd.h>
    99
     
    1919        }
    2020        else if (framsgmodule)
    21                 Hprintf(framsgmodule, "loadSString", HMLV_WARN, error ? error : "can't open file \"%s\"", filename);
     21                logPrintf(framsgmodule, "loadSString", LOG_WARN, error ? error : "can't open file \"%s\"", filename);
    2222        return ret;
    2323}
  • cpp/frams/util/validitychecks.cpp

    r374 r375  
    33// See LICENSE.txt for details.
    44
    5 #include "stderrors.h"
     5#include "validitychecks.h"
    66#include <frams/util/sstringutils.h>
    7 #include <common/hmessage.h>
     7#include <common/log.h>
    88
    99bool listIndexCheck(SList* list,int index,const char* msgobj,const char* msgfun)
     
    1313        {
    1414        if (size>0)
    15                 Hprintf(msgobj,msgfun,HMLV_ERROR,"Invalid index %d (allowed range is 0..%d)",index,size-1);
     15                logPrintf(msgobj,msgfun,LOG_ERROR,"Invalid index %d (allowed range is 0..%d)",index,size-1);
    1616        else
    17                 Hprintf(msgobj,msgfun,HMLV_ERROR,"Invalid index %d (this list is empty)",index);
     17                logPrintf(msgobj,msgfun,LOG_ERROR,"Invalid index %d (this list is empty)",index);
    1818        return 0;
    1919        }
     
    2929        {
    3030        SString msg2=SString(msg)+": \"%s\" (adjusted to \"%s\")";
    31         Hprintf(msgobj,msgfun,HMLV_WARN,msg2.c_str(),in.c_str(),corrected.c_str());
     31        logPrintf(msgobj,msgfun,LOG_WARN,msg2.c_str(),in.c_str(),corrected.c_str());
    3232        }
    3333return corrected;
  • cpp/frams/util/validitychecks.h

    r372 r375  
    33// See LICENSE.txt for details.
    44
    5 #ifndef _STDERRORS_H_
    6 #define _STDERRORS_H_
     5#ifndef _VALIDITY_CHECKS_H_
     6#define _VALIDITY_CHECKS_H_
    77
    88#include <frams/util/list.h>
     
    1010
    1111bool listIndexCheck(SList* list,int index,const char* msgobj,const char* msgfun);
    12 SString stringCheck(SString& in,const char* msgobj,const char* msgfun,const char* msg,SString (*checker)(SString& in)=0);
     12SString stringCheck(SString& in,const char* msgobj,const char* msgfun,const char* msg,SString (*checker)(SString& in)=NULL);
    1313
    1414#endif
Note: See TracChangeset for help on using the changeset viewer.