sink.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_SINK_H__
00022 #define __CLASSAD_SINK_H__
00023 
00024 #include "classad/common.h"
00025 #include "classad/exprTree.h"
00026 #include <vector>
00027 #include <utility>  // for pair template
00028 #include <string>
00029 
00030 BEGIN_NAMESPACE( classad )
00031 
00032 
00033 class ClassAdUnParser
00034 {
00035     public:
00037         ClassAdUnParser( );
00038 
00040         virtual ~ClassAdUnParser( );
00041 
00045         void setXMLUnparse(bool doXMLUnparse);
00046 
00047         // The default delimiter for strings is '\"'
00048         // This can be changed to '\'' to unparse quoted attributes, with this function
00049         void setDelimiter(char delim);
00050 
00055         void Unparse( std::string &buffer, const Value &val );
00056 
00061         void Unparse( std::string &buffer, const ExprTree *expr );
00062 
00063             //  for backcompatibility only - NAC
00064         void SetOldClassAd( bool );
00065         bool GetOldClassAd();
00066 
00067         virtual void UnparseAux( std::string &buffer,
00068                                  const Value&,Value::NumberFactor );
00069         virtual void UnparseAux( std::string &buffer, 
00070                                  const ExprTree *tree, 
00071                                  std::string &ref, bool absolute=false );
00072         virtual void UnparseAux( std::string &buffer, Operation::OpKind op, 
00073                     ExprTree *op1, ExprTree *op2, ExprTree *op3 );
00074         virtual void UnparseAux(std::string &buffer, std::string &fnName, 
00075                     std::vector<ExprTree*>& args);
00076         virtual void UnparseAux( std::string &buffer, 
00077                     std::vector< std::pair< std::string, ExprTree*> >& attrlist );
00078         virtual void UnparseAux( std::string &buffer, std::vector<ExprTree*>& );
00079 
00080         // to unparse attribute names (quoted & unquoted attributes)
00081         virtual void UnparseAux( std::string &buffer, std::string identifier);
00082 
00083         // table of string representation of operators
00084         static const char *opString[];
00085 
00086  protected:
00087         bool oldClassAd;
00088         bool xmlUnparse;
00089         char delimiter; // string delimiter - initialized to '\"' in the constructor
00090 };
00091 
00092 
00094 class PrettyPrint : public ClassAdUnParser
00095 {
00096     public:
00098         PrettyPrint( );
00100         virtual ~PrettyPrint( );
00101 
00103         void SetClassAdIndentation( int=4 );
00105         int  GetClassAdIndentation( );
00106 
00108         void SetListIndentation( int=4 );
00110         int  GetListIndentation( );
00111 
00112         void SetWantStringQuotes( bool );
00113         bool GetWantStringQuotes( );
00114 
00116         void SetMinimalParentheses( bool );
00118         bool GetMinimalParentheses( );
00119 
00120         virtual void UnparseAux( std::string &buffer, Operation::OpKind op, 
00121                     ExprTree *op1, ExprTree *op2, ExprTree *op3 );
00122         virtual void UnparseAux( std::string &buffer,
00123                     std::vector< std::pair< std::string, ExprTree*> >& attrlist );
00124         virtual void UnparseAux( std::string &buffer, std::vector<ExprTree*>& );
00125 
00126     private:
00127         int  classadIndent;
00128         int  listIndent;
00129         bool wantStringQuotes;
00130         bool minimalParens;
00131         int  indentLevel;
00132 };
00133 
00134 END_NAMESPACE // classad
00135 
00136 #endif//__CLASSAD_SINK_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends