ctioga2 0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +339 -0
- data/Changelog +6 -0
- data/bin/ctioga2 +26 -0
- data/lib/ctioga2/commands/arguments.rb +58 -0
- data/lib/ctioga2/commands/commands.rb +258 -0
- data/lib/ctioga2/commands/doc/doc.rb +118 -0
- data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
- data/lib/ctioga2/commands/doc/help.rb +95 -0
- data/lib/ctioga2/commands/doc/html.rb +230 -0
- data/lib/ctioga2/commands/doc/introspection.rb +211 -0
- data/lib/ctioga2/commands/doc/man.rb +279 -0
- data/lib/ctioga2/commands/doc/markup.rb +359 -0
- data/lib/ctioga2/commands/general-commands.rb +119 -0
- data/lib/ctioga2/commands/general-types.rb +118 -0
- data/lib/ctioga2/commands/groups.rb +73 -0
- data/lib/ctioga2/commands/interpreter.rb +257 -0
- data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
- data/lib/ctioga2/commands/parsers/file.rb +186 -0
- data/lib/ctioga2/commands/strings.rb +303 -0
- data/lib/ctioga2/commands/type.rb +100 -0
- data/lib/ctioga2/commands/variables.rb +101 -0
- data/lib/ctioga2/data/backends/backend.rb +260 -0
- data/lib/ctioga2/data/backends/backends.rb +39 -0
- data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
- data/lib/ctioga2/data/backends/backends/math.rb +121 -0
- data/lib/ctioga2/data/backends/backends/text.rb +335 -0
- data/lib/ctioga2/data/backends/description.rb +405 -0
- data/lib/ctioga2/data/backends/factory.rb +73 -0
- data/lib/ctioga2/data/backends/parameter.rb +109 -0
- data/lib/ctioga2/data/datacolumn.rb +245 -0
- data/lib/ctioga2/data/dataset.rb +233 -0
- data/lib/ctioga2/data/filters.rb +131 -0
- data/lib/ctioga2/data/merge.rb +43 -0
- data/lib/ctioga2/data/point.rb +72 -0
- data/lib/ctioga2/data/stack.rb +294 -0
- data/lib/ctioga2/graphics/coordinates.rb +73 -0
- data/lib/ctioga2/graphics/elements.rb +111 -0
- data/lib/ctioga2/graphics/elements/containers.rb +111 -0
- data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
- data/lib/ctioga2/graphics/elements/element.rb +90 -0
- data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
- data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
- data/lib/ctioga2/graphics/generator.rb +68 -0
- data/lib/ctioga2/graphics/legends.rb +108 -0
- data/lib/ctioga2/graphics/legends/area.rb +199 -0
- data/lib/ctioga2/graphics/legends/items.rb +183 -0
- data/lib/ctioga2/graphics/legends/provider.rb +58 -0
- data/lib/ctioga2/graphics/legends/storage.rb +65 -0
- data/lib/ctioga2/graphics/root.rb +209 -0
- data/lib/ctioga2/graphics/styles.rb +30 -0
- data/lib/ctioga2/graphics/styles/axes.rb +247 -0
- data/lib/ctioga2/graphics/styles/background.rb +122 -0
- data/lib/ctioga2/graphics/styles/base.rb +115 -0
- data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
- data/lib/ctioga2/graphics/styles/curve.rb +101 -0
- data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
- data/lib/ctioga2/graphics/styles/factory.rb +351 -0
- data/lib/ctioga2/graphics/styles/legend.rb +63 -0
- data/lib/ctioga2/graphics/styles/plot.rb +410 -0
- data/lib/ctioga2/graphics/styles/sets.rb +64 -0
- data/lib/ctioga2/graphics/styles/texts.rb +277 -0
- data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
- data/lib/ctioga2/graphics/types.rb +188 -0
- data/lib/ctioga2/graphics/types/bijection.rb +79 -0
- data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
- data/lib/ctioga2/graphics/types/boxes.rb +157 -0
- data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
- data/lib/ctioga2/graphics/types/point.rb +247 -0
- data/lib/ctioga2/log.rb +97 -0
- data/lib/ctioga2/metabuilder/type.rb +316 -0
- data/lib/ctioga2/metabuilder/types.rb +39 -0
- data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
- data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
- data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
- data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
- data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
- data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
- data/lib/ctioga2/plotmaker.rb +677 -0
- data/lib/ctioga2/postprocess.rb +115 -0
- data/lib/ctioga2/utils.rb +120 -0
- data/setup.rb +1586 -0
- metadata +144 -0
@@ -0,0 +1,405 @@
|
|
1
|
+
# description.rb : a system for
|
2
|
+
# Copyright (C) 2006, 2009 Vincent Fourmond
|
3
|
+
|
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.
|
8
|
+
|
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.
|
13
|
+
|
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
|
17
|
+
|
18
|
+
require 'ctioga2/utils'
|
19
|
+
require 'ctioga2/data/backends/parameter'
|
20
|
+
require 'ctioga2/commands/commands'
|
21
|
+
require 'ctioga2/commands/groups'
|
22
|
+
|
23
|
+
module CTioga2
|
24
|
+
|
25
|
+
Version::register_svn_info('$Revision: 59 $', '$Date: 2009-05-28 23:15:50 +0200 (Thu, 28 May 2009) $')
|
26
|
+
|
27
|
+
|
28
|
+
module Data
|
29
|
+
|
30
|
+
module Backends
|
31
|
+
|
32
|
+
# The Description class is a meta-information class that records several
|
33
|
+
# informations about the class:
|
34
|
+
#
|
35
|
+
# * a basic name, code-like, which is used mainly for internal
|
36
|
+
# purposes;
|
37
|
+
# * a long name, more explanatory, in proper English (or any
|
38
|
+
# other language. By the way, it should definitely be
|
39
|
+
# translated in a production environment);
|
40
|
+
# * a description itself, some small text describing the nature
|
41
|
+
# of the class;
|
42
|
+
# * a list of all the Parameters that are important for the class,
|
43
|
+
# and enough to recreate the state of an object.
|
44
|
+
#
|
45
|
+
# This class is fairly general, and can be subclassed to fit specific
|
46
|
+
# needs. An example is in the SciYAG/Backend system, where the description
|
47
|
+
# of a backend is derived from Description.
|
48
|
+
#
|
49
|
+
# To make use of the Description system for a class, use the following:
|
50
|
+
#
|
51
|
+
# class SomeClass
|
52
|
+
# extend MetaBuilder::DescriptionExtend
|
53
|
+
# include MetaBuilder::DescriptionInclude
|
54
|
+
#
|
55
|
+
# describe 'someclass', 'Some nice class', <<EOD
|
56
|
+
# The description of a nice class
|
57
|
+
# EOD
|
58
|
+
#
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# Descriptions can be used in two completely different manners:
|
62
|
+
#
|
63
|
+
# * you can use a single Description to facilitate the interface
|
64
|
+
# with the user to query|save parameters;
|
65
|
+
# * you can use the Description system to describe a whole set of
|
66
|
+
# classes providing similar functions and sharing a base ancestor,
|
67
|
+
# such as series of input|output plugins, database formats,
|
68
|
+
# themes... In this case, the Description system can act as a real
|
69
|
+
# plugin factory, recording every new subclass of the base one
|
70
|
+
# and providing facilities to prompt the user.
|
71
|
+
#
|
72
|
+
# Please note that if you want to use the facilities to dynamically
|
73
|
+
# create objects at run-time, the classes used by describe
|
74
|
+
# *should not need any parameter for #initialize*.
|
75
|
+
#
|
76
|
+
# TODO: add functions to prepare commands to set the various
|
77
|
+
# parameters
|
78
|
+
#
|
79
|
+
# TODO: write the parameters stuff again...
|
80
|
+
class BackendDescription
|
81
|
+
# The Class to instantiate.
|
82
|
+
attr_accessor :object_class
|
83
|
+
|
84
|
+
# The name of the class (short, code-like)
|
85
|
+
attr_accessor :name
|
86
|
+
|
87
|
+
# (text) description !
|
88
|
+
attr_accessor :description
|
89
|
+
|
90
|
+
# Long name, the one for public display
|
91
|
+
attr_accessor :long_name
|
92
|
+
|
93
|
+
# The parameter list. The parameters are added when they are found
|
94
|
+
# in the class description, and will be used in the order found
|
95
|
+
# in this list to recreate the state; beware if one parameter is
|
96
|
+
# depending on another one.
|
97
|
+
attr_reader :param_list
|
98
|
+
|
99
|
+
# A hash index on the (short) name and the symbols of the parameters,
|
100
|
+
# for quick access. None of those should overlap.
|
101
|
+
attr_reader :param_hash
|
102
|
+
|
103
|
+
# The priority of the CmdGroup
|
104
|
+
DefaultBackendGroupPriority = 20
|
105
|
+
|
106
|
+
|
107
|
+
# Initializes a Description
|
108
|
+
def initialize(cls, name, long_name, description = "", register = true)
|
109
|
+
@object_class = cls
|
110
|
+
@name = name
|
111
|
+
@long_name = long_name
|
112
|
+
@description = description
|
113
|
+
@param_list = []
|
114
|
+
@param_hash = {}
|
115
|
+
@init_param_list = []
|
116
|
+
|
117
|
+
if register
|
118
|
+
Backend.register_class(self)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Adds a new parameter to the description
|
123
|
+
def add_param(param)
|
124
|
+
@param_list << param
|
125
|
+
|
126
|
+
# Update the parameter hash, for easy access.
|
127
|
+
@param_hash[param.reader_symbol] = param
|
128
|
+
@param_hash[param.writer_symbol] = param
|
129
|
+
@param_hash[param.name] = param
|
130
|
+
|
131
|
+
# Update the current group, if necessary
|
132
|
+
@current_group.add_parameter(param) unless @current_group.nil?
|
133
|
+
end
|
134
|
+
|
135
|
+
# Creates an instance of the Backend described by this
|
136
|
+
# BackendDescription. It takes parameters that are fed
|
137
|
+
# to the new function, but don't use them.
|
138
|
+
def instantiate(*a)
|
139
|
+
return @object_class.new(*a)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Creates a set of Cmd to interact with a given
|
143
|
+
# Backend. Commands created are:
|
144
|
+
# * one for each parameter to allow modification of its type
|
145
|
+
# * one for the selection of the Backend, allowing the use of
|
146
|
+
# optional arguments to change (permanently) the behaviour
|
147
|
+
# of the Backend.
|
148
|
+
#
|
149
|
+
# In addition, this function creates a group to store Backend
|
150
|
+
# commands.
|
151
|
+
#
|
152
|
+
# TODO: finish this !!!
|
153
|
+
def create_backend_commands
|
154
|
+
group = CmdGroup.
|
155
|
+
new("backend-#{@name}",
|
156
|
+
"The '#{@name}' backend: #{@long_name}",
|
157
|
+
"The commands in this group drive the "+
|
158
|
+
"behaviour of the #{@long_name} backend.\n" +
|
159
|
+
@description,
|
160
|
+
DefaultBackendGroupPriority)
|
161
|
+
|
162
|
+
backend_options = {}
|
163
|
+
|
164
|
+
# Again, each is needed for scoping problems.
|
165
|
+
@param_list.each do |param|
|
166
|
+
arg = CmdArg.new(param.type, param.name)
|
167
|
+
a = Cmd.new("#{@name}-#{param.name}",
|
168
|
+
nil, "--#{@name}-#{param.name}",
|
169
|
+
[arg], {},
|
170
|
+
"Set the #{param.long_name} parameter of backend '#{@name}'",
|
171
|
+
param.description, group) do |plotmaker, value|
|
172
|
+
plotmaker.data_stack.backend_factory.
|
173
|
+
set_backend_parameter_value(@name, param.name, value)
|
174
|
+
end
|
175
|
+
backend_options[param.name] = arg.dup
|
176
|
+
end
|
177
|
+
|
178
|
+
# TODO: add option parsing
|
179
|
+
Cmd.new("#{@name}", nil, "--#{@name}", [],
|
180
|
+
backend_options, "Selects the '#{@name}' backend",
|
181
|
+
nil, group) do |plotmaker, options|
|
182
|
+
plotmaker.data_stack.backend_factory.set_current_backend(@name)
|
183
|
+
for k,v in options
|
184
|
+
plotmaker.data_stack.backend_factory.
|
185
|
+
set_backend_parameter_value(@name, k, v)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
# This module should be used with +extend+ to provide the class
|
193
|
+
# with descriptions functionnalities. Please not that all the
|
194
|
+
# *instance* methods defined here will become *class* methods in
|
195
|
+
# the class you extend.
|
196
|
+
#
|
197
|
+
# This module defines several methods to add a description
|
198
|
+
# (#describe) to a class, to add parameters (#param,
|
199
|
+
# #param_noaccess) and to import parameters from parents
|
200
|
+
# (#inherit_parameters).
|
201
|
+
#
|
202
|
+
# Factories can be created using the #craete_factory statement.
|
203
|
+
# This makes the current class the factory repository for all
|
204
|
+
# the subclasses. It creates a factory class method returning
|
205
|
+
# the base factory. You can use #register_class to register the
|
206
|
+
# current class into the base factory class.
|
207
|
+
module BackendDescriptionExtend
|
208
|
+
|
209
|
+
# The functions for factory handling.
|
210
|
+
|
211
|
+
# Makes this class the factory class for all subclasses. It
|
212
|
+
# creates four class methods: base_factory, that always points
|
213
|
+
# to the closest factory in the hierarchy and three methods
|
214
|
+
# used internally.
|
215
|
+
#
|
216
|
+
# If _auto_ is true, the subclasses are all automatically
|
217
|
+
# registered to the factory. If _register_self_ is true the
|
218
|
+
# class itself is registered. It is probably not a good idea,
|
219
|
+
# so it is off by default.
|
220
|
+
def create_factory(auto = true, register_self = false)
|
221
|
+
cls = self
|
222
|
+
# we create a temporary module so that we can use
|
223
|
+
# define_method with a block and extend this class with it
|
224
|
+
mod = Module.new
|
225
|
+
mod.send(:define_method, :factory) do
|
226
|
+
return cls
|
227
|
+
end
|
228
|
+
mod.send(:define_method, :private_description_list) do
|
229
|
+
return @registered_descriptions
|
230
|
+
end
|
231
|
+
mod.send(:define_method, :private_description_hash) do
|
232
|
+
return @registered_descriptions_hash
|
233
|
+
end
|
234
|
+
# Creates an accessor for the factory class
|
235
|
+
mod.send(:define_method, :private_auto_register) do
|
236
|
+
@auto_register_subclasses
|
237
|
+
end
|
238
|
+
self.extend(mod)
|
239
|
+
|
240
|
+
# Creates the necessary arrays|hashes to handle the
|
241
|
+
# registered classes:
|
242
|
+
@registered_descriptions = []
|
243
|
+
@registered_descriptions_hash = {}
|
244
|
+
|
245
|
+
@auto_register_subclasses = auto
|
246
|
+
end
|
247
|
+
|
248
|
+
# Checks if the class has a factory
|
249
|
+
def has_factory?
|
250
|
+
return self.respond_to?(:factory)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Returns the base description if there is one, or nil if
|
254
|
+
# there isn't
|
255
|
+
def base_description
|
256
|
+
if has_factory?
|
257
|
+
return factory.description
|
258
|
+
else
|
259
|
+
return nil
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
# Returns the description list of the factory. Raises an
|
264
|
+
# exception if there is no factory
|
265
|
+
def factory_description_list
|
266
|
+
raise "Must have a factory" unless has_factory?
|
267
|
+
return factory.private_description_list
|
268
|
+
end
|
269
|
+
|
270
|
+
# Returns the description hash of the factory. Raises an
|
271
|
+
# exception if there is no factory
|
272
|
+
def factory_description_hash
|
273
|
+
raise "Must have a factory" unless has_factory?
|
274
|
+
return factory.private_description_hash
|
275
|
+
end
|
276
|
+
|
277
|
+
# Returns the factory description with the given name
|
278
|
+
def factory_description(name)
|
279
|
+
raise "Must have a factory" unless has_factory?
|
280
|
+
return factory_description_hash.fetch(name)
|
281
|
+
end
|
282
|
+
|
283
|
+
# Returns the Class object associated with the given name in
|
284
|
+
# the factory
|
285
|
+
def factory_class(name)
|
286
|
+
return factory_description(name).object_class
|
287
|
+
end
|
288
|
+
|
289
|
+
# Registers the given description to the factory. If no
|
290
|
+
# description is given, the current class is registered.
|
291
|
+
def register_class(desc = nil)
|
292
|
+
raise "One of the superclasses should have a 'factory' statement" unless
|
293
|
+
has_factory?
|
294
|
+
desc = description if desc.nil?
|
295
|
+
factory_description_list << desc
|
296
|
+
factory_description_hash[desc.name] = desc
|
297
|
+
end
|
298
|
+
|
299
|
+
# Returns the Description of the class.
|
300
|
+
def description
|
301
|
+
return @description
|
302
|
+
end
|
303
|
+
|
304
|
+
# Sets the description of the class. It is probably way better
|
305
|
+
# to use #describe, or write your own class method in the base
|
306
|
+
# class in the case of a family of classes.
|
307
|
+
def set_description(desc)
|
308
|
+
@description = desc
|
309
|
+
if has_factory? and factory.private_auto_register
|
310
|
+
register_class
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
# Registers an new parameter, with the following properties:
|
316
|
+
# * _writer_ is the name of the method used to write that parameter;
|
317
|
+
# * _reader_ the name of the method that returns its current value;
|
318
|
+
# * _name_ is a short code-like name of the parameter (typically
|
319
|
+
# lowercase);
|
320
|
+
# * _long_name_ is a more descriptive name, properly capitalized and
|
321
|
+
# localized if possible;
|
322
|
+
# * _type_ is it's type. Please see the MetaBuilder::ParameterType
|
323
|
+
# for a better description of what is a type;
|
324
|
+
# * _desc_ is a proper (short) description of the parameter,
|
325
|
+
# something that would fit on a What's this box, for instance.
|
326
|
+
# * _attrs_ are optional parameters that may come useful, see
|
327
|
+
# Parameter#attributes documentation.
|
328
|
+
#
|
329
|
+
# You might want to use the #param_reader, #param_writer, and
|
330
|
+
# #param_accessor facilities that create the respective
|
331
|
+
# accessors in addition. A typical example would be:
|
332
|
+
#
|
333
|
+
# param :set_size, :size, 'size', "Size", {:type => :integer},
|
334
|
+
# "The size !!"
|
335
|
+
def param(writer, reader, name, long_name, type,
|
336
|
+
desc = "")
|
337
|
+
raise "Use describe first" if description.nil?
|
338
|
+
param = nil
|
339
|
+
param = Parameter.new(name, writer, reader,
|
340
|
+
long_name, type, desc)
|
341
|
+
description.add_param(param)
|
342
|
+
return param
|
343
|
+
end
|
344
|
+
|
345
|
+
# The same as #param, but creates a attr_reader in addition
|
346
|
+
def param_reader(writer, reader, name, long_name, type,
|
347
|
+
desc = "")
|
348
|
+
attr_reader reader
|
349
|
+
return param(writer, reader, name, long_name, type, desc)
|
350
|
+
end
|
351
|
+
|
352
|
+
# The same as #param, except that _writer_ is made from
|
353
|
+
# _symbol_ by appending a = at the end. An attr_writer is
|
354
|
+
# created for the _symbol_.
|
355
|
+
def param_writer(symbol, name, long_name, type,
|
356
|
+
desc = "")
|
357
|
+
writer = (symbol.to_s + '=').to_sym
|
358
|
+
attr_writer symbol
|
359
|
+
return param(writer, symbol, name, long_name, type, desc)
|
360
|
+
end
|
361
|
+
|
362
|
+
# The same as #param_writer, except that an attr_writer is
|
363
|
+
# created for the _symbol_ instead of only a attr_writer. The
|
364
|
+
# most useful of the four methods. Typical use:
|
365
|
+
#
|
366
|
+
# param_accessor :name, 'name', "Object name", {:type => :string},
|
367
|
+
# "The name of the object"
|
368
|
+
def param_accessor(symbol, name, long_name, type,
|
369
|
+
desc = "")
|
370
|
+
writer = (symbol.to_s + '=').to_sym
|
371
|
+
attr_accessor symbol
|
372
|
+
return param(writer, symbol, name, long_name, type, desc)
|
373
|
+
end
|
374
|
+
|
375
|
+
# Creates a description attached to the current class. It
|
376
|
+
# needs to be used before anything else.
|
377
|
+
def describe(name, longname = name, desc = "")
|
378
|
+
d = Description.new(self, name, longname, desc)
|
379
|
+
set_description(d)
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
# Imports the given parameters directly from the parent class.
|
384
|
+
# This function is quite naive and will not look further than
|
385
|
+
# the direct #superclass.
|
386
|
+
def inherit_parameters(*names)
|
387
|
+
if self.superclass.respond_to?(:description)
|
388
|
+
parents_params = self.superclass.description.param_hash
|
389
|
+
for n in names
|
390
|
+
if parents_params.key?(n)
|
391
|
+
description.add_param(parents_params[n])
|
392
|
+
else
|
393
|
+
warn "Param #{n} not found"
|
394
|
+
end
|
395
|
+
end
|
396
|
+
else
|
397
|
+
warn "The parent class has no description"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# factory.rb : a class holdling a set of Backends
|
2
|
+
# Copyright (C) 2009 Vincent Fourmond
|
3
|
+
|
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.
|
8
|
+
#
|
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.
|
13
|
+
#
|
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
|
17
|
+
|
18
|
+
require 'ctioga2/utils'
|
19
|
+
require 'ctioga2/data/backends/backend'
|
20
|
+
|
21
|
+
module CTioga2
|
22
|
+
|
23
|
+
Version::register_svn_info('$Revision: 2 $', '$Date: 2009-04-25 14:03:30 +0200 (Sat, 25 Apr 2009) $')
|
24
|
+
|
25
|
+
module Data
|
26
|
+
|
27
|
+
module Backends
|
28
|
+
|
29
|
+
# This class holds an instance of all the different Backend
|
30
|
+
# available, and features a 'current backend'.
|
31
|
+
class BackendFactory
|
32
|
+
|
33
|
+
# A hash name (as in Description#name) -> Backend
|
34
|
+
attr_accessor :backends
|
35
|
+
|
36
|
+
# The current Backend
|
37
|
+
attr_accessor :current
|
38
|
+
|
39
|
+
# Creates a new BackendFactory
|
40
|
+
def initialize(default)
|
41
|
+
@backends = {}
|
42
|
+
@backend_descriptions = Backend.list_backends
|
43
|
+
for backend in @backend_descriptions.keys
|
44
|
+
reset_backend(backend)
|
45
|
+
# Add commands
|
46
|
+
@backend_descriptions[backend].create_backend_commands
|
47
|
+
end
|
48
|
+
@current = @backends[default]
|
49
|
+
end
|
50
|
+
|
51
|
+
# Resets the given backend to its default values.
|
52
|
+
def reset_backend(backend)
|
53
|
+
@backends[backend] = @backend_descriptions[backend].instantiate
|
54
|
+
end
|
55
|
+
|
56
|
+
# Selects the current backend
|
57
|
+
def set_current_backend(backend)
|
58
|
+
@current = @backends[backend]
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
# Sets the (raw) value of the parameter of the given backend
|
63
|
+
def set_backend_parameter_value(backend, param, value)
|
64
|
+
b = @backends[backend]
|
65
|
+
# This is way too complicated !
|
66
|
+
b.description.param_hash[param].set_value(b, value)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|