Permalink
Browse files

Organize FFI calls

  • Loading branch information...
1 parent c8526d2 commit 31202971e1685cd6bd0b05d79d06a110e2b9e565 @jamesdabbs committed Apr 11, 2013
Showing with 112 additions and 101 deletions.
  1. +5 −83 lib/steffi/ffi.rb
  2. +30 −0 lib/steffi/ffi/basic.rb
  3. +19 −0 lib/steffi/ffi/constructors.rb
  4. +58 −0 lib/steffi/ffi/vector.rb
  5. +0 −18 lib/steffi/graph/constructors.rb
View
@@ -33,87 +33,9 @@ def self.method_missing name, *args, &block
send :"igraph_#{name}", *args, &block
end
end
-
- enum :neimode, [:out, 1, :in, 2, :all, 3, :total, 3]
-
- # 4.2.1 Graph constructors and deconstructors
- bind :empty, [:pointer, :int, :bool]
- bind :copy, [:pointer, :pointer]
- bind :destroy, [:pointer]
- # bind :empty_attrs, [:pointer, :int, :bool, :pointer] # graph, vertex count, directed?, (void *) attributes
-
- # 4.2.2 Basic query operations
- bind :vcount, [:pointer], :int
- bind :ecount, [:pointer], :int
- bind :edge, [:pointer, :int, :pointer, :pointer]
- bind :get_eid, [:pointer, :pointer, :int, :int, :bool, :bool]
- bind :get_eids, [:pointer, :pointer, :pointer, :pointer, :bool, :bool]
- bind :neighbors, [:pointer, :pointer, :int, :neimode]
- bind :incident, [:pointer, :pointer, :int, :neimode]
- bind :is_directed, [:pointer], :bool
- # bind :get_eids_multi, [:pointer, :pointer, :pointer, :pointer, :bool, :bool] # graph, &[edge #]. &[pairs], &[path], directed?, error?
- # bind :degree, [:pointer, :pointer, :int, :bool] # graph, &[results], vids, mode, loops?
-
- # 4.2.3 Adding and deleting vertices and edges
- bind :add_edge, [:pointer, :int, :int]
- # bind :add_edges, [:pointer, :pointer, :pointer] # graph, [edges], (void *) attrs
- # bind :add_vertices, [:pointer, :int, :pointer] # graph, id, (void *) attr
- # bind :delete_edges, [:pointer, :pointer] # graph, eids
- # bind :delete_vertices, [:pointer, :pointer] # graph, vids
-
- # 7.2.2
- bind :vector_init, [:pointer, :long]
- bind :vector_init_seq, [:pointer, :double, :double]
- # bind :vector_init_copy, [:pointer, :pointer, :long] # vector, data, length
- # bind :vector_copy, [:pointer, :pointer] # from, to
- # bind :vector_destroy, [:pointer] # vector
-
- # 7.2.3 Initializing elements
- # bind :vector_null, [:pointer], :void # vector
- # bind :vector_fill, [:pointer, :double], :void # vector, value
-
- # 7.2.4 Accessing elements
- bind :vector_e, [:pointer, :long], :double
- bind :vector_set, [:pointer, :long, :double], :void
- bind :vector_tail, [:pointer], :double
- # bind :vector_e_ptr, [:pointer, :long], :pointer # vector, pos => address
-
- # 7.2.5 Vector views
- # bind :vector_view, [:pointer, :pointer, :long], :pointer # vector, data, len => vector
-
- # 7.2.6 Copying vectors
- # bind :vector_copy_to, [:pointer, :pointer], :void # vector, array
- # bind :vector_update, [:pointer, :pointer] # to, from
- # bind :vector_append, [:pointer, :pointer] # to, from
- # bind :vector_swap, [:pointer, :pointer] # v1, v2
-
- # 7.2.7 Exchanging elements
- # ...
- # 7.2.8 Vector operations
- # ...
- # 7.2.9 Vector comparisons
- # ...
- # 7.2.10 Finding minimum and maximum
- # ...
-
- # 7.2.11 Vector properties
- bind :vector_empty, [:pointer], :bool
- bind :vector_size, [:pointer], :long
- # bind :vector_capacity, [:pointer], :long # vector => alloc'd cap
- # bind :vector_sum, [:pointer], :double # vector => sum
- # bind :vector_prod, [:pointer], :double # vector => prod
- # bind :vector_isininterval, [:pointer, :double, :double], :bool # vector, low, high => pass?
- # bind :vector_maxdifference, [:pointer, :pointer], :double # v1, v2 => max termwise diff
-
- # 7.2.12 Searching for elements
- # ...
- # 7.2.13 Resizing operations
- # ...
- # 7.2.14 Sorting
- # ...
- # 7.2.15 Set operations on sorted vectors
- # ...
- # 7.2.16 Pointer vectors
- # ...
end
-end
+end
+
+require_relative 'ffi/basic'
+require_relative 'ffi/vector'
+require_relative 'ffi/constructors'
View
@@ -0,0 +1,30 @@
+module Steffi
+ module Igraph
+ enum :neimode, [:out, 1, :in, 2, :all, 3, :total, 3]
+
+ # 4.2.1 Graph constructors and deconstructors
+ bind :empty, [:pointer, :int, :bool]
+ bind :copy, [:pointer, :pointer]
+ bind :destroy, [:pointer]
+ # bind :empty_attrs, [:pointer, :int, :bool, :pointer] # graph, vertex count, directed?, (void *) attributes
+
+ # 4.2.2 Basic query operations
+ bind :vcount, [:pointer], :int
+ bind :ecount, [:pointer], :int
+ bind :edge, [:pointer, :int, :pointer, :pointer]
+ bind :get_eid, [:pointer, :pointer, :int, :int, :bool, :bool]
+ bind :get_eids, [:pointer, :pointer, :pointer, :pointer, :bool, :bool]
+ bind :neighbors, [:pointer, :pointer, :int, :neimode]
+ bind :incident, [:pointer, :pointer, :int, :neimode]
+ bind :is_directed, [:pointer], :bool
+ # bind :get_eids_multi, [:pointer, :pointer, :pointer, :pointer, :bool, :bool] # graph, &[edge #]. &[pairs], &[path], directed?, error?
+ # bind :degree, [:pointer, :pointer, :int, :bool] # graph, &[results], vids, mode, loops?
+
+ # 4.2.3 Adding and deleting vertices and edges
+ bind :add_edge, [:pointer, :int, :int]
+ # bind :add_edges, [:pointer, :pointer, :pointer] # graph, [edges], (void *) attrs
+ # bind :add_vertices, [:pointer, :int, :pointer] # graph, id, (void *) attr
+ # bind :delete_edges, [:pointer, :pointer] # graph, eids
+ # bind :delete_vertices, [:pointer, :pointer] # graph, vids
+ end
+end
@@ -0,0 +1,19 @@
+module Steffi
+ module Igraph
+ enum :erdos_renyi, [:gnp, :gnm]
+ enum :star_mode, [:out, :in, :undirected, :mutual]
+ enum :tree_mode, [:out, :in, :undirected]
+
+ bind :read_graph_edgelist, [:pointer, :pointer, :int, :bool], :int
+ bind :read_graph_gml, [:pointer, :pointer], :int
+ bind :atlas, [:pointer, :int], :int
+ bind :cited_type_game, [:pointer, :int, :pointer, :pointer, :int, :bool], :int
+ bind :erdos_renyi_game, [:pointer, :int, :int, :double, :bool, :bool], :int
+ bind :forest_fire_game, [:pointer, :int, :double, :double, :int, :bool], :int
+ bind :famous, [:pointer, :string], :int
+ bind :full, [:pointer, :int, :bool, :bool], :int
+ bind :ring, [:pointer, :int, :bool, :bool, :bool], :int
+ bind :star, [:pointer, :int, :star_mode, :int], :int
+ bind :tree, [:pointer, :int, :int, :int], :int
+ end
+end
View
@@ -0,0 +1,58 @@
+module Steffi
+ module Igraph
+ # 7.2.2
+ bind :vector_init, [:pointer, :long]
+ bind :vector_init_seq, [:pointer, :double, :double]
+ # bind :vector_init_copy, [:pointer, :pointer, :long] # vector, data, length
+ # bind :vector_copy, [:pointer, :pointer] # from, to
+ # bind :vector_destroy, [:pointer] # vector
+
+ # 7.2.3 Initializing elements
+ # bind :vector_null, [:pointer], :void # vector
+ # bind :vector_fill, [:pointer, :double], :void # vector, value
+
+ # 7.2.4 Accessing elements
+ bind :vector_e, [:pointer, :long], :double
+ bind :vector_set, [:pointer, :long, :double], :void
+ bind :vector_tail, [:pointer], :double
+ # bind :vector_e_ptr, [:pointer, :long], :pointer # vector, pos => address
+
+ # 7.2.5 Vector views
+ # bind :vector_view, [:pointer, :pointer, :long], :pointer # vector, data, len => vector
+
+ # 7.2.6 Copying vectors
+ # bind :vector_copy_to, [:pointer, :pointer], :void # vector, array
+ # bind :vector_update, [:pointer, :pointer] # to, from
+ # bind :vector_append, [:pointer, :pointer] # to, from
+ # bind :vector_swap, [:pointer, :pointer] # v1, v2
+
+ # 7.2.7 Exchanging elements
+ # ...
+ # 7.2.8 Vector operations
+ # ...
+ # 7.2.9 Vector comparisons
+ # ...
+ # 7.2.10 Finding minimum and maximum
+ # ...
+
+ # 7.2.11 Vector properties
+ bind :vector_empty, [:pointer], :bool
+ bind :vector_size, [:pointer], :long
+ bind :vector_sum, [:pointer], :double # vector => sum
+ bind :vector_prod, [:pointer], :double # vector => prod
+ # bind :vector_capacity, [:pointer], :long # vector => alloc'd cap
+ # bind :vector_isininterval, [:pointer, :double, :double], :bool # vector, low, high => pass?
+ # bind :vector_maxdifference, [:pointer, :pointer], :double # v1, v2 => max termwise diff
+
+ # 7.2.12 Searching for elements
+ # ...
+ # 7.2.13 Resizing operations
+ # ...
+ # 7.2.14 Sorting
+ # ...
+ # 7.2.15 Set operations on sorted vectors
+ # ...
+ # 7.2.16 Pointer vectors
+ # ...
+ end
+end
@@ -1,23 +1,5 @@
module Steffi
- module Igraph
- enum :erdos_renyi, [:gnp, :gnm]
- enum :star_mode, [:out, :in, :undirected, :mutual]
- enum :tree_mode, [:out, :in, :undirected]
-
- bind :read_graph_edgelist, [:pointer, :pointer, :int, :bool], :int
- bind :read_graph_gml, [:pointer, :pointer], :int
- bind :atlas, [:pointer, :int], :int
- bind :cited_type_game, [:pointer, :int, :pointer, :pointer, :int, :bool], :int
- bind :erdos_renyi_game, [:pointer, :int, :int, :double, :bool, :bool], :int
- bind :forest_fire_game, [:pointer, :int, :double, :double, :int, :bool], :int
- bind :famous, [:pointer, :string], :int
- bind :full, [:pointer, :int, :bool, :bool], :int
- bind :ring, [:pointer, :int, :bool, :bool, :bool], :int
- bind :star, [:pointer, :int, :star_mode, :int], :int
- bind :tree, [:pointer, :int, :int, :int], :int
- end
-
class Graph
class << self

0 comments on commit 3120297

Please sign in to comment.