30 #ifndef GENAPI_FILESTREAM_H_ 31 #define GENAPI_FILESTREAM_H_ 60 #if defined (_MSC_VER) 66 # if defined(GENICAM_FORCE_AUTO_IMPLIB) || (!defined(GENICAM_NO_AUTO_IMPLIB) && !defined(GENAPI_EXPORTS)) 67 # if defined (_WIN32) && defined (_MT ) 68 # pragma comment(lib, LIB_NAME( "GenApi" )) 70 # error Invalid configuration 76 #if defined (_MSC_VER) 77 # pragma warning(push) 78 # pragma warning (disable: 4251) // class 'GenApi::CPointer<T>' needs to have dll-interface to be used by clients of class 'GenICam::FileProtocolAdapter' 90 virtual bool openFile(
const char * pFileName, std::ios_base::openmode mode) = 0;
91 virtual bool closeFile(
const char * pFileName) = 0;
94 virtual int64_t getBufSize(
const char * pFileName, std::ios_base::openmode mode) = 0;
95 virtual bool deleteFile(
const char * pFileName) = 0;
147 virtual bool openFile(
const char * pFileName, std::ios_base::openmode mode);
160 virtual bool closeFile(
const char * pFileName);
223 virtual int64_t getBufSize(
const char * pFileName, std::ios_base::openmode mode);
236 virtual bool deleteFile(
const char * pFileName);
239 void WaitUntilFileOperationExecuteDone(
bool Validate =
true );
243 struct FileProtocolAdapterImpl;
244 FileProtocolAdapterImpl*
m_pImpl;
249 :
public std::basic_streambuf<CharType, Traits> {
257 using std::basic_streambuf<CharType, Traits>::gptr;
259 using std::basic_streambuf<CharType, Traits>::egptr;
261 using std::basic_streambuf<CharType, Traits>::eback;
263 using std::basic_streambuf<CharType, Traits>::gbump;
265 using std::basic_streambuf<CharType, Traits>::setg;
269 : m_pBuffer(0), m_BufSize(0), m_pAdapter(0), m_fpos(0) {
291 if (!m_pAdapter || !m_pAdapter->attach(pInterface)){
300 if (!(m_pAdapter->openFile(pFileName, mode))){
316 m_pBuffer =
new char_type[(
unsigned int)m_BufSize /
sizeof(char_type)];
319 setg(m_pBuffer, m_pBuffer + m_BufSize,m_pBuffer + m_BufSize);
323 std::basic_streambuf<CharType, Traits>::_Init();
334 return m_pAdapter != 0;
338 filebuf_type * ret = 0;
339 if (this->is_open()) {
341 if(m_pAdapter->closeFile(m_file.c_str())){
357 if (gptr() < egptr() )
358 return traits_type::to_int_type(*gptr());
361 return traits_type::eof();
363 return traits_type::to_int_type(*gptr());
368 if (gptr() != eback() || eback()<gptr()) {
370 if (!traits_type::eq_int_type(c, traits_type::eof() ) )
371 *(gptr()) = static_cast<char_type>(traits_type::not_eof(c));
372 return traits_type::not_eof(c);
374 return traits_type::eof();
395 setg(m_pBuffer, m_pBuffer , m_pBuffer + retval);
397 return GENICAM_NAMESPACE::INTEGRAL_CAST2<int, GenICam_streamsize>(retval);
404 IDevFileStreamBuf&
operator=(
const IDevFileStreamBuf&);
409 :
public std::basic_streambuf<CharType, Traits> {
421 using std::basic_streambuf<CharType, Traits>::pbase;
423 using std::basic_streambuf<CharType, Traits>::pptr;
425 using std::basic_streambuf<CharType, Traits>::epptr;
427 using std::basic_streambuf<CharType, Traits>::pbump;
431 : m_pBuffer(0), m_file(0), m_pAdapter(0), m_fpos(0) {
441 char_type *pBuffer = NULL;
442 filebuf_type *pFileBuf = NULL;
448 if (pAdapter->
attach( pInterface ))
450 if (pAdapter->
openFile( pFileName, mode ))
454 pBuffer =
new char_type[GENICAM_NAMESPACE::INTEGRAL_CAST<size_t>( bufSize ) /
sizeof( char_type )];
457 std::basic_streambuf<CharType, Traits>::setp( pBuffer, pBuffer + bufSize );
459 std::swap( m_pAdapter, pAdapter );
460 std::swap( m_pBuffer, pBuffer );
483 return m_pAdapter != 0;
487 filebuf_type * ret = 0;
488 bool syncFailed =
false;
489 if (this->is_open()) {
494 if(m_pAdapter->closeFile(m_file)){
513 if (n < epptr() - pptr() ) {
514 memcpy( pptr(), s, (
size_t)(n *
sizeof(char_type)));
515 pbump( GENICAM_NAMESPACE::INTEGRAL_CAST2<int>(n) );
519 if (traits_type::eq_int_type(std::basic_streambuf<CharType, Traits>::sputc(s[i]), traits_type::eof()))
526 int_type
overflow(int_type c = traits_type::eof()) {
527 if (buffer_out() < 0) {
528 return traits_type::eof();
530 if (!traits_type::eq_int_type (c, traits_type::eof() ) )
531 return std::basic_streambuf<CharType, Traits>::sputc(static_cast<char_type>(c));
533 return traits_type::not_eof(c);
538 return GENICAM_NAMESPACE::INTEGRAL_CAST<int>(buffer_out());
548 int64_t cnt = pptr() - pbase();
551 int64_t res = m_pAdapter->
write(m_pBuffer, m_fpos, cnt, m_file);
560 pbump(- GENICAM_NAMESPACE::INTEGRAL_CAST<int>(cnt));
570 :
public std::basic_ostream<CharType, Traits> {
581 #if defined (_MSC_VER) 583 : ostream_type(
std::_Noinit), m_streambuf() {
584 this->init(&m_streambuf);
588 : ostream_type(std::_Noinit), m_streambuf() {
589 this->init(&m_streambuf);
590 this->open(pInterface, pFileName, mode);
594 #elif defined (__GNUC__) 596 : ostream_type(), m_streambuf() {
597 this->init(&m_streambuf);
601 : ostream_type(), m_streambuf() {
602 this->init(&m_streambuf);
603 this->open(pInterface, pFileName, mode);
609 # error Unknown C++ library 615 return const_cast<filebuf_type*
>(&m_streambuf);
636 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc) {
637 if (!m_streambuf.
open(pInterface,pFileName, mode)){
638 this->setstate(std::ios_base::failbit);
650 if (!m_streambuf.
close())
651 this->setstate(std::ios_base::failbit);
656 :
public std::basic_istream<CharType, Traits> {
668 #if defined (_MSC_VER) 670 : istream_type(
std::_Noinit), m_streambuf() {
671 this->init(&m_streambuf);
675 std::ios_base::openmode mode = std::ios_base::in)
676 : istream_type(std::_Noinit), m_streambuf() {
677 this->init(&m_streambuf);
678 this->open(pInterface, pFileName, mode);
682 #elif defined (__APPLE__) 684 : istream_type(0), m_streambuf() {
685 this->init(&m_streambuf);
689 std::ios_base::openmode mode = std::ios_base::in)
690 : istream_type(0), m_streambuf() {
691 this->init(&m_streambuf);
692 this->open(pInterface, pFileName, mode);
696 #elif defined (__GNUC__) 698 : istream_type(), m_streambuf() {
699 this->init(&m_streambuf);
703 std::ios_base::openmode mode = std::ios_base::in)
704 : istream_type(), m_streambuf() {
705 this->init(&m_streambuf);
706 this->open(pInterface, pFileName, mode);
711 # error Unknown C++ library 716 return const_cast<filebuf_type*
>(&m_streambuf);
735 std::ios_base::openmode mode = std::ios_base::in) {
736 if (!m_streambuf.
open(pInterface,pFileName, mode))
737 this->setstate(std::ios_base::failbit);
746 if (!m_streambuf.
close())
747 this->setstate(std::ios_base::failbit);
755 #if defined (_MSC_VER) 756 # pragma warning(pop) void open(GENAPI_NAMESPACE::INodeMap *pInterface, const char *pFileName, std::ios_base::openmode mode=std::ios_base::out|std::ios_base::trunc)
Open file on device in write mode.
ODevFileStreamBase< char, std::char_traits< char > > ODevFileStream
std::basic_ostream< CharType, Traits > ostream_type
#define GENICAM_INTERFACE
virtual GenICam_streamsize read(char *buf, int64_t offs, GenICam_streamsize len, const char *pFileName)=0
void close()
Close the file on device.
filebuf_type * open(GENAPI_NAMESPACE::INodeMap *pInterface, const char *pFileName, std::ios_base::openmode mode=std::ios_base::in)
helpers for pragma linkage
filebuf_type * rdbuf() const
std::basic_istream< CharType, Traits > istream_type
GENICAM_NAMESPACE::gcstring m_file
FileProtocolAdapter * m_pAdapter
std::basic_ios< CharType, Traits > ios_type
Adapter between the std::iostreambuf and the SFNC Features representing the device filesystem...
virtual bool openFile(const char *pFileName, std::ios_base::openmode mode)=0
int_type overflow(int_type c=traits_type::eof())
virtual void operator=(bool Value)
Set node value.
void open(GENAPI_NAMESPACE::INodeMap *pInterface, const char *pFileName, std::ios_base::openmode mode=std::ios_base::in)
virtual GenICam_streamsize write(const char *buf, int64_t offs, int64_t len, const char *pFileName)
writes data into a file
Traits::int_type int_type
GenICam_streamsize m_BufSize
GENICAM_INTERFACE INodeMap
Interface to access the node map.
IDevFileStreamBuf< CharType, Traits > filebuf_type
IDevFileStreamBuf< CharType, Traits > filebuf_type
int_type pbackfail(int_type c)
FileProtocolAdapter * m_pAdapter
Traits::int_type int_type
virtual bool closeFile(const char *pFileName)=0
GenICam_streamsize xsputn(const char_type *s, GenICam_streamsize n)
virtual int64_t getBufSize(const char *pFileName, std::ios_base::openmode mode)=0
ODevFileStreamBuf< CharType, Traits > filebuf_type
FileProtocolAdapterImpl * m_pImpl
virtual bool openFile(const char *pFileName, std::ios_base::openmode mode)
open a file on the device
virtual bool attach(GENAPI_NAMESPACE::INodeMap *pInterface)
attach file protocol adapter to nodemap
virtual GenICam_streamsize read(char *buf, int64_t offs, GenICam_streamsize len, const char *pFileName)
read data from the device into a buffer
Traits::char_type char_type
Forward declarations for GenICam types.
Traits::char_type char_type
filebuf_type * open(GENAPI_NAMESPACE::INodeMap *pInterface, const char *pFileName, std::ios_base::openmode mode)
int64_t GenICam_streamsize
virtual bool deleteFile(const char *pFileName)=0
std::basic_ios< CharType, Traits > ios_type
A string class which is a clone of std::string.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFileProtocolAdapter
Adapter between the std::iostreambuf and the SFNC Features representing the device filesystem...
void close()
Close the file on the device.
ODevFileStreamBuf< CharType, Traits > filebuf_type
filebuf_type * rdbuf() const
IDevFileStreamBase< char, std::char_traits< char > > IDevFileStream
Traits::off_type off_type
Traits::pos_type pos_type
virtual const char * c_str(void) const
Lexical analyzer for CIntSwissKnife.
virtual GenICam_streamsize write(const char *buf, int64_t offs, int64_t len, const char *pFileName)=0
GenICam common utilities.
virtual int64_t getBufSize(const char *pFileName, std::ios_base::openmode mode)
fetch max FileAccessBuffer length for a file