Class: MxxRu::Generators::Impl::Cpp::TemplateParams

Inherits:
Object
  • Object
show all
Defined in:
lib/mxx_ru/generators/impl/cpp/generation.rb

Overview

Class to be used in ERb template generation.

Usage:

template_params = TemplateParams.new( target_type, options )
template = ERb.new( IO.read( some_template_file ) )
result = template.generate( template.get_binding )

Constant Summary collapse

YOUR_TARGET_NAME =

For a case when target_name is undetectable.

'your target name'
YOUR_IMPLIB_PATH =

For a case when implib_path is undetectable.

'your import library path'
@@setup_target_functions =

Dependencies between target_type and setup_target function name.

{
    LIB => 'lib_target',
    LIB_COLLECTION => 'lib_collection_target',
    DLL => 'dll_target',
    EXE => 'exe_target',
    COMPOSITE => 'composite_target'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_type, options) ⇒ TemplateParams

Param target_type must be present in @@setup_target_functions.



155
156
157
158
159
160
161
162
163
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 155

def initialize( target_type, options )
  TemplateParams.check_target_type( target_type )

  @target_type = target_type
  @options = options

  try_setup_target_name
  try_setup_implib_name
end

Instance Attribute Details

#implib_pathObject (readonly)

Name of import library path.



152
153
154
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 152

def implib_path
  @implib_path
end

#target_nameObject (readonly)

Name of target.



150
151
152
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 150

def target_name
  @target_name
end

#target_typeObject (readonly)

Type of target.



148
149
150
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 148

def target_type
  @target_type
end

Class Method Details

.check_target_type(target_type) ⇒ Object

target_type checker.

Raises exception if target_type has unsupported value.



136
137
138
139
140
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 136

def TemplateParams.check_target_type( target_type )
  if nil == @@setup_target_functions.fetch( target_type, nil )
    raise InvalidValueEx.new( "unsupported target_type: #{target_type}" )
  end
end

Instance Method Details

#get_bindingObject

Returns binding to use in ERb generation.



178
179
180
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 178

def get_binding
  binding
end

#has_or_require_implibObject

Returns true if implib_path need to be defined for this type of target. Or, in case of EXE target, if implib_path defined in options. (Under Windows even EXEs may have import libraries).



173
174
175
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 173

def has_or_require_implib
  DLL == @target_type || nil != @options.implib_path
end

#setup_target_functionObject

Name of setup target functions (like lib_target, dll_target, etc).



166
167
168
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 166

def setup_target_function
  @@setup_target_functions.fetch( @target_type )
end