Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. # distutils: language = c++
  2. # distutils: sources = ../src/writer.cc ../src/reader.cc ../src/exception.cc
  3.  
  4. from libcpp cimport bool
  5.  
  6. cdef extern from "writer.hpp" namespace "szn::logfile":
  7.     cdef cppclass Writer:
  8.         Writer(const char*, const size_t, const bool) except +
  9.         void write(const char*, const size_t) except +
  10.         void close()
  11.         void sync()
  12.  
  13. cdef class PyWriter:
  14.     cdef Writer * thisptr
  15.  
  16.     def __cinit__(self, file_path, checkpoint_size=1024, create_index=True):
  17.         cdef const char* c_file_path = file_path
  18.         cdef size_t c_checkpoint_size = checkpoint_size
  19.         cdef bool c_create_index = create_index
  20.  
  21.         self.thisptr = new Writer(c_file_path, c_checkpoint_size,
  22.                                   c_create_index)
  23.  
  24.     def write(self, data):
  25.         cdef const char* c_data = data
  26.         cdef size_t c_data_size = len(data)
  27.         self.thisptr.write(c_data, c_data_size)
  28.  
  29.     def close(self):
  30.         self.thisptr.close()
  31.  
  32.     def sync(self):
  33.         self.thisptr.sync()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement