code format

This commit is contained in:
2022-12-14 14:13:52 +03:00
parent 430a41fefc
commit c2b8a8d6da
297 changed files with 27331 additions and 24162 deletions

View File

@@ -5,22 +5,22 @@
* \~russian Локальный файл
*/
/*
PIP - Platform Independent Primitives
File
Ivan Pelipenko peri4ko@yandex.ru
PIP - Platform Independent Primitives
File
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIFILE_H
@@ -34,11 +34,10 @@
//! \~\brief
//! \~english Local file.
//! \~russian Локальный файл.
class PIP_EXPORT PIFile: public PIIODevice
{
class PIP_EXPORT PIFile: public PIIODevice {
PIIODEVICE(PIFile, "file");
public:
//! \~english Constructs file with empty path
//! \~russian Создает файл с пустым путём
explicit PIFile();
@@ -55,20 +54,23 @@ public:
//! \~english Local file or directory information.
//! \~russian Информация о локальном файле или директории.
struct PIP_EXPORT FileInfo {
//! \~english Constructs %FileInfo with path "path_". No information gathered
//! \~russian Создает %FileInfo с путём "path_". Информация не собирается
FileInfo(const PIString & path_ = PIString()) {path = path_; size = 0; id_group = id_user = 0;}
FileInfo(const PIString & path_ = PIString()) {
path = path_;
size = 0;
id_group = id_user = 0;
}
//! \~english Type flags
//! \~russian Флаги типа
enum Flag {
File /*! \~english File \~russian Файл */ = 0x01,
Dir /*! \~english Directory \~russian Директория */ = 0x02,
Dot /*! \~english '.', current directory \~russian '.', текущая директория */ = 0x04,
DotDot /*! \~english '..', parent directory \~russian '..', родительская директория */ = 0x08,
SymbolicLink /*! \~english Symbolic link \~russian Символическая ссылка */ = 0x10,
Hidden /*! \~english Hidden \~russian Скрытый */ = 0x20
File /*! \~english File \~russian Файл */ = 0x01,
Dir /*! \~english Directory \~russian Директория */ = 0x02,
Dot /*! \~english '.', current directory \~russian '.', текущая директория */ = 0x04,
DotDot /*! \~english '..', parent directory \~russian '..', родительская директория */ = 0x08,
SymbolicLink /*! \~english Symbolic link \~russian Символическая ссылка */ = 0x10,
Hidden /*! \~english Hidden \~russian Скрытый */ = 0x20
};
typedef PIFlags<FileInfo::Flag> Flags;
@@ -78,16 +80,23 @@ public:
//! \~russian Разрешения локального файла или директории.
struct PIP_EXPORT Permissions {
Permissions(uchar r = 0): raw(r) {}
Permissions(bool r, bool w, bool e): raw(0) {read = r; write = w; exec = e;}
Permissions(bool r, bool w, bool e): raw(0) {
read = r;
write = w;
exec = e;
}
//! \~english Returns as string (from "---" to "rwx")
//! \~russian Возвращает как строку (от "---" до "rwx")
PIString toString() const {return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-");}
PIString toString() const { return PIString(read ? "r" : "-") + PIString(write ? "w" : "-") + PIString(exec ? "x" : "-"); }
//! \~english Convertion to \c int
//! \~russian Преобразование в \c int
operator int() const {return raw;}
Permissions & operator =(int v) {raw = v; return *this;}
operator int() const { return raw; }
Permissions & operator=(int v) {
raw = v;
return *this;
}
union {
uchar raw;
struct {
@@ -97,7 +106,7 @@ public:
};
};
};
//! \~english Path
//! \~russian Путь
PIString path;
@@ -137,7 +146,7 @@ public:
//! \~english Permissions for other
//! \~russian Разрешения для остальных
Permissions perm_other;
//! \~english Returns name, without directory
//! \~russian Возвращает имя, без директории
@@ -157,43 +166,42 @@ public:
//! \~english Returns if it`s directory
//! \~russian Возвращает директория ли это
bool isDir() const {return flags[Dir];}
bool isDir() const { return flags[Dir]; }
//! \~english Returns if it`s file
//! \~russian Возвращает файл ли это
bool isFile() const {return flags[File];}
bool isFile() const { return flags[File]; }
//! \~english Returns if it`s symbolic link
//! \~russian Возвращает символическая ссылка ли это
bool isSymbolicLink() const {return flags[SymbolicLink];}
bool isSymbolicLink() const { return flags[SymbolicLink]; }
//! \~english Returns if Hidden flag set
//! \~russian Возвращает установлен ли флаг Hidden
bool isHidden() const {return flags[Hidden];}
bool isHidden() const { return flags[Hidden]; }
};
//! \~english Open temporary file with open mode "mode"
//! \~russian Открывает временный файл с режимом открытия "mode"
bool openTemporary(PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
//! \~english Immediate write all buffered data to disk
//! \~russian Немедленно записывает все буферизированные данные на диск
void flush() override;
//! \~english Move read/write position to "position"
//! \~russian Перемещает позицию чтения/записи на "position"
void seek(llong position);
//! \~english Move read/write position to the begin of the file
//! \~russian Перемещает позицию чтения/записи на начало файла
void seekToBegin();
//! \~english Move read/write position to the end of the file
//! \~russian Перемещает позицию чтения/записи на конец файла
void seekToEnd();
//! \~english Move read/write position to text line number "line" beginning
//! \~russian Перемещает позицию чтения/записи на начало текстовой строки номер "line"
void seekToLine(llong line);
@@ -201,47 +209,47 @@ public:
//! \~english Skip "bytes" bytes (move position next to "bytes" bytes)
//! \~russian Пропускает "bytes" байт (перемещает позицию на "bytes" байт вперёд)
void skip(llong bytes);
//! \~english Read one char and return it
//! \~russian Читает один байт и возвращает его
char readChar();
//! \~english Read all file content to "data" and return readed bytes count. Position leaved unchanged
//! \~russian Читает всё содержимое файла в "data" и возвращает количество прочитанных байт. Позиция остаётся неизменной
llong readAll(void * data);
//! \~english Read all file content to byte array and return it. Position leaved unchanged
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
PIByteArray readAll(bool forceRead = false);
//! \~english Set file path to "path" and reopen file if need
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
void setPath(const PIString & path);
//! \~english Returns file size in bytes
//! \~russian Возвращает размер файла в байтах
llong size() const;
ssize_t bytesAvailable() const override {return size() - pos();}
ssize_t bytesAvailable() const override { return size() - pos(); }
//! \~english Returns read/write position
//! \~russian Возвращает позицию чтения/записи
llong pos() const;
//! \~english Returns if position is at the end of file
//! \~russian Возвращает достигнут ли конец файла
bool isEnd() const;
//! \~english Returns if file is empty
//! \~russian Возвращает пустой ли файл
bool isEmpty() const {return (size() <= 0);}
bool isEmpty() const { return (size() <= 0); }
//! \~english Returns \a PIFile::FileInfo of current file
//! \~russian Возвращает \a PIFile::FileInfo текущего файла
FileInfo fileInfo() const {return fileInfo(path());}
FileInfo fileInfo() const { return fileInfo(path()); }
//! \~english Write size and content of "v" (serialize)
//! \~russian Пишет в файл размер и содержимое "v" (сериализация)
@@ -250,48 +258,48 @@ public:
//! \~english Read size of byte array and it content (deserialize)
//! \~russian Читает из файла размер байтового массива и его содержимое (десериализация)
PIByteArray get();
EVENT_HANDLER(void, clear);
EVENT_HANDLER(void, remove);
EVENT_HANDLER1(void, resize, llong, new_size) {resize(new_size, 0);}
EVENT_HANDLER1(void, resize, llong, new_size) { resize(new_size, 0); }
EVENT_HANDLER2(void, resize, llong, new_size, uchar, fill);
//! \~english Returns if file with path "path" exists
//! \~russian Возвращает существует ли файл с путём "path"
static bool isExists(const PIString & path);
//! \~english Remove file with path "path" and returns if remove successful
//! \~russian Удаляет файл с путём "path" и возвращает успешность операции
static bool remove(const PIString & path);
//! \~english Rename file with path "from" to path "to" and returns if rename successful
//! \~russian Переименовывает файл с путём "path" на "to" и возвращает успешность операции
static bool rename(const PIString & from, const PIString & to);
//! \~english Returns \a PIFile::FileInfo of file or dir with path "path"
//! \~russian Возвращает \a PIFile::FileInfo файла или директории с путём "path"
static FileInfo fileInfo(const PIString & path);
//! \~english Apply "info" parameters to file or dir with path "path"
//! \~russian Применяет параметры "info" к файлу или директории с путём "path"
static bool applyFileInfo(const PIString & path, const FileInfo & info);
//! \~english Apply "info" parameters to file or dir with path "info".path
//! \~russian Применяет параметры "info" к файлу или директории с путём "info".path
static bool applyFileInfo(const FileInfo & info) {return applyFileInfo(info.path, info);}
//! \handlers
//! \{
static bool applyFileInfo(const FileInfo & info) { return applyFileInfo(info.path, info); }
//! \handlers
//! \{
//! \fn void clear()
//! \~english Clear content of file
//! \~russian Очищает содержимое файла
//! \fn void resize(llong new_size)
//! \~english Resize file to "new_size" with null-byte fill
//! \~russian Изменяет размер файла на "new_size" с заполнением нулевыми байтами
//! \fn void resize(llong new_size, uchar fill)
//! \~english Resize file to "new_size" with "fill" fill
//! \~russian Изменяет размер файла на "new_size" с заполнением байтами "fill"
@@ -305,7 +313,7 @@ public:
//! \{
#ifdef DOXYGEN
#endif
//! \}
//! \}
protected:
PIString constructFullPathDevice() const override;
@@ -316,28 +324,26 @@ protected:
ssize_t writeDevice(const void * data, ssize_t max_size) override;
bool openDevice() override;
bool closeDevice() override;
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Sequential | PIIODevice::Reliable;}
DeviceInfoFlags deviceInfoFlags() const override { return PIIODevice::Sequential | PIIODevice::Reliable; }
private:
PIString strType(const PIIODevice::DeviceMode type);
PRIVATE_DECLARATION(PIP_EXPORT)
int fdi = -1;
int fdi = -1;
llong _size = -1;
PIString prec_str;
};
//! \relatesalso PICout
//! \~english Output operator to \a PICout
//! \~russian Оператор вывода в \a PICout
inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
inline PICout operator<<(PICout s, const PIFile::FileInfo & v) {
s.saveAndSetControls(0);
s << "FileInfo(\"" << v.path << "\", " << PIString::readableSize(v.size) << ", "
<< v.perm_user.toString() << " " << v.perm_group.toString() << " " << v.perm_other.toString() << ", "
<< v.time_access.toString() << ", " << v.time_modification.toString()
<< ", 0x" << PICoutManipulators::Hex << v.flags << ")";
s << "FileInfo(\"" << v.path << "\", " << PIString::readableSize(v.size) << ", " << v.perm_user.toString() << " "
<< v.perm_group.toString() << " " << v.perm_other.toString() << ", " << v.time_access.toString() << ", "
<< v.time_modification.toString() << ", 0x" << PICoutManipulators::Hex << v.flags << ")";
s.restoreControls();
return s;
}
@@ -347,8 +353,8 @@ inline PICout operator <<(PICout s, const PIFile::FileInfo & v) {
//! \~english Store operator.
//! \~russian Оператор сохранения.
BINARY_STREAM_WRITE(PIFile::FileInfo) {
s << v.path << v.size << v.time_access << v.time_modification <<
v.flags << v.id_user << v.id_group << v.perm_user.raw << v.perm_group.raw << v.perm_other.raw;
s << v.path << v.size << v.time_access << v.time_modification << v.flags << v.id_user << v.id_group << v.perm_user.raw
<< v.perm_group.raw << v.perm_other.raw;
return s;
}
@@ -356,8 +362,8 @@ BINARY_STREAM_WRITE(PIFile::FileInfo) {
//! \~english Restore operator.
//! \~russian Оператор извлечения.
BINARY_STREAM_READ(PIFile::FileInfo) {
s >> v.path >> v.size >> v.time_access >> v.time_modification >>
v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >> v.perm_group.raw >> v.perm_other.raw;
s >> v.path >> v.size >> v.time_access >> v.time_modification >> v.flags >> v.id_user >> v.id_group >> v.perm_user.raw >>
v.perm_group.raw >> v.perm_other.raw;
return s;
}