30 #ifndef GENAPI_FILESTREAM_H_ 31 #define GENAPI_FILESTREAM_H_ 59 #if defined (_MSC_VER) 65 # if defined(GENICAM_FORCE_AUTO_IMPLIB) || (!defined(GENICAM_NO_AUTO_IMPLIB) && !defined(GENAPI_EXPORTS)) 66 # if defined (_WIN32) && defined (_MT ) 67 # pragma comment(lib, LIB_NAME( "GenApi" )) 69 # error Invalid configuration 75 #if defined (_MSC_VER) 76 # pragma warning(push) 77 # pragma warning (disable: 4251) // class 'GenApi::CPointer<T>' needs to have dll-interface to be used by clients of class 'GenICam::FileProtocolAdapter' 86 interface GENAPI_DECL_ABSTRACT IFileProtocolAdapter
89 virtual bool openFile(
const char * pFileName, std::ios_base::openmode mode) = 0;
90 virtual bool closeFile(
const char * pFileName) = 0;
93 virtual int64_t getBufSize(
const char * pFileName, std::ios_base::openmode mode) = 0;
94 virtual bool deleteFile(
const char * pFileName) = 0;
146 virtual bool openFile(
const char * pFileName, std::ios_base::openmode mode);
159 virtual bool closeFile(
const char * pFileName);
222 virtual int64_t getBufSize(
const char * pFileName, std::ios_base::openmode mode);
235 virtual bool deleteFile(
const char * pFileName);
238 void WaitUntilFileOperationExecuteDone(
bool Validate =
true );
242 struct FileProtocolAdapterImpl;
243 FileProtocolAdapterImpl*
m_pImpl;
248 :
public std::basic_streambuf<CharType, Traits> {
256 using std::basic_streambuf<CharType, Traits>::gptr;
258 using std::basic_streambuf<CharType, Traits>::egptr;
260 using std::basic_streambuf<CharType, Traits>::eback;
262 using std::basic_streambuf<CharType, Traits>::gbump;
264 using std::basic_streambuf<CharType, Traits>::setg;
268 : m_pBuffer(0), m_BufSize(0), m_pAdapter(0), m_fpos(0) {
290 if (!m_pAdapter || !m_pAdapter->attach(pInterface)){
299 if (!(m_pAdapter->openFile(pFileName, mode))){
315 m_pBuffer =
new char_type[(
unsigned int)m_BufSize /
sizeof(char_type)];
318 setg(m_pBuffer, m_pBuffer + m_BufSize,m_pBuffer + m_BufSize);
322 std::basic_streambuf<CharType, Traits>::_Init();
333 return m_pAdapter != 0;
337 filebuf_type * ret = 0;
338 if (this->is_open()) {
340 if(m_pAdapter->closeFile(m_file.c_str())){
356 if (gptr() < egptr() )
357 return traits_type::to_int_type(*gptr());
360 return traits_type::eof();
362 return traits_type::to_int_type(*gptr());
367 if (gptr() != eback() || eback()<gptr()) {
369 if (!traits_type::eq_int_type(c, traits_type::eof() ) )
370 *(gptr()) = static_cast<char_type>(traits_type::not_eof(c));
371 return traits_type::not_eof(c);
373 return traits_type::eof();
394 setg(m_pBuffer, m_pBuffer , m_pBuffer + retval);
396 return GENICAM_NAMESPACE::INTEGRAL_CAST2<int, GenICam_streamsize>(retval);
403 IDevFileStreamBuf&
operator=(
const IDevFileStreamBuf&);
408 :
public std::basic_streambuf<CharType, Traits> {
420 using std::basic_streambuf<CharType, Traits>::pbase;
422 using std::basic_streambuf<CharType, Traits>::pptr;
424 using std::basic_streambuf<CharType, Traits>::epptr;
426 using std::basic_streambuf<CharType, Traits>::pbump;
430 : m_pBuffer(0), m_file(0), m_pAdapter(0), m_fpos(0) {
443 if (!m_pAdapter || !m_pAdapter->attach(pInterface)){
453 if (!(m_pAdapter->openFile(pFileName, mode))){
468 const int64_t bufSize = m_pAdapter->getBufSize(m_file,mode);
469 m_pBuffer =
new char_type[GENICAM_NAMESPACE::INTEGRAL_CAST<size_t>(bufSize) /
sizeof(char_type)];
470 std::basic_streambuf<CharType, Traits>::setp(m_pBuffer, m_pBuffer + bufSize);
477 return m_pAdapter != 0;
481 filebuf_type * ret = 0;
482 bool syncFailed =
false;
483 if (this->is_open()) {
488 if(m_pAdapter->closeFile(m_file)){
507 if (n < epptr() - pptr() ) {
508 memcpy( pptr(), s, (
size_t)(n *
sizeof(char_type)));
509 pbump( GENICAM_NAMESPACE::INTEGRAL_CAST2<int>(n) );
513 if (traits_type::eq_int_type(std::basic_streambuf<CharType, Traits>::sputc(s[i]), traits_type::eof()))
520 int_type
overflow(int_type c = traits_type::eof()) {
521 if (buffer_out() < 0) {
522 return traits_type::eof();
524 if (!traits_type::eq_int_type (c, traits_type::eof() ) )
525 return std::basic_streambuf<CharType, Traits>::sputc(static_cast<char_type>(c));
527 return traits_type::not_eof(c);
532 return GENICAM_NAMESPACE::INTEGRAL_CAST<int>(buffer_out());
542 int64_t cnt = pptr() - pbase();
545 int64_t res = m_pAdapter->
write(m_pBuffer, m_fpos, cnt, m_file);
554 pbump(- GENICAM_NAMESPACE::INTEGRAL_CAST<int>(cnt));
564 :
public std::basic_ostream<CharType, Traits> {
575 #if defined (_MSC_VER) 577 : ostream_type(
std::_Noinit), m_streambuf() {
578 this->init(&m_streambuf);
582 : ostream_type(std::_Noinit), m_streambuf() {
583 this->init(&m_streambuf);
584 this->open(pInterface, pFileName, mode);
588 #elif defined (__GNUC__) 590 : ostream_type(), m_streambuf() {
591 this->init(&m_streambuf);
595 : ostream_type(), m_streambuf() {
596 this->init(&m_streambuf);
597 this->open(pInterface, pFileName, mode);
603 # error Unknown C++ library 609 return const_cast<filebuf_type*
>(&m_streambuf);
630 std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc) {
631 if (!m_streambuf.
open(pInterface,pFileName, mode)){
632 this->setstate(std::ios_base::failbit);
644 if (!m_streambuf.
close())
645 this->setstate(std::ios_base::failbit);
650 :
public std::basic_istream<CharType, Traits> {
662 #if defined (_MSC_VER) 664 : istream_type(
std::_Noinit), m_streambuf() {
665 this->init(&m_streambuf);
669 std::ios_base::openmode mode = std::ios_base::in)
670 : istream_type(std::_Noinit), m_streambuf() {
671 this->init(&m_streambuf);
672 this->open(pInterface, pFileName, mode);
676 #elif defined (__APPLE__) 678 : istream_type(0), m_streambuf() {
679 this->init(&m_streambuf);
683 std::ios_base::openmode mode = std::ios_base::in)
684 : istream_type(0), m_streambuf() {
685 this->init(&m_streambuf);
686 this->open(pInterface, pFileName, mode);
690 #elif defined (__GNUC__) 692 : istream_type(), m_streambuf() {
693 this->init(&m_streambuf);
697 std::ios_base::openmode mode = std::ios_base::in)
698 : istream_type(), m_streambuf() {
699 this->init(&m_streambuf);
700 this->open(pInterface, pFileName, mode);
705 # error Unknown C++ library 710 return const_cast<filebuf_type*
>(&m_streambuf);
729 std::ios_base::openmode mode = std::ios_base::in) {
730 if (!m_streambuf.
open(pInterface,pFileName, mode))
731 this->setstate(std::ios_base::failbit);
740 if (!m_streambuf.
close())
741 this->setstate(std::ios_base::failbit);
749 #if defined (_MSC_VER) 750 # 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
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.
interface GENAPI_DECL_ABSTRACT INodeMap
Interface to access the node map.
Traits::int_type int_type
GenICam_streamsize m_BufSize
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 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.
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
Part of the generic device API.
virtual GenICam_streamsize write(const char *buf, int64_t offs, int64_t len, const char *pFileName)=0
GenICam common utilities.