DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
File.hpp
Go to the documentation of this file.
1/*
2 * File.h
3 * OksSystem
4 *
5 * Created by Matthias Wiesmann on 04.01.05.
6 * Copyright 2005 CERN. All rights reserved.
7 *
8 */
9
10#ifndef OKSSYSTEM_FILE
11#define OKSSYSTEM_FILE
12
13#include <string>
14#include <vector>
15
16#include <sys/types.h>
17#include <sys/stat.h>
18
19#include "okssystem/User.hpp"
20
21namespace OksSystem {
22
32 class File {
33public:
34 typedef std::vector<OksSystem::File> file_list_t ;
35protected:
36 std::string m_full_name ;
37 void set_name(const std::string &name);
38 static const char * const HUMAN_SIZE_STR[] ;
39 static const char * const HUMAN_OPEN_STR[] ;
40 static const int KILOBYTE ;
41 static int unit(int u) ;
42 mode_t get_mode() const ;
43 static const char * const FILE_COMMAND_PATH ;
44public:
45 static const char * const FILE_FLAG_STR ;
46 static const char * const FILE_PROTOCOL ;
47
48 static std::string protocol(const std::string &url) throw();
49 static std::string extension(const std::string &url) throw();
50 static std::string uri(const std::string &url) throw() ;
51 static std::string short_name(const std::string &url) throw();
52 static int depth(const std::string &path) throw() ;
53
54 static std::string first_line(const std::string &text);
55
56 static File from_url(const std::string &url);
57
58 static std::string working_directory() ;
59 static void working_directory(const File &dir);
60 static std::string expand_home(const std::string path) ;
61 static std::string pretty_permissions(mode_t permissions);
62 static std::string to_string(mode_t permissions) throw() ;
63 static std::string pretty_open_flag(int flags) ;
64 static std::string pretty_size(size_t size, bool cut_small);
65
66 File(const std::string &name);
67 File(const char* name) ;
68 File(const File& other) ;
69 virtual ~File() {}
70 operator std::string() const throw() ;
71 operator const char* () const throw() ;
72 operator bool() const throw() ;
73 bool equals(const File &other) const throw() ;
74 operator size_t() const ;
75
76 const std::string &full_name() const throw() ;
77 const char* c_full_name() const throw() ;
78 std::string short_name() const throw() ;
79 std::string parent_name() const throw() ;
80 std::string extension() const throw();
81 int depth() const throw() ;
82
83 OksSystem::File parent() const ;
84 OksSystem::File child(const std::string &name) const ;
85 OksSystem::File temporary(const std::string &prefix) const ;
86
87 bool exists() const throw() ;
88 mode_t permissions() const ;
89 std::string pretty_permissions() const ;
90 size_t size() const ;
91 uid_t owner_id() const ;
92 User owner() const ;
93 gid_t group() const ;
94 bool is_regular() const ;
95 bool is_directory() const ;
96 bool is_fifo() const ;
97 std::string file_type() const ;
98 file_list_t directory() const ;
99
100 void unlink() const ;
101 void rmdir() const ;
102
103 void remove() const ;
104 void rename(const File &other) const ;
105 void permissions(mode_t permissions) const ;
106 void make_dir(mode_t permissions) const ;
107 void make_path(mode_t permissions) const ;
108 void make_fifo(mode_t permissions) const ;
109
110 void ensure_path(mode_t permissions) const ;
111
112 std::istream* input() const ;
113 std::ostream* output(bool append=false) const ;
114 } ; // File
115} // OksSystem
116
117std::ostream& operator<<(std::ostream& stream, const OksSystem::File& file);
118bool operator ==(const OksSystem::File &a, const OksSystem::File &b) throw();
119bool operator !=(const OksSystem::File &a, const OksSystem::File &b) throw();
120
121
122#endif
123
124
125
Wrapper for file operations.
Definition File.hpp:32
static std::string protocol(const std::string &url)
extracts the protocol part of an url *‍/
Definition File.cpp:66
static const int KILOBYTE
number of bytes in a kilobyte *‍/
Definition File.hpp:40
std::string short_name() const
short name for file *‍/
Definition File.cpp:419
void unlink() const
deletes (unlinks) file *‍/
Definition File.cpp:646
bool is_directory() const
is the file a regular file *‍/
Definition File.cpp:584
void make_path(mode_t permissions) const
creates a full path *‍/
Definition File.cpp:761
static std::string uri(const std::string &url)
extracts the local path of an url *‍/
Definition File.cpp:101
static const char *const FILE_PROTOCOL
string for the file protocol *‍/
Definition File.hpp:46
User owner() const
owner of the file *‍/
Definition File.cpp:550
OksSystem::File parent() const
parent of the current file *‍/
Definition File.cpp:446
void rmdir() const
deletes directory *‍/
Definition File.cpp:652
file_list_t directory() const
list of file in directory *‍/
Definition File.cpp:614
std::string extension() const
extension for file *‍/
Definition File.cpp:436
mode_t permissions() const
permissions for the file *‍/
Definition File.cpp:500
std::istream * input() const
returns an input stream from the file*‍/
Definition File.cpp:815
std::string parent_name() const
path of directory containing file *‍/
Definition File.cpp:427
File(const std::string &name)
Definition File.cpp:296
static std::string pretty_open_flag(int flags)
pretty prints open flags *‍/
Definition File.cpp:227
static File from_url(const std::string &url)
build a file out of an URL *‍/
Definition File.cpp:151
static const char *const HUMAN_OPEN_STR[]
strings for pretty printing open flags *‍/
Definition File.hpp:36
std::string file_type() const
type of the file *‍/
Definition File.cpp:600
int depth() const
depth of the file *‍/
Definition File.cpp:440
static std::string first_line(const std::string &text)
extracts the first line of a text *‍/
Definition File.cpp:139
size_t size() const
size of file *‍/
Definition File.cpp:530
static int unit(int u)
calculates the value of a computer unit of order n (i.e KB,GB, etc *‍/
Definition File.cpp:256
static const char *const FILE_COMMAND_PATH
Definition File.hpp:43
static std::string to_string(mode_t permissions)
converts permission to string *‍/
Definition File.cpp:518
void ensure_path(mode_t permissions) const
creates the parent path *‍/
Definition File.cpp:776
void rename(const File &other) const
rename or moves the file *‍/
Definition File.cpp:686
void remove() const
recursively delete files and directories *‍/
Definition File.cpp:665
OksSystem::File temporary(const std::string &prefix) const
Definition File.cpp:455
static const char *const HUMAN_SIZE_STR[]
strings for pretty printing file sizes *‍/
Definition File.hpp:35
const char * c_full_name() const
Definition File.cpp:412
static std::string working_directory()
current directory of process *‍/
Definition File.cpp:160
void make_dir(mode_t permissions) const
creates a directory *‍/
Definition File.cpp:717
static std::string pretty_size(size_t size, bool cut_small)
pretty prints a file size *‍/
Definition File.cpp:271
uid_t owner_id() const
owner id of file *‍/
Definition File.cpp:542
void make_fifo(mode_t permissions) const
creates a FIFO (named pipe) *‍/
Definition File.cpp:786
bool equals(const File &other) const
compare two files *‍/
Definition File.cpp:347
OksSystem::File child(const std::string &name) const
named child of the current directory *‍/
Definition File.cpp:450
void set_name(const std::string &name)
sets the name of the file *‍/
Definition File.cpp:380
static const char *const FILE_FLAG_STR
column headers for display of permissions *‍/
Definition File.hpp:45
gid_t group() const
group of file *‍/
Definition File.cpp:559
const std::string & full_name() const
full name for file *‍/
Definition File.cpp:406
static std::string expand_home(const std::string path)
resolve home directory *‍/
Definition File.cpp:185
std::ostream * output(bool append=false) const
returns an output stream to the file*‍/
Definition File.cpp:832
virtual ~File()
Definition File.hpp:69
mode_t get_mode() const
get mode associated with file (permission + type) *‍/
Definition File.cpp:485
std::string m_full_name
full name (path) of the file *‍/
Definition File.hpp:36
bool is_fifo() const
is the file a named pipe *‍/
Definition File.cpp:594
std::vector< OksSystem::File > file_list_t
Definition File.hpp:34
bool is_regular() const
is the file a directory *‍/
Definition File.cpp:573
std::string pretty_permissions() const
pretty permissions for the file *‍/
Definition File.cpp:509