UFile.h
Go to the documentation of this file.
00001 /*
00002 *  utilite is a cross-platform library with
00003 *  useful utilities for fast and small developing.
00004 *  Copyright (C) 2010  Mathieu Labbe
00005 *
00006 *  utilite is free library: you can redistribute it and/or modify
00007 *  it under the terms of the GNU Lesser General Public License as published by
00008 *  the Free Software Foundation, either version 3 of the License, or
00009 *  (at your option) any later version.
00010 *
00011 *  utilite is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *  GNU Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public License
00017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #ifndef FILE_H
00021 #define FILE_H
00022 
00023 #include "rtabmap/utilite/UtiLiteExp.h" // DLL export/import defines
00024 
00025 #include "rtabmap/utilite/UDirectory.h"
00026 #include <string>
00027 
00033 class UTILITE_EXP UFile
00034 {
00035 public:
00041         static bool exists(const std::string &filePath);
00042 
00048         static long length(const std::string &filePath);
00049 
00055         static int erase(const std::string &filePath);
00056 
00063         static int rename(const std::string &oldFilePath,
00064                                                   const std::string &newFilePath);
00065 
00071         static std::string getName(const std::string & filePath);
00072 
00077         static std::string getExtension(const std::string &filePath);
00078 
00084         static void copy(const std::string & from, const std::string & to);
00085 
00086 public:
00091         UFile(const std::string & path) : path_(path) {}
00092         ~UFile() {}
00093 
00098         bool isValid() {return exists(path_);}
00099 
00104         bool exists() {return exists(path_);}
00105 
00110         long length() {return length(path_);}
00111 
00116         int rename(const std::string &newName)
00117         {
00118                 std::string ext = this->getExtension();
00119                 std::string newPath = UDirectory::getDir(path_) + std::string("/") + newName;
00120                 if(ext.size())
00121                 {
00122                         newPath += std::string(".") + getExtension(path_);
00123                 }
00124                 int result = rename(path_, newPath);
00125                 if(result == 0)
00126                 {
00127                         path_ = newPath;
00128                 }
00129                 return result;
00130         }
00135         std::string getName() {return getName(path_);}
00140         std::string getExtension() {return getExtension(path_);}
00141 
00146         void copy(const std::string & to) {copy(path_, to);}
00147 
00148 private:
00149         std::string path_;
00150 };
00151 
00152 #endif


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:42