Main Page | Class Hierarchy | Class List | File List | Class Members

common.h

00001 /*********************************************************************
00002  *
00003  * Condor ClassAd library
00004  * Copyright (C) 1990-2003, Condor Team, Computer Sciences Department,
00005  * University of Wisconsin-Madison, WI and Rajesh Raman.
00006  *
00007  * This source code is covered by the Condor Public License, which can
00008  * be found in the accompanying LICENSE file, or online at
00009  * www.condorproject.org.
00010  *
00011  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00012  * AND THE UNIVERSITY OF WISCONSIN-MADISON "AS IS" AND ANY EXPRESS OR
00013  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00014  * WARRANTIES OF MERCHANTABILITY, OF SATISFACTORY QUALITY, AND FITNESS
00015  * FOR A PARTICULAR PURPOSE OR USE ARE DISCLAIMED. THE COPYRIGHT
00016  * HOLDERS AND CONTRIBUTORS AND THE UNIVERSITY OF WISCONSIN-MADISON
00017  * MAKE NO MAKE NO REPRESENTATION THAT THE SOFTWARE, MODIFICATIONS,
00018  * ENHANCEMENTS OR DERIVATIVE WORKS THEREOF, WILL NOT INFRINGE ANY
00019  * PATENT, COPYRIGHT, TRADEMARK, TRADE SECRET OR OTHER PROPRIETARY
00020  * RIGHT.
00021  *
00022  *********************************************************************/
00023 
00024 
00025 #ifndef __COMMON_H__
00026 #define __COMMON_H__
00027 
00028 #if defined( WANT_NAMESPACES ) && defined(__cplusplus)
00029 #define BEGIN_NAMESPACE( x ) namespace x {
00030 #define END_NAMESPACE }
00031 #else
00032 #define BEGIN_NAMESPACE( x )
00033 #define END_NAMESPACE
00034 #endif
00035 
00036 #ifdef CLASSAD_DISTRIBUTION
00037 #ifndef _GNU_SOURCE
00038 #define _GNU_SOURCE /* to get definition for strptime on Linux */
00039 #endif
00040 
00041 #ifndef __EXTENSIONS__
00042 #define __EXTENSIONS__ /* to get gmtime_r and localtime_r on Solaris */
00043 #endif
00044 
00045 #ifndef _POSIX_C_SOURCE
00046 #define _POSIX_C_SOURCE 199506L /* To get asctime_r */
00047 #endif
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <time.h>
00052 #include <math.h>
00053 #ifndef WIN32
00054         #include <unistd.h>
00055         #define DLL_IMPORT_MAGIC  /* a no-op on Unix */
00056 #endif
00057 #include <errno.h>
00058 #include <ctype.h>
00059 
00060 #ifndef WORD_BIT
00061 #define WORD_BIT 32
00062 #endif
00063 
00064 
00065 
00066 #ifdef WIN32
00067         // special definitions we need for Windows
00068 #define DLL_IMPORT_MAGIC __declspec(dllimport)
00069 #include <windows.h>
00070 #include <float.h>
00071 #include <io.h>
00072 #define fsync _commit
00073 #define open _open
00074 #define strcasecmp _stricmp
00075 #define rint(num) floor(num + .5)
00076 #define isnan _isnan
00077         // isinf() defined in util.h
00078 
00079 
00080 
00081 #define snprintf _snprintf
00082 
00083         // Disable warnings about multiple template instantiations
00084         // (done for gcc)
00085 #pragma warning( disable : 4660 )  
00086         // Disable warnings about forcing bools
00087 #pragma warning( disable : 4800 )  
00088         // Disable warnings about truncated debug identifiers
00089 #pragma warning( disable : 4786 )
00090         // use new SDK stuff in STLport
00091 #define _STLP_NEW_PLATFORM_SDK
00092 #endif // WIN32
00093 
00094 
00095 #else /* CLASSAD_DISTRIBUTION isn't defined */
00096 
00097 #ifndef _POSIX_C_SOURCE
00098 #define _POSIX_C_SOURCE 199506L /* To get asctime_r */
00099 #endif
00100 
00101 #include "condor_common.h"
00102 #include "condor_debug.h"
00103 #include "condor_attributes.h"
00104 #endif /* CLASSAD_DISTRIBUTION */
00105 
00106 #include "classad_features.h"
00107 #include "debug.h"
00108 
00109 #ifdef __cplusplus
00110 #include <string>
00111 #endif
00112 
00113 BEGIN_NAMESPACE( classad )
00114 
00115 static const char ATTR_AD                                       []      = "Ad";
00116 static const char ATTR_CONTEXT                          []      = "Context";
00117 static const char ATTR_DEEP_MODS                        []      = "DeepMods";
00118 static const char ATTR_DELETE_AD                        []      = "DeleteAd";
00119 static const char ATTR_DELETES                          []      = "Deletes";
00120 static const char ATTR_KEY                                      []      = "Key";
00121 static const char ATTR_NEW_AD                           []      = "NewAd";
00122 static const char ATTR_OP_TYPE                          []      = "OpType";
00123 static const char ATTR_PARENT_VIEW_NAME         []      = "ParentViewName";
00124 static const char ATTR_PARTITION_EXPRS          []  = "PartitionExprs";
00125 static const char ATTR_PARTITIONED_VIEWS        []      = "PartitionedViews";
00126 static const char ATTR_PROJECT_THROUGH          []      = "ProjectThrough";
00127 static const char ATTR_RANK_HINTS                       []      = "RankHints";
00128 static const char ATTR_REPLACE                          []      = "Replace";
00129 static const char ATTR_SUBORDINATE_VIEWS        []      = "SubordinateViews";
00130 static const char ATTR_UPDATES                          []      = "Updates";
00131 static const char ATTR_WANT_LIST                        []      = "WantList";
00132 static const char ATTR_WANT_PRELUDE                     []      = "WantPrelude";
00133 static const char ATTR_WANT_RESULTS                     []      = "WantResults";
00134 static const char ATTR_WANT_POSTLUDE            []      = "WantPostlude";
00135 static const char ATTR_VIEW_INFO                        []      = "ViewInfo";
00136 static const char ATTR_VIEW_NAME                        []      = "ViewName";
00137 static const char ATTR_XACTION_NAME                     []      = "XactionName";
00138 
00139 #if defined( CLASSAD_DISTRIBUTION )
00140 static const char ATTR_REQUIREMENTS                     []      = "Requirements";
00141 static const char ATTR_RANK                                     []      = "Rank";
00142 #endif
00143 
00144 #if defined(__cplusplus)
00145 struct CaseIgnLTStr {
00146     bool operator( )( const std::string &s1, const std::string &s2 ) const {
00147        return( strcasecmp( s1.c_str( ), s2.c_str( ) ) < 0 );
00148         }
00149 };
00150 
00151 struct CaseIgnEqStr {
00152         bool operator( )( const std::string &s1, const std::string &s2 ) const {
00153                 return( strcasecmp( s1.c_str( ), s2.c_str( ) ) == 0 );
00154         }
00155 };
00156 
00157 class ExprTree;
00158 struct ExprHash {
00159         size_t operator()( const ExprTree *const &x ) const {
00160                 return( (size_t)x );
00161         }
00162 };
00163 
00164 struct StringHash {
00165         size_t operator()( const std::string &s ) const {
00166                 size_t h = 0;
00167                 for( int i = s.size()-1; i >= 0; i-- ) {
00168                         h = 5*h + s[i];
00169                 }
00170                 return( h );
00171         }
00172 };
00173 
00174 struct StringCaseIgnHash {
00175         size_t operator()( const std::string &s ) const {
00176                 size_t h = 0;
00177                 for( int i = s.size()-1; i >= 0; i-- ) {
00178                         h = 5*h + tolower(s[i]);
00179                 }
00180                 return( h );
00181         }
00182 };
00183 extern std::string       CondorErrMsg;
00184 #endif
00185 
00186 extern int              CondorErrno;
00187 static const std::string NULL_XACTION = "";
00188 
00189 END_NAMESPACE // classad
00190 
00191 char* strnewp( const char* );
00192 
00193 #if defined(CLASSAD_DISTRIBUTION)
00194 #include "classadErrno.h"
00195 #else
00196 #include "condor_errno.h"
00197 #endif
00198 
00199 #endif//__COMMON_H__