
require 'erb'



class Generator

	#
	# \brief Constructor
	#
	def initialize
		# Max Arguments
		@maxArgumentCount = 16
	end

	def thisHeaderHasBeenGenerated(name)
		"/*!
** \\internal This file is automatically generated by '#{name}'.
** Please make any modifications you wish to this script instead of
** this file, as they will otherwise be lost at the next generation.
*/"
	end

	# getter
	def argumentCount
		@maxArgumentCount
	end
	# setter
	def argumentCount= (value)
		@maxArgumentCount = value
	end

	def templateParameterList(count, prefix = ', ', name = 'A')
		ret = ''
		if count > 0
			ret += prefix
		end
		(0..count - 1).each do |i|
			if i != 0
				ret += ', '
			end
			ret += "class #{name}#{i}"
		end
		ret
	end

	def list(count, name = 'A', prefix = '', suffix = '', separator = ', ', nmprefix = '', nmsuffix = '')
		ret = ''
		if count > 0
			ret += prefix
		end
		(0..count - 1).each do |i|
			if i != 0
				ret += separator
			end
			ret += "#{nmprefix}#{name}#{i}#{nmsuffix}"
		end
		if count > 0
			ret += suffix
		end
		ret
	end

	def variableList(count, name = 'A', varname = 'a', prefix = '')
		ret = ''
		if count > 0
			ret += prefix
		end
		(0..count - 1).each do |i|
			if i != 0
				ret += ', '
			end
			ret += "#{name}#{i} #{varname}#{i}"
		end
		ret
	end

	def xArgumentsToStr(count)
		if count == 0
			return "0 argument"
		else
			return (count == 1) ? "1 argument" : "#{count} arguments"
		end
	end

	def templateParameterListDoxygen(count)
		ret = ''
		(0..count-1).each do |i|
			ret += "\t** \\tparam A#{i} The type of the "
			# todo use `when`
			ret += case i
				when 0 then "first"
				when 1 then "second"
				when 2 then "third"
				else "#{i+1}th"
			end
			ret += " argument"
			if i != count - 1
				ret += "\n"
			end
		end
		ret
	end

	def include(fname)
		erb = ERB.new(IO.read(File.dirname(__FILE__) + '/../../' + fname), nil, nil, 'erbout')
		erb.filename = fname
		generator = self
		i = 0
		return erb.result(binding())
	end

	def include(fname,i)
		erb = ERB.new(IO.read(File.dirname(__FILE__) + '/../../' + fname), nil, nil, 'erbout')
		erb.filename = fname
		generator = self
		return erb.result(binding())
	end


end


