FileUtils.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: FileUtils.hpp 79 2006-08-10 15:45:45Z pben $"
00002 
00003 
00004 
00010 #ifndef GPSTK_FILEUTILS_HPP
00011 #define GPSTK_FILEUTILS_HPP
00012 
00013 //============================================================================
00014 //
00015 //  This file is part of GPSTk, the GPS Toolkit.
00016 //
00017 //  The GPSTk is free software; you can redistribute it and/or modify
00018 //  it under the terms of the GNU Lesser General Public License as published
00019 //  by the Free Software Foundation; either version 2.1 of the License, or
00020 //  any later version.
00021 //
00022 //  The GPSTk is distributed in the hope that it will be useful,
00023 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00024 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025 //  GNU Lesser General Public License for more details.
00026 //
00027 //  You should have received a copy of the GNU Lesser General Public
00028 //  License along with GPSTk; if not, write to the Free Software Foundation,
00029 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00030 //  
00031 //  Copyright 2004, The University of Texas at Austin
00032 //
00033 //============================================================================
00034 
00035 //============================================================================
00036 //
00037 //This software developed by Applied Research Laboratories at the University of
00038 //Texas at Austin, under contract to an agency or agencies within the U.S. 
00039 //Department of Defense. The U.S. Government retains all rights to use,
00040 //duplicate, distribute, disclose, or release this software. 
00041 //
00042 //Pursuant to DoD Directive 523024 
00043 //
00044 // DISTRIBUTION STATEMENT A: This software has been approved for public 
00045 //                           release, distribution is unlimited.
00046 //
00047 //=============================================================================
00048 
00049 
00050 
00051 
00052 
00053 
00054 #ifdef __sun
00055 #include <libgen.h>
00056 #else
00057 #include <sys/stat.h>
00058 #include <sys/types.h>
00059 #endif
00060 
00061 #include <fstream>
00062 #include <string>
00063 #include "StringUtils.hpp"
00064 
00065 #ifdef _MSC_VER
00066 #include <direct.h>
00067 #endif
00068 
00069 namespace gpstk
00070 {
00073 
00077    namespace FileUtils
00078    {
00088       inline int makeDir(const std::string& path, unsigned mode)
00089       {
00090 #ifdef __sun
00091          mkdirp(path.c_str(), mode);
00092 #else
00093          int rc = 0;
00094          std::string::size_type i = 0;
00095 
00096          while ((i = path.find('/',i+1)) != std::string::npos)
00097          {
00098             std::string thispath(path.substr(0,i));
00099             if (thispath[thispath.length() - 1] == '/')
00100                thispath.erase(thispath.length() - 1);
00101 #ifdef _MSC_VER
00102             _mkdir(path.c_str());
00103 #else
00104             mkdir(thispath.c_str(), mode);
00105 #endif
00106          }
00107 #ifdef _MSC_VER
00108          _mkdir(path.c_str());
00109 #else
00110          mkdir(path.c_str(), mode);
00111 #endif
00112 
00113 #endif // __sun
00114          return 0;
00115       }
00116 
00123       inline int makeDir(const char* path, unsigned mode)
00124       {
00125          return makeDir(std::string(path), mode);
00126       }
00127 
00135       inline bool fileAccessCheck(const char* fname, 
00136                                   std::ios::openmode mode=std::ios::in)
00137       {
00138         std::fstream test(fname, mode);
00139         return !test.fail();
00140       }
00141 
00142       inline bool fileAccessCheck(const std::string& fname, 
00143                                   std::ios::openmode mode=std::ios::in)
00144       {
00145          return fileAccessCheck(fname.c_str(), mode);
00146       }
00147       
00148 
00149    } // namespace FileUtils
00150 
00152 
00153 } // namespace
00154 
00155 
00156 #endif

Generated on Tue May 22 03:30:58 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1