Class: MxxRu::Cpp::SpreadableOption

Inherits:
Object
  • Object
show all
Defined in:
lib/mxx_ru/cpp/target.rb

Overview

Auxiliary class for a storage of options, which can be broken on 3 groups: global, local and upspread. Examples of such options are: defines, include_paths, compiler_options, linker_options, …

Constant Summary collapse

ALL_OPT_METHOD =

A name of a method, which should be used for reception of all options.

"all"
ALL_UPSPREAD_METHOD =

A name of a method, which should be used for reception of all upspread options.

"all_upspreads"
@@last_change_time =

The global tick counter which is used for check that cached values are still correct. Is increased at each reference to add.

1
@@cache_times =

Global hash, in which the time of last change of options with a concrete name is fixed.

Hash.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_option_name) ⇒ SpreadableOption

Constructor.

a_option_name

The name of an option, which serves the given object. This name will be used for fixation of time of caching in @@cache_times object.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/mxx_ru/cpp/target.rb', line 209

def initialize( a_option_name )

  @@cache_times[ a_option_name ] = 1

  # Own name.
  @name = a_option_name

  # Own options.
  @locals = Array.new
  # Spreadable options.
  @upspreads = Array.new

  # Cached value of all method.
  @all_cache_value = Array.new
  # @@last_change_time value at caching moment in all method.
  @all_cache_time = 0

  # Cached value of all_upspread method.
  @all_upspread_cache_value = Array.new
  # @@last_change_time value at caching moment in all_upspread method.
  @all_upspread_cache_time = 0

end

Class Method Details

.refresh_option_change_time(a_option_name) ⇒ Object

Set new time of change of value of an option. This method is intended for use at change of global options, which are stored separately from spreadable-options, but which values are included in values of spreadable-options.



199
200
201
202
# File 'lib/mxx_ru/cpp/target.rb', line 199

def SpreadableOption.refresh_option_change_time( a_option_name )
  @@last_change_time = @@last_change_time + 1
  @@cache_times[ a_option_name ] = @@last_change_time
end

Instance Method Details

#add(a_option, a_mode = MxxRu::Cpp::Target::OPT_LOCAL) ⇒ Object

Add option.

a_option

Added value.

a_mode

Local or upspread option. Is set by values MxxRu::Cpp::Target::OPT_LOCAL, MxxRu::Cpp::Target::OPT_UPSPEAD.



239
240
241
242
243
# File 'lib/mxx_ru/cpp/target.rb', line 239

def add(
  a_option,
  a_mode = MxxRu::Cpp::Target::OPT_LOCAL )
  add_unique_to( a_option, check_opt_mode( a_mode ) )
end

#all(a_globals, a_subprojects, a_upspreads_method) ⇒ Object

To generate the list of all options.

a_globals

The storage of global options, from which is necessary to take values.

a_subprojects

The list of all subordinated projects. Array of MxxRu::AbstractTarget.

a_upspreads_method

The name of a method, which needs to be called from the subordinated project, to get it’s list of all upspread options.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/mxx_ru/cpp/target.rb', line 259

def all(
  a_globals,
  a_subprojects,
  a_upspreads_method )

  if @all_cache_time < @@cache_times[ @name ]
    # It is necessary to calculate cache anew.
    r = Array.new
    r << a_globals << @locals

    # At the same time it is possible to update cache of upspread-options.
    try_update_upspread_options( a_subprojects, a_upspreads_method )

    r << @all_upspread_cache_value
      
    @all_cache_value = r.flatten.uniq
    @all_cache_time = @@last_change_time
  end

  return @all_cache_value
end

#all_upspreads(a_subprojects, a_upspreads_method) ⇒ Object

To generate the list of all upspread options.

a_subprojects

The list of all subordinated projects. Array of MxxRu::AbstractTarget.

a_upspreads_method

The name of a method, which needs to be called from the subordinated project, to get it’s list of all upspread options.



288
289
290
291
292
293
294
295
# File 'lib/mxx_ru/cpp/target.rb', line 288

def all_upspreads(
  a_subprojects,
  a_upspreads_method )

  try_update_upspread_options( a_subprojects, a_upspreads_method )

  return @all_upspread_cache_value
end

#upspeads_onlyObject

To get only upspread options..



246
247
248
# File 'lib/mxx_ru/cpp/target.rb', line 246

def upspeads_only
  return @upspreads
end