Value.cpp 1.94 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
// ------------------------------------------------------------------------
// $RCSfile: Value.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: Value
//   The class for the OPAL VALUE command.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:37 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------

#include "BasicActions/Value.h"
#include "Attributes/Attributes.h"
#include <iomanip>
#include <iostream>
#include <vector>


// Class Value
// ------------------------------------------------------------------------

extern Inform *gmsg;

Value::Value():
    Action(1, "VALUE",
           "The \"VALUE\" statement prints a list of expressions and "
           "their values.") {
    itsAttr[0] = Attributes::makeRealArray
                 ("VALUE", "The values to be evaluated");
37 38

    registerOwnership(AttributeHandler::STATEMENT);
gsell's avatar
gsell committed
39 40 41
}


42
Value::Value(const std::string &name, Value *parent):
gsell's avatar
gsell committed
43 44 45 46 47 48 49 50
    Action(name, parent)
{}


Value::~Value()
{}


51
Value *Value::clone(const std::string &name) {
gsell's avatar
gsell committed
52 53 54 55 56
    return new Value(name, this);
}


void Value::execute() {
snuverink_j's avatar
snuverink_j committed
57
    *gmsg << "\nvalue: " << itsAttr[0] << " = {";
gsell's avatar
gsell committed
58 59 60 61 62 63 64
    //  std::streamsize old_prec = *gmsg.precision(12);
    const std::vector<double> array = Attributes::getRealArray(itsAttr[0]);
    std::vector<double>::const_iterator i = array.begin();

    while(i != array.end()) {
        *gmsg << *i++;
        if(i == array.end()) break;
snuverink_j's avatar
snuverink_j committed
65
        *gmsg << ", ";
gsell's avatar
gsell committed
66 67 68 69 70 71 72
    }

    *gmsg << "}\n" << endl;
    //  *gmsg.precision(old_prec);
}

void Value::parse(Statement &statement) {
73 74
    // parse, but don't evaluate (for printing mainly)
    parseShortcut(statement, false);
75
}