FileUtils.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_FILEUTILS_HPP
45 #define GNSSTK_FILEUTILS_HPP
46 
47 // #ifdef __sun
48 // #include <libgen.h>
49 // #else
50 #include <sys/types.h>
51 #include <sys/stat.h>
52 #include <iostream>
53 // #endif
54 
55 #include <fstream>
56 #include <string>
57 #include "StringUtils.hpp"
58 
59 #ifdef WIN32
60 #include <direct.h>
61 #include <io.h>
62 #endif
63 
64 using namespace std;
65 namespace gnsstk
66 {
68 
69 
73  namespace FileUtils
74  {
85 #ifdef WIN32
86  inline int makeDir(const std::string& path, unsigned mode)
87  {
88  std::string temppath = path;
89 
90  //Clean up windows file path
91  std::replace(temppath.begin(), temppath.end(), '\\', '/');
92  std::string::size_type i = 0;
93 
94  while ((i = temppath.find('/',i+1)) != std::string::npos)
95  {
96  std::string thispath(temppath.substr(0,i));
97  if (thispath[thispath.length() - 1] == '/')
98  thispath.erase(thispath.length() - 1);
99  _mkdir(thispath.c_str());
100 
101  }
102  _mkdir(temppath.c_str());
103  return 0;
104  }
105 #else
106  inline int makeDir(const std::string& path, unsigned mode)
107  {
108  // #ifdef __sun
109  // mkdirp(path.c_str(), mode);
110  // #else
111  std::string::size_type i = 0;
112 
113  while ((i = path.find('/',i+1)) != std::string::npos)
114  {
115  std::string thispath(path.substr(0,i));
116  if (thispath[thispath.length() - 1] == '/')
117  thispath.erase(thispath.length() - 1);
118 
119  mkdir(thispath.c_str(), mode);
120 
121  }
122  mkdir(path.c_str(), mode);
123  // #endif
124  return 0;
125  }
126 
127 #endif
128 
134  inline int makeDir(const char* path, unsigned mode)
135  {
136  return makeDir(std::string(path), mode);
137  }
138 
151  inline bool fileAccessCheck(const char* fname,
152  std::ios::openmode mode=std::ios::in)
153  {
154  std::fstream test(fname, mode);
155  return !test.fail();
156  }
157 
158  inline bool fileAccessCheck(const std::string& fname,
159  std::ios::openmode mode=std::ios::in)
160  {
161  return fileAccessCheck(fname.c_str(), mode);
162  }
163 
164 
165  } // namespace FileUtils
166 
168 
169 } // namespace
170 
171 
172 #endif
StringUtils.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::FileUtils::fileAccessCheck
bool fileAccessCheck(const std::string &fname, std::ios::openmode mode=std::ios::in)
Definition: FileUtils.hpp:158
gnsstk::FileUtils::makeDir
int makeDir(const char *path, unsigned mode)
Definition: FileUtils.hpp:134
std
Definition: Angle.hpp:142


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39