PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/src/wrappers/common/library/wrapper_handler.e

http://github.com/tybor/Liberty
Specman e | 101 lines | 80 code | 12 blank | 9 comment | 7 complexity | dae8112654366778dcded9be72ec6986 MD5 | raw file
  1note
  2   description:
  3      "A class that can handle WRAPPER's internals"
  4   copyright:
  5      "[
  6               Copyright (C) 2005-2017: Paolo Redaelli
  7
  8               This library is free software; you can redistribute it and/or
  9               modify it under the terms of the GNU Lesser General Public License
 10               as published by the Free Software Foundation; either version 2.1 of
 11               the License, or (at your option) any later version.
 12
 13               This library is distributed in the hope that it will be useful, but
 14               WITHOUT ANY WARRANTY; without even the implied warranty of
 15               MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16               Lesser General Public License for more details.
 17
 18               You should have received a copy of the GNU Lesser General Public
 19               License along with this library; if not, write to the Free Software
 20               Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21               02110-1301 USA
 22         ]"
 23deferred class WRAPPER_HANDLER
 24   -- A class that can access some internal representation of a WRAPPER.
 25
 26insert
 27   ANY
 28      undefine is_equal, copy, out_in_tagged_out_memory, fill_tagged_out_memory
 29      end
 30   EXCEPTIONS
 31      export {} all
 32      undefine is_equal, copy, out_in_tagged_out_memory, fill_tagged_out_memory
 33      end
 34
 35feature {} -- Utility features
 36   null_or (a_wrapper: WRAPPER): POINTER
 37         -- The handle of `a_wrapper', or the default_pointer if
 38         -- `a_wrapper' is Void
 39      do
 40         if a_wrapper /= Void then
 41            Result := a_wrapper.handle
 42         end
 43      ensure
 44         definition: Result = default_pointer or else a_wrapper /= Void and then Result = a_wrapper.handle
 45      end
 46
 47   null_or_string (a_string: ABSTRACT_STRING): POINTER
 48         -- A pointer to a memory area containing the content of `a_string' or
 49         -- default_pointer if `a_string' is Void. The memory area may be the
 50         -- internal buffer of `a_string' or a newly allocated one.
 51      do
 52         if a_string /= Void then
 53            Result := a_string.to_external
 54         else
 55            check
 56               Result.is_null
 57            end
 58         end
 59      ensure
 60         definition: Result = default_pointer or (a_string /= Void implies Result = a_string.to_external)
 61      end
 62
 63   null_or_array (a_collection: WRAPPER_COLLECTION[WRAPPER]): POINTER
 64         -- A pointer to the contenct of `a_collection' or NULL (default_pointer) if `a_collection' is Void
 65      do
 66         if a_collection /= Void then
 67            Result := a_collection.as_c_array.to_pointer
 68         end
 69      ensure
 70         definition: a_collection = Void implies Result.is_null and a_collection /= Void implies Result.is_not_null
 71      end
 72
 73   collection_to_c_array (a_collection: COLLECTION[WRAPPER]): FAST_ARRAY[POINTER]
 74         -- An array containing the pointers to the objects wrapped by `a_collection' wrappers.
 75         -- TODO: avoid creating a new array whenever possible.
 76      require
 77         a_collection /= Void
 78         not a_collection.is_empty
 79      local
 80         i: ITERATOR[WRAPPER]
 81      do
 82         create Result.with_capacity(a_collection.count)
 83         from
 84            i := a_collection.new_iterator
 85            i.start
 86         until
 87            i.is_off
 88         loop
 89            Result.add_last(i.item.handle)
 90            i.next
 91         end
 92      end
 93
 94feature {} -- Wrapper related exceptions
 95   pointer_to_unwrapped_deferred_object: STRING "A C function returned a pointer to an unwrapped object which is wrapped by a deferred class. It is not possible to create a correct wrapper."
 96
 97   retrieved_object_mismatch: STRING "Retrieved_object_mismatch: the Eiffel wrapper associated with a pointer is not an actual wrapper for the object referred by that pointer "
 98
 99   copying_an_uncopyable: STRING "Trying to copy an uncopyable wrapper: such objects are usually shortly lived"
100
101end -- class WRAPPER_HANDLER