require "chise/util"
module CHISE
+ module ChiseValue; end
+ module TableAccessModule; end
+
class DataSource
NONE = 0
Berkeley_DB = 1
end
end
- module ChiseValue; end
+ class FeatureTable
+ include ChiseValue
+ include TableAccessModule
- class AttributeTable
- def initialize(dir, cat, keytype, name, amask, mmask)
- dbdir = dir + cat + keytype
- #FileUtils.mkdir_p(dbdir.to_s) unless dbdir.directory?
- name = name.path
- name = name.escape
- name = name.escape_win_filename
- path = dbdir + name
-# qp path, amask, mmask
- raise unless path.exist?
-# @db = BDB::Hash.open(path.to_s, amask, mmask)
- @db = BDB::Hash.open(path.to_s)
- at_exit {
- close
+ def set_value(cid, value)
+ setup_db(true)
+ return nil if @db.nil?
+ @db.put(format_char_id(cid), value)
+ end
+
+ def get_value(cid)
+ setup_db
+ return nil if @db.nil?
+ @db.get(format_char_id(cid))
+ end
+
+ def each
+ setup_db
+ return nil if @db.nil?
+ @db.each {|k, v|
+ yield(parse_c_string(k), v)
}
end
- def close
- return if @db.nil?
- begin
- @db.sync
- @db.close
- rescue
- end
+ private
+ def setup_db(writable=nil)
+ setup_db_exec(writable, "character", "feature")
end
+ end
+
+ class CCSTable
+ include ChiseValue
+ include TableAccessModule
- def get(k)
- @db.get(k)
+ def decode(code_point)
+ setup_db
+ return nil if @db.nil?
+ v = @db.get(code_point.to_s)
+ return nil if v.nil?
+ parse_c_string(v)
end
- def put(k, v)
- @db.put(k, v)
+ def set_decoded_char(code_point, cid)
+ setup_db(true)
+ return nil if @db.nil?
+ @db.put(code_point.to_s, format_char_id(cid))
end
- def each
- @db.each {|k, v| yield(k, v) }
+ private
+ def setup_db(writable=nil)
+ setup_db_exec(writable, "character", "by_feature")
end
end
end
end
- class FeatureTable
- include ChiseValue
- include TableAccessModule
-
- def set_value(cid, value)
- setup_db(true)
- return nil if @db.nil?
- key = format_char_id(cid)
- @db.put(key, value)
- end
-
- def get_value(cid)
- setup_db
- return nil if @db.nil?
- key = format_char_id(cid)
- @db.get(key)
- end
-
- def each
- setup_db
- return nil if @db.nil?
- @db.each {|k, v|
- cid = parse_c_string(k)
- yield(cid, v)
+ class AttributeTable
+ def initialize(dir, cat, keytype, name, amask, mmask)
+ dbdir = dir + cat + keytype
+ #FileUtils.mkdir_p(dbdir.to_s) unless dbdir.directory?
+ path = dbdir + name.path.escape.escape_win_filename
+# qp path, amask, mmask
+ raise unless path.exist?
+# @db = BDB::Hash.open(path.to_s, amask, mmask)
+ @db = BDB::Hash.open(path.to_s)
+ at_exit {
+ close
}
end
- private
- def setup_db(writable=nil)
- setup_db_exec(writable, "character", "feature")
- end
- end
-
- class CCSTable
- include ChiseValue
- include TableAccessModule
-
- def decode(code_point)
- setup_db
- k = code_point.to_s
- v = @db.get(k)
- return nil if v.nil?
- cid = parse_c_string(v)
- cid
- end
-
- def set_decoded_char(code_point, cid)
- setup_db(true)
- k = code_point.to_s
- v = format_char_id(cid)
- @db.put(k, v)
+ def close
+ return if @db.nil?
+ begin
+ @db.sync
+ @db.close
+ rescue
+ end
end
- private
- def setup_db(writable=nil)
- setup_db_exec(writable, "character", "by_feature")
- end
+ def get(k) @db.get(k); end
+ def put(k, v) @db.put(k, v); end
+ def each() @db.each {|k, v| yield(k, v) } end
end
module ChiseValue