#!/usr/bin/python
#
# Copyright 2012 Google, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Google Author(s): Behdad Esfahbod

def permute (n, m, ns, i):
	if i == 0:
		const = ''
		for j in range (len (ns)):
			if ns[j] in ns[j+1:]:
				const = 'Const'
				break;
		ns = [str (x) for x in ns]
		args = ','.join (ns)
		name = '##'.join ('c'+x for x in ns)
		print "	%sSwizzle%d<T,%d,%s> %s; \\" % (const, n, m, args, name)
		return
	for j in range (m):
		permute (n, m, ns + [j], i - 1)

print "/* Generated by swizzle.py.  Do not modify */"
print "#ifndef GLOSSY_SL_METATYPES_SWIZZLE_HH"
print "#define GLOSSY_SL_METATYPES_SWIZZLE_HH"
print
for m in range (2, 5):
	print
	sig = ','.join ("c%d"%i for i in range (m))
	print "#define GLOSSY_SL_METATYPES_SWIZZLE%d_PERMUTE(%s) \\" % (m,sig)
	for n in range (1, 5):
		permute (n, m, [], n)
	print "	/**/"
	print "#define GLOSSY_SL_METATYPES_SWIZZLE%d \\" % m
	for s in ["xyzw", "rgba", "stpq"]:
		sig = ','.join (s[:m])
		print "	GLOSSY_SL_METATYPES_SWIZZLE%d_PERMUTE(%s) \\" % (m,sig)
	print "	/**/"
print
print "#endif /* GLOSSY_SL_METATYPES_SWIZZLE_HH */"
