1################################################################################
2#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
3#  Read the zproject/README.md for information about making permanent changes. #
4################################################################################
5
6module CZMQ
7  module FFI
8
9    # work with directory patches
10    # @note This class is 100% generated using zproject.
11    class ZdirPatch
12      # Creates a new file
13      CREATE = 1
14
15      # Delete a file
16      DELETE = 2
17
18      # Raised when one tries to use an instance of {ZdirPatch} after
19      # the internal pointer to the native object has been nullified.
20      class DestroyedError < RuntimeError; end
21
22      # Boilerplate for self pointer, initializer, and finalizer
23      class << self
24        alias :__new :new
25      end
26      # Attaches the pointer _ptr_ to this instance and defines a finalizer for
27      # it if necessary.
28      # @param ptr [::FFI::Pointer]
29      # @param finalize [Boolean]
30      def initialize(ptr, finalize = true)
31        @ptr = ptr
32        if @ptr.null?
33          @ptr = nil # Remove null pointers so we don't have to test for them.
34        elsif finalize
35          @finalizer = self.class.create_finalizer_for @ptr
36          ObjectSpace.define_finalizer self, @finalizer
37        end
38      end
39      # @param ptr [::FFI::Pointer]
40      # @return [Proc]
41      def self.create_finalizer_for(ptr)
42        Proc.new do
43          ptr_ptr = ::FFI::MemoryPointer.new :pointer
44          ptr_ptr.write_pointer ptr
45          ::CZMQ::FFI.zdir_patch_destroy ptr_ptr
46        end
47      end
48      # @return [Boolean]
49      def null?
50        !@ptr or @ptr.null?
51      end
52      # Return internal pointer
53      # @return [::FFI::Pointer]
54      def __ptr
55        raise DestroyedError unless @ptr
56        @ptr
57      end
58      # So external Libraries can just pass the Object to a FFI function which expects a :pointer
59      alias_method :to_ptr, :__ptr
60      # Nullify internal pointer and return pointer pointer.
61      # @note This detaches the current instance from the native object
62      #   and thus makes it unusable.
63      # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
64      #   pointing to the native object
65      def __ptr_give_ref
66        raise DestroyedError unless @ptr
67        ptr_ptr = ::FFI::MemoryPointer.new :pointer
68        ptr_ptr.write_pointer @ptr
69        __undef_finalizer if @finalizer
70        @ptr = nil
71        ptr_ptr
72      end
73      # Undefines the finalizer for this object.
74      # @note Only use this if you need to and can guarantee that the native
75      #   object will be freed by other means.
76      # @return [void]
77      def __undef_finalizer
78        ObjectSpace.undefine_finalizer self
79        @finalizer = nil
80      end
81
82      # Create new patch
83      # @param path [String, #to_s, nil]
84      # @param file [Zfile, #__ptr]
85      # @param op [Integer, #to_int, #to_i]
86      # @param alias_ [String, #to_s, nil]
87      # @return [CZMQ::ZdirPatch]
88      def self.new(path, file, op, alias_)
89        file = file.__ptr if file
90        op = Integer(op)
91        ptr = ::CZMQ::FFI.zdir_patch_new(path, file, op, alias_)
92        __new ptr
93      end
94
95      # Destroy a patch
96      #
97      # @return [void]
98      def destroy()
99        return unless @ptr
100        self_p = __ptr_give_ref
101        result = ::CZMQ::FFI.zdir_patch_destroy(self_p)
102        result
103      end
104
105      # Create copy of a patch. If the patch is null, or memory was exhausted,
106      # returns null.
107      #
108      # @return [ZdirPatch]
109      def dup()
110        raise DestroyedError unless @ptr
111        self_p = @ptr
112        result = ::CZMQ::FFI.zdir_patch_dup(self_p)
113        result = ZdirPatch.__new result, true
114        result
115      end
116
117      # Return patch file directory path
118      #
119      # @return [String]
120      def path()
121        raise DestroyedError unless @ptr
122        self_p = @ptr
123        result = ::CZMQ::FFI.zdir_patch_path(self_p)
124        result
125      end
126
127      # Return patch file item
128      #
129      # @return [Zfile]
130      def file()
131        raise DestroyedError unless @ptr
132        self_p = @ptr
133        result = ::CZMQ::FFI.zdir_patch_file(self_p)
134        result = Zfile.__new result, false
135        result
136      end
137
138      # Return operation
139      #
140      # @return [Integer]
141      def op()
142        raise DestroyedError unless @ptr
143        self_p = @ptr
144        result = ::CZMQ::FFI.zdir_patch_op(self_p)
145        result
146      end
147
148      # Return patch virtual file path
149      #
150      # @return [String]
151      def vpath()
152        raise DestroyedError unless @ptr
153        self_p = @ptr
154        result = ::CZMQ::FFI.zdir_patch_vpath(self_p)
155        result
156      end
157
158      # Calculate hash digest for file (create only)
159      #
160      # @return [void]
161      def digest_set()
162        raise DestroyedError unless @ptr
163        self_p = @ptr
164        result = ::CZMQ::FFI.zdir_patch_digest_set(self_p)
165        result
166      end
167
168      # Return hash digest for patch file
169      #
170      # @return [String]
171      def digest()
172        raise DestroyedError unless @ptr
173        self_p = @ptr
174        result = ::CZMQ::FFI.zdir_patch_digest(self_p)
175        result
176      end
177
178      # Self test of this class.
179      #
180      # @param verbose [Boolean]
181      # @return [void]
182      def self.test(verbose)
183        verbose = !(0==verbose||!verbose) # boolean
184        result = ::CZMQ::FFI.zdir_patch_test(verbose)
185        result
186      end
187    end
188  end
189end
190
191################################################################################
192#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
193#  Read the zproject/README.md for information about making permanent changes. #
194################################################################################
195