Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • km3py/jppy
  • hwarnhofer/jppy_hannes
2 results
Show changes
Showing
with 4985 additions and 0 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef __JLANG__JFILE__
#define __JLANG__JFILE__
#include <fcntl.h>
#include "JLang/JBinaryIO.hh"
#include "JLang/JAbstractFile.hh"
#include "JLang/JFileDescriptorMask.hh"
#include "JLang/JTimeval.hh"
#include <unistd.h>
/**
* \author mdejong
*/
namespace JLANG {}
namespace JPP { using namespace JLANG; }
namespace JLANG {
/**
* The JFile class extends the JAbstractFile class.
* This class implements the JBinaryInput and JBinaryOutput interfaces.
*/
class JFile :
public JAbstractFile,
public JBinaryInput,
public JBinaryOutput
{
public:
/**
* Default constructor.
*/
JFile() :
JAbstractFile(),
result(0)
{}
/**
* Constructor.
*
* \param file file descriptor
*/
JFile(const JAbstractFile& file) :
JAbstractFile(file),
result(1)
{}
/**
* Close file.
*/
void close()
{
if (fileDescriptor != FILE_CLOSED) {
::close(fileDescriptor);
fileDescriptor = FILE_CLOSED;
result = 0;
}
}
/**
* Read data from file.
*
* \param buffer buffer
* \param length number of bytes to read
* \return number of bytes read
*/
virtual int read(char* buffer, const int length)
{
return (result = ::read(fileDescriptor, buffer, length));
}
/**
* Write data to file.
*
* \param buffer buffer
* \param length number of bytes to write
* \return number of bytes written
*/
virtual int write(const char* buffer, const int length)
{
return (result = ::write(fileDescriptor, buffer, length));
}
/**
* Check availability of input.
* This method returns true if at least one byte can be read without blocking.
*
* \param timeout timeout
* \return true if ready to read; else false
*/
bool in_avail(JTimeval timeout = JTimeval::min()) const
{
return JFileDescriptorMask(*this).in_avail(timeout);
}
/**
* Check availability of output.
* This method returns true if at least one byte can be written without blocking.
*
* \param timeout timeout
* \return true if ready to write; else false
*/
bool out_avail(JTimeval timeout = JTimeval::min()) const
{
return JFileDescriptorMask(*this).out_avail(timeout);
}
/**
* Check status.
*
* \return true if last I/O operation successful; else false
*/
virtual bool good() const
{
return is_open() && !eof() && !bad();
}
/**
* Check status.
*
* \return true if last I/O operation caused logical error; else false
*/
virtual bool fail() const
{
return result == 0;
}
/**
* Check status.
*
* \return true if last I/O operation caused read/write error; else false
*/
virtual bool bad() const
{
return fail();
}
/**
* Check end of file.
*
* \return true if end of file; else false
*/
virtual bool eof() const
{
return result == EOF;
}
private:
int result;
};
}
#endif
This diff is collapsed.
#ifndef __JLANG__JFILESTREAM__
#define __JLANG__JFILESTREAM__
#include <istream>
#include <ostream>
#include "JLang/JFile.hh"
#include "JLang/JFileStreamBuffer.hh"
/**
* \author mdejong
*/
namespace JLANG {}
namespace JPP { using namespace JLANG; }
namespace JLANG {
/**
* Streaming of input.
*/
class JFileInputStream :
protected JFileInputStreamBuffer,
public std::istream
{
public:
/**
* Constructor.
*
* \param file file
* \param size size of internal buffer
*/
JFileInputStream(const JAbstractFile& file,
const std::size_t size = 65536) :
JFileInputStreamBuffer(file, size),
std::istream(this)
{}
};
/**
* Streaming of output.
*/
class JFileOutputStream :
protected JFileOutputStreamBuffer,
public std::ostream
{
public:
/**
* Constructor.
*
* \param file file
* \param size size of internal buffer
*/
JFileOutputStream(const JAbstractFile& file,
const std::size_t size = 65536) :
JFileOutputStreamBuffer(file, size),
std::ostream(this)
{}
};
/**
* Streaming of input and output.
*/
class JFileStream :
protected JFileStreamBuffer,
public std::iostream
{
public:
/**
* Constructor.
*
* \param in input file
* \param out output file
* \param size size of internal buffer
*/
JFileStream(const JAbstractFile& in,
const JAbstractFile& out,
const std::size_t size = 65536) :
JFileStreamBuffer (in, out, size),
std::iostream(this)
{}
};
}
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef __JLANG__JNULLTYPE__
#define __JLANG__JNULLTYPE__
/**
* \author mdejong
*/
namespace JLANG {}
namespace JPP { using namespace JLANG; }
namespace JLANG {
/**
* Auxiliary class for no type definition.
* This class can be used to terminate a type list, define a default template argument, etc.
*/
struct JNullType {};
}
#endif
This diff is collapsed.
This diff is collapsed.
#ifndef __JLANG__JOBJECTSTREAMIO__
#define __JLANG__JOBJECTSTREAMIO__
#include <fstream>
#include "JLang/JObjectIO.hh"
/**
* \author mdejong
*/
namespace JLANG {}
namespace JPP { using namespace JLANG; }
namespace JLANG {
/**
* Auxiliary base class for storing and loading a single object to and from an ASCII file, respectively.
* The implementation of this functionality is based on a static cast of
* the given template parameter (known as "curiously recurring template pattern").
*/
template<class T>
struct JObjectStreamIO {
/**
* Load from input file.
*
* \param file_name file name
*/
void load(const char* file_name)
{
JLANG::load<std::ifstream>(file_name, static_cast<T&>(*this));
}
/**
* Store to output file.
*
* \param file_name file name
*/
void store(const char* file_name) const
{
JLANG::store<std::ofstream>(file_name, static_cast<const T&>(*this));
}
};
}
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.