#
#  extmod.rb
#
#   Copyright (c) 1999,2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
#
#   This program is free software.
#   You can distribute/modify this program under the terms of
#   the GNU General Public License version 2 or later.
#
# usage:
#
#   class State
#     abstract :next_state
#     # classes under State must have 'next_state' method
#   end
#
#   class Address
#     property :addr, String, true, true
#     # 'addr' attribute, type String, both Read and Write is permitted
#   end
#

require 'amstd/to_s'
require 'amstd/must'


class Module

  def abstract( name )
    mname = _name2str( name )

    module_eval %-
      def #{mname}( *args, &blk )
        raise NotImplementedError, "abstract method '#{mname}' called"
      end
    -
  end

  def property( name, tipe, r, w )
    name = _name2str( name )
    tipe = _type2str( tipe )

    if r then
      attr name
    end
    if w then
      module_eval %-
        def #{name}=(arg)
          arg.must #{tipe}
          @#{name} = arg
          arg
        end
      -
    end
  end
  alias attribute property

end
