Value.cpp 1.98 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
// ------------------------------------------------------------------------
// $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"
20

gsell's avatar
gsell committed
21
#include "Attributes/Attributes.h"
22 23 24 25
#include "Parser/Statement.h"
#include "Utility/Inform.h"

#include <string>
gsell's avatar
gsell committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
#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");
40 41

    registerOwnership(AttributeHandler::STATEMENT);
gsell's avatar
gsell committed
42 43 44
}


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


Value::~Value()
{}


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


void Value::execute() {
snuverink_j's avatar
snuverink_j committed
60
    *gmsg << "\nvalue: " << itsAttr[0] << " = {";
gsell's avatar
gsell committed
61 62 63 64 65 66 67
    //  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
68
        *gmsg << ", ";
gsell's avatar
gsell committed
69 70 71 72 73 74 75
    }

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

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