RTAB-Map 0.25.2
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
UFile.h
1/*
2Copyright (c) 2010, Mathieu Labbe
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holders nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef FILE_H
29#define FILE_H
30
31#include "rtabmap/utilite/utilite_export.h" // DLL export/import defines
32
33#include "rtabmap/utilite/UDirectory.h"
34#include <string>
35
41class UTILITE_EXPORT UFile
42{
43public:
49 static bool exists(const std::string &filePath);
50
56 static long length(const std::string &filePath);
57
63 static int erase(const std::string &filePath);
64
71 static int rename(const std::string &oldFilePath,
72 const std::string &newFilePath);
73
79 static std::string getName(const std::string & filePath);
80
85 static std::string getExtension(const std::string &filePath);
86
92 static void copy(const std::string & from, const std::string & to);
93
94public:
99 UFile(const std::string & path) : path_(path) {}
100 ~UFile() {}
101
106 bool isValid() {return exists(path_);}
107
112 bool exists() {return exists(path_);}
113
118 long length() {return length(path_);}
119
124 int rename(const std::string &newName)
125 {
126 std::string ext = this->getExtension();
127 std::string newPath = UDirectory::getDir(path_) + std::string("/") + newName;
128 if(ext.size())
129 {
130 newPath += std::string(".") + getExtension(path_);
131 }
132 int result = rename(path_, newPath);
133 if(result == 0)
134 {
135 path_ = newPath;
136 }
137 return result;
138 }
143 std::string getName() {return getName(path_);}
148 std::string getExtension() {return getExtension(path_);}
149
154 void copy(const std::string & to) {copy(path_, to);}
155
156private:
157 std::string path_;
158};
159
160#endif
static std::string getDir(const std::string &filePath)
Definition UFile.h:42
long length()
Definition UFile.h:118
UFile(const std::string &path)
Definition UFile.h:99
static int erase(const std::string &filePath)
static std::string getName(const std::string &filePath)
int rename(const std::string &newName)
Definition UFile.h:124
bool exists()
Definition UFile.h:112
static int rename(const std::string &oldFilePath, const std::string &newFilePath)
void copy(const std::string &to)
Definition UFile.h:154
std::string getExtension()
Definition UFile.h:148
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:106
static long length(const std::string &filePath)
std::string getName()
Definition UFile.h:143