UFile.h
Go to the documentation of this file.
1 /*
2 * utilite is a cross-platform library with
3 * useful utilities for fast and small developing.
4 * Copyright (C) 2010 Mathieu Labbe
5 *
6 * utilite is free library: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * utilite is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef FILE_H
21 #define FILE_H
22 
23 #include "rtabmap/utilite/UtiLiteExp.h" // DLL export/import defines
24 
26 #include <string>
27 
34 {
35 public:
41  static bool exists(const std::string &filePath);
42 
48  static long length(const std::string &filePath);
49 
55  static int erase(const std::string &filePath);
56 
63  static int rename(const std::string &oldFilePath,
64  const std::string &newFilePath);
65 
71  static std::string getName(const std::string & filePath);
72 
77  static std::string getExtension(const std::string &filePath);
78 
84  static void copy(const std::string & from, const std::string & to);
85 
86 public:
91  UFile(const std::string & path) : path_(path) {}
92  ~UFile() {}
93 
98  bool isValid() {return exists(path_);}
99 
104  bool exists() {return exists(path_);}
105 
110  long length() {return length(path_);}
111 
116  int rename(const std::string &newName)
117  {
118  std::string ext = this->getExtension();
119  std::string newPath = UDirectory::getDir(path_) + std::string("/") + newName;
120  if(ext.size())
121  {
122  newPath += std::string(".") + getExtension(path_);
123  }
124  int result = rename(path_, newPath);
125  if(result == 0)
126  {
127  path_ = newPath;
128  }
129  return result;
130  }
135  std::string getName() {return getName(path_);}
140  std::string getExtension() {return getExtension(path_);}
141 
146  void copy(const std::string & to) {copy(path_, to);}
147 
148 private:
149  std::string path_;
150 };
151 
152 #endif
std::string getName()
Definition: UFile.h:135
long length()
Definition: UFile.h:110
static std::string getDir(const std::string &filePath)
Definition: UDirectory.cpp:273
#define UTILITE_EXP
Definition: UtiLiteExp.h:33
void copy(const std::string &to)
Definition: UFile.h:146
std::string getName(void *handle)
UFile(const std::string &path)
Definition: UFile.h:91
~UFile()
Definition: UFile.h:92
std::string getExtension()
Definition: UFile.h:140
int rename(const std::string &newName)
Definition: UFile.h:116
bool isValid()
Definition: UFile.h:98
std::string path_
Definition: UFile.h:149
bool exists()
Definition: UFile.h:104
Definition: UFile.h:33
GLM_FUNC_DECL genType::value_type length(genType const &x)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:40