MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
file.cpp
1//=============================================================================================================
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "file.h"
40#include <fstream>
41
42#include <cstdio>
43
44//=============================================================================================================
45// USED NAMESPACES
46//=============================================================================================================
47
48using namespace UTILSLIB;
49
50//=============================================================================================================
51// DEFINE MEMBER METHODS
52//=============================================================================================================
53
54bool File::exists(const char* filePath)
55{
56 std::ifstream infile(filePath);
57 return infile.good();
58}
59
60//=============================================================================================================
61
62bool File::exists(const std::string& filePath)
63{
64 return exists(filePath.c_str());
65}
66
67//=============================================================================================================
68
69bool File::copy(const char* sourcePath, const char* destPath)
70{
71 if (!exists(sourcePath) || exists(destPath)){
72 return false;
73 }
74 std::ifstream source(sourcePath, std::ios::binary);
75 std::ofstream destination(destPath, std::ios::binary);
76
77 if(destination << source.rdbuf()){
78 return true;
79 } else {
80 return false;
81 }
82}
83
84//=============================================================================================================
85
86bool File::copy(const std::string& sourcePath, const std::string& destPath)
87{
88 return copy(sourcePath.c_str(), destPath.c_str());
89}
90
91//=============================================================================================================
92
93bool File::rename(const char* sourcePath, const char* destPath)
94{
95 if (!exists(sourcePath) || exists(destPath)){
96 return false;
97 }
98 return !std::rename(sourcePath, destPath); //std::rename returns 0 upon success
99}
100
101//=============================================================================================================
102
103bool File::rename(const std::string& sourcePath, const std::string& destPath)
104{
105 return rename(sourcePath.c_str(), destPath.c_str());
106}
107
108//=============================================================================================================
109
110bool File::remove(const char* filePath)
111{
112 if (!exists(filePath)){
113 return false;
114 }
115
116 return !std::remove(filePath); //std::remove returns 0 upon success
117}
118
119//=============================================================================================================
120
121bool File::remove(const std::string& filePath)
122{
123 return remove(filePath.c_str());
124}
125
126//=============================================================================================================
127
128bool File::create(const char *filePath)
129{
130 if (exists(filePath)){
131 return false;
132 }
133
134 std::ofstream a(filePath);
135
136 return exists(filePath);
137}
138
139//=============================================================================================================
140
141bool File::create(const std::string& filePath)
142{
143 return create(filePath.c_str());
144}
145
146//=============================================================================================================
147
148#ifdef QT_CORE_LIB // QString oveloads
149bool File::exists(const QString& filePath)
150{
151 return exists(filePath.toStdString().c_str());
152}
153
154//=============================================================================================================
155
156bool File::copy(const QString& sourcePath, const QString& destPath)
157{
158 return copy(sourcePath.toStdString().c_str(), destPath.toStdString().c_str());
159}
160
161//=============================================================================================================
162
163bool File::rename(const QString& sourcePath, const QString& destPath)
164{
165 return rename(sourcePath.toStdString().c_str(), destPath.toStdString().c_str());
166}
167
168//=============================================================================================================
169
170bool File::remove(const QString& filePath)
171{
172 return remove(filePath.toStdString().c_str());
173}
174
175//=============================================================================================================
176
177bool File::create(const QString& filePath)
178{
179 return create(filePath.toStdString().c_str());
180}
181#endif
static bool rename(const char *sourcePath, const char *destPath)
Definition file.cpp:93
static bool copy(const char *sourcePath, const char *destPath)
Definition file.cpp:69
static bool remove(const char *filePath)
Definition file.cpp:110
static bool exists(const char *filePath)
Definition file.cpp:54
static bool create(const char *filePath)
Definition file.cpp:128