/* ---- This file is part of SECONDO. Copyright (C) 2004, University in Hagen, Department of Computer Science, Database Systems for New Applications. SECONDO 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 2 of the License, or (at your option) any later version. SECONDO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SECONDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ---- April 2006, M. Spiekermann. The file Algebra.h need to be divided into Operators.h. TypeConstructors.h, AlgebraClassDef.h and AlgebraInit.h */ #ifndef SEC_OPERATOR_H #define SEC_OPERATOR_H #include #include #include #include "NestedList.h" #include "NList.h" #include "AlgebraTypes.h" #include "CostEstimation.h" //extern NestedList* nl; /* 1 Class ~Operator~ An operator instance consists of * a name * at least one value mapping function, sometimes called evaluation function * a type Mapping function, returned the operator's result type with respect to input parameters type * a selection function calculating the index of a value mapping function with respect to input parameter types * a boolean telling whether this operator supports progress queries, default is false. * a boolean indicating whether this operator does not want automatic evaluation of its arguments (example: ifthenelse operator), default is false. * a boolean indicating whether this operator needs arguments to be passed to type mapping functions, default is false. * a boolean indicating whether this operator uses (large) main memory buffers, default is false. All properties of operators are set in the constructor. Only the value mapping functions have to be registered later on since their number is arbitrary. This number is set in the constructor (~noF~). */ struct OperatorInfo { std::string name; std::string signature; std::string syntax; std::string meaning; std::string example; std::string remark; bool supportsProgress; bool requestsArgs; bool usesArgsInTypeMapping; bool usesMemory; bool supportsInitFinish; OperatorInfo() : name(""), signature(""), syntax(""), meaning(""), example(""), remark(""), supportsProgress(false), requestsArgs(false), usesArgsInTypeMapping(false), usesMemory(false), supportsInitFinish(false) {} OperatorInfo(const OperatorInfo& o) : name(o.name), signature(o.signature), syntax(o.syntax), meaning(o.meaning), example(o.example), remark(o.remark), supportsProgress(o.supportsProgress), requestsArgs(o.requestsArgs), usesArgsInTypeMapping(o.usesArgsInTypeMapping), usesMemory(o.usesMemory), supportsInitFinish(o.supportsInitFinish) {} OperatorInfo( const std::string& _name, const std::string& _signature, const std::string& _syntax, const std::string& _meaning, const std::string& _example ) { name = _name; signature = _signature; syntax = _syntax; meaning = _meaning; example = _example; remark=""; supportsProgress = false; requestsArgs = false; usesArgsInTypeMapping = false; usesMemory = false; supportsInitFinish = false; } OperatorInfo( const std::string& opName, const std::string& specStr); ~OperatorInfo(){ name.clear(); signature.clear(); syntax.clear(); meaning.clear(); example.clear(); remark.clear(); } std::string str() const; ListExpr list() const; void appendSignature(const std::string& sig); std::ostream& Print(std::ostream& o) const{ o << "OperatorInfo[ " << name << ", " << signature <<", " << syntax << ", " << meaning << ", " << example << ", " << remark << ", " << "supportsProgress = " << supportsProgress << ", " << "requestsArgs = " << requestsArgs << ", " << "usesArgsInTypeMapping = " << usesArgsInTypeMapping << ", " << "usesMemory = " << usesMemory << "," << "supportsInitFinisg = " << supportsInitFinish << "]"; return o; } }; std::ostream& operator<<(std::ostream& o, const OperatorInfo& oi); class OperatorSpec{ public: OperatorSpec ( const std::string& _signature, const std::string& _syntax, const std::string& _meaning, const std::string& _example, const std::string& _remark = ""): signature(_signature), syntax(_syntax), meaning(_meaning), example(_example), remark(_remark) {} static std::string getListString( const std::string& _signature, const std::string& _syntax, const std::string& _meaning, const std::string _example, const std::string& _remark = "") { std::stringstream ss; ss << "( ( " << "\"Signature\"" << "\"Syntax\"" << "\"Meaning\"" << "\"Example\""; if(_remark.length()==0){ ss << "\"Comment\""; } ss << ")" << endl; ss << "("; ss << "" << _signature << "" << endl; ss << "" << _syntax << "" << endl; ss << "" << _meaning << "" << endl; ss << "" << _example << "" << endl; if(_remark.length() == 0){ ss << "" << _remark << "" << endl; } ss << "))"; return ss.str(); } std::string getStr(){ return getListString(signature,syntax,meaning,example,remark); } ~OperatorSpec() { signature.clear(); syntax.clear(); meaning.clear(); example.clear(); remark.clear(); } private: std::string signature; std::string syntax; std::string meaning; std::string example; std::string remark; }; class Operator { public: Operator( const std::string& nm, const std::string& spec, const int noF, ValueMapping vms[], SelectFunction sf, TypeMapping tm, CreateCostEstimation* createCE = 0 ); /* Constructs an operator with ~noF~ overloaded evaluation functions. */ Operator( const std::string& nm, const std::string& spec, ValueMapping vm, SelectFunction sf, TypeMapping tm, CreateCostEstimation createCE = 0 ); /* Constructs an operator with *one* evaluation functions. */ Operator( const OperatorInfo& oi, ValueMapping vm, TypeMapping tm, CreateCostEstimation createCE = 0 ); Operator( const OperatorInfo& oi, ValueMapping vms[], SelectFunction sf, TypeMapping tm, CreateCostEstimation* createCE = 0 ); /* Versions using ~OperatorInfo~. */ virtual ~Operator() { if(valueMap){ delete[] valueMap; } if(calls){ delete[] calls; } if(createCostEstimation){ delete[] createCostEstimation; } if(costEstimation){ for(int i=0;i=0 && index < numOfFunctions); calls[index]++; } /* Increments the number of calls; */ int GetCalls(){ int sum = 0; for(int i=0;i