UFile.h
Go to the documentation of this file.
00001 // Taken from UtiLite library r185 [www.utilite.googlecode.com]
00002 
00003 /*
00004 *  utilite is a cross-platform library with
00005 *  useful utilities for fast and small developing.
00006 *  Copyright (C) 2010  Mathieu Labbe
00007 *
00008 *  utilite is free library: you can redistribute it and/or modify
00009 *  it under the terms of the GNU Lesser General Public License as published by
00010 *  the Free Software Foundation, either version 3 of the License, or
00011 *  (at your option) any later version.
00012 *
00013 *  utilite is distributed in the hope that it will be useful,
00014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 *  GNU Lesser General Public License for more details.
00017 *
00018 *  You should have received a copy of the GNU Lesser General Public License
00019 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef FILE_H
00023 #define FILE_H
00024 
00025 //#include "utilite/UtiLiteExp.h" // DLL export/import defines
00026 
00027 #include "utilite/UDirectory.h"
00028 #include <string>
00029 
00035 class UFile
00036 {
00037 public:
00043         static bool exists(const std::string &filePath);
00044 
00050         static long length(const std::string &filePath);
00051 
00057         static int erase(const std::string &filePath);
00058 
00065         static int rename(const std::string &oldFilePath,
00066                                                   const std::string &newFilePath);
00067 
00073         static std::string getName(const std::string & filePath);
00074 
00075         static std::string getExtension(const std::string &filePath);
00076 
00077 public:
00082         UFile(const std::string & path) : path_(path) {}
00083         ~UFile() {}
00084 
00089         bool isValid() {return exists(path_);}
00090 
00095         bool exists() {return exists(path_);}
00096 
00101         long length() {return length(path_);}
00102 
00107         int rename(const std::string &newName)
00108         {
00109                 std::string ext = this->getExtension();
00110                 std::string newPath = UDirectory::getDir(path_) + std::string("/") + newName;
00111                 if(ext.size())
00112                 {
00113                         newPath += std::string(".") + getExtension(path_);
00114                 }
00115                 int result = rename(path_, newPath);
00116                 if(result == 0)
00117                 {
00118                         path_ = newPath;
00119                 }
00120                 return result;
00121         }
00126         std::string getName() {return getName(path_);}
00131         std::string getExtension() {return getExtension(path_);}
00132 
00133 private:
00134         std::string path_;
00135 };
00136 
00137 #endif


find_object_2d
Author(s): Mathieu Labbe
autogenerated on Thu Aug 27 2015 13:00:33