common.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 
00022 #ifndef __CLASSAD_COMMON_H__
00023 #define __CLASSAD_COMMON_H__
00024 
00025 #ifndef WIN32
00026 #include <strings.h>
00027 #endif
00028 
00029 #if defined( WANT_CLASSAD_NAMESPACE ) && defined(__cplusplus)
00030 #define BEGIN_NAMESPACE( x ) namespace x {
00031 #define END_NAMESPACE }
00032 #else
00033 #define BEGIN_NAMESPACE( x )
00034 #define END_NAMESPACE
00035 #endif
00036 
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 #ifdef WIN32
00046     // These must be defined before any of the
00047     // other headers are pulled in.
00048 #define _STLP_NEW_PLATFORM_SDK
00049 #define _STLP_NO_OWN_IOSTREAMS 1
00050 
00051 // Disable warnings about calling posix functions like open()
00052 // instead of _open()
00053 #define _CRT_NONSTDC_NO_WARNINGS
00054 
00055 // Disable warnings about possible loss of data, since "we know what
00056 // we are doing" and fixing them correctly would require too much 
00057 // time from one of us. (Maybe this should be a student exercise.)
00058 #pragma warning( disable : 4244 )
00059 
00060 #endif /* WIN32 */
00061 
00062 #include <stdio.h>
00063 #include <stdlib.h>
00064 #include <time.h>
00065 #include <limits.h>
00066 #include <math.h>
00067 #ifndef WIN32
00068     #include <unistd.h>
00069     #define DLL_IMPORT_MAGIC  /* a no-op on Unix */
00070 #endif
00071 #include <errno.h>
00072 #include <ctype.h>
00073 
00074 
00075 
00076 
00077 #ifdef WIN32
00078 
00079     // special definitions we need for Windows
00080 #ifndef DLL_IMPORT_MAGIC
00081 #define DLL_IMPORT_MAGIC __declspec(dllimport)
00082 #endif
00083 #include <windows.h>
00084 #include <float.h>
00085 #include <io.h>
00086 #define fsync _commit
00087 #define strcasecmp _stricmp
00088 #ifndef rint
00089 #define rint(num) floor(num + .5)
00090 #endif
00091 #define isnan _isnan
00092     // isinf() defined in util.h
00093 
00094 #include <hash_map>
00095 
00096 #define snprintf _snprintf
00097 
00098     // Disable warnings about multiple template instantiations
00099     // (done for gcc)
00100 #pragma warning( disable : 4660 )  
00101     // Disable warnings about forcing bools
00102 #pragma warning( disable : 4800 )  
00103     // Disable warnings about truncated debug identifiers
00104 #pragma warning( disable : 4786 )
00105 
00106 #endif // WIN32
00107 
00108 
00109 #include "classad/debug.h"
00110 
00111 #ifdef __cplusplus
00112 #include <string>
00113 #endif
00114 #include <cstring>
00115 #include <string.h>
00116 
00117 BEGIN_NAMESPACE( classad )
00118 
00119 extern const char * const ATTR_AD;
00120 extern const char * const ATTR_CONTEXT;
00121 extern const char * const ATTR_DEEP_MODS;
00122 extern const char * const ATTR_DELETE_AD;
00123 extern const char * const ATTR_DELETES;
00124 extern const char * const ATTR_KEY;
00125 extern const char * const ATTR_NEW_AD;
00126 extern const char * const ATTR_OP_TYPE;
00127 extern const char * const ATTR_PARENT_VIEW_NAME;
00128 extern const char * const ATTR_PARTITION_EXPRS;
00129 extern const char * const ATTR_PARTITIONED_VIEWS;
00130 extern const char * const ATTR_PROJECT_THROUGH;
00131 extern const char * const ATTR_RANK_HINTS;
00132 extern const char * const ATTR_REPLACE;
00133 extern const char * const ATTR_SUBORDINATE_VIEWS;
00134 extern const char * const ATTR_UPDATES;
00135 extern const char * const ATTR_WANT_LIST;
00136 extern const char * const ATTR_WANT_PRELUDE;
00137 extern const char * const ATTR_WANT_RESULTS;
00138 extern const char * const ATTR_WANT_POSTLUDE;
00139 extern const char * const ATTR_VIEW_INFO;
00140 extern const char * const ATTR_VIEW_NAME;
00141 extern const char * const ATTR_XACTION_NAME;
00142 
00143 extern const char * const ATTR_REQUIREMENTS;
00144 extern const char * const ATTR_RANK;
00145 
00146 #if defined(__cplusplus)
00147 struct CaseIgnLTStr {
00148     bool operator( )( const std::string &s1, const std::string &s2 ) const {
00149        return( strcasecmp( s1.c_str( ), s2.c_str( ) ) < 0 );
00150     }
00151 };
00152 
00153 struct CaseIgnEqStr {
00154     bool operator( )( const std::string &s1, const std::string &s2 ) const {
00155         return( strcasecmp( s1.c_str( ), s2.c_str( ) ) == 0 );
00156     }
00157 };
00158 
00159 class ExprTree;
00160 struct ExprHash {
00161     size_t operator()( const ExprTree *const &x ) const {
00162         return( (size_t)x );
00163     }
00164 };
00165 
00166 struct StringHash {
00167     size_t operator()( const std::string &s ) const {
00168         unsigned long h = 0;
00169         char const *ch;
00170         for( ch = s.c_str(); *ch; ch++ ) {
00171             h = 5*h + (unsigned char)*ch;
00172         }
00173         return (size_t)h;
00174     }
00175 };
00176 
00177 struct StringCaseIgnHash
00178 #ifdef WIN32
00179     : public stdext::hash_compare <std::string>
00180 #endif
00181 {
00182     size_t operator()( const std::string &s ) const {
00183         unsigned long h = 0;
00184         char const *ch;
00185         for( ch = s.c_str(); *ch; ch++ ) {
00186             h = 5*h + (unsigned char)tolower(*ch);
00187         }
00188         return (size_t)h;
00189     }
00190 #ifdef WIN32
00191         // On Windows, the hash_map comparison operator is less-than,
00192         // not equal-to.
00193     bool operator( )( const std::string &s1, const std::string &s2 ) const {
00194         return( strcasecmp( s1.c_str( ), s2.c_str( ) ) < 0 );
00195     }
00196 #endif
00197 };
00198 extern std::string       CondorErrMsg;
00199 #endif
00200 
00201 extern int      CondorErrno;
00202 
00203 END_NAMESPACE // classad
00204 
00205 char* strnewp( const char* );
00206 
00207 #include "classad/classadErrno.h"
00208 
00209 #endif//__CLASSAD_COMMON_H__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends