Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

utils.h

00001 //FILE:         utils.h
00002 //AUTHOR:       Nathan Cournia <nathan@cournia.com>
00003 
00004 #ifndef COURNIA_UTILS_H
00005 #define COURNIA_UTILS_H 1
00006 
00007 #include <iostream>
00008 #include <string>
00009 
00011 
00015 namespace utils 
00016 {
00017         //error space for utils::functions.
00018         //Not thread safe, but should be easy to do so.
00019         //Do not access the variable outside of the utils:: namespace.
00020         //Use utils::get_error( void ) to get the error message.
00021         extern std::string error;
00022 
00023         //used internally by utils:: functions to clear the error message
00024         inline void clear_error( void )
00025         {
00026                 error = "none";
00027         }
00028 
00029         //used internally by utils:: functions to set error
00030         inline void set_error( const std::string& msg )
00031         {
00032                 error = msg;
00033         }
00034 
00036         inline const std::string& get_error( void )
00037         {
00038                 return error;
00039         }
00040         
00042 
00047         std::string add_slash( const std::string& filename );
00048 
00050 
00053         void to_upper( std::string& str );
00054 
00056         std::string to_upper( const std::string& str );
00057 
00059 
00062         bool stricmp( const std::string& a, const std::string& b );
00063 
00065 
00069         bool check_extension( const std::string& file, const std::string& ext );
00070 
00072         std::string trim( const std::string& str );
00073         
00075         std::string rtrim( const std::string& str );
00076 
00078 
00086         template <class T>
00087         std::istream&
00088         read( std::istream& stream, T& in )
00089         {
00090                 char buffer[ sizeof( T ) ];
00091                 stream.read( (char*)buffer, sizeof( T ) );
00092                 in = *((T*)(&buffer[0]));
00093                 return stream;
00094         }
00095 
00097 
00105         template <class T>
00106         std::ostream&
00107         write( std::ostream& stream, const T& out )
00108         {
00109                 return stream.write( (char*)(&out), sizeof( T ) );
00110         }
00111 
00112         //system dependent functions
00113         //the following methods should be defined in in a seperate .cpp
00114         //for each system.  for example: posix.cpp, windows.cpp, mac.cpp, etc.
00115         
00117 
00121         bool mkdir( const std::string& filename );
00122         
00124 
00128         bool exists( const std::string& filename );
00129         
00131 
00135         bool can_read( const std::string& filename );
00136 
00138 
00142         bool is_dir( const std::string& filename );
00143 
00145 
00149         bool is_link( const std::string& filename );
00150 
00152 
00156         bool chdir( const std::string& filename );
00157 
00159 
00166         std::string get_valid_absolute_dir( const std::string& filename );
00167 
00169 
00176         std::string get_absolute_dir( const std::string& filename );
00177 
00179 
00182         std::string get_filename( const std::string& filename );
00183         
00184 }
00185 
00186 #endif

Generated on Tue Feb 11 18:49:42 2003 for uber by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002