Commit ee21e4b1 authored by acpaquette's avatar acpaquette Committed by amystamile-usgs
Browse files

Blob Swig Wrapper (#4613)

* Moved wrapper under one package

* Add pvl construction from reading a string, give access to blob internals

* Updated meta.yaml to build isisio rather than isispvl
parent 6ede7f3e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
{% set build_number = "0" %}

package:
  name: isispvl
  name: isisio
  version: {{ version }}

source:
@@ -57,7 +57,7 @@ requirements:

tests:
  imports:
    - isispvl
    - isisio
  commands:
    - test -e $PREFIX/lib/libcore${SHLIB_EXT}
    - test -e $PREFIX/include/isis/Pvl.h
+1 −0
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ message("\tBUILD TESTS: ${buildTests}")
message("\tBUILD CORE: ${buildCore}")
message("\tBUILD MISSIONS: ${buildMissions}")
message("\tBUILD CORE TESTS: ${BUILD_CORE_TESTS}")
message("\tBUILD SWIG: ${ISIS_BUILD_SWIG}")
message("\tJP2K SUPPORT: ${JP2KFLAG}")
message("\tPYTHON BINDINGS: ${pybindings}")
message("\tISISDATA: ${isisData}")
+45 −0
Original line number Diff line number Diff line
%module isisblob
%{
    #include "Blob.h"
%}

%include "Blob.h"
%nodefaultdtor Isis::Blob;

%extend Isis::Blob {

  Blob(const char* name, const char* type) {
    QString qname(name);
    QString qtype(type);
    Isis::Blob *blob = new Isis::Blob(qname, qtype);
    return blob;
  }

  Blob(const char* name, const char* type, const char* file) {
    QString qname(name);
    QString qtype(type);
    QString qfile(file);
    Isis::Blob *blob = new Isis::Blob(qname, qtype, file);
    return blob;
  }

  void Write(const char *file) {
    QString qfile(file);

    $self->Write(file);
  }

  char * getStringBuffer() {
    int bufferSize = $self->Size();
    char * buffer = $self->getBuffer();
    std::ostringstream os;
    for (int i = 0; i < bufferSize; i++) os << buffer[i];
    os << '\0';

    std::string str = os.str();
    char * cstr = new char [str.length()+1];
    std::strcpy (cstr, str.c_str());
    return cstr;
  }

}
+45 −0
Original line number Diff line number Diff line
%module isisio

%{
    #include <string>
    #include <sstream>
%}

%include std_string.i
%include std_vector.i
%include exception.i

%include "pvlKeyword.i"
%include "PvlContainer.h"
%include "pvlGroup.i"

%include "pvlObject.i"
%nodefaultdtor Isis::PvlObject;


class QString
{
public:
    static QString fromStdString(const std::string &s);
    std::string toStdString() const;
    QString(const char* str);
    ~QString();

    int size() const;
    int count() const;
    int length() const;
    bool isEmpty() const;
};

%exception{
    try {
        $action
    } catch (std::exception const& e) {
        SWIG_exception(SWIG_RuntimeError, (std::string("std::exception: ") + e.what()).c_str());
    } catch (...) {
        SWIG_exception(SWIG_UnknownError, "Unknown error");
    }
}

%include "isisblob.i"
%include "isispvl.i"
+5 −37
Original line number Diff line number Diff line
%module isispvl
%{
    #include <string>
    #include <sstream>
    #include "Pvl.h"
%}

%include std_string.i
%include std_vector.i
%include exception.i

%include "pvlKeyword.i"
%include "PvlContainer.h"
%include "pvlGroup.i"

%include "pvlObject.i"
%nodefaultdtor Isis::PvlObject;

%include "Pvl.h"
%nodefaultdtor Isis::Pvl;

@@ -35,6 +22,11 @@
    return pvl;
  }

  void readString(const char *pvlString) {
    std::istringstream in(pvlString);
    in >> *$self;
  }

  void read(const char* file) {
    QString qfile(file);
    $self->read(qfile);
@@ -45,27 +37,3 @@
    $self->write(qfile);
  }
}

class QString
{
public:
    static QString fromStdString(const std::string &s);
    std::string toStdString() const;
    QString(const char* str);
    ~QString();

    int size() const;
    int count() const;
    int length() const;
    bool isEmpty() const;
};

%exception{
    try {
        $action
    } catch (std::exception const& e) {
        SWIG_exception(SWIG_RuntimeError, (std::string("std::exception: ") + e.what()).c_str());
    } catch (...) {
        SWIG_exception(SWIG_UnknownError, "Unknown error");
    }
}
Loading