From: eto Date: Sat, 12 Jun 2004 04:52:12 +0000 (+0000) Subject: n.c. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=b1b2cc1a24b673a932a0a439723e158ecf06c6c3;p=chise%2Fruby.git n.c. --- diff --git a/chise/rbchise.rb b/chise/rbchise.rb index f12c238..e43ee16 100755 --- a/chise/rbchise.rb +++ b/chise/rbchise.rb @@ -7,6 +7,9 @@ require "fileutils" require "chise/util" module CHISE + module ChiseValue; end + module TableAccessModule; end + class DataSource NONE = 0 Berkeley_DB = 1 @@ -55,44 +58,57 @@ module CHISE 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 @@ -130,63 +146,32 @@ module CHISE 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 diff --git a/test/test-ccs.rb b/test/test-ccs.rb index 24d26db..e69de29 100755 --- a/test/test-ccs.rb +++ b/test/test-ccs.rb @@ -1,10 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. - -require "common" - -class TestCCS < Test::Unit::TestCase - def test_ccs - @cs = ChiseDB.instance - end -end