00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #ifndef FUNCTIONTEMPLATE_JUN_22_2005
00067 #define FUNCTIONTEMPLATE_JUN_22_2005
00068
00069 #include "predicatetemplate.h"
00070
00071 class FunctionTemplate : public PredicateTemplate
00072 {
00073 public:
00074 static const char* EMPTY_FTEMPLATE_NAME;
00075 public:
00076 FunctionTemplate() : PredicateTemplate(), retTypeId_(-1),retTypeName_(NULL) {}
00077 virtual ~FunctionTemplate() { delete [] retTypeName_; }
00078
00079
00080
00081 void setRetTypeId(const int& id, const Domain* const & domain);
00082
00083
00084
00085 void setRetTypeName(const char* const & name, const Domain* const & domain);
00086
00087
00088 int getRetTypeId() const { return retTypeId_; }
00089
00090
00091 const char* getRetTypeName() const { return retTypeName_; }
00092
00093
00094 static string createInternalFuncTypeName(const char* const & funcName,
00095 const Array<string>& typeNames)
00096 {
00097 string ftName;
00098 ftName.append(funcName);
00099 for (int i = 0; i < typeNames.size(); i++)
00100 {
00101 ftName.append("_").append(typeNames[i]);
00102 }
00103 return ftName;
00104 }
00105
00106 static bool isInternalFunctionTemplateName(const char* funcName)
00107 {
00108 return (strncmp(funcName, SUCC_NAME, strlen(SUCC_NAME)) == 0 ||
00109 strncmp(funcName, PLUS_NAME, strlen(PLUS_NAME)) == 0 ||
00110 strncmp(funcName, MINUS_NAME, strlen(MINUS_NAME)) == 0 ||
00111 strncmp(funcName, TIMES_NAME, strlen(TIMES_NAME)) == 0 ||
00112 strncmp(funcName, DIVIDEDBY_NAME, strlen(DIVIDEDBY_NAME)) == 0 ||
00113 strncmp(funcName, MOD_NAME, strlen(MOD_NAME)) == 0 ||
00114 strncmp(funcName, CONCAT_NAME, strlen(CONCAT_NAME)) == 0);
00115 }
00116
00117 static bool isInternalFunctionUnaryTemplateName(const char* funcName)
00118 {
00119 return (strncmp(funcName, SUCC_NAME, strlen(SUCC_NAME)) == 0);
00120 }
00121
00122
00123 bool isInternalFunctionTemplate() const
00124 {
00125 return (strncmp(name_, SUCC_NAME, strlen(SUCC_NAME)) == 0 ||
00126 strncmp(name_, PLUS_NAME, strlen(PLUS_NAME)) == 0 ||
00127 strncmp(name_, MINUS_NAME, strlen(MINUS_NAME)) == 0 ||
00128 strncmp(name_, TIMES_NAME, strlen(TIMES_NAME)) == 0 ||
00129 strncmp(name_, DIVIDEDBY_NAME, strlen(DIVIDEDBY_NAME)) == 0 ||
00130 strncmp(name_, MOD_NAME, strlen(MOD_NAME)) == 0 ||
00131 strncmp(name_, CONCAT_NAME, strlen(CONCAT_NAME)) == 0);
00132 }
00133
00134 ostream& print(ostream& out) const
00135 {
00136 out << retTypeName_ << " ";
00137 out << name_ << "(";
00138 for (int i = 0; i < termTypesAsStr_->size(); i++)
00139 {
00140 out << (*termTypesAsStr_)[i];
00141 out << ((i!=termTypesAsStr_->size()-1)?",":")");
00142 }
00143 return out;
00144 }
00145
00146
00147 ostream& printWithStrVar(ostream& out) const
00148 {
00149 out << retTypeName_ << " ";
00150 out << name_ << "(";
00151 for (int i = 0; i < termTypesAsStr_->size(); i++)
00152 {
00153 out << "a" << i+1;
00154 out << ((i!=termTypesAsStr_->size()-1)?",":")");
00155 }
00156 return out;
00157 }
00158
00159
00160 private:
00161 int retTypeId_;
00162 char* retTypeName_;
00163 };
00164
00165 #endif