1919%nothread;
2020
2121#ifndef SWIGIMPORTED
22- %constant char * __doc__ = " Classes to access files, memory and remote data." ;
22+ %constant char * __doc__ =
23+ " Class interface to access files, memory and remote data." ;
2324#endif
2425
2526#pragma SWIG nowarn=321 // 'open' conflicts with a built-in name in python
2930%include " shared/enum.i"
3031%include " shared/exception.i"
3132%include " shared/keep_reference.i"
32- %include " shared/remoteio_derived.i"
3333%include " shared/unique_ptr.i"
3434%include " shared/windows_path.i"
3535
@@ -48,81 +48,54 @@ UNIQUE_PTR(Exiv2::BasicIo);
4848%thread Exiv2::BasicIo::mmap;
4949%thread Exiv2::BasicIo::munmap;
5050%thread Exiv2::BasicIo::read;
51- %thread Exiv2::MemIo::read;
5251%thread Exiv2::BasicIo::seek;
53- %thread Exiv2::FileIo::size;
54- %thread Exiv2::FileIo::tell;
5552%thread Exiv2::BasicIo::transfer;
5653%thread Exiv2::BasicIo::write;
57- %thread Exiv2::MemIo::write;
5854
5955// Some calls don't raise exceptions
60- %noexception Exiv2::MemIo::close;
6156%noexception Exiv2::BasicIo::eof;
6257%noexception Exiv2::BasicIo::error;
6358%noexception Exiv2::BasicIo::isopen;
64- %noexception Exiv2::MemIo::mmap;
65- %noexception Exiv2::MemIo::munmap;
66- %noexception Exiv2::RemoteIo::munmap;
67- %noexception Exiv2::MemIo::open;
6859%noexception Exiv2::BasicIo::path;
69- %noexception Exiv2::MemIo::read;
70- %noexception Exiv2::MemIo::seek;
71- %noexception Exiv2::RemoteIo::seek;
72- %noexception Exiv2::MemIo::size;
73- %noexception Exiv2::RemoteIo::size;
74- %noexception Exiv2::MemIo::tell;
75- %noexception Exiv2::RemoteIo::tell;
76- %noexception Exiv2::MemIo::write;
7760
7861// Convert path encoding on Windows
7962WINDOWS_PATH (const std::string& path)
8063WINDOWS_PATH(const std::string& orgPath)
8164WINDOWS_PATH(const std::string& url)
8265WINDOWS_PATH_OUT(path)
8366
84- // Convert BasicIo return values to actual subclass
85- %fragment(" basicio_subtype" , " header" ) {
86- static swig_type_info* basicio_subtype (Exiv2::BasicIo* ptr) {
87- if (dynamic_cast <Exiv2::MemIo*>(ptr))
88- return $descriptor (Exiv2::MemIo*);
89- else if (dynamic_cast <Exiv2::FileIo*>(ptr)) {
90- if (dynamic_cast <Exiv2::XPathIo*>(ptr))
91- return $descriptor (Exiv2::XPathIo*);
92- else
93- return $descriptor (Exiv2::FileIo*);
67+ // Add method to get the subclass type
68+ %feature(" docstring" ) Exiv2::BasicIo::ioType "Return the derived class type.
69+
70+ You shouldn't usually need to know the type of IO as they all have
71+ the same interface.
72+ :rtype: str
73+ :return: A class name such as ""FileIo""."
74+ %extend Exiv2::BasicIo {
75+ const char * ioType () {
76+ if (dynamic_cast <Exiv2::MemIo*>($self))
77+ return " MemIo" ;
78+ else if (dynamic_cast <Exiv2::FileIo*>($self)) {
79+ if (dynamic_cast <Exiv2::XPathIo*>($self))
80+ return " XPathIo" ;
81+ return " FileIo" ;
82+ }
83+ else if (dynamic_cast <Exiv2::RemoteIo*>($self)) {
84+ if (dynamic_cast <Exiv2::HttpIo*>($self))
85+ return " HttpIo" ;
86+ %#ifdef EXV_USE_CURL
87+ else if (dynamic_cast <Exiv2::CurlIo*>($self))
88+ return " CurlIo" ;
89+ %#endif
90+ %#ifdef EXV_USE_SSH
91+ else if (dynamic_cast <Exiv2::SshIo*>($self))
92+ return " SshIo" ;
93+ %#endif
94+ return " RemoteIo" ;
95+ }
96+ return " unknown" ;
9497 }
95- else if (dynamic_cast <Exiv2::RemoteIo*>(ptr)) {
96- if (dynamic_cast <Exiv2::HttpIo*>(ptr))
97- return $descriptor (Exiv2::HttpIo*);
98- #ifdef EXV_USE_CURL
99- else if (dynamic_cast <Exiv2::CurlIo*>(ptr))
100- return $descriptor (Exiv2::CurlIo*);
101- #endif
102- else
103- return $descriptor (Exiv2::RemoteIo*);
104- }
105- return $descriptor (Exiv2::BasicIo*);
106- };
107- }
108- %typemap(out, fragment=" basicio_subtype" ) Exiv2::BasicIo& {
109- $result = SWIG_NewPointerObj ($1 , basicio_subtype ($1 ), 0 );
110- }
111- %typemap(out, fragment=" basicio_subtype" ) Exiv2::BasicIo::SMART_PTR {
112- Exiv2::BasicIo* ptr = (&$1 )->release ();
113- $result = SWIG_NewPointerObj (
114- ptr, basicio_subtype (ptr), SWIG_POINTER_OWN);
115- }
116-
117- // CurlIo destructor isn't seen by SWIG in v0.27.x
118- #if EXIV2_VERSION_HEX < 0x001c0000
119- #ifdef EXV_USE_CURL
120- %extend Exiv2::CurlIo {
121- ~CurlIo () {};
12298}
123- %ignore Exiv2::CurlIo::~CurlIo;
124- #endif
125- #endif
12699
127100// readOrThrow & seekOrThrow use ErrorCode internally without Exiv2:: prefix
128101// as if SWIG doesn't realise ErrorCode is in the Exiv2 namespace
@@ -143,10 +116,6 @@ KEEP_REFERENCE(Exiv2::BasicIo&)
143116INPUT_BUFFER_RO(const Exiv2::byte* data, long wcount)
144117INPUT_BUFFER_RO(const Exiv2::byte* data, size_t wcount)
145118
146- // Allow MemIo to be ceated from a buffer
147- INPUT_BUFFER_RO_EX(const Exiv2::byte* data, long size)
148- INPUT_BUFFER_RO_EX(const Exiv2::byte* data, size_t size)
149-
150119// BasicIo::read can write to a Python buffer
151120OUTPUT_BUFFER_RW(Exiv2::byte* buf, long rcount)
152121OUTPUT_BUFFER_RW(Exiv2::byte* buf, size_t rcount)
@@ -159,12 +128,12 @@ OUTPUT_BUFFER_RW(Exiv2::byte* buf, size_t rcount)
159128RETURN_VIEW (Exiv2::byte* mmap, $1 ? arg1->size () : 0,
160129 arg2 ? PyBUF_WRITE : PyBUF_READ,)
161130
162- %define EXTEND_BASICIO(io_type )
163- // Enable len(io_type )
164- %feature( " python:slot " , " sq_length " , functype= " lenfunc " ) io_type ::size;
165- // Expose io_type contents as a Python buffer
166- %fragment(" get_ptr_size" {io_type }, " header" ) {
167- static bool get_ptr_size (io_type * self, bool is_writeable,
131+ // Enable len(Exiv2::BasicIo )
132+ %feature( " python:slot " , " sq_length " , functype= " lenfunc " )
133+ Exiv2::BasicIo ::size;
134+ // Expose Exiv2::BasicIo contents as a Python buffer
135+ %fragment(" get_ptr_size" {Exiv2::BasicIo }, " header" ) {
136+ static bool get_ptr_size (Exiv2::BasicIo * self, bool is_writeable,
168137 Exiv2::byte*& ptr, Py_ssize_t& size) {
169138 if (self->open ())
170139 return false ;
@@ -183,20 +152,15 @@ static bool get_ptr_size(io_type* self, bool is_writeable,
183152 return true ;
184153};
185154}
186- %fragment (" release_ptr" {io_type }, " header" ) {
187- static void release_ptr (io_type * self) {
155+ %fragment (" release_ptr" {Exiv2::BasicIo }, " header" ) {
156+ static void release_ptr (Exiv2::BasicIo * self) {
188157 SWIG_PYTHON_THREAD_BEGIN_ALLOW;
189158 self->munmap ();
190159 self->close ();
191160 SWIG_PYTHON_THREAD_END_ALLOW;
192161};
193162}
194- EXPOSE_OBJECT_BUFFER (io_type, true , true )
195- %enddef // EXTEND_BASICIO
196-
197- EXTEND_BASICIO (Exiv2::FileIo)
198- EXTEND_BASICIO (Exiv2::MemIo)
199- EXTEND_BASICIO (Exiv2::RemoteIo)
163+ EXPOSE_OBJECT_BUFFER (Exiv2::BasicIo, true , true )
200164
201165// Make enum more Pythonic
202166DEFINE_CLASS_ENUM (BasicIo, Position, " Seek starting positions." ,
@@ -210,21 +174,21 @@ DEPRECATED_ENUM(BasicIo, Position, "Seek starting positions.",
210174 " cur" , Exiv2::BasicIo::cur,
211175 " end" , Exiv2::BasicIo::end);
212176
213- %ignore Exiv2::BasicIo::~BasicIo;
214177%ignore Exiv2::BasicIo::bigBlock_;
178+ %ignore Exiv2::BasicIo::operator =;
215179%ignore Exiv2::BasicIo::populateFakeData;
216180%ignore Exiv2::curlWriter;
217181%ignore Exiv2::IoCloser;
218182%ignore Exiv2::ReplaceStringInPlace;
219183%ignore Exiv2::readFile;
220184%ignore Exiv2::writeFile;
221- %ignore Exiv2::XPathIo::GEN_FILE_EXT ;
222- %ignore Exiv2::XPathIo::TEMP_FILE_EXT ;
223- %ignore Exiv2::CurlIo:: operator = ;
224- %ignore Exiv2::FileIo:: operator = ;
225- %ignore Exiv2::HttpIo:: operator = ;
226- %ignore Exiv2::MemIo:: operator = ;
227- %ignore Exiv2::SshIo:: operator = ;
185+ %ignore Exiv2::CurlIo ;
186+ %ignore Exiv2::FileIo ;
187+ %ignore Exiv2::HttpIo ;
188+ %ignore Exiv2::MemIo ;
189+ %ignore Exiv2::RemoteIo ;
190+ %ignore Exiv2::SshIo ;
191+ %ignore Exiv2::XPathIo ;
228192%ignore EXV_XPATH_MEMIO;
229193
230194%include " exiv2/basicio.hpp"
0 commit comments