literals.h

00001 /***************************************************************
00002  *
00003  * Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
00004  * University of Wisconsin-Madison, WI.
00005  * 
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you
00007  * may not use this file except in compliance with the License.  You may
00008  * obtain a copy of the License at
00009  * 
00010  *    http://www.apache.org/licenses/LICENSE-2.0
00011  * 
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  *
00018  ***************************************************************/
00019 
00020 
00021 #ifndef __CLASSAD_LITERALS_H__
00022 #define __CLASSAD_LITERALS_H__
00023 
00024 #include <vector>
00025 
00026 BEGIN_NAMESPACE( classad )
00027 
00028 typedef std::vector<ExprTree*> ArgumentList;
00029 
00033 class Literal : public ExprTree 
00034 {
00035     public:
00037         virtual ~Literal ();
00038 
00040         Literal(const Literal &literal);
00041 
00043         Literal &operator=(const Literal &literal);
00044 
00050         static Literal* MakeAbsTime( abstime_t *now=NULL );
00051 
00052         /* Creates an absolute time literal, from the string timestr, 
00053          *parsing it as the regular expression:
00054          D* dddd [D* dd [D* dd [D* dd [D* dd [D* dd D*]]]]] [-dddd | +dddd | z | Z]
00055          D => non-digit, d=> digit
00056          Ex - 2003-01-25T09:00:00-0600
00057         */
00058         static Literal* MakeAbsTime( std::string timestr);
00059 
00065         static Literal* MakeRelTime( time_t secs=-1 );
00066 
00074         static Literal* MakeRelTime( time_t t1, time_t t2 );
00075 
00076         /* Creates a relative time literal, from the string timestr, 
00077          *parsing it as [[[days+]hh:]mm:]ss
00078          * Ex - 1+00:02:00
00079         */      
00080         static Literal* MakeRelTime(std::string str);
00081 
00082         static Literal* MakeReal(std::string realstr);
00083 
00085         virtual ExprTree* Copy( ) const;
00086 
00087         void CopyFrom(const Literal &literal);
00088 
00096         static Literal*MakeLiteral( const Value& v, Value::NumberFactor f=
00097                     Value::NO_FACTOR );
00098 
00103         void GetComponents( Value& v, Value::NumberFactor &f ) const;
00104 
00108         void GetValue( Value& v ) const;
00109         
00110         /* Takes the number of seconds since the epoch as argument - epochsecs, 
00111          *and returns the timezone offset(relative to GMT) in the currect locality
00112          */
00113         static int findOffset(time_t epochsecs);
00114 
00115         virtual bool SameAs(const ExprTree *tree) const;
00116 
00117         friend bool operator==(Literal &literal1, Literal &literal2);
00118 
00119     protected:
00121         Literal ();
00122 
00123     private:
00124         friend class FunctionCall;
00125         friend class ClassAd;
00126         friend class ExprList;
00127         friend class Operation;
00128 
00129         virtual void _SetParentScope( const ClassAd* ){ }
00130         virtual bool _Flatten( EvalState&, Value&, ExprTree*&, int* ) const;
00131         virtual bool _Evaluate (EvalState &, Value &) const;
00132         virtual bool _Evaluate (EvalState &, Value &, ExprTree *&) const;
00133 
00134         // literal specific information
00135         Value               value;
00136         Value::NumberFactor factor;
00137 };
00138 
00139 END_NAMESPACE // classad
00140 
00141 #endif//__CLASSAD_LITERALS_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends