23.06.2014 - PICodeParser, PICodeInfo, PIConnection, new binary "pip_cmg"

This commit is contained in:
peri4
2014-06-23 21:08:27 +04:00
parent 2e5e75c4c4
commit 15a20d40ac
56 changed files with 10315 additions and 760 deletions

85
pidir.h
View File

@@ -21,26 +21,40 @@
#define PIDIR_H
#include "pifile.h"
#include "pistring.h"
#if !defined(WINDOWS) && !defined(ANDROID)
#ifdef ANDROID
# include <sys/dirent.h>
#if !defined(ANDROID)
#ifdef WINDOWS
# undef S_IFDIR
# undef S_IFREG
# undef S_IFLNK
# undef S_IFBLK
# undef S_IFCHR
# undef S_IFSOCK
# define S_IFDIR 0x01
# define S_IFREG 0x02
# define S_IFLNK 0x04
# define S_IFBLK 0x08
# define S_IFCHR 0x10
# define S_IFSOCK 0x20
#else
# include <sys/dir.h>
# ifdef ANDROID
# include <sys/dirent.h>
# else
# include <sys/dir.h>
# endif
# include <sys/stat.h>
#endif
#include <sys/stat.h>
#define S_IFHDN 0x40
class PIP_EXPORT PIDir
{
public:
PIDir();
PIDir(const PIString & dir);
~PIDir() {close();}
PIDir(const PIString & dir = PIString());
PIDir(const PIFile & file);
struct DirEntry {
DirEntry() {;}
DirEntry(const PIString & name_, const int & mode_, const int & size_) {
name = name_; mode = mode_; size = size_;}
DirEntry(const PIString & name_ = PIString(), int mode_ = 0, int size_ = 0) {
name = name_; mode = mode_; size = size_;
}
PIString name;
int mode;
@@ -52,41 +66,62 @@ public:
bool isBlockDevice() const {return (mode & S_IFBLK);}
bool isCharacterDevice() const {return (mode & S_IFCHR);}
bool isSocket() const {return (mode & S_IFSOCK);}
bool isHidden() const {return (mode & S_IFHDN);}
};
bool isExists() const {return (dir_ != 0);}
bool isAbsolute() const {if (path_.size() == 0) return false; return (path_[0] == separator);}
bool isExists() const {return PIDir::isExists(path_);}
bool isAbsolute() const;
bool isRelative() const {return !isAbsolute();}
const PIString & path() const {return path_;}
PIString absolutePath() const;
PIDir & cleanPath();
PIDir cleanedPath() {PIDir d(path_); d.cleanPath(); return d;}
PIString absolutePath();
bool mkDir(bool withParents = true);
PIDir cleanedPath() const {PIDir d(path_); d.cleanPath(); return d;}
PIDir & setDir(const PIString & path);
bool setCurrent() {return PIDir::setCurrent(path_);}
PIVector<DirEntry> entries();
bool make(bool withParents = true);
bool remove() {return PIDir::remove(path_);}
bool rename(const PIString & new_name) {if (!PIDir::rename(path_, new_name)) return false; path_ = new_name; return true;}
PIDir & cd(const PIString & path);
PIDir & up() {return cd("..");}
bool operator ==(const PIDir & d) const;
bool operator !=(const PIDir & d) const {return !((*this) == d);}
static const PIChar separator;
static PIDir current();
static PIDir home();
static PIDir temporary();
static bool mkDir(const PIString & path, bool withParents = true);
static bool rmDir(const PIString & path);
static bool isExists(const PIString & path) {return PIDir(path).isExists();}
//static bool rmDir(const PIString & path);
static bool isExists(const PIString & path);
static bool make(const PIString & path, bool withParents = true);
static bool remove(const PIString & path) {return removeDir(path);}
static bool rename(const PIString & path, const PIString & new_name) {return PIDir::renameDir(path, new_name);}
static bool setCurrent(const PIString & path);
static bool setCurrent(const PIDir & dir) {return setCurrent(dir.path_);}
private:
bool open();
bool close();
static bool makeDir(const PIString & path);
static bool removeDir(const PIString & path);
static bool renameDir(const PIString & path, const PIString & new_name);
PIString path_;
DIR * dir_;
};
inline bool operator <(const PIDir::DirEntry & v0, const PIDir::DirEntry & v1) {return (v0.name < v1.name);}
inline bool operator >(const PIDir::DirEntry & v0, const PIDir::DirEntry & v1) {return (v0.name > v1.name);}
inline bool operator ==(const PIDir::DirEntry & v0, const PIDir::DirEntry & v1) {return (v0.name == v1.name);}
inline bool operator !=(const PIDir::DirEntry & v0, const PIDir::DirEntry & v1) {return (v0.name != v1.name);}
inline PICout operator <<(PICout s, const PIDir & v) {s.setControl(0, true); s << "PIDir(\"" << v.path() << "\")"; s.restoreControl(); return s;}
inline PICout operator <<(PICout s, const PIDir::DirEntry & v) {s.setControl(0, true); s << "DirEntry(\"" << v.name << "\", " << v.size << " b, " << PIString::fromNumber(v.mode, 16) << ")"; s.restoreControl(); return s;}
#endif
#endif // PIDIR_H