radarlib 1.4.6
io.hpp
Go to the documentation of this file.
1/*
2 * Radar Library
3 *
4 * Copyright (C) 2009-2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Author: Guido Billi <guidobilli@gmail.com>
21 */
22
26
27#ifndef __RADAR_IO_HPP__
28#define __RADAR_IO_HPP__
29
30#include <string>
31#include <vector>
32#include <fstream>
33#include <stdexcept>
34
35#include <radarlib/defs.h>
36
37namespace Radar {
38
39/*===========================================================================*/
40
46class RADAR_API FileSystem
47{
48public:
54 static bool fileExists (const std::string& path);
60 static bool dirExists (const std::string& path);
66 static void changeDir (const std::string& path);
71 static std::string getCurrentDir ();
78 static void mkDirTree (const std::string& path);
84 static void rmDirTree (const std::string& path);
92 static void listFiles(std::vector<std::string>& result, const std::string& path, bool completePath = false);
100 static void listDirs(std::vector<std::string>& result, const std::string& path, bool completePath = false);
106 static void createFile(const std::string& path);
113 static void createFile(const std::string& path, const std::string& msg);
117 static size_t getFileSize(const std::string& path);
118};
119
125class RADAR_API Path
126{
127public:
133 static std::string getBasePath(const std::string& path);
139 static std::string getFileName(const std::string& path);
145 static std::string getFileExt(const std::string& path);
152 static std::string changeExt(const std::string& path, const std::string& newext);
158 static std::string removeExt(const std::string& path);
159
160};
161
162/*===========================================================================*/
163
164}
165
166#endif
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
FileSystem class.
Definition io.hpp:47
static bool fileExists(const std::string &path)
Check the existence of a file.
static void listFiles(std::vector< std::string > &result, const std::string &path, bool completePath=false)
Get the list of all the files in a directory.
static bool dirExists(const std::string &path)
Check the existence of a directory.
static void listDirs(std::vector< std::string > &result, const std::string &path, bool completePath=false)
Get the list of all the direct sub directories of a specified directory.
static void createFile(const std::string &path)
Touch a file like unix system command 'touch'.
Definition io.cpp:499
static void changeDir(const std::string &path)
Change the current working directory.
static void rmDirTree(const std::string &path)
Remove a directory and all its sub directories.
static void mkDirTree(const std::string &path)
Create a directory and all its parent directories if they don't exist If the directory already exists...
static std::string getCurrentDir()
Get the current working directory.
static size_t getFileSize(const std::string &path)
Get the size in bytes of the given file.
File path manipulation routines.
Definition io.hpp:126
static std::string changeExt(const std::string &path, const std::string &newext)
Returns the path indicated after changing che extension.
Definition io.cpp:560
static std::string getBasePath(const std::string &path)
Extract the parent directory path of a file or directory indicated.
Definition io.cpp:532
static std::string getFileName(const std::string &path)
Extract the file or directory name from a generic path.
Definition io.cpp:540
static std::string getFileExt(const std::string &path)
Extract the directory or file exstension without the dot.
Definition io.cpp:552
static std::string removeExt(const std::string &path)
Remove the extension from a file or directory path.
Definition io.cpp:568
Internal library macros.