Added UFile::copy()

git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@909 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
matlabbe
2013-06-18 17:08:37 +00:00
parent 6c656e7c57
commit ffbf4c8ba3
2 changed files with 14 additions and 2 deletions
+4
View File
@@ -72,6 +72,8 @@ public:
static std::string getExtension(const std::string &filePath); static std::string getExtension(const std::string &filePath);
static void copy(const std::string & from, const std::string & to);
public: public:
/** /**
* Create a UFile object with path initialized to an existing file . * Create a UFile object with path initialized to an existing file .
@@ -128,6 +130,8 @@ public:
*/ */
std::string getExtension() {return getExtension(path_);} std::string getExtension() {return getExtension(path_);}
void copy(const std::string & to) {copy(path_, to);}
private: private:
std::string path_; std::string path_;
}; };
+10 -2
View File
@@ -57,13 +57,13 @@ long UFile::length(const std::string &filePath)
int UFile::erase(const std::string &filePath) int UFile::erase(const std::string &filePath)
{ {
return remove(filePath.c_str()); return std::remove(filePath.c_str());
} }
int UFile::rename(const std::string &oldFilePath, int UFile::rename(const std::string &oldFilePath,
const std::string &newFilePath) const std::string &newFilePath)
{ {
return rename(oldFilePath.c_str(), newFilePath.c_str()); return std::rename(oldFilePath.c_str(), newFilePath.c_str());
} }
std::string UFile::getName(const std::string & filePath) std::string UFile::getName(const std::string & filePath)
@@ -93,3 +93,11 @@ std::string UFile::getExtension(const std::string &filePath)
} }
return ""; return "";
} }
void UFile::copy(const std::string & from, const std::string & to)
{
std::ifstream src(from.c_str());
std::ofstream dst(to.c_str());
dst << src.rdbuf();
}