00001
00002 #include "FWCore/ParameterSet/interface/OperatorNode.h"
00003 #include "FWCore/ParameterSet/interface/OperandNode.h"
00004 #include "FWCore/ParameterSet/interface/Visitor.h"
00005 #include "FWCore/Utilities/interface/EDMException.h"
00006
00007 #include <iosfwd>
00008
00009 namespace edm {
00010
00011 namespace pset {
00012
00013
00014
00015
00016 std::string makeOpName()
00017 {
00018 static int opcount = 0;
00019 std::ostringstream ost;
00020 ++opcount;
00021 ost << "op" << opcount;
00022 return ost.str();
00023 }
00024
00025 bool operator_or_operand(NodePtr n)
00026 {
00027 Node* p = n.operator->();
00028 return
00029 ( dynamic_cast<OperatorNode*>(p) != 0 ||
00030 dynamic_cast<OperandNode*>(p) != 0 );
00031 }
00032
00033
00034
00035
00036
00037 OperatorNode::OperatorNode(const std::string& type,
00038 NodePtr left,
00039 NodePtr right,
00040 int line):
00041 Node(makeOpName(), line),
00042 type_(type),
00043 left_(left),
00044 right_(right)
00045 {
00046 assert( operator_or_operand(left) );
00047 assert( operator_or_operand(right) );
00048 left_->setParent(this);
00049 right_->setParent(this);
00050 }
00051
00052 std::string OperatorNode::type() const { return type_; }
00053
00054
00055 Node * OperatorNode::clone() const
00056 {
00057 OperatorNode * newNode = new OperatorNode(*this);
00058 newNode->left_ = NodePtr( left_->clone() );
00059 newNode->right_ = NodePtr( right_->clone() );
00060 newNode->left_->setParent(newNode);
00061 newNode->right_->setParent(newNode);
00062 return newNode;
00063 }
00064
00065
00066 void OperatorNode::print(std::ostream& ost, Node::PrintOptions options) const
00067 {
00068 ost << "( " << left_ << " " << type_ << " " << right_ << " )";
00069 }
00070
00071
00072 bool OperatorNode::findChild(const std::string & childName, NodePtr & result)
00073 {
00074 bool foundLeft = left()->findChild(childName, result);
00075 bool foundRight = right()->findChild(childName, result);
00076
00077 if(foundLeft && foundRight)
00078 {
00079 throw edm::Exception(errors::Configuration)
00080 << "A child named " << childName
00081 << " was found on both sides of an operator"
00082 << "\nfrom " << traceback();
00083 }
00084 return (foundLeft || foundRight);
00085 }
00086
00087
00088 void OperatorNode::accept(Visitor& v) const
00089 {
00090 v.visitOperator(*this);
00091
00092 }
00093
00094 }
00095 }