00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef __CLASSAD_FN_CALL_H__
00022 #define __CLASSAD_FN_CALL_H__
00023 
00024 #include <map>
00025 #include <vector>
00026 #include "classad/classad.h"
00027 
00028 BEGIN_NAMESPACE( classad )
00029 
00030 typedef std::vector<ExprTree*> ArgumentList;
00031 
00032 typedef struct 
00033 {
00034     std::string       functionName;
00035 
00036     
00037     
00038     
00039     
00040     void         *function;
00041     
00042     
00043     
00044     
00045     int          flags;
00046 } ClassAdFunctionMapping;
00047 
00048 
00049 
00050 
00051 
00052 typedef  ClassAdFunctionMapping *(*ClassAdSharedLibraryInit)(void);
00053 
00055 class FunctionCall : public ExprTree
00056 {
00057  public:
00058     typedef bool(*ClassAdFunc)(const char*, const ArgumentList&, EvalState&,
00059                                Value&);
00060 
00062     FunctionCall(FunctionCall &functioncall);
00063 
00065     virtual ~FunctionCall ();
00066     
00067     FunctionCall & operator=(FunctionCall &functioncall);
00068 
00074     static FunctionCall *MakeFunctionCall( const std::string &fnName, 
00075                                            std::vector<ExprTree*> &argList );
00076     
00081     void GetComponents( std::string &, std::vector<ExprTree*> &) const;
00082     
00084     virtual ExprTree* Copy( ) const;
00085     
00086     bool CopyFrom(const FunctionCall &functioncall);
00087 
00088     virtual bool SameAs(const ExprTree *tree) const;
00089 
00090     friend bool operator==(const FunctionCall &fn1, const FunctionCall &fn2);
00091 
00092     static void RegisterFunction(std::string &functionName, ClassAdFunc function);
00093     static void RegisterFunctions(ClassAdFunctionMapping *functions);
00094 
00095     static bool RegisterSharedLibraryFunctions(const char *shared_library_path);
00096 
00097  protected:
00099     FunctionCall ();
00100     
00101     typedef std::map<std::string, void*, CaseIgnLTStr > FuncTable;
00102     
00103  private:
00104     virtual void _SetParentScope( const ClassAd* );
00105     virtual bool _Evaluate( EvalState &, Value & ) const;
00106     virtual bool _Evaluate( EvalState &, Value &, ExprTree *& ) const;
00107     virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00108     
00109     
00110     
00111     
00112     
00113     static FuncTable &getFunctionTable(void);
00114     static bool      initialized;
00115     
00116     
00117     std::string     functionName;
00118     ClassAdFunc     function;
00119     ArgumentList    arguments;
00120 
00121     
00122     
00123     
00124     static bool isType(const char*,const ArgumentList&,EvalState&,Value&);
00125     
00126     
00127     static bool testMember(const char*,const ArgumentList&,EvalState&,
00128                            Value&);
00129     
00130     
00131     
00132 
00133 
00134 
00135 
00136 
00137     static bool size(const char*,const ArgumentList&,EvalState&,
00138                      Value&);
00139     static bool sumAvg(const char*,const ArgumentList&,EvalState&,
00140                        Value&);
00141     static bool minMax(const char*,const ArgumentList&,EvalState&,
00142                        Value&);
00143     static bool listCompare(const char*,const ArgumentList&,EvalState&,
00144                             Value&);
00145     
00146     
00147 
00148 
00149     static bool epochTime (const char *, const ArgumentList &argList, 
00150                            EvalState &, Value &val);
00151     static bool currentTime(const char*,const ArgumentList&,EvalState&,
00152                             Value&);
00153     static bool timeZoneOffset(const char*,const ArgumentList&,EvalState&,
00154                                Value&);
00155     static bool dayTime(const char*,const ArgumentList&,EvalState&,Value&);
00156     static bool makeTime(const char*,const ArgumentList&,EvalState&,Value&);
00157     
00158 
00159 
00160     
00161     static bool getField(const char*,const ArgumentList&,EvalState&,Value&);
00162     static bool splitTime(const char*,const ArgumentList&,EvalState&,Value&);
00163     static bool formatTime(const char*,const ArgumentList&,EvalState&,Value&);
00164     
00165     
00166 
00167 
00168 
00169 
00170     
00171     static bool strCat(const char*,const ArgumentList&,EvalState&,Value&);
00172     static bool changeCase(const char*,const ArgumentList&,EvalState&,
00173                            Value&);
00174     static bool subString(const char*,const ArgumentList&,EvalState&,
00175                           Value&);
00176     static bool compareString(const char*,const ArgumentList&,EvalState&,
00177                           Value&);
00178     
00179     
00180     static bool matchPattern(const char*,const ArgumentList&,EvalState&,
00181                              Value&);
00182     static bool substPattern( const char*,const ArgumentList &argList,EvalState &state, Value &result );
00183 
00184     static bool matchPatternMember(const char*,const ArgumentList &argList,EvalState &state,
00185                               Value &result);
00186 
00187     
00188     static bool convInt(const char*,const ArgumentList&,EvalState&,Value&);
00189     static bool convReal(const char*,const ArgumentList&,EvalState&,Value&);
00190     static bool convString(const char*,const ArgumentList&,EvalState&,
00191                            Value&);
00192 
00193     static bool convBool(const char*,const ArgumentList&,EvalState&,Value&);
00194     static bool convTime(const char*,const ArgumentList&,EvalState&,Value&);
00195     
00196     
00197     static bool doMath(const char*,const ArgumentList&,EvalState&,Value&);
00198     static bool random(const char*,const ArgumentList&,EvalState&,Value&);
00199 
00200     static bool ifThenElse( const char* name,const ArgumentList &argList,EvalState &state,Value &result );
00201     
00202     static bool interval( const char* name,const ArgumentList &argList,EvalState &state,Value &result );
00203 
00204     static bool eval( const char* name,const ArgumentList &argList,EvalState &state,Value &result );
00205 
00206     
00207 };
00208 
00209 END_NAMESPACE 
00210 
00211 #endif//__CLASSAD_FN_CALL_H__