RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UFile.h
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/utilite_export.h" // DLL export/import defines
24
25#include "rtabmap/utilite/UDirectory.h"
26#include <string>
27
33class UTILITE_EXPORT UFile
34{
35public:
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
86public:
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
148private:
149 std::string path_;
150};
151
152#endif
static std::string getDir(const std::string &filePath)
Definition UFile.h:34
long length()
Definition UFile.h:110
UFile(const std::string &path)
Definition UFile.h:91
static int erase(const std::string &filePath)
static std::string getName(const std::string &filePath)
int rename(const std::string &newName)
Definition UFile.h:116
bool exists()
Definition UFile.h:104
static int rename(const std::string &oldFilePath, const std::string &newFilePath)
void copy(const std::string &to)
Definition UFile.h:146
std::string getExtension()
Definition UFile.h:140
static void copy(const std::string &from, const std::string &to)
static bool exists(const std::string &filePath)
static std::string getExtension(const std::string &filePath)
bool isValid()
Definition UFile.h:98
static long length(const std::string &filePath)
std::string getName()
Definition UFile.h:135