1## 2# We manage a set of attributes. Each attribute has a symbol name and a bit 3# value. 4 5class RDoc::Markup::Attributes 6 7 ## 8 # The special attribute type. See RDoc::Markup#add_special 9 10 attr_reader :special 11 12 ## 13 # Creates a new attributes set. 14 15 def initialize 16 @special = 1 17 18 @name_to_bitmap = [ 19 [:_SPECIAL_, @special], 20 ] 21 22 @next_bitmap = @special << 1 23 end 24 25 ## 26 # Returns a unique bit for +name+ 27 28 def bitmap_for name 29 bitmap = @name_to_bitmap.assoc name 30 31 unless bitmap then 32 bitmap = @next_bitmap 33 @next_bitmap <<= 1 34 @name_to_bitmap << [name, bitmap] 35 else 36 bitmap = bitmap.last 37 end 38 39 bitmap 40 end 41 42 ## 43 # Returns a string representation of +bitmap+ 44 45 def as_string bitmap 46 return 'none' if bitmap.zero? 47 res = [] 48 49 @name_to_bitmap.each do |name, bit| 50 res << name if (bitmap & bit) != 0 51 end 52 53 res.join ',' 54 end 55 56 ## 57 # yields each attribute name in +bitmap+ 58 59 def each_name_of bitmap 60 return enum_for __method__, bitmap unless block_given? 61 62 @name_to_bitmap.each do |name, bit| 63 next if bit == @special 64 65 yield name.to_s if (bitmap & bit) != 0 66 end 67 end 68 69end 70 71