Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 58 lines (48 sloc) 1.639 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.

#ifndef INCLUDED_GRAS_SBUFFER_I
#define INCLUDED_GRAS_SBUFFER_I

%module (package="gras") GRAS_SBuffer

%{
#include <gras/gras.hpp>
#include <gras/sbuffer.hpp>
%}

////////////////////////////////////////////////////////////////////////
// comprehend base class
////////////////////////////////////////////////////////////////////////
#ifndef SWIG_INTRUSIVE_PTR_NAMESPACE
#define SWIG_INTRUSIVE_PTR_NAMESPACE boost
%include <intrusive_ptr.i>
#endif
%template (boost_intrusive_ptr_gras_sbuffer_impl) boost::intrusive_ptr<gras::SBufferImpl>;

////////////////////////////////////////////////////////////////////////
// Export swig element comprehension
////////////////////////////////////////////////////////////////////////
%include <gras/gras.hpp>
%include <gras/sbuffer.hpp>

////////////////////////////////////////////////////////////////////////
// Replace the get method
////////////////////////////////////////////////////////////////////////
%extend gras::SBuffer
{
    %insert("python")
    %{
        def get(self):
            from gras.GRAS_Utils import pointer_to_ndarray
            addr = long(self.get_actual_memory())
            readonly = hasattr(self, 'readonly') and getattr(self, 'readonly')
            return pointer_to_ndarray(
                addr=addr + self.offset,
                nitems=self.length,
                readonly=readonly
            )
    %}

    size_t __len__(void)
    {
        return ($self)->length;
    }

    bool __nonzero__(void)
    {
        return bool(*($self));
    }
}

#endif /*INCLUDED_GRAS_SBUFFER_I*/
Something went wrong with that request. Please try again.