BoolConstant.cpp 1.69 KB
Newer Older
gsell's avatar
gsell committed
1
//
2 3
// Class BoolConstant
//   The BOOL CONSTANT definition.
gsell's avatar
gsell committed
4
//
5 6
// Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
gsell's avatar
gsell committed
7
//
8 9 10 11 12 13 14 15 16
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
gsell's avatar
gsell committed
17 18
//
#include "ValueDefinitions/BoolConstant.h"
19

gsell's avatar
gsell committed
20 21 22
#include "Attributes/Attributes.h"
#include "Utilities/Options.h"

23
#include <iostream>
gsell's avatar
gsell committed
24 25 26 27 28 29 30 31


BoolConstant::BoolConstant():
    ValueDefinition(1, "BOOL_CONSTANT",
                    "The \"BOOL CONSTANT\" statement defines a global "
                    "logical constant:\n"
                    "\tBOOL CONSTANT <name> = <Bool-expression>;\n") {
    itsAttr[0] = Attributes::makeBool("VALUE", "The constant value");
32 33

    registerOwnership(AttributeHandler::STATEMENT);
gsell's avatar
gsell committed
34 35 36
}


37
BoolConstant::BoolConstant(const std::string &name, BoolConstant *parent):
gsell's avatar
gsell committed
38 39 40 41 42 43 44 45 46 47 48 49 50
    ValueDefinition(name, parent)
{}


BoolConstant::~BoolConstant()
{}


bool BoolConstant::canReplaceBy(Object *) {
    return false;
}


51
BoolConstant *BoolConstant::clone(const std::string &name) {
gsell's avatar
gsell committed
52 53 54 55 56 57 58 59 60 61 62 63 64
    return new BoolConstant(name, this);
}


bool BoolConstant::getBool() const {
    return Attributes::getBool(itsAttr[0]);
}


void BoolConstant::print(std::ostream &os) const {
    os << "BOOL CONST " << getOpalName() << '=' << itsAttr[0] << ';';
    os << std::endl;
}
65 66 67

void BoolConstant::printValue(std::ostream &os) const {
    os << itsAttr[0];
68
}