28 #ifndef GENAPI_FILESTREAM_H_ 29 #define GENAPI_FILESTREAM_H_ 52 typedef int64_t GenICam_streamsize;
58 #if defined (_MSC_VER) 60 # include <Base/GCLinkage.h> 64 # if defined(GENICAM_FORCE_AUTO_IMPLIB) || (!defined(GENICAM_NO_AUTO_IMPLIB) && !defined(GENAPI_EXPORTS)) 65 # if defined (_WIN32) && defined (_MT ) 66 # pragma comment(lib, LIB_NAME( "GenApi" )) 68 # error Invalid configuration 74 #if defined (_MSC_VER) 75 # pragma warning(push) 76 # pragma warning (disable: 4251) // class 'GenApi::CPointer<T>' needs to have dll-interface to be used by clients of class 'GenICam::FileProtocolAdapter' 88 virtual bool openFile(
const char * pFileName, std::ios_base::openmode mode) = 0;
89 virtual bool closeFile(
const char * pFileName) = 0;
90 virtual GenICam_streamsize write(
const char * buf, int64_t offs, int64_t len,
const char * pFileName) = 0;
91 virtual GenICam_streamsize read(
char * buf, int64_t offs, GenICam_streamsize len,
const char * pFileName) = 0;
92 virtual int64_t getBufSize(
const char * pFileName, std::ios_base::openmode mode) = 0;
93 virtual bool deleteFile(
const char * pFileName) = 0;
145 virtual bool openFile(
const char * pFileName, std::ios_base::openmode mode);
158 virtual bool closeFile(
const char * pFileName);
181 virtual GenICam_streamsize write(
const char * buf, int64_t offs, int64_t len,
const char * pFileName);
204 virtual GenICam_streamsize read(
char * buf, int64_t offs, GenICam_streamsize len,
const char * pFileName);
221 virtual int64_t getBufSize(
const char * pFileName, std::ios_base::openmode mode);
234 virtual bool deleteFile(
const char * pFileName);
237 void WaitUntilFileOperationExecuteDone(
bool Validate =
true );
241 struct FileProtocolAdapterImpl;
242 FileProtocolAdapterImpl* m_pImpl;
246 template<
typename CharType,
typename Traits>
class IDevFileStreamBuf
247 :
public std::basic_streambuf<CharType, Traits> {
249 typedef Traits traits_type;
250 typedef typename Traits::int_type int_type;
251 typedef typename Traits::char_type char_type;
252 typedef IDevFileStreamBuf<CharType, Traits> filebuf_type;
255 using std::basic_streambuf<CharType, Traits>::gptr;
257 using std::basic_streambuf<CharType, Traits>::egptr;
259 using std::basic_streambuf<CharType, Traits>::eback;
261 using std::basic_streambuf<CharType, Traits>::gbump;
263 using std::basic_streambuf<CharType, Traits>::setg;
267 : m_pBuffer(0), m_BufSize(0), m_pAdapter(0), m_fpos(0) {
284 filebuf_type *open(
GENAPI_NAMESPACE::INodeMap * pInterface,
const char * pFileName, std::ios_base::openmode mode = std::ios_base::in ) {
289 if (!m_pAdapter || !m_pAdapter->attach(pInterface)){
298 if (!(m_pAdapter->openFile(pFileName, mode))){
313 m_BufSize = (GenICam_streamsize)m_pAdapter->getBufSize(m_file.c_str(), mode);
314 m_pBuffer =
new char_type[(
unsigned int)m_BufSize /
sizeof(char_type)];
317 setg(m_pBuffer, m_pBuffer + m_BufSize,m_pBuffer + m_BufSize);
321 std::basic_streambuf<CharType, Traits>::_Init();
332 return m_pAdapter != 0;
335 filebuf_type *close() {
336 filebuf_type * ret = 0;
337 if (this->is_open()) {
339 if(m_pAdapter->closeFile(m_file.c_str())){
354 int_type underflow() {
355 if (gptr() < egptr() )
356 return traits_type::to_int_type(*gptr());
359 return traits_type::eof();
361 return traits_type::to_int_type(*gptr());
365 int_type pbackfail(int_type c) {
366 if (gptr() != eback() || eback()<gptr()) {
368 if (!traits_type::eq_int_type(c, traits_type::eof() ) )
369 *(gptr()) = static_cast<char_type>(traits_type::not_eof(c));
370 return traits_type::not_eof(c);
372 return traits_type::eof();
376 char_type * m_pBuffer;
377 GenICam_streamsize m_BufSize;
387 GenICam_streamsize retval = m_pAdapter->
read(m_pBuffer, m_fpos, m_BufSize, m_file.c_str());
393 setg(m_pBuffer, m_pBuffer , m_pBuffer + retval);
395 return GENICAM_NAMESPACE::INTEGRAL_CAST2<int, GenICam_streamsize>(retval);
401 IDevFileStreamBuf(
const IDevFileStreamBuf&);
402 IDevFileStreamBuf&
operator=(
const IDevFileStreamBuf&);
406 template<
typename CharType,
typename Traits>
class ODevFileStreamBuf
407 :
public std::basic_streambuf<CharType, Traits> {
408 typedef Traits traits_type;
410 typedef typename Traits::int_type int_type;
411 typedef typename Traits::char_type char_type;
412 typedef typename Traits::pos_type pos_type;
413 typedef typename Traits::off_type off_type;
415 typedef ODevFileStreamBuf<CharType, Traits> filebuf_type;
419 using std::basic_streambuf<CharType, Traits>::pbase;
421 using std::basic_streambuf<CharType, Traits>::pptr;
423 using std::basic_streambuf<CharType, Traits>::epptr;
425 using std::basic_streambuf<CharType, Traits>::pbump;
429 : m_pBuffer(0), m_file(0), m_pAdapter(0), m_fpos(0) {
432 ~ODevFileStreamBuf() {
439 char_type *pBuffer = NULL;
440 filebuf_type *pFileBuf = NULL;
446 if (pAdapter->
attach( pInterface ))
448 if (pAdapter->
openFile( pFileName, mode ))
450 if (int64_t bufSize = pAdapter->
getBufSize( pFileName, mode ))
452 pBuffer =
new char_type[GENICAM_NAMESPACE::INTEGRAL_CAST<size_t>( bufSize ) /
sizeof( char_type )];
455 std::basic_streambuf<CharType, Traits>::setp( pBuffer, pBuffer + bufSize );
457 std::swap( m_pAdapter, pAdapter );
458 std::swap( m_pBuffer, pBuffer );
481 return m_pAdapter != 0;
484 filebuf_type *close() {
485 filebuf_type * ret = 0;
486 bool syncFailed =
false;
487 if (this->is_open()) {
492 if(m_pAdapter->closeFile(m_file)){
510 GenICam_streamsize xsputn(
const char_type * s, GenICam_streamsize n) {
511 if (n < epptr() - pptr() ) {
512 memcpy( pptr(), s, (
size_t)(n *
sizeof(char_type)));
513 pbump( GENICAM_NAMESPACE::INTEGRAL_CAST2<int>(n) );
516 for (GenICam_streamsize i = 0; i<n; ++i) {
517 if (traits_type::eq_int_type(std::basic_streambuf<CharType, Traits>::sputc(s[i]), traits_type::eof()))
524 int_type overflow(int_type c = traits_type::eof()) {
525 if (buffer_out() < 0) {
526 return traits_type::eof();
528 if (!traits_type::eq_int_type (c, traits_type::eof() ) )
529 return std::basic_streambuf<CharType, Traits>::sputc(static_cast<char_type>(c));
531 return traits_type::not_eof(c);
536 return GENICAM_NAMESPACE::INTEGRAL_CAST<int>(buffer_out());
540 char_type * m_pBuffer;
545 int64_t buffer_out() {
546 int64_t cnt = pptr() - pbase();
549 int64_t res = m_pAdapter->
write(m_pBuffer, m_fpos, cnt, m_file);
558 pbump(- GENICAM_NAMESPACE::INTEGRAL_CAST<int>(cnt));
563 ODevFileStreamBuf(
const ODevFileStreamBuf&);
564 ODevFileStreamBuf & operator =(
const ODevFileStreamBuf&);
567 template<
typename CharType,
typename Traits>
class ODevFileStreamBase
568 :
public std::basic_ostream<CharType, Traits> {
571 typedef ODevFileStreamBuf<CharType, Traits> filebuf_type;
572 typedef std::basic_ios<CharType, Traits> ios_type;
573 typedef std::basic_ostream<CharType, Traits> ostream_type;
576 filebuf_type m_streambuf;
579 #if defined (_MSC_VER) 581 : ostream_type(std::_Noinit), m_streambuf() {
582 this->init(&m_streambuf);
585 ODevFileStreamBase(
GENAPI_NAMESPACE::INodeMap * pInterface,
const char * pFileName, std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc)
586 : ostream_type(std::_Noinit), m_streambuf() {
587 this->init(&m_streambuf);
588 this->open(pInterface, pFileName, mode);
592 #elif defined (__GNUC__) 594 : ostream_type(), m_streambuf() {
595 this->init(&m_streambuf);
598 ODevFileStreamBase(
GENAPI_NAMESPACE::INodeMap * pInterface,
const char * pFileName, std::ios_base::openmode mode = std::ios_base::out|std::ios_base::trunc)
599 : ostream_type(), m_streambuf() {
600 this->init(&m_streambuf);
601 this->open(pInterface, pFileName, mode);
607 # error Unknown C++ library 612 filebuf_type *rdbuf()
const {
613 return const_cast<filebuf_type*
>(&m_streambuf);
620 bool is_open()
const {
621 return m_streambuf.is_open();
634 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc) {
635 if (!m_streambuf.open(pInterface,pFileName, mode)){
636 this->setstate(std::ios_base::failbit);
648 if (!m_streambuf.close())
649 this->setstate(std::ios_base::failbit);
653 template<
typename CharType,
typename Traits>
class IDevFileStreamBase
654 :
public std::basic_istream<CharType, Traits> {
658 typedef IDevFileStreamBuf<CharType, Traits> filebuf_type;
659 typedef std::basic_ios<CharType, Traits> ios_type;
660 typedef std::basic_istream<CharType, Traits> istream_type;
663 filebuf_type m_streambuf;
666 #if defined (_MSC_VER) 668 : istream_type(std::_Noinit), m_streambuf() {
669 this->init(&m_streambuf);
673 std::ios_base::openmode mode = std::ios_base::in)
674 : istream_type(std::_Noinit), m_streambuf() {
675 this->init(&m_streambuf);
676 this->open(pInterface, pFileName, mode);
680 #elif defined (__APPLE__) 682 : istream_type(0), m_streambuf() {
683 this->init(&m_streambuf);
687 std::ios_base::openmode mode = std::ios_base::in)
688 : istream_type(0), m_streambuf() {
689 this->init(&m_streambuf);
690 this->open(pInterface, pFileName, mode);
694 #elif defined (__GNUC__) 696 : istream_type(), m_streambuf() {
697 this->init(&m_streambuf);
701 std::ios_base::openmode mode = std::ios_base::in)
702 : istream_type(), m_streambuf() {
703 this->init(&m_streambuf);
704 this->open(pInterface, pFileName, mode);
709 # error Unknown C++ library 713 filebuf_type *rdbuf()
const {
714 return const_cast<filebuf_type*
>(&m_streambuf);
721 bool is_open()
const {
722 return m_streambuf.is_open();
733 std::ios_base::openmode mode = std::ios_base::in) {
734 if (!m_streambuf.open(pInterface,pFileName, mode))
735 this->setstate(std::ios_base::failbit);
744 if (!m_streambuf.close())
745 this->setstate(std::ios_base::failbit);
749 typedef ODevFileStreamBase<char, std::char_traits<char> > ODevFileStream;
750 typedef IDevFileStreamBase<char, std::char_traits<char> > IDevFileStream;
753 #if defined (_MSC_VER) 754 # pragma warning(pop) virtual int64_t getBufSize(const char *pFileName, std::ios_base::openmode mode)
fetch max FileAccessBuffer length for a file
virtual bool openFile(const char *pFileName, std::ios_base::openmode mode)
open a file on the device
Adapter between the std::iostreambuf and the SFNC Features representing the device filesystem...
Definition: Filestream.h:104
virtual GenICam_streamsize write(const char *buf, int64_t offs, int64_t len, const char *pFileName)
writes data into a file
virtual GenICam_streamsize read(char *buf, int64_t offs, GenICam_streamsize len, const char *pFileName)
read data from the device into a buffer
virtual IBoolean & operator=(bool Value)
Set node value.
Definition: IBoolean.h:62
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFileProtocolAdapter
Adapter between the std::iostreambuf and the SFNC Features representing the device filesystem...
Definition: Filestream.h:86
Forward declarations for GenICam types.
GENICAM_INTERFACE INodeMap
Interface to access the node map.
Definition: INode.h:50
A string class which is a clone of std::string.
Definition: GCString.h:50
virtual bool attach(GENAPI_NAMESPACE::INodeMap *pInterface)
attach file protocol adapter to nodemap
Definition: ChunkAdapter.h:37
GenICam common utilities.