Exemple #1
0
            // Read a natural 
            Natural natural(
                Optizelle::Messaging const & msg,
                Json::Value const & json,
                std::string const & name
            ) {
                // Set the error message
                std::string const err_msg = "Invalid JSON parameter: "
                    + name + " contains an invalid natural.";

                // As long as we have an unsigned integer, grab it
                if(json.isUInt())
                    return Natural(Json::Value::UInt64(json.asUInt64()));
                
                // If we have an integer, grab it if it's positive
                else if(json.isInt()) {
                    Integer val(json.asInt64());
                    if(val>=0)
                        return Natural(val);
                    else
                        msg.error(err_msg);

                // Anything else is an error
                } else
                    msg.error(err_msg);

                // We should not hit this point
                throw;
            }
void StrBrowserGraphic::draw (Canvas* c, Graphic* gs) {
    Coord xmax, ymax;
    CanvasVar* cvar = GetCanvasVar();

    if (cvar == nil) {
        Natural(xmax, ymax);
    } else {
        xmax = cvar->xmax();
        ymax = cvar->ymax();
    }
    update(gs);

    static Brush* b;
    if (b == nil) {
        b = new Brush(0xbbbb, 1);
        Ref(b);
    }

    _p->SetBrush(b);
    _p->ClearRect(c, 0, 0, xmax, ymax);
    _p->Rect(c, 0, 0, xmax, ymax);
    _p->Line(c, 0, 0, xmax, ymax);
    _p->Line(c, 0, ymax, xmax, 0);

    const Font* font = _p->GetFont();
    const char* text = GetText();
    int w = font->Width(text);
    int h = font->Height();
    _p->Text(c, text, (xmax+1-w)/2, (ymax+1-h)/2);
}
Exemple #3
0
 Natural operator<<(int sh) const {
     int n=sh+ndigs;
     int d[n];
     REP(i,sh) d[i]=0;
     REP(i,ndigs) d[i+sh]=digs[i];
     return Natural(n,d);
 }
Exemple #4
0
Natural::operator bool() const {
    if (*this == Natural(0))
        return false;
    return true;
}