Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

myenv.h

Go to the documentation of this file.
00001 // This may look like C code, but it is really -*- C++ -*-
00002 // ************************************************************************
00003 //
00004 //                      A standard environment
00005 //                        I am accustomed to
00006 //
00007 // $Id: myenv.h,v 1.1 2004/05/21 21:02:52 maxx Exp $
00008 
00009 #ifndef __GNUC__
00010 #pragma once
00011 #endif
00012 #ifndef _myenv_h
00013 #define _myenv_h
00014 
00015 #ifdef __GNUC__
00016 #pragma interface
00017 #endif
00018 
00019 #include <stdio.h>
00020 
00021     
00022 namespace linalg 
00023 {
00024     using namespace linalg;
00025     
00026 //------------------------------------------------------------------------
00027 //                  Patches to the standard environment
00028 
00029 
00030 #if 0 // uncomment if the compiler sucks...
00031 typedef int bool;
00032 #define false 0
00033 #define true (!false)
00034 //enum bool {false,true};
00035 #endif
00036 
00037                                 // Like strncpy(), but ALWAYS terminates
00038                                 // the destination string
00039 char * xstrncpy(char * dest, const char * src, const int len);
00040 
00041 inline long int sqr(const int x)                { return x*x; }
00042 
00043 double       pow(double, long);
00044 double       pow(long, long);
00045 
00046                 // Works just as a regular getenv:
00047                 // searches the process' environment for a string of the form
00048                 // name=value and, if the string is
00049                 // present, returns a pointer to the 'value' part of the
00050                 // string.
00051                 // If the string is not present, the default_value is
00052                 // returned, unless it is nil.
00053                 // If the default_value was nil and the string wasn't found,
00054                 // the function prints the message that the name wasn't
00055                 // found, and aborts the program
00056 
00057 const char * xgetenv(const char * name, const char * default_value);
00058 
00059                                 // Return TRUE if string s1 starts with s2
00060                                 // i.e., s2 is a prefix of s1
00061                                 // Case doesn't matter
00062 bool does_start_with_ci(const char * s1, const char * s2);
00063 
00064 
00065                 // Obtain the size of an existing file
00066                 // If you don't want the function to abort when
00067                 // the file wasn't found/couldn't be accessed,
00068                 // supply your own default action by subclassing from
00069                 // GFS_Default and overriding 'operator ()'
00070 extern struct GFS_Default { virtual size_t operator () (const char * file_name); }
00071         GFS_default;
00072 size_t get_file_size(const char * file_name,
00073                      GFS_Default& on_error = GFS_default);
00074 
00075                                 // libg++ nifty timing functions
00076                                 // return_elapsed_time(Last_time) returns
00077                                 // process time (in secs) since Last_Time
00078                                 // If Last_time == 0.0, return time since
00079                                 // the last call to start_timer()
00080 #if !defined(__GNUC__) || ((__GNUC__ == 2) && (__GNUC_MINOR__ > 7))
00081 double start_timer(void);
00082 double return_elapsed_time(const double Last_Time);
00083 #endif
00084 
00085 
00086 //------------------------------------------------------------------------
00087 //      Assertions, aborts, and related stderr printing
00088 
00089                                 // Print an error message on stderr and
00090                                 // abort, arguments like those of printf()
00091 void _error(const char * message,...);
00092 
00093                                 // Print a message on stderr
00094                                 // It looks and acts like printf(), only
00095                                 // prints on stderr (which is unbuffered...)
00096 void message(const char * message,...);
00097 
00098 #ifndef assert
00099 #define assert(ex) \
00100         (void)((ex) ? 1 : \
00101               (_error("Failed assertion " #ex " at line %d of `%s'.\n", \
00102                __LINE__, __FILE__), 0))
00103 #define assertval(ex) assert(ex)
00104 #endif
00105 
00106 #define assure(expr,message) \
00107         if      (expr) {;}                              \
00108         else _error("%s\n at line %d of '%s'.",message,__LINE__, __FILE__)
00109 
00110 
00111         
00112                                 // Strings of symbols
00113                                 // They may be used as a delimiting lines
00114 extern const char _Minuses [];
00115 extern const char _Asteriscs [];
00116 extern const char _Equals [];
00117 
00118 }
00119 #endif
00120 

Generated on Wed Dec 15 21:20:29 2004 for vuVolume by  doxygen 1.3.9.1