class MxxRu::Cpp::Spreadable_option
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, …
Constants
- ALL_OPT_METHOD
A name of a method, which should be used for reception of all options.
- ALL_UPSPREAD_METHOD
A name of a method, which should be used for reception of all upspread options.
Public Class Methods
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.
# 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
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.
# 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
Public Instance Methods
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.
# 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
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.
# 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
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.
# 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
To get only upspread options..
# File lib/mxx_ru/cpp/target.rb, line 246 def upspeads_only return @upspreads end
Protected Instance Methods
Add value to Array, if that value is still is not present there.
# File lib/mxx_ru/cpp/target.rb, line 299 def add_unique_to( what, to ) if !to.include?( what ) to.push( what ) SpreadableOption::refresh_option_change_time( @name ) end end
Check up value of a mode parameter on equality either OPT_UPSPREAD, or OPT_LOCAL and return object of Array type, in which it is necessary to place value.
- a_mode
-
mode parameter value for check.
# File lib/mxx_ru/cpp/target.rb, line 312 def check_opt_mode( a_mode ) if MxxRu::Cpp::Target::OPT_UPSPREAD == a_mode return @upspreads elsif MxxRu::Cpp::Target::OPT_LOCAL == a_mode return @locals else raise MxxRu::InvalidValueEx.new( "invalid option mode #{a_mode}" ) end end
Checks upspread options cache time and updates upspread options if needed.
# File lib/mxx_ru/cpp/target.rb, line 326 def try_update_upspread_options( subprojects, upspreads_method ) if @all_upspread_cache_time < @@cache_times[ @name ] # It is necessary to calculate cache anew. r = Array.new r << @upspreads subprojects.each { |p| if p.kind_of?( MxxRu::Cpp::Target ) r << p.send( upspreads_method ) end } @all_upspread_cache_value = r.flatten.uniq @all_upspread_cache_time = @@last_change_time end end