// Aqsis
// Copyright (c) 1997 - 2001, Paul C. Gregory
//
// Contact: pgregory@aqsis.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

/**
 * Copyright (C) 2006-2007  NTT DATA CORPORATION
 * 
 * Version: 1.0.0 2007/04/01
 *  
 */
package net.cellcomputing.himawari.library.cache;


/**
 * 
 * レンダリングキャッシング用の基底クラス
 * 
 * @author NTT DATA Corporation
 */
public abstract strictfp class RiCacheBase {

	protected int		m_count;
	protected String[]	m_tokens;
	protected Object[]	m_values;
	protected int		m_constant_size;
	protected int		m_uniform_size;
	protected int		m_varying_size;
	protected int		m_vertex_size;
	protected int		m_facevarying_size;
	
	//************************************************************************//
	//*** コンストラクタの定義
	//************************************************************************//
	
	public RiCacheBase(){
		m_count = 0;
		m_tokens = null;
		m_values = null;
	}
	
	public void destruct(){
		
		m_tokens = null;
		m_values = null;
		
//		// Delete the plist
//		int i;
//		for(i=0; i<m_count; i++)
//		{
//			SqParameterDeclaration Decl = QGetRenderContext().FindParameterDecl( m_tokens[i] );
//			if(Decl.m_Type.getValue() == type_string)
//			{
//				int size = 1;
//				switch( Decl.m_Class.getValue() )
//				{
//				case class_constant:
//					size = m_constant_size;
//					break;
//					
//				case class_uniform:
//					size = m_uniform_size;
//					break;
//					
//				case class_varying:
//					size = m_varying_size;
//					break;
//					
//				case class_vertex:
//					size = m_vertex_size;
//					break;
//					
//				case class_facevarying:
//					size = m_facevarying_size;
//					break;
//				}
//				int j;
//				for(j=0; j<size; j++)
//					delete[](reinterpret_cast<RtString*>(m_values[i])[j]);
//			}
//			delete[](m_tokens[i]);
//			delete[](m_values[i]);
//		}
//		
//		delete[] m_tokens;
//		delete[] m_values;
	}
	
	//************************************************************************//
	//*** メソッドの定義
	//************************************************************************//

	public abstract void ReCall();

	protected  void CachePlist(int count, String tokens[], Object values[], 
							int constant_size, int uniform_size, int varying_size, int vertex_size, int facevarying_size )
	{
		// Cache the sizes as we need them during destruction.
		m_constant_size = constant_size;
		m_uniform_size = uniform_size;
		m_varying_size = varying_size;
		m_vertex_size = vertex_size;
		m_facevarying_size = facevarying_size;
		
		m_count = count;
		m_tokens = new String[count];
		m_values = new Object[count];
		
		//Javaだとこれだけでよさそう
		if( count > 0 )
		{
			System.arraycopy( tokens, 0, m_tokens, 0, count );
			System.arraycopy( values, 0, m_values, 0, count );
		}
//		int i;
//		for(i=0; i<count; i++)
//		{
//			String	token = tokens[ i ];
//			Object	value = values[ i ];
//			
//			String newtoken = new String(token);
//			m_tokens[i] = newtoken;
//			
//			
//			
//			SqParameterDeclaration Decl = null;
//			try {
//				Decl = QGetRenderContext().FindParameterDecl( token );
//			} catch (XqException e) {
//				e.printStackTrace();
//			}
//			
//			// Work out the amount of data to copy determined by the
//			// class, the type and the array size.
//			int size = 1;
//			switch( Decl.m_Class.getValue() )
//			{
//			case class_constant:
//				size = constant_size;
//				break;
//				
//			case class_uniform:
//				size = uniform_size;
//				break;
//				
//			case class_varying:
//				size = varying_size;
//				break;
//				
//			case class_vertex:
//				size = vertex_size;
//				break;
//				
//			case class_facevarying:
//				size = facevarying_size;
//				break;
//			}
//			
//			// If it is a compound type, increase the length by the number of elements.
//			if( Decl.m_Type.getValue() == type_point ||
//					Decl.m_Type.getValue() == type_normal ||
//					Decl.m_Type.getValue() == type_color ||
//					Decl.m_Type.getValue() == type_vector)
//				size *= 3;
//			else if( Decl.m_Type.getValue() == type_hpoint)
//				size *= 4;
//			else if( Decl.m_Type.getValue() == type_matrix)
//				size *= 16;
//			
//			// If it is an array, increase the size by the number of elements in the array.
//			size *= Decl.m_Count;
//			
//			int j;
//			switch( Decl.m_Type.getValue() )
//			{
//			case type_integer:
//				m_values[i] = CopyAtomicValue(size, (Integer[])(values[i]));
//				break;
//				
//			case type_point:
//			case type_color:
//			case type_normal:
//			case type_vector:
//			case type_hpoint:
//			case type_matrix:
//			case type_float:
//				m_values[i] = CopyAtomicValue(size, (Float[])(values[i]));
//				break;
//				
//			case type_string:
//			{
//				String[] copyvalue = new String[size];
//				for(j=0; j<size; j++)
//				{
////					RtString item = new char[strlen((String[])(value)[j])];
////					strcpy(item, reinterpret_cast<RtString*>(value)[j]);
//					String item = new String( ((String[])value)[j] );
//					copyvalue[j] = item;
//				}
//				m_values[i] = (Object)(copyvalue);
//			}
//			break;
//			}					
//		}
	}
//	
//	protected  Object[] CopyAtomicValue(int size, Object[] value)
//	{
//		Object[] copyvalue = new Object[size];
//		int j;
//		for(j=0; j<size; j++)
//			copyvalue[j] = value[j];
//		return( copyvalue );
//	}
	
}

