6e7acd9a8a8a072d9f2dfc762fc8828381f13f44
[chise/ruby.git] / lib / chise / rbchise.rb
1 #!/usr/bin/env ruby
2 # 'rbchise.so' ext compatible library by eto 2003-0317
3 # $Id: rbchise.rb,v 1.2 2003-11-30 13:16:38 eto Exp $
4 # Copyright (C) 2002-2003 Kouichirou Eto, All rights reserved.
5 # This is free software with ABSOLUTELY NO WARRANTY.
6 # You can redistribute it and/or modify it under the terms of the GNU GPL2.
7
8 require 'bdb'
9 require 'chise/config'
10
11 module CHISE
12
13   class DataSource #======================================================================
14     NONE = 0
15     Berkeley_DB = 1
16     #DEFAULT_CHAR_DB_DIR = "/usr/local/lib/chise/char-db"
17     #DEFAULT_CHAR_DB_DIR = "d:/chise/char-db"
18     def initialize(type=Berkeley_DB, location = nil)
19       @type, @location = type, location
20       @location = Config.instance.db_dir.to_s if @location
21     end
22     def close
23     end
24     def open_decofing_table(ccs)
25       DecodingTable.new(self, ccs)
26     end
27     def open_feature_table(feature)
28       FeatureTable.new(self, feature)
29     end
30   end
31
32   class AttributeTable #======================================================================
33     def open(from, to, real_subtpe, accessmask, modemask)
34     end
35     def get_value(char_id)
36       @db.get(char_id)
37     end
38     def close
39     end
40   end
41   
42   class DecodingTable #======================================================================
43     def initialize(ds, ccs)
44       @ds, @ccs = ds, ccs
45       #\82±\82±\82Åopen\82·\82é
46       @db = nil
47     end
48     def get_char(code_point)
49       @db.get(code_point)
50     end
51     def close
52     end
53   end
54   
55   class FeatureTable #======================================================================
56     def initialize(ds, feature)
57       @ds, @feature = ds, feature
58       #\82±\82±\82Åopen\82·\82é
59       @db = nil
60     end
61     def get_value(char_id)
62       @db.get(char_id)
63     end
64     def close
65     end
66   end
67   
68   class Value #======================================================================
69     def initialize(v)
70       @v = v;
71     end
72     def to_s()      @v;    end
73   end
74   
75 end
76
77 #----------------------------------------------------------------------end.