1
# parameter.rb : A class to describe a parameter
2
# Copyright (C) 2006 Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
require 'ctioga2/utils'
20
require 'ctioga2/metabuilder/type'
24
Version::register_svn_info('$Revision: 17 $', '$Date: 2009-04-28 22:22:22 +0200 (Tue, 28 Apr 2009) $')
30
# A parameter describes a way of storing some information into an
31
# instance of an object. No type checking is done on the target object
32
# when the actual reading/writing is done. However, the type checking
33
# is done upstream by the Description system.
35
# A Parameter consists of several things:
37
# * a #name, to identify it in a unique fashion;
38
# * a #type, used to convert to and from String and for user
39
# interaction in general;
40
# * some explanative text, used to inform the user: #long_name and
42
# * two symbols that are used to gain read and write access of the
43
# parameter on the target object.
45
# The Parameter class can be used to maintain a set of
46
# meta-informations about types in a given object.
49
# The short name of the parameter
52
# The long name of the parameter, to be translated
53
attr_accessor :long_name
55
# The function names that should be used to set the symbol and
56
# retrieve it's current value. The corresponding functions should
57
# read or return a string, and writer(reader) should be a noop.
58
attr_accessor :reader_symbol, :writer_symbol
60
# The (text) description of the parameter
61
attr_accessor :description
63
# The actual Commands::CommandType of the parameter
66
# Creates a new Parameter with the given symbols. Remember that
67
# if you don't intend to use #get, #get_raw, #set and #set_raw,
68
# you don't need to pass meaningful values to _writer_symbol_ and
70
def initialize(name, writer_symbol,
75
@writer_symbol = writer_symbol
76
@reader_symbol = reader_symbol
77
@description = description
78
@long_name = long_name
79
@type = Commands::CommandType::get_type(type)
83
# Sets directly the target parameter, without type conversion
84
def set_value(target, val)
85
target.send(@writer_symbol, val)
88
# Uses the #writer_symbol of the _target_ to set the value of the
89
# parameter to the one converted from the String _str_
90
def set_from_string(target, str)
91
set_value(target, string_to_type(str))
95
# Aquires the value from the backend, and returns it in the
97
def get_string(target)
98
return type_to_string(get_value(target))
101
# Aquires the value from the backend, and returns it.
102
def get_value(target)
103
target.send(@reader_symbol)