summaryrefslogtreecommitdiff
path: root/lib/ffi/struct_layout_builder.rb
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2010-08-07 21:01:31 +1000
committerWayne Meissner <wmeissner@gmail.com>2010-08-07 21:01:31 +1000
commit281e656ccba5c06702eee9d69dd83e1680d22e55 (patch)
tree98ddb4eee2329fbbb2774241f77cdb867afb8901 /lib/ffi/struct_layout_builder.rb
parentfd3d1118ae68c43fc4a570ee0cbd9b281e565180 (diff)
downloadffi-281e656ccba5c06702eee9d69dd83e1680d22e55.tar.gz
License update and misc cleanups.
Diffstat (limited to 'lib/ffi/struct_layout_builder.rb')
-rw-r--r--lib/ffi/struct_layout_builder.rb78
1 files changed, 35 insertions, 43 deletions
diff --git a/lib/ffi/struct_layout_builder.rb b/lib/ffi/struct_layout_builder.rb
index b1aecbc..c1aec44 100644
--- a/lib/ffi/struct_layout_builder.rb
+++ b/lib/ffi/struct_layout_builder.rb
@@ -3,28 +3,20 @@
#
# All rights reserved.
#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
+# This file is part of ruby-ffi.
#
-# * Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * Neither the name of the Evan Phoenix nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
+# This code is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License version 3 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+# version 3 for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module FFI
class StructLayoutBuilder
@@ -67,18 +59,18 @@ module FFI
NUMBER_TYPES = [
- FFI::Type::INT8,
- FFI::Type::UINT8,
- FFI::Type::INT16,
- FFI::Type::UINT16,
- FFI::Type::INT32,
- FFI::Type::UINT32,
- FFI::Type::LONG,
- FFI::Type::ULONG,
- FFI::Type::INT64,
- FFI::Type::UINT64,
- FFI::Type::FLOAT32,
- FFI::Type::FLOAT64,
+ Type::INT8,
+ Type::UINT8,
+ Type::INT16,
+ Type::UINT16,
+ Type::INT32,
+ Type::UINT32,
+ Type::LONG,
+ Type::ULONG,
+ Type::INT64,
+ Type::UINT64,
+ Type::FLOAT32,
+ Type::FLOAT64,
]
def add(name, type, offset = nil)
@@ -103,18 +95,18 @@ module FFI
end
def add_struct(name, type, offset = nil)
- add(name, FFI::Type::Struct.new(type), offset)
+ add(name, Type::Struct.new(type), offset)
end
def add_array(name, type, count, offset = nil)
- add(name, FFI::Type::Array.new(type, count), offset)
+ add(name, Type::Array.new(type, count), offset)
end
def build
# Add tail padding if the struct is not packed
size = @packed ? @size : align(@size, @alignment)
- FFI::StructLayout.new(@fields, size, @alignment)
+ StructLayout.new(@fields, size, @alignment)
end
private
@@ -125,13 +117,13 @@ module FFI
def field_for_type(name, offset, type)
field_class = case
- when type.is_a?(FFI::Type::Function)
+ when type.is_a?(Type::Function)
StructLayout::Function
- when type.is_a?(FFI::Type::Struct)
+ when type.is_a?(Type::Struct)
StructLayout::InnerStruct
- when type.is_a?(FFI::Type::Array)
+ when type.is_a?(Type::Array)
StructLayout::Array
when type.is_a?(FFI::Enum)
@@ -140,19 +132,19 @@ module FFI
when NUMBER_TYPES.include?(type)
StructLayout::Number
- when type == FFI::Type::POINTER
+ when type == Type::POINTER
StructLayout::Pointer
- when type == FFI::Type::STRING
+ when type == Type::STRING
StructLayout::String
- when type.is_a?(Class) && type < FFI::StructLayout::Field
+ when type.is_a?(Class) && type < StructLayout::Field
type
when type.is_a?(DataConverter)
- return StructLayout::Mapped.new(name, offset, FFI::Type::Mapped.new(type), field_for_type(name, offset, type.native_type))
+ return StructLayout::Mapped.new(name, offset, Type::Mapped.new(type), field_for_type(name, offset, type.native_type))
- when type.is_a?(FFI::Type::Mapped)
+ when type.is_a?(Type::Mapped)
return StructLayout::Mapped.new(name, offset, type, field_for_type(name, offset, type.native_type))
else