initial cleanup of interface

This commit is contained in:
tqchen
2014-02-06 16:03:04 -08:00
parent 57fef8bc54
commit ee6a0c7f4a
5 changed files with 0 additions and 332 deletions

View File

@@ -1,52 +0,0 @@
#ifndef _XGBOOST_STREAM_H_
#define _XGBOOST_STREAM_H_
#include <cstdio>
/*!
* \file xgboost_stream.h
* \brief general stream interface
* \author Tianqi Chen: tianqi.tchen@gmail.com
*/
namespace xgboost{
namespace utils{
/*! \brief interface of stream I/O, used to serialize tensor data */
class IStream{
public:
/*!
* \brief read data from stream
* \param ptr pointer to memory buffer
* \param size size of block
* \return usually is the size of data readed
*/
virtual size_t Read( void *ptr, size_t size ) = 0;
/*!
* \brief write data to stream
* \param ptr pointer to memory buffer
* \param size size of block
*/
virtual void Write( const void *ptr, size_t size ) = 0;
/*! \brief virtual destructor */
virtual ~IStream( void ){}
};
/*! \brief implementation of file i/o stream */
class FileStream: public IStream{
private:
FILE *fp;
public:
FileStream( FILE *fp ){
this->fp = fp;
}
virtual size_t Read( void *ptr, size_t size ){
return fread( ptr, size, 1, fp );
}
virtual void Write( const void *ptr, size_t size ){
fwrite( ptr, size, 1, fp );
}
inline void Close( void ){
fclose( fp );
}
};
};
};
#endif

View File

@@ -1,58 +0,0 @@
#ifndef _XGBOOST_UTILS_H_
#define _XGBOOST_UTILS_H_
#ifdef _MSC_VER
#define fopen64 fopen
#else
// use 64 bit offset, either to include this header in the beginning, or
#ifdef _FILE_OFFSET_BITS
#if _FILE_OFFSET_BITS == 32
#warning "FILE OFFSET BITS defined to be 32 bit"
#endif
#endif
#ifdef __APPLE__
#define off64_t off_t
#define fopen64 fopen
#endif
#define _FILE_OFFSET_BITS 64
extern "C"{
#include <sys/types.h>
};
#include <cstdio>
#endif
#include <cstdio>
#include <cstdlib>
namespace utils{
inline void Error( const char *msg ){
fprintf( stderr, "%s\n",msg );
exit( -1 );
}
inline void Assert( bool exp ){
if( !exp ) error( "assert_error" );
}
inline void Assert( bool exp, const char *msg ){
if( !exp ) error( msg );
}
inline void Warning( const char *msg ){
fprintf( stderr, "warning:%s\n",msg );
}
inline FILE *FopenCheck( const char *fname , const char *flag ){
FILE *fp = fopen64( fname , flag );
if( fp == NULL ){
fprintf( stderr, "can not open file \"%s\"\n",fname );
exit( -1 );
}
return fp;
}
};
#endif