All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreFile.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreFile.h
thread-safe File object
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library 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 2.1 of the License, or (at your option) any later version.
This library 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 library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QOREFILE_H
#define _QORE_QOREFILE_H
#include <fcntl.h>
#include <sys/file.h>
#include <unistd.h>
#include <string>
class QoreTermIOS;
class Queue;
class QoreFile {
private:
struct qore_qf_private *priv;
protected:
DLLLOCAL QoreFile(const QoreFile&);
DLLLOCAL QoreFile& operator=(const QoreFile&);
public:
DLLEXPORT QoreFile(const QoreEncoding *cs = QCS_DEFAULT);
DLLEXPORT ~QoreFile();
DLLEXPORT int open(const char *fn, int flags = O_RDONLY, int mode = 0777, const QoreEncoding *cs = QCS_DEFAULT);
DLLEXPORT int open2(ExceptionSink *xsink, const char *fn, int flags = O_RDONLY, int mode = 0777, const QoreEncoding *cs = QCS_DEFAULT);
DLLEXPORT int close();
DLLEXPORT void setEncoding(const QoreEncoding *cs);
DLLEXPORT const QoreEncoding *getEncoding() const;
DLLEXPORT int sync();
DLLEXPORT QoreStringNode* readLine(ExceptionSink* xsink);
DLLEXPORT QoreStringNode* readLine(bool incl_eol, ExceptionSink* xsink);
DLLEXPORT int readLine(QoreString &str);
DLLEXPORT int readLine(QoreString &str, bool incl_eol);
DLLEXPORT QoreStringNode* readUntil(const char* bytes, bool incl_bytes, ExceptionSink* xsink);
DLLEXPORT int readUntil(char byte, QoreString& str, bool incl_bytes = true);
DLLEXPORT int readUntil(const char* bytes, QoreString& str, bool incl_bytes = true);
DLLEXPORT int write(const QoreString *str, ExceptionSink *xsink);
DLLEXPORT int write(const BinaryNode *b, ExceptionSink *xsink);
DLLEXPORT int write(const void *data, qore_size_t len, ExceptionSink *xsink);
DLLEXPORT int writei1(char i, ExceptionSink *xsink);
DLLEXPORT int writei2(short i, ExceptionSink *xsink);
DLLEXPORT int writei4(int i, ExceptionSink *xsink);
DLLEXPORT int writei8(int64 i, ExceptionSink *xsink);
DLLEXPORT int writei2LSB(short i, ExceptionSink *xsink);
DLLEXPORT int writei4LSB(int i, ExceptionSink *xsink);
DLLEXPORT int writei8LSB(int64 i, ExceptionSink *xsink);
DLLEXPORT int readu1(unsigned char *val, ExceptionSink *xsink);
DLLEXPORT int readu2(unsigned short *val, ExceptionSink *xsink);
DLLEXPORT int readu4(unsigned int *val, ExceptionSink *xsink);
DLLEXPORT int readu2LSB(unsigned short *val, ExceptionSink *xsink);
DLLEXPORT int readu4LSB(unsigned int *val, ExceptionSink *xsink);
DLLEXPORT int readi1(char *val, ExceptionSink *xsink);
DLLEXPORT int readi2(short *val, ExceptionSink *xsink);
DLLEXPORT int readi4(int *val, ExceptionSink *xsink);
DLLEXPORT int readi8(int64 *val, ExceptionSink *xsink);
DLLEXPORT int readi2LSB(short *val, ExceptionSink *xsink);
DLLEXPORT int readi4LSB(int *val, ExceptionSink *xsink);
DLLEXPORT int readi8LSB(int64 *val, ExceptionSink *xsink);
DLLEXPORT QoreStringNode *read(qore_offset_t size, ExceptionSink *xsink);
DLLEXPORT int read(QoreString &str, qore_offset_t size, ExceptionSink *xsink);
DLLEXPORT BinaryNode *readBinary(qore_offset_t size, ExceptionSink *xsink);
DLLEXPORT int readBinary(BinaryNode &b, qore_offset_t size, ExceptionSink *xsink);
DLLEXPORT QoreStringNode *read(qore_offset_t size, int timeout_ms, ExceptionSink *xsink);
DLLEXPORT BinaryNode *readBinary(qore_offset_t size, int timeout_ms, ExceptionSink *xsink);
DLLEXPORT qore_size_t setPos(qore_size_t pos);
DLLEXPORT qore_size_t getPos();
DLLEXPORT qore_size_t getPos() const;
DLLEXPORT QoreStringNode *getchar();
DLLEXPORT QoreStringNode *getchar(ExceptionSink *xsink);
DLLEXPORT std::string getFileNameStr() const;
DLLEXPORT QoreStringNode* getFileName() const;
#if (!defined _WIN32 && !defined __WIN32__) || defined __CYGWIN__
DLLEXPORT int chown(uid_t owner, gid_t group, ExceptionSink *xsink);
DLLEXPORT int lockBlocking(struct flock &fl, ExceptionSink *xsink);
DLLEXPORT int lock(const struct flock &fl, ExceptionSink *xsink);
DLLEXPORT int getLockInfo(struct flock &fl, ExceptionSink *xsink);
#endif
DLLEXPORT bool isDataAvailable(int timeout_ms, ExceptionSink *xsink) const;
DLLEXPORT QoreListNode *stat(ExceptionSink *xsink) const;
DLLEXPORT QoreHashNode *hstat(ExceptionSink *xsink) const;
DLLEXPORT QoreHashNode *statvfs(ExceptionSink *xsink) const;
#if 0
DLLEXPORT int preallocate(fstore_t &fs, ExceptionSink *xsink);
#endif
DLLEXPORT int getFD() const;
DLLEXPORT bool isOpen() const;
DLLEXPORT bool isTty() const;
DLLLOCAL int setTerminalAttributes(int action, QoreTermIOS *ios, ExceptionSink *xsink) const;
DLLLOCAL int getTerminalAttributes(QoreTermIOS *ios, ExceptionSink *xsink) const;
// NOTE: QoreFile::makeSpecial() can only be called right after the constructor (private API)
DLLLOCAL void makeSpecial(int sfd);
DLLLOCAL void setEventQueue(Queue *cbq, ExceptionSink *xsink);
DLLLOCAL void cleanup(ExceptionSink *xsink);
};
class QoreFileHelper : QorePrivateObjectAccessHelper {
public:
DLLEXPORT QoreFileHelper(QoreObject* obj, ExceptionSink* xsink);
DLLEXPORT ~QoreFileHelper();
DLLEXPORT QoreFile* operator*() const;
DLLEXPORT QoreFile* operator->() const;
};
#endif // _QORE_QOREFILE_H