<commit_before>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2007-2008, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of Image Engine Design nor the names of any
//       other contributors to this software may be used to endorse or
//       promote products derived from this software without specific prior
//       written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include <boost/python.hpp>

#include "IECore/TypeIds.h"
#include "IECore/bindings/TypeIdBinding.h"

using namespace boost::python;

namespace IECore
{

void bindTypeId()
{
	enum_<TypeId>("TypeId")
		.value("Invalid", InvalidTypeId )
		.value("Object", ObjectTypeId )
		.value("Data", DataTypeId )
		.value("FloatVectorData", FloatVectorDataTypeId )
		.value("DoubleVectorData", DoubleVectorDataTypeId )
		.value("IntVectorData", IntVectorDataTypeId )
		.value("UIntVectorData", UIntVectorDataTypeId )
		.value("CharVectorData", CharVectorDataTypeId )
		.value("UCharVectorData", UCharVectorDataTypeId )
		.value("V2fVectorData", V2fVectorDataTypeId )
		.value("V2dVectorData", V2dVectorDataTypeId )
		.value("V3fVectorData", V3fVectorDataTypeId )
		.value("V3dVectorData", V3dVectorDataTypeId )
		.value("Box3fVectorData", Box3fVectorDataTypeId )
		.value("Box3dVectorData", Box3dVectorDataTypeId )
		.value("M33fVectorData", M33fVectorDataTypeId )
		.value("M33dVectorData", M33dVectorDataTypeId )
		.value("M44fVectorData", M44fVectorDataTypeId )
		.value("M44dVectorData", M44dVectorDataTypeId )
		.value("QuatfVectorData", QuatfVectorDataTypeId )
		.value("QuatdVectorData", QuatdVectorDataTypeId )
		.value("StringVectorData", StringVectorDataTypeId )
		.value("FloatData", FloatDataTypeId )
		.value("DoubleData", DoubleDataTypeId )
		.value("IntData", IntDataTypeId )
		.value("UIntData", UIntDataTypeId )
		.value("CharData", CharDataTypeId )
		.value("UCharData", UCharDataTypeId )
		.value("StringData",StringDataTypeId )
		.value("CompoundData", CompoundDataTypeId )
		.value("V2iData", V2iDataTypeId )
		.value("V2fData", V2fDataTypeId )
		.value("V3fData", V3fDataTypeId )
		.value("V2dData", V2dDataTypeId )
		.value("V3dData", V3dDataTypeId )
		.value("Box2fData", Box2fDataTypeId )
		.value("Box3fData", Box3fDataTypeId )
		.value("Box2dData", Box2dDataTypeId )
		.value("Box3dData", Box3dDataTypeId )
		.value("M44fData", M44fDataTypeId )
		.value("M44dData", M44dDataTypeId )
		.value("QuatfData", QuatfDataTypeId )
		.value("QuatdData", QuatdDataTypeId )
		.value("Color3fData", Color3fDataTypeId )
		.value("Color4fData", Color4fDataTypeId )
		.value("Color3dData", Color3dDataTypeId )
		.value("Color4dData", Color4dDataTypeId )
		.value("Color3fVectorData", Color3fVectorDataTypeId )
		.value("Color4fVectorData", Color4fVectorDataTypeId )
		.value("Color3dVectorData", Color3dVectorDataTypeId )
		.value("Color4dVectorData", Color4dVectorDataTypeId )
		.value("BlindDataHolder", BlindDataHolderTypeId )
		.value("Renderable", RenderableTypeId )
		.value("CompoundObject", CompoundObjectTypeId )
		.value("M33fData", M33fDataTypeId )
		.value("M33dData", M33dDataTypeId )
		.value("Box2fVectorData", Box2fVectorDataTypeId )
		.value("Box2dVectorData", Box2dVectorDataTypeId )
		.value("BoolData", BoolDataTypeId )
		.value("Primitive", PrimitiveTypeId )
		.value("PointsPrimitive", PointsPrimitiveTypeId )
		.value("ImagePrimitive", ImagePrimitiveTypeId )
		.value("MeshPrimitive", MeshPrimitiveTypeId )
		.value("Box2iData", Box2iDataTypeId )
		.value("HalfVectorData", HalfVectorDataTypeId )
		.value("Shader", ShaderTypeId )
		.value("RunTimeTyped", RunTimeTypedTypeId )
		.value("Parameter", ParameterTypeId )
		.value("CompoundParameter", CompoundParameterTypeId )
		.value("StringParameter", StringParameterTypeId )
		.value("ValidatedStringParameter", ValidatedStringParameterTypeId )
		.value("FileNameParameter", FileNameParameterTypeId )
		.value("IntParameter", IntParameterTypeId )
		.value("FloatParameter", FloatParameterTypeId )
		.value("DoubleParameter", DoubleParameterTypeId )
		.value("BoolParameter", BoolParameterTypeId )
		.value("V2fParameter", V2fParameterTypeId )
		.value("V3fParameter", V3fParameterTypeId )
		.value("V2dParameter", V2dParameterTypeId )
		.value("V3dParameter", V3dParameterTypeId )
		.value("Color3fParameter", Color3fParameterTypeId )
		.value("Color4fParameter", Color4fParameterTypeId )
		.value("Box2iParameter", Box2iParameterTypeId )
		.value("Box2fParameter", Box2fParameterTypeId )
		.value("Box3fParameter", Box3fParameterTypeId )
		.value("Box2dParameter", Box2dParameterTypeId )
		.value("Box3dParameter", Box3dParameterTypeId )
		.value("M44fParameter",  M44fParameterTypeId )
		.value("M44dParameter",  M44dParameterTypeId )
		.value("IntVectorParameter", IntVectorParameterTypeId )
		.value("FloatVectorParameter", FloatVectorParameterTypeId )
		.value("DoubleVectorParameter", DoubleVectorParameterTypeId )
		.value("StringVectorParameter", StringVectorParameterTypeId )
		.value("V2fVectorParameter", V2fVectorParameterTypeId )
		.value("V3fVectorParameter", V3fVectorParameterTypeId )
		.value("V2dVectorParameter", V2dVectorParameterTypeId )
		.value("V3dVectorParameter", V3dVectorParameterTypeId )
		.value("Box3fVectorParameter", Box3fVectorParameterTypeId )
		.value("Box3dVectorParameter", Box3dVectorParameterTypeId )
		.value("M33fVectorParameter", M33fVectorParameterTypeId )
		.value("M44fVectorParameter", M44fVectorParameterTypeId )
		.value("M33dVectorParameter", M33dVectorParameterTypeId )
		.value("M44dVectorParameter", M44dVectorParameterTypeId )
		.value("QuatfVectorParameter", QuatfVectorParameterTypeId )
		.value("QuatdVectorParameter", QuatdVectorParameterTypeId )
		.value("Color3fVectorParameter", Color3fVectorParameterTypeId )
		.value("Color4fVectorParameter", Color4fVectorParameterTypeId )
		.value("NullObject", NullObjectTypeId )
		.value("Parameterised", ParameterisedTypeId )
		.value("Op", OpTypeId )
		.value("Reader", ReaderTypeId )
		.value("Writer", WriterTypeId )
		.value("ImageReader", ImageReaderTypeId )
		.value("ImageWriter", ImageWriterTypeId )
		.value("CINImageReader", CINImageReaderTypeId )
		.value("CINImageWriter", CINImageWriterTypeId )
		.value("DPXImageReader", DPXImageReaderTypeId )
		.value("DPXImageWriter", DPXImageWriterTypeId )
		.value("EXRImageReader", EXRImageReaderTypeId )
		.value("EXRImageWriter", EXRImageWriterTypeId )
		.value("JPEGImageReader", JPEGImageReaderTypeId )
		.value("JPEGImageWriter", JPEGImageWriterTypeId )
		.value("TIFFImageReader", TIFFImageReaderTypeId )
		.value("TIFFImageWriter", TIFFImageWriterTypeId )
		.value("ObjectReader", ObjectReaderTypeId )
		.value("ObjectWriter", ObjectWriterTypeId )
		.value("PDCParticleReader", PDCParticleReaderTypeId )
		.value("PDCParticleWriter", PDCParticleWriterTypeId )
		.value("PathParameter", PathParameterTypeId )
		.value("DirNameParameter", DirNameParameterTypeId )
		.value("V3iData", V3iDataTypeId )
		.value("Box3iData", Box3iDataTypeId )
		.value("ObjectParameter", ObjectParameterTypeId )
		.value("ModifyOp", ModifyOpTypeId )
		.value("ImageOp", ImageOpTypeId )
		.value("PrimitiveOp", PrimitiveOpTypeId )
		.value("Procedural", ProceduralTypeId )
		.value("Box3iParameter", Box3iParameterTypeId )
		.value("V2iParameter", V2iParameterTypeId )
		.value("V3iParameter", V3iParameterTypeId )
		.value("ParticleReader", ParticleReaderTypeId )
		.value("ParticleWriter", ParticleWriterTypeId )
		.value("MotionPrimitive", MotionPrimitiveTypeId )
		.value("Transform", TransformTypeId )
		.value("MatrixTransform", MatrixTransformTypeId )
		.value("MotionTransform", MotionTransformTypeId )
		.value("MatrixMotionTransform", MatrixMotionTransformTypeId )
		.value("Group", GroupTypeId )
		.value("AttributeState", AttributeStateTypeId )
		.value("VisibleRenderable", VisibleRenderableTypeId )
		.value("StateRenderable", StateRenderableTypeId )
		.value("OBJReader", OBJReaderTypeId)
		.value("TransformationMatrixfData", TransformationMatrixfDataTypeId)
		.value("TransformationMatrixdData", TransformationMatrixdDataTypeId)
		.value("PointNormalsOp", PointNormalsOpTypeId)
		.value("PointDensitiesOp", PointDensitiesOpTypeId)
		.value("BoolVectorData", BoolVectorDataTypeId)
		.value("VectorDataFilterOp", VectorDataFilterOpTypeId)
		.value("RenderableParameter", RenderableParameterTypeId)
		.value("StateRenderableParameter", StateRenderableParameterTypeId)
		.value("AttributeStateParameter", AttributeStateParameterTypeId)
		.value("ShaderParameter", ShaderParameterTypeId)
		.value("TransformParameter", TransformParameterTypeId)
		.value("MatrixMotionTransformParameter", MatrixMotionTransformParameterTypeId)
		.value("MatrixTransformParameter", MatrixTransformParameterTypeId)
		.value("VisibleRenderableParameter", VisibleRenderableParameterTypeId)
		.value("GroupParameter", GroupParameterTypeId)
		.value("MotionPrimitiveParameter", MotionPrimitiveParameterTypeId)
		.value("PrimitiveParameter", PrimitiveParameterTypeId)
		.value("ImagePrimitiveParameter", ImagePrimitiveParameterTypeId)
		.value("MeshPrimitiveParameter", MeshPrimitiveParameterTypeId)
		.value("PointsPrimitiveParameter", PointsPrimitiveParameterTypeId)
		.value("PreWorldRenderable", PreWorldRenderableTypeId)
		.value("Camera", CameraTypeId)
		.value("NURBSPrimitive", NURBSPrimitiveTypeId)
		.value("DataCastOp", DataCastOpTypeId)
		.value("DataPromoteOp", DataPromoteOpTypeId)
		.value("PointBoundsOp", PointBoundsOpTypeId)
		.value("V2iVectorData", V2iVectorDataTypeId)
		.value("V3iVectorData", V3iVectorDataTypeId)
		.value("PointMeshOp", PointMeshOpTypeId)
		.value("ParticleMeshOp", ParticleMeshOpTypeId)
		.value("HalfData", HalfDataTypeId)
		.value("MeshPrimitiveOp", MeshPrimitiveOpTypeId)
		.value("PrimitiveEvaluator", PrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveEvaluator", MeshPrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveImplicitSurfaceOp", MeshPrimitiveImplicitSurfaceOpTypeId)
		.value("TriangulateOp", TriangulateOpTypeId)
		.value("SpherePrimitiveEvaluator", SpherePrimitiveEvaluatorTypeId)
		.value("SpherePrimitive", SpherePrimitiveTypeId)
		.value("Converter", ConverterTypeId)
		.value("ToCoreConverter", ToCoreConverterTypeId)
		.value("ImageCropOp", ImageCropOpTypeId)
		.value("MeshPrimitiveShrinkWrapOp", MeshPrimitiveShrinkWrapOpTypeId)
		.value("ImagePrimitiveEvaluator", ImagePrimitiveEvaluatorTypeId)
		.value("FromCoreConverter", FromCoreConverterTypeId)
		.value("ShortData", ShortDataTypeId )
		.value("UShortData", UShortDataTypeId )
		.value("ShortVectorData", ShortVectorDataTypeId )
		.value("UShortVectorData", UShortVectorDataTypeId )
		.value("PathVectorParameter", PathVectorParameterTypeId )
		.value("ColorTransformOp", ColorTransformOpTypeId )
		.value("TransformOp", TransformOpTypeId )
		.value("CurvesPrimitive", CurvesPrimitiveTypeId )
		.value("ImageDiffOp", ImageDiffOpTypeId )
		.value("MeshNormalsOp", MeshNormalsOpTypeId )
		.value("Font", FontTypeId )
		.value("MeshMergeOp", MeshMergeOpTypeId )
		.value("UniformRandomPointDistributionOp", UniformRandomPointDistributionOpTypeId )
		.value("Int64Data", Int64DataTypeId )
		.value("UInt64Data", UInt64DataTypeId )
		.value("Int64VectorData", Int64VectorDataTypeId )
		.value("UInt64VectorData", UInt64VectorDataTypeId )
		.value("MappedRandomPointDistributionOp", MappedRandomPointDistributionOpTypeId )
	;
}

}
<commit_msg>Added TypeId binding<commit_after>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2007-2008, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of Image Engine Design nor the names of any
//       other contributors to this software may be used to endorse or
//       promote products derived from this software without specific prior
//       written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include <boost/python.hpp>

#include "IECore/TypeIds.h"
#include "IECore/bindings/TypeIdBinding.h"

using namespace boost::python;

namespace IECore
{

void bindTypeId()
{
	enum_<TypeId>("TypeId")
		.value("Invalid", InvalidTypeId )
		.value("Object", ObjectTypeId )
		.value("Data", DataTypeId )
		.value("FloatVectorData", FloatVectorDataTypeId )
		.value("DoubleVectorData", DoubleVectorDataTypeId )
		.value("IntVectorData", IntVectorDataTypeId )
		.value("UIntVectorData", UIntVectorDataTypeId )
		.value("CharVectorData", CharVectorDataTypeId )
		.value("UCharVectorData", UCharVectorDataTypeId )
		.value("V2fVectorData", V2fVectorDataTypeId )
		.value("V2dVectorData", V2dVectorDataTypeId )
		.value("V3fVectorData", V3fVectorDataTypeId )
		.value("V3dVectorData", V3dVectorDataTypeId )
		.value("Box3fVectorData", Box3fVectorDataTypeId )
		.value("Box3dVectorData", Box3dVectorDataTypeId )
		.value("M33fVectorData", M33fVectorDataTypeId )
		.value("M33dVectorData", M33dVectorDataTypeId )
		.value("M44fVectorData", M44fVectorDataTypeId )
		.value("M44dVectorData", M44dVectorDataTypeId )
		.value("QuatfVectorData", QuatfVectorDataTypeId )
		.value("QuatdVectorData", QuatdVectorDataTypeId )
		.value("StringVectorData", StringVectorDataTypeId )
		.value("FloatData", FloatDataTypeId )
		.value("DoubleData", DoubleDataTypeId )
		.value("IntData", IntDataTypeId )
		.value("UIntData", UIntDataTypeId )
		.value("CharData", CharDataTypeId )
		.value("UCharData", UCharDataTypeId )
		.value("StringData",StringDataTypeId )
		.value("CompoundData", CompoundDataTypeId )
		.value("V2iData", V2iDataTypeId )
		.value("V2fData", V2fDataTypeId )
		.value("V3fData", V3fDataTypeId )
		.value("V2dData", V2dDataTypeId )
		.value("V3dData", V3dDataTypeId )
		.value("Box2fData", Box2fDataTypeId )
		.value("Box3fData", Box3fDataTypeId )
		.value("Box2dData", Box2dDataTypeId )
		.value("Box3dData", Box3dDataTypeId )
		.value("M44fData", M44fDataTypeId )
		.value("M44dData", M44dDataTypeId )
		.value("QuatfData", QuatfDataTypeId )
		.value("QuatdData", QuatdDataTypeId )
		.value("Color3fData", Color3fDataTypeId )
		.value("Color4fData", Color4fDataTypeId )
		.value("Color3dData", Color3dDataTypeId )
		.value("Color4dData", Color4dDataTypeId )
		.value("Color3fVectorData", Color3fVectorDataTypeId )
		.value("Color4fVectorData", Color4fVectorDataTypeId )
		.value("Color3dVectorData", Color3dVectorDataTypeId )
		.value("Color4dVectorData", Color4dVectorDataTypeId )
		.value("BlindDataHolder", BlindDataHolderTypeId )
		.value("Renderable", RenderableTypeId )
		.value("CompoundObject", CompoundObjectTypeId )
		.value("M33fData", M33fDataTypeId )
		.value("M33dData", M33dDataTypeId )
		.value("Box2fVectorData", Box2fVectorDataTypeId )
		.value("Box2dVectorData", Box2dVectorDataTypeId )
		.value("BoolData", BoolDataTypeId )
		.value("Primitive", PrimitiveTypeId )
		.value("PointsPrimitive", PointsPrimitiveTypeId )
		.value("ImagePrimitive", ImagePrimitiveTypeId )
		.value("MeshPrimitive", MeshPrimitiveTypeId )
		.value("Box2iData", Box2iDataTypeId )
		.value("HalfVectorData", HalfVectorDataTypeId )
		.value("Shader", ShaderTypeId )
		.value("RunTimeTyped", RunTimeTypedTypeId )
		.value("Parameter", ParameterTypeId )
		.value("CompoundParameter", CompoundParameterTypeId )
		.value("StringParameter", StringParameterTypeId )
		.value("ValidatedStringParameter", ValidatedStringParameterTypeId )
		.value("FileNameParameter", FileNameParameterTypeId )
		.value("IntParameter", IntParameterTypeId )
		.value("FloatParameter", FloatParameterTypeId )
		.value("DoubleParameter", DoubleParameterTypeId )
		.value("BoolParameter", BoolParameterTypeId )
		.value("V2fParameter", V2fParameterTypeId )
		.value("V3fParameter", V3fParameterTypeId )
		.value("V2dParameter", V2dParameterTypeId )
		.value("V3dParameter", V3dParameterTypeId )
		.value("Color3fParameter", Color3fParameterTypeId )
		.value("Color4fParameter", Color4fParameterTypeId )
		.value("Box2iParameter", Box2iParameterTypeId )
		.value("Box2fParameter", Box2fParameterTypeId )
		.value("Box3fParameter", Box3fParameterTypeId )
		.value("Box2dParameter", Box2dParameterTypeId )
		.value("Box3dParameter", Box3dParameterTypeId )
		.value("M44fParameter",  M44fParameterTypeId )
		.value("M44dParameter",  M44dParameterTypeId )
		.value("IntVectorParameter", IntVectorParameterTypeId )
		.value("FloatVectorParameter", FloatVectorParameterTypeId )
		.value("DoubleVectorParameter", DoubleVectorParameterTypeId )
		.value("StringVectorParameter", StringVectorParameterTypeId )
		.value("V2fVectorParameter", V2fVectorParameterTypeId )
		.value("V3fVectorParameter", V3fVectorParameterTypeId )
		.value("V2dVectorParameter", V2dVectorParameterTypeId )
		.value("V3dVectorParameter", V3dVectorParameterTypeId )
		.value("Box3fVectorParameter", Box3fVectorParameterTypeId )
		.value("Box3dVectorParameter", Box3dVectorParameterTypeId )
		.value("M33fVectorParameter", M33fVectorParameterTypeId )
		.value("M44fVectorParameter", M44fVectorParameterTypeId )
		.value("M33dVectorParameter", M33dVectorParameterTypeId )
		.value("M44dVectorParameter", M44dVectorParameterTypeId )
		.value("QuatfVectorParameter", QuatfVectorParameterTypeId )
		.value("QuatdVectorParameter", QuatdVectorParameterTypeId )
		.value("Color3fVectorParameter", Color3fVectorParameterTypeId )
		.value("Color4fVectorParameter", Color4fVectorParameterTypeId )
		.value("NullObject", NullObjectTypeId )
		.value("Parameterised", ParameterisedTypeId )
		.value("Op", OpTypeId )
		.value("Reader", ReaderTypeId )
		.value("Writer", WriterTypeId )
		.value("ImageReader", ImageReaderTypeId )
		.value("ImageWriter", ImageWriterTypeId )
		.value("CINImageReader", CINImageReaderTypeId )
		.value("CINImageWriter", CINImageWriterTypeId )
		.value("DPXImageReader", DPXImageReaderTypeId )
		.value("DPXImageWriter", DPXImageWriterTypeId )
		.value("EXRImageReader", EXRImageReaderTypeId )
		.value("EXRImageWriter", EXRImageWriterTypeId )
		.value("JPEGImageReader", JPEGImageReaderTypeId )
		.value("JPEGImageWriter", JPEGImageWriterTypeId )
		.value("TIFFImageReader", TIFFImageReaderTypeId )
		.value("TIFFImageWriter", TIFFImageWriterTypeId )
		.value("ObjectReader", ObjectReaderTypeId )
		.value("ObjectWriter", ObjectWriterTypeId )
		.value("PDCParticleReader", PDCParticleReaderTypeId )
		.value("PDCParticleWriter", PDCParticleWriterTypeId )
		.value("PathParameter", PathParameterTypeId )
		.value("DirNameParameter", DirNameParameterTypeId )
		.value("V3iData", V3iDataTypeId )
		.value("Box3iData", Box3iDataTypeId )
		.value("ObjectParameter", ObjectParameterTypeId )
		.value("ModifyOp", ModifyOpTypeId )
		.value("ImageOp", ImageOpTypeId )
		.value("PrimitiveOp", PrimitiveOpTypeId )
		.value("Procedural", ProceduralTypeId )
		.value("Box3iParameter", Box3iParameterTypeId )
		.value("V2iParameter", V2iParameterTypeId )
		.value("V3iParameter", V3iParameterTypeId )
		.value("ParticleReader", ParticleReaderTypeId )
		.value("ParticleWriter", ParticleWriterTypeId )
		.value("MotionPrimitive", MotionPrimitiveTypeId )
		.value("Transform", TransformTypeId )
		.value("MatrixTransform", MatrixTransformTypeId )
		.value("MotionTransform", MotionTransformTypeId )
		.value("MatrixMotionTransform", MatrixMotionTransformTypeId )
		.value("Group", GroupTypeId )
		.value("AttributeState", AttributeStateTypeId )
		.value("VisibleRenderable", VisibleRenderableTypeId )
		.value("StateRenderable", StateRenderableTypeId )
		.value("OBJReader", OBJReaderTypeId)
		.value("TransformationMatrixfData", TransformationMatrixfDataTypeId)
		.value("TransformationMatrixdData", TransformationMatrixdDataTypeId)
		.value("PointNormalsOp", PointNormalsOpTypeId)
		.value("PointDensitiesOp", PointDensitiesOpTypeId)
		.value("BoolVectorData", BoolVectorDataTypeId)
		.value("VectorDataFilterOp", VectorDataFilterOpTypeId)
		.value("RenderableParameter", RenderableParameterTypeId)
		.value("StateRenderableParameter", StateRenderableParameterTypeId)
		.value("AttributeStateParameter", AttributeStateParameterTypeId)
		.value("ShaderParameter", ShaderParameterTypeId)
		.value("TransformParameter", TransformParameterTypeId)
		.value("MatrixMotionTransformParameter", MatrixMotionTransformParameterTypeId)
		.value("MatrixTransformParameter", MatrixTransformParameterTypeId)
		.value("VisibleRenderableParameter", VisibleRenderableParameterTypeId)
		.value("GroupParameter", GroupParameterTypeId)
		.value("MotionPrimitiveParameter", MotionPrimitiveParameterTypeId)
		.value("PrimitiveParameter", PrimitiveParameterTypeId)
		.value("ImagePrimitiveParameter", ImagePrimitiveParameterTypeId)
		.value("MeshPrimitiveParameter", MeshPrimitiveParameterTypeId)
		.value("PointsPrimitiveParameter", PointsPrimitiveParameterTypeId)
		.value("PreWorldRenderable", PreWorldRenderableTypeId)
		.value("Camera", CameraTypeId)
		.value("NURBSPrimitive", NURBSPrimitiveTypeId)
		.value("DataCastOp", DataCastOpTypeId)
		.value("DataPromoteOp", DataPromoteOpTypeId)
		.value("PointBoundsOp", PointBoundsOpTypeId)
		.value("V2iVectorData", V2iVectorDataTypeId)
		.value("V3iVectorData", V3iVectorDataTypeId)
		.value("PointMeshOp", PointMeshOpTypeId)
		.value("ParticleMeshOp", ParticleMeshOpTypeId)
		.value("HalfData", HalfDataTypeId)
		.value("MeshPrimitiveOp", MeshPrimitiveOpTypeId)
		.value("PrimitiveEvaluator", PrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveEvaluator", MeshPrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveImplicitSurfaceOp", MeshPrimitiveImplicitSurfaceOpTypeId)
		.value("TriangulateOp", TriangulateOpTypeId)
		.value("SpherePrimitiveEvaluator", SpherePrimitiveEvaluatorTypeId)
		.value("SpherePrimitive", SpherePrimitiveTypeId)
		.value("Converter", ConverterTypeId)
		.value("ToCoreConverter", ToCoreConverterTypeId)
		.value("ImageCropOp", ImageCropOpTypeId)
		.value("MeshPrimitiveShrinkWrapOp", MeshPrimitiveShrinkWrapOpTypeId)
		.value("ImagePrimitiveEvaluator", ImagePrimitiveEvaluatorTypeId)
		.value("FromCoreConverter", FromCoreConverterTypeId)
		.value("ShortData", ShortDataTypeId )
		.value("UShortData", UShortDataTypeId )
		.value("ShortVectorData", ShortVectorDataTypeId )
		.value("UShortVectorData", UShortVectorDataTypeId )
		.value("PathVectorParameter", PathVectorParameterTypeId )
		.value("ColorTransformOp", ColorTransformOpTypeId )
		.value("TransformOp", TransformOpTypeId )
		.value("CurvesPrimitive", CurvesPrimitiveTypeId )
		.value("ImageDiffOp", ImageDiffOpTypeId )
		.value("MeshNormalsOp", MeshNormalsOpTypeId )
		.value("Font", FontTypeId )
		.value("MeshMergeOp", MeshMergeOpTypeId )
		.value("UniformRandomPointDistributionOp", UniformRandomPointDistributionOpTypeId )
		.value("Int64Data", Int64DataTypeId )
		.value("UInt64Data", UInt64DataTypeId )
		.value("Int64VectorData", Int64VectorDataTypeId )
		.value("UInt64VectorData", UInt64VectorDataTypeId )
		.value("MappedRandomPointDistributionOp", MappedRandomPointDistributionOpTypeId )
		.value("PointRepulsionOp", PointRepulsionOpTypeId )
	;
}

}
<|endoftext|>


<commit_before>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2007-2008, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of Image Engine Design nor the names of any
//       other contributors to this software may be used to endorse or
//       promote products derived from this software without specific prior
//       written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include <boost/python.hpp>

#include "IECore/TypeIds.h"
#include "IECore/bindings/TypeIdBinding.h"

using namespace boost::python;

namespace IECore
{

void bindTypeId()
{
	enum_<TypeId>("TypeId")
		.value("Invalid", InvalidTypeId )
		.value("Object", ObjectTypeId )
		.value("Data", DataTypeId )
		.value("FloatVectorData", FloatVectorDataTypeId )
		.value("DoubleVectorData", DoubleVectorDataTypeId )
		.value("IntVectorData", IntVectorDataTypeId )
		.value("UIntVectorData", UIntVectorDataTypeId )
		.value("CharVectorData", CharVectorDataTypeId )
		.value("UCharVectorData", UCharVectorDataTypeId )
		.value("V2fVectorData", V2fVectorDataTypeId )
		.value("V2dVectorData", V2dVectorDataTypeId )
		.value("V3fVectorData", V3fVectorDataTypeId )
		.value("V3dVectorData", V3dVectorDataTypeId )
		.value("Box3fVectorData", Box3fVectorDataTypeId )
		.value("Box3dVectorData", Box3dVectorDataTypeId )
		.value("M33fVectorData", M33fVectorDataTypeId )
		.value("M33dVectorData", M33dVectorDataTypeId )
		.value("M44fVectorData", M44fVectorDataTypeId )
		.value("M44dVectorData", M44dVectorDataTypeId )
		.value("QuatfVectorData", QuatfVectorDataTypeId )
		.value("QuatdVectorData", QuatdVectorDataTypeId )
		.value("StringVectorData", StringVectorDataTypeId )
		.value("FloatData", FloatDataTypeId )
		.value("DoubleData", DoubleDataTypeId )
		.value("IntData", IntDataTypeId )
		.value("UIntData", UIntDataTypeId )
		.value("CharData", CharDataTypeId )
		.value("UCharData", UCharDataTypeId )
		.value("StringData",StringDataTypeId )
		.value("CompoundData", CompoundDataTypeId )
		.value("V2iData", V2iDataTypeId )
		.value("V2fData", V2fDataTypeId )
		.value("V3fData", V3fDataTypeId )
		.value("V2dData", V2dDataTypeId )
		.value("V3dData", V3dDataTypeId )
		.value("Box2fData", Box2fDataTypeId )
		.value("Box3fData", Box3fDataTypeId )
		.value("Box2dData", Box2dDataTypeId )
		.value("Box3dData", Box3dDataTypeId )
		.value("M44fData", M44fDataTypeId )
		.value("M44dData", M44dDataTypeId )
		.value("QuatfData", QuatfDataTypeId )
		.value("QuatdData", QuatdDataTypeId )
		.value("Color3fData", Color3fDataTypeId )
		.value("Color4fData", Color4fDataTypeId )
		.value("Color3dData", Color3dDataTypeId )
		.value("Color4dData", Color4dDataTypeId )
		.value("Color3fVectorData", Color3fVectorDataTypeId )
		.value("Color4fVectorData", Color4fVectorDataTypeId )
		.value("Color3dVectorData", Color3dVectorDataTypeId )
		.value("Color4dVectorData", Color4dVectorDataTypeId )
		.value("BlindDataHolder", BlindDataHolderTypeId )
		.value("Renderable", RenderableTypeId )
		.value("CompoundObject", CompoundObjectTypeId )
		.value("M33fData", M33fDataTypeId )
		.value("M33dData", M33dDataTypeId )
		.value("Box2fVectorData", Box2fVectorDataTypeId )
		.value("Box2dVectorData", Box2dVectorDataTypeId )
		.value("BoolData", BoolDataTypeId )
		.value("Primitive", PrimitiveTypeId )
		.value("PointsPrimitive", PointsPrimitiveTypeId )
		.value("ImagePrimitive", ImagePrimitiveTypeId )
		.value("MeshPrimitive", MeshPrimitiveTypeId )
		.value("Box2iData", Box2iDataTypeId )
		.value("HalfVectorData", HalfVectorDataTypeId )
		.value("Shader", ShaderTypeId )
		.value("RunTimeTyped", RunTimeTypedTypeId )
		.value("Parameter", ParameterTypeId )
		.value("CompoundParameter", CompoundParameterTypeId )
		.value("StringParameter", StringParameterTypeId )
		.value("ValidatedStringParameter", ValidatedStringParameterTypeId )
		.value("FileNameParameter", FileNameParameterTypeId )
		.value("IntParameter", IntParameterTypeId )
		.value("FloatParameter", FloatParameterTypeId )
		.value("DoubleParameter", DoubleParameterTypeId )
		.value("BoolParameter", BoolParameterTypeId )
		.value("V2fParameter", V2fParameterTypeId )
		.value("V3fParameter", V3fParameterTypeId )
		.value("V2dParameter", V2dParameterTypeId )
		.value("V3dParameter", V3dParameterTypeId )
		.value("Color3fParameter", Color3fParameterTypeId )
		.value("Color4fParameter", Color4fParameterTypeId )
		.value("Box2iParameter", Box2iParameterTypeId )
		.value("Box2fParameter", Box2fParameterTypeId )
		.value("Box3fParameter", Box3fParameterTypeId )
		.value("Box2dParameter", Box2dParameterTypeId )
		.value("Box3dParameter", Box3dParameterTypeId )
		.value("M44fParameter",  M44fParameterTypeId )
		.value("M44dParameter",  M44dParameterTypeId )
		.value("IntVectorParameter", IntVectorParameterTypeId )
		.value("FloatVectorParameter", FloatVectorParameterTypeId )
		.value("DoubleVectorParameter", DoubleVectorParameterTypeId )
		.value("StringVectorParameter", StringVectorParameterTypeId )
		.value("V2fVectorParameter", V2fVectorParameterTypeId )
		.value("V3fVectorParameter", V3fVectorParameterTypeId )
		.value("V2dVectorParameter", V2dVectorParameterTypeId )
		.value("V3dVectorParameter", V3dVectorParameterTypeId )
		.value("Box3fVectorParameter", Box3fVectorParameterTypeId )
		.value("Box3dVectorParameter", Box3dVectorParameterTypeId )
		.value("M33fVectorParameter", M33fVectorParameterTypeId )
		.value("M44fVectorParameter", M44fVectorParameterTypeId )
		.value("M33dVectorParameter", M33dVectorParameterTypeId )
		.value("M44dVectorParameter", M44dVectorParameterTypeId )
		.value("QuatfVectorParameter", QuatfVectorParameterTypeId )
		.value("QuatdVectorParameter", QuatdVectorParameterTypeId )
		.value("Color3fVectorParameter", Color3fVectorParameterTypeId )
		.value("Color4fVectorParameter", Color4fVectorParameterTypeId )
		.value("NullObject", NullObjectTypeId )
		.value("Parameterised", ParameterisedTypeId )
		.value("Op", OpTypeId )
		.value("Reader", ReaderTypeId )
		.value("Writer", WriterTypeId )
		.value("ImageReader", ImageReaderTypeId )
		.value("ImageWriter", ImageWriterTypeId )
		.value("CINImageReader", CINImageReaderTypeId )
		.value("CINImageWriter", CINImageWriterTypeId )
		.value("DPXImageReader", DPXImageReaderTypeId )
		.value("DPXImageWriter", DPXImageWriterTypeId )
		.value("EXRImageReader", EXRImageReaderTypeId )
		.value("EXRImageWriter", EXRImageWriterTypeId )
		.value("JPEGImageReader", JPEGImageReaderTypeId )
		.value("JPEGImageWriter", JPEGImageWriterTypeId )
		.value("TIFFImageReader", TIFFImageReaderTypeId )
		.value("TIFFImageWriter", TIFFImageWriterTypeId )
		.value("ObjectReader", ObjectReaderTypeId )
		.value("ObjectWriter", ObjectWriterTypeId )
		.value("PDCParticleReader", PDCParticleReaderTypeId )
		.value("PDCParticleWriter", PDCParticleWriterTypeId )
		.value("PathParameter", PathParameterTypeId )
		.value("DirNameParameter", DirNameParameterTypeId )
		.value("V3iData", V3iDataTypeId )
		.value("Box3iData", Box3iDataTypeId )
		.value("ObjectParameter", ObjectParameterTypeId )
		.value("ModifyOp", ModifyOpTypeId )
		.value("ImageOp", ImageOpTypeId )
		.value("PrimitiveOp", PrimitiveOpTypeId )
		.value("Procedural", ProceduralTypeId )
		.value("Box3iParameter", Box3iParameterTypeId )
		.value("V2iParameter", V2iParameterTypeId )
		.value("V3iParameter", V3iParameterTypeId )
		.value("ParticleReader", ParticleReaderTypeId )
		.value("ParticleWriter", ParticleWriterTypeId )
		.value("MotionPrimitive", MotionPrimitiveTypeId )
		.value("Transform", TransformTypeId )
		.value("MatrixTransform", MatrixTransformTypeId )
		.value("MotionTransform", MotionTransformTypeId )
		.value("MatrixMotionTransform", MatrixMotionTransformTypeId )
		.value("Group", GroupTypeId )
		.value("AttributeState", AttributeStateTypeId )
		.value("VisibleRenderable", VisibleRenderableTypeId )
		.value("StateRenderable", StateRenderableTypeId )
		.value("OBJReader", OBJReaderTypeId)
		.value("TransformationMatrixfData", TransformationMatrixfDataTypeId)
		.value("TransformationMatrixdData", TransformationMatrixdDataTypeId)
		.value("PointNormalsOp", PointNormalsOpTypeId)
		.value("PointDensitiesOp", PointDensitiesOpTypeId)
		.value("BoolVectorData", BoolVectorDataTypeId)
		.value("VectorDataFilterOp", VectorDataFilterOpTypeId)
		.value("RenderableParameter", RenderableParameterTypeId)
		.value("StateRenderableParameter", StateRenderableParameterTypeId)
		.value("AttributeStateParameter", AttributeStateParameterTypeId)
		.value("ShaderParameter", ShaderParameterTypeId)
		.value("TransformParameter", TransformParameterTypeId)
		.value("MatrixMotionTransformParameter", MatrixMotionTransformParameterTypeId)
		.value("MatrixTransformParameter", MatrixTransformParameterTypeId)
		.value("VisibleRenderableParameter", VisibleRenderableParameterTypeId)
		.value("GroupParameter", GroupParameterTypeId)
		.value("MotionPrimitiveParameter", MotionPrimitiveParameterTypeId)
		.value("PrimitiveParameter", PrimitiveParameterTypeId)
		.value("ImagePrimitiveParameter", ImagePrimitiveParameterTypeId)
		.value("MeshPrimitiveParameter", MeshPrimitiveParameterTypeId)
		.value("PointsPrimitiveParameter", PointsPrimitiveParameterTypeId)
		.value("PreWorldRenderable", PreWorldRenderableTypeId)
		.value("Camera", CameraTypeId)
		.value("NURBSPrimitive", NURBSPrimitiveTypeId)
		.value("DataCastOp", DataCastOpTypeId)
		.value("DataPromoteOp", DataPromoteOpTypeId)
		.value("PointBoundsOp", PointBoundsOpTypeId)
		.value("V2iVectorData", V2iVectorDataTypeId)
		.value("V3iVectorData", V3iVectorDataTypeId)
		.value("PointMeshOp", PointMeshOpTypeId)
		.value("ParticleMeshOp", ParticleMeshOpTypeId)
		.value("HalfData", HalfDataTypeId)
		.value("MeshPrimitiveOp", MeshPrimitiveOpTypeId)
		.value("PrimitiveEvaluator", PrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveEvaluator", MeshPrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveImplicitSurfaceOp", MeshPrimitiveImplicitSurfaceOpTypeId)
		.value("TriangulateOp", TriangulateOpTypeId)
		.value("SpherePrimitiveEvaluator", SpherePrimitiveEvaluatorTypeId)
		.value("SpherePrimitive", SpherePrimitiveTypeId)
		.value("Converter", ConverterTypeId)
		.value("ToCoreConverter", ToCoreConverterTypeId)
		.value("ImageCropOp", ImageCropOpTypeId)
		.value("MeshPrimitiveShrinkWrapOp", MeshPrimitiveShrinkWrapOpTypeId)
		.value("ImagePrimitiveEvaluator", ImagePrimitiveEvaluatorTypeId)
		.value("FromCoreConverter", FromCoreConverterTypeId)
		.value("ShortData", ShortDataTypeId )
		.value("UShortData", UShortDataTypeId )
		.value("ShortVectorData", ShortVectorDataTypeId )
		.value("UShortVectorData", UShortVectorDataTypeId )
		.value("PathVectorParameter", PathVectorParameterTypeId )
		.value("ColorTransformOp", ColorTransformOpTypeId )
		.value("TransformOp", TransformOpTypeId )
		.value("CurvesPrimitive", CurvesPrimitiveTypeId )
		.value("ImageDiffOp", ImageDiffOpTypeId )
		.value("MeshNormalsOp", MeshNormalsOpTypeId )
		.value("Font", FontTypeId )
		.value("MeshMergeOp", MeshMergeOpTypeId )
		.value("UniformRandomPointDistributionOp", UniformRandomPointDistributionOpTypeId )
		.value("Int64Data", Int64DataTypeId )
		.value("UInt64Data", UInt64DataTypeId )
		.value("Int64VectorData", Int64VectorDataTypeId )
		.value("UInt64VectorData", UInt64VectorDataTypeId )
		.value("MappedRandomPointDistributionOp", MappedRandomPointDistributionOpTypeId )
		.value("PointRepulsionOp", PointRepulsionOpTypeId )
		.value("Grade", GradeTypeId )
		.value("LuminanceOp", LuminanceOpTypeId )
		.value("ImagePrimitiveOp", ImagePrimitiveOpTypeId )
		.value("ChannelOp", ChannelOpTypeId )
		.value("SummedAreaOp", SummedAreaOpTypeId )
		.value("Box2iVectorData", Box2iVectorDataTypeId )
		.value("Box3iVectorData", Box3iVectorDataTypeId )
		.value("MedianCutSampler", MedianCutSamplerTypeId )
		.value("EnvMapSampler", EnvMapSamplerTypeId )
		.value("MeshVertexReorderOp", MeshVertexReorderOpTypeId )
		.value("SplineffData", SplineffDataTypeId )
		.value("SplineddData", SplineddDataTypeId )
		.value("SplinefColor3fData", SplinefColor3fDataTypeId )
		.value("SplinefColor4fData", SplinefColor4fDataTypeId )
		.value("SplineffParameter", SplineffParameterTypeId )
		.value("SplineddParameter", SplineddParameterTypeId )
		.value("SplinefColor3fParameter", SplinefColor3fParameterTypeId )
		.value("SplinefColor4fParameter", SplinefColor4fParameterTypeId )
		.value("CompoundObjectParameter", CompoundObjectParameterTypeId )
		.value("DisplayDriver", DisplayDriverTypeId )
		.value("DisplayDriverCreator", DisplayDriverCreatorTypeId )
		.value("ImageDisplayDriver", ImageDisplayDriverTypeId )
	;
}

}
<commit_msg>Added missing type id<commit_after>//////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2007-2008, Image Engine Design Inc. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are
//  met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//
//     * Neither the name of Image Engine Design nor the names of any
//       other contributors to this software may be used to endorse or
//       promote products derived from this software without specific prior
//       written permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
//  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
//  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
//  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
//  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
//  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#include <boost/python.hpp>

#include "IECore/TypeIds.h"
#include "IECore/bindings/TypeIdBinding.h"

using namespace boost::python;

namespace IECore
{

void bindTypeId()
{
	enum_<TypeId>("TypeId")
		.value("Invalid", InvalidTypeId )
		.value("Object", ObjectTypeId )
		.value("Data", DataTypeId )
		.value("FloatVectorData", FloatVectorDataTypeId )
		.value("DoubleVectorData", DoubleVectorDataTypeId )
		.value("IntVectorData", IntVectorDataTypeId )
		.value("UIntVectorData", UIntVectorDataTypeId )
		.value("CharVectorData", CharVectorDataTypeId )
		.value("UCharVectorData", UCharVectorDataTypeId )
		.value("V2fVectorData", V2fVectorDataTypeId )
		.value("V2dVectorData", V2dVectorDataTypeId )
		.value("V3fVectorData", V3fVectorDataTypeId )
		.value("V3dVectorData", V3dVectorDataTypeId )
		.value("Box3fVectorData", Box3fVectorDataTypeId )
		.value("Box3dVectorData", Box3dVectorDataTypeId )
		.value("M33fVectorData", M33fVectorDataTypeId )
		.value("M33dVectorData", M33dVectorDataTypeId )
		.value("M44fVectorData", M44fVectorDataTypeId )
		.value("M44dVectorData", M44dVectorDataTypeId )
		.value("QuatfVectorData", QuatfVectorDataTypeId )
		.value("QuatdVectorData", QuatdVectorDataTypeId )
		.value("StringVectorData", StringVectorDataTypeId )
		.value("FloatData", FloatDataTypeId )
		.value("DoubleData", DoubleDataTypeId )
		.value("IntData", IntDataTypeId )
		.value("UIntData", UIntDataTypeId )
		.value("CharData", CharDataTypeId )
		.value("UCharData", UCharDataTypeId )
		.value("StringData",StringDataTypeId )
		.value("CompoundData", CompoundDataTypeId )
		.value("V2iData", V2iDataTypeId )
		.value("V2fData", V2fDataTypeId )
		.value("V3fData", V3fDataTypeId )
		.value("V2dData", V2dDataTypeId )
		.value("V3dData", V3dDataTypeId )
		.value("Box2fData", Box2fDataTypeId )
		.value("Box3fData", Box3fDataTypeId )
		.value("Box2dData", Box2dDataTypeId )
		.value("Box3dData", Box3dDataTypeId )
		.value("M44fData", M44fDataTypeId )
		.value("M44dData", M44dDataTypeId )
		.value("QuatfData", QuatfDataTypeId )
		.value("QuatdData", QuatdDataTypeId )
		.value("Color3fData", Color3fDataTypeId )
		.value("Color4fData", Color4fDataTypeId )
		.value("Color3dData", Color3dDataTypeId )
		.value("Color4dData", Color4dDataTypeId )
		.value("Color3fVectorData", Color3fVectorDataTypeId )
		.value("Color4fVectorData", Color4fVectorDataTypeId )
		.value("Color3dVectorData", Color3dVectorDataTypeId )
		.value("Color4dVectorData", Color4dVectorDataTypeId )
		.value("BlindDataHolder", BlindDataHolderTypeId )
		.value("Renderable", RenderableTypeId )
		.value("CompoundObject", CompoundObjectTypeId )
		.value("M33fData", M33fDataTypeId )
		.value("M33dData", M33dDataTypeId )
		.value("Box2fVectorData", Box2fVectorDataTypeId )
		.value("Box2dVectorData", Box2dVectorDataTypeId )
		.value("BoolData", BoolDataTypeId )
		.value("Primitive", PrimitiveTypeId )
		.value("PointsPrimitive", PointsPrimitiveTypeId )
		.value("ImagePrimitive", ImagePrimitiveTypeId )
		.value("MeshPrimitive", MeshPrimitiveTypeId )
		.value("Box2iData", Box2iDataTypeId )
		.value("HalfVectorData", HalfVectorDataTypeId )
		.value("Shader", ShaderTypeId )
		.value("RunTimeTyped", RunTimeTypedTypeId )
		.value("Parameter", ParameterTypeId )
		.value("CompoundParameter", CompoundParameterTypeId )
		.value("StringParameter", StringParameterTypeId )
		.value("ValidatedStringParameter", ValidatedStringParameterTypeId )
		.value("FileNameParameter", FileNameParameterTypeId )
		.value("IntParameter", IntParameterTypeId )
		.value("FloatParameter", FloatParameterTypeId )
		.value("DoubleParameter", DoubleParameterTypeId )
		.value("BoolParameter", BoolParameterTypeId )
		.value("V2fParameter", V2fParameterTypeId )
		.value("V3fParameter", V3fParameterTypeId )
		.value("V2dParameter", V2dParameterTypeId )
		.value("V3dParameter", V3dParameterTypeId )
		.value("Color3fParameter", Color3fParameterTypeId )
		.value("Color4fParameter", Color4fParameterTypeId )
		.value("Box2iParameter", Box2iParameterTypeId )
		.value("Box2fParameter", Box2fParameterTypeId )
		.value("Box3fParameter", Box3fParameterTypeId )
		.value("Box2dParameter", Box2dParameterTypeId )
		.value("Box3dParameter", Box3dParameterTypeId )
		.value("M44fParameter",  M44fParameterTypeId )
		.value("M44dParameter",  M44dParameterTypeId )
		.value("IntVectorParameter", IntVectorParameterTypeId )
		.value("FloatVectorParameter", FloatVectorParameterTypeId )
		.value("DoubleVectorParameter", DoubleVectorParameterTypeId )
		.value("StringVectorParameter", StringVectorParameterTypeId )
		.value("V2fVectorParameter", V2fVectorParameterTypeId )
		.value("V3fVectorParameter", V3fVectorParameterTypeId )
		.value("V2dVectorParameter", V2dVectorParameterTypeId )
		.value("V3dVectorParameter", V3dVectorParameterTypeId )
		.value("Box3fVectorParameter", Box3fVectorParameterTypeId )
		.value("Box3dVectorParameter", Box3dVectorParameterTypeId )
		.value("M33fVectorParameter", M33fVectorParameterTypeId )
		.value("M44fVectorParameter", M44fVectorParameterTypeId )
		.value("M33dVectorParameter", M33dVectorParameterTypeId )
		.value("M44dVectorParameter", M44dVectorParameterTypeId )
		.value("QuatfVectorParameter", QuatfVectorParameterTypeId )
		.value("QuatdVectorParameter", QuatdVectorParameterTypeId )
		.value("Color3fVectorParameter", Color3fVectorParameterTypeId )
		.value("Color4fVectorParameter", Color4fVectorParameterTypeId )
		.value("NullObject", NullObjectTypeId )
		.value("Parameterised", ParameterisedTypeId )
		.value("Op", OpTypeId )
		.value("Reader", ReaderTypeId )
		.value("Writer", WriterTypeId )
		.value("ImageReader", ImageReaderTypeId )
		.value("ImageWriter", ImageWriterTypeId )
		.value("CINImageReader", CINImageReaderTypeId )
		.value("CINImageWriter", CINImageWriterTypeId )
		.value("DPXImageReader", DPXImageReaderTypeId )
		.value("DPXImageWriter", DPXImageWriterTypeId )
		.value("EXRImageReader", EXRImageReaderTypeId )
		.value("EXRImageWriter", EXRImageWriterTypeId )
		.value("JPEGImageReader", JPEGImageReaderTypeId )
		.value("JPEGImageWriter", JPEGImageWriterTypeId )
		.value("TIFFImageReader", TIFFImageReaderTypeId )
		.value("TIFFImageWriter", TIFFImageWriterTypeId )
		.value("ObjectReader", ObjectReaderTypeId )
		.value("ObjectWriter", ObjectWriterTypeId )
		.value("PDCParticleReader", PDCParticleReaderTypeId )
		.value("PDCParticleWriter", PDCParticleWriterTypeId )
		.value("PathParameter", PathParameterTypeId )
		.value("DirNameParameter", DirNameParameterTypeId )
		.value("V3iData", V3iDataTypeId )
		.value("Box3iData", Box3iDataTypeId )
		.value("ObjectParameter", ObjectParameterTypeId )
		.value("ModifyOp", ModifyOpTypeId )
		.value("ImageOp", ImageOpTypeId )
		.value("PrimitiveOp", PrimitiveOpTypeId )
		.value("Procedural", ProceduralTypeId )
		.value("Box3iParameter", Box3iParameterTypeId )
		.value("V2iParameter", V2iParameterTypeId )
		.value("V3iParameter", V3iParameterTypeId )
		.value("ParticleReader", ParticleReaderTypeId )
		.value("ParticleWriter", ParticleWriterTypeId )
		.value("MotionPrimitive", MotionPrimitiveTypeId )
		.value("Transform", TransformTypeId )
		.value("MatrixTransform", MatrixTransformTypeId )
		.value("MotionTransform", MotionTransformTypeId )
		.value("MatrixMotionTransform", MatrixMotionTransformTypeId )
		.value("Group", GroupTypeId )
		.value("AttributeState", AttributeStateTypeId )
		.value("VisibleRenderable", VisibleRenderableTypeId )
		.value("StateRenderable", StateRenderableTypeId )
		.value("OBJReader", OBJReaderTypeId)
		.value("TransformationMatrixfData", TransformationMatrixfDataTypeId)
		.value("TransformationMatrixdData", TransformationMatrixdDataTypeId)
		.value("PointNormalsOp", PointNormalsOpTypeId)
		.value("PointDensitiesOp", PointDensitiesOpTypeId)
		.value("BoolVectorData", BoolVectorDataTypeId)
		.value("VectorDataFilterOp", VectorDataFilterOpTypeId)
		.value("RenderableParameter", RenderableParameterTypeId)
		.value("StateRenderableParameter", StateRenderableParameterTypeId)
		.value("AttributeStateParameter", AttributeStateParameterTypeId)
		.value("ShaderParameter", ShaderParameterTypeId)
		.value("TransformParameter", TransformParameterTypeId)
		.value("MatrixMotionTransformParameter", MatrixMotionTransformParameterTypeId)
		.value("MatrixTransformParameter", MatrixTransformParameterTypeId)
		.value("VisibleRenderableParameter", VisibleRenderableParameterTypeId)
		.value("GroupParameter", GroupParameterTypeId)
		.value("MotionPrimitiveParameter", MotionPrimitiveParameterTypeId)
		.value("PrimitiveParameter", PrimitiveParameterTypeId)
		.value("ImagePrimitiveParameter", ImagePrimitiveParameterTypeId)
		.value("MeshPrimitiveParameter", MeshPrimitiveParameterTypeId)
		.value("PointsPrimitiveParameter", PointsPrimitiveParameterTypeId)
		.value("PreWorldRenderable", PreWorldRenderableTypeId)
		.value("Camera", CameraTypeId)
		.value("NURBSPrimitive", NURBSPrimitiveTypeId)
		.value("DataCastOp", DataCastOpTypeId)
		.value("DataPromoteOp", DataPromoteOpTypeId)
		.value("PointBoundsOp", PointBoundsOpTypeId)
		.value("V2iVectorData", V2iVectorDataTypeId)
		.value("V3iVectorData", V3iVectorDataTypeId)
		.value("PointMeshOp", PointMeshOpTypeId)
		.value("ParticleMeshOp", ParticleMeshOpTypeId)
		.value("HalfData", HalfDataTypeId)
		.value("MeshPrimitiveOp", MeshPrimitiveOpTypeId)
		.value("PrimitiveEvaluator", PrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveEvaluator", MeshPrimitiveEvaluatorTypeId)
		.value("MeshPrimitiveImplicitSurfaceOp", MeshPrimitiveImplicitSurfaceOpTypeId)
		.value("TriangulateOp", TriangulateOpTypeId)
		.value("SpherePrimitiveEvaluator", SpherePrimitiveEvaluatorTypeId)
		.value("SpherePrimitive", SpherePrimitiveTypeId)
		.value("Converter", ConverterTypeId)
		.value("ToCoreConverter", ToCoreConverterTypeId)
		.value("ImageCropOp", ImageCropOpTypeId)
		.value("MeshPrimitiveShrinkWrapOp", MeshPrimitiveShrinkWrapOpTypeId)
		.value("ImagePrimitiveEvaluator", ImagePrimitiveEvaluatorTypeId)
		.value("FromCoreConverter", FromCoreConverterTypeId)
		.value("ShortData", ShortDataTypeId )
		.value("UShortData", UShortDataTypeId )
		.value("ShortVectorData", ShortVectorDataTypeId )
		.value("UShortVectorData", UShortVectorDataTypeId )
		.value("PathVectorParameter", PathVectorParameterTypeId )
		.value("ColorTransformOp", ColorTransformOpTypeId )
		.value("TransformOp", TransformOpTypeId )
		.value("CurvesPrimitive", CurvesPrimitiveTypeId )
		.value("ImageDiffOp", ImageDiffOpTypeId )
		.value("MeshNormalsOp", MeshNormalsOpTypeId )
		.value("Font", FontTypeId )
		.value("MeshMergeOp", MeshMergeOpTypeId )
		.value("UniformRandomPointDistributionOp", UniformRandomPointDistributionOpTypeId )
		.value("Int64Data", Int64DataTypeId )
		.value("UInt64Data", UInt64DataTypeId )
		.value("Int64VectorData", Int64VectorDataTypeId )
		.value("UInt64VectorData", UInt64VectorDataTypeId )
		.value("MappedRandomPointDistributionOp", MappedRandomPointDistributionOpTypeId )
		.value("PointRepulsionOp", PointRepulsionOpTypeId )
		.value("Grade", GradeTypeId )
		.value("LuminanceOp", LuminanceOpTypeId )
		.value("ImagePrimitiveOp", ImagePrimitiveOpTypeId )
		.value("ChannelOp", ChannelOpTypeId )
		.value("SummedAreaOp", SummedAreaOpTypeId )
		.value("Box2iVectorData", Box2iVectorDataTypeId )
		.value("Box3iVectorData", Box3iVectorDataTypeId )
		.value("MedianCutSampler", MedianCutSamplerTypeId )
		.value("EnvMapSampler", EnvMapSamplerTypeId )
		.value("MeshVertexReorderOp", MeshVertexReorderOpTypeId )
		.value("SplineffData", SplineffDataTypeId )
		.value("SplineddData", SplineddDataTypeId )
		.value("SplinefColor3fData", SplinefColor3fDataTypeId )
		.value("SplinefColor4fData", SplinefColor4fDataTypeId )
		.value("SplineffParameter", SplineffParameterTypeId )
		.value("SplineddParameter", SplineddParameterTypeId )
		.value("SplinefColor3fParameter", SplinefColor3fParameterTypeId )
		.value("SplinefColor4fParameter", SplinefColor4fParameterTypeId )
		.value("CompoundObjectParameter", CompoundObjectParameterTypeId )
		.value("DisplayDriver", DisplayDriverTypeId )
		.value("DisplayDriverCreator", DisplayDriverCreatorTypeId )
		.value("ImageDisplayDriver", ImageDisplayDriverTypeId )
		.value("ClientDisplayDriver", ClientDisplayDriverTypeId )
	;
}

}
<|endoftext|>


<commit_before>#include "convergence/final_checker_or_n.h"

#include <memory>
#include <optional>

#include <gtest/gtest.h>

#include "convergence/status.h"
#include "convergence/moments/tests/multi_moment_checker_mock.h"
#include "data/moment_types.h"
#include "test_helpers/gmock_wrapper.h"

namespace {

using ::testing::_;
using ::testing::Expectation;
using ::testing::NiceMock;
using ::testing::Return;
using namespace bart::convergence;

class ConvergenceFinalCheckerOrNMultiMomentTest : public ::testing::Test {
 protected:
  using FinalMultiMomentChecker =
      FinalCheckerOrN<bart::data::MomentsMap , moments::MultiMomentCheckerI>;

  std::unique_ptr<NiceMock<moments::MultiMomentCheckerMock>> checker_ptr;

  bart::data::MomentsMap moment_map_one, moment_map_two;
  void SetUp() override;
};

void ConvergenceFinalCheckerOrNMultiMomentTest::SetUp() {
  checker_ptr = std::make_unique<NiceMock<moments::MultiMomentCheckerMock>>();
  ON_CALL(*checker_ptr, CheckIfConverged(_,_))
      .WillByDefault(Return(true));
  ON_CALL(*checker_ptr, delta())
      .WillByDefault(Return(std::nullopt));
  ON_CALL(*checker_ptr, failed_index())
      .WillByDefault(Return(std::nullopt));
}

// -- CUSTOM ASSERTION FOR COMPARING STATUS STRUCTS --

::testing::AssertionResult CompareStatus(const Status lhs, const Status rhs) {
  if (lhs.iteration_number != rhs.iteration_number) {
    return ::testing::AssertionFailure() << "Iteration number mismatch "
                                         << lhs.iteration_number << " != "
                                         << rhs.iteration_number;
  } else if (lhs.max_iterations != rhs.max_iterations) {
    return ::testing::AssertionFailure() << "Max iteration number mismatch "
                                         << lhs.max_iterations << " != "
                                         << rhs.max_iterations;
  } else if (lhs.is_complete != rhs.is_complete) {
    return ::testing::AssertionFailure() << "Convergence completion mismatch "
                                         << lhs.is_complete << " != "
                                         << rhs.is_complete;
  } else if (lhs.failed_index != rhs.failed_index) {
    return ::testing::AssertionFailure() << "Failed index mismatch "
                                         << lhs.failed_index.value_or(-1) << " != "
                                         << rhs.failed_index.value_or(-1);
  } else if (lhs.delta != rhs.delta) {
    return ::testing::AssertionFailure() << "Delta mismatch "
                                         << lhs.delta.value_or(-1) << " != "
                                         << rhs.delta.value_or(-1);
  }
  return ::testing::AssertionSuccess();
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, Constructor) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));

  EXPECT_EQ(checker_ptr, nullptr);
}

// Verify setters and getters work properly
TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, SettersAndGetters) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));

  EXPECT_EQ(test_checker.max_iterations(), 100);
  test_checker.SetMaxIterations(50);
  EXPECT_EQ(test_checker.max_iterations(), 50);

  EXPECT_EQ(test_checker.iteration(), 0);
  test_checker.SetIteration(10);
  EXPECT_EQ(test_checker.iteration(), 10);
}

// -- CONVERGENCE TESTS --

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, GoodConvergence) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status good_convergence = {1, 100, true, std::nullopt, std::nullopt};

  auto result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);
  EXPECT_TRUE(CompareStatus(result, good_convergence));
  EXPECT_TRUE(CompareStatus(test_checker.convergence_status(),
                            good_convergence));
  EXPECT_TRUE(test_checker.convergence_is_complete());
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, GoodConvergenceAfterBad) {
  Expectation bad_convergence = EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .Times(5)
      .WillRepeatedly(Return(false));
  EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .After(bad_convergence)
      .WillOnce(Return(true));

  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status result, good_convergence = {6, 100, true, std::nullopt, std::nullopt};

  for (int i = 0; i < 6; ++i)
    result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);

  EXPECT_TRUE(CompareStatus(result, good_convergence));
  EXPECT_TRUE(test_checker.convergence_is_complete());
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, BadConvergenceAfterGood) {

  auto delta = std::make_optional<double>(0.123);
  auto failed_index = std::make_optional<int>(5);

  Expectation good_convergence = EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .Times(5)
      .WillRepeatedly(Return(true));
  EXPECT_CALL(*checker_ptr, delta())
      .Times(5)
      .WillRepeatedly(::testing::DoDefault());
  EXPECT_CALL(*checker_ptr, failed_index())
      .Times(5)
      .WillRepeatedly(::testing::DoDefault());
  Expectation bad_convergence = EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .After(good_convergence)
      .WillOnce(Return(false));
  EXPECT_CALL(*checker_ptr, delta())
      .After(bad_convergence)
      .WillOnce(Return(delta));
  EXPECT_CALL(*checker_ptr, failed_index())
      .After(bad_convergence)
      .WillOnce(Return(failed_index));

  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status result, expected = {6, 100, false, failed_index, delta};

  for (int i = 0; i < 6; ++i)
    result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);

  EXPECT_TRUE(CompareStatus(result, expected));
  EXPECT_FALSE(test_checker.convergence_is_complete());
}
//
TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, MaxIterationsReached) {

  auto delta = std::make_optional<double>(0.123);
  auto failed_index = std::make_optional<int>(5);

  ON_CALL(*checker_ptr, CheckIfConverged(_,_))
      .WillByDefault(Return(false));
  ON_CALL(*checker_ptr, delta())
      .WillByDefault(Return(delta));
  ON_CALL(*checker_ptr, failed_index())
      .WillByDefault(Return(failed_index));

  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status result, expected = {10, 10, true, failed_index, delta};

  test_checker.SetMaxIterations(10).SetIteration(9);

  result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);

  EXPECT_TRUE(CompareStatus(result, expected));
  EXPECT_TRUE(test_checker.convergence_is_complete());
}

// -- ERRORS --
// Verify setters and getters throw the correct errors
TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, SettersBadValues) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));

  EXPECT_ANY_THROW(test_checker.SetIteration(-10));
  EXPECT_ANY_THROW(test_checker.SetMaxIterations(-10));
  EXPECT_ANY_THROW(test_checker.SetMaxIterations(0));

}

} // namespace

<commit_msg>removed all base class tests from FinalCheckerOrNMultiMoment tests<commit_after>#include "convergence/final_checker_or_n.h"

#include <memory>
#include <optional>

#include <gtest/gtest.h>

#include "convergence/status.h"
#include "convergence/moments/tests/multi_moment_checker_mock.h"
#include "convergence/tests/final_test.h"
#include "data/moment_types.h"
#include "test_helpers/gmock_wrapper.h"

namespace {

using ::testing::_;
using ::testing::Expectation;
using ::testing::NiceMock;
using ::testing::Return;
using namespace bart::convergence;
using bart::convergence::testing::CompareStatus;

class ConvergenceFinalCheckerOrNMultiMomentTest :
    public bart::convergence::testing::ConvergenceFinalTest<bart::data::MomentsMap> {
 protected:
  using FinalMultiMomentChecker =
      FinalCheckerOrN<bart::data::MomentsMap , moments::MultiMomentCheckerI>;

  std::unique_ptr<NiceMock<moments::MultiMomentCheckerMock>> checker_ptr;

  bart::data::MomentsMap moment_map_one, moment_map_two;
  void SetUp() override;
};

void ConvergenceFinalCheckerOrNMultiMomentTest::SetUp() {
  checker_ptr = std::make_unique<NiceMock<moments::MultiMomentCheckerMock>>();
  ON_CALL(*checker_ptr, CheckIfConverged(_,_))
      .WillByDefault(Return(true));
  ON_CALL(*checker_ptr, delta())
      .WillByDefault(Return(std::nullopt));
  ON_CALL(*checker_ptr, failed_index())
      .WillByDefault(Return(std::nullopt));
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, BaseClassTests) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  TestBaseMethods(&test_checker);
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, Constructor) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));

  EXPECT_EQ(checker_ptr, nullptr);
}

// -- CONVERGENCE TESTS --

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, GoodConvergence) {
  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status good_convergence = {1, 100, true, std::nullopt, std::nullopt};

  auto result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);
  EXPECT_TRUE(CompareStatus(result, good_convergence));
  EXPECT_TRUE(CompareStatus(test_checker.convergence_status(),
                            good_convergence));
  EXPECT_TRUE(test_checker.convergence_is_complete());
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, GoodConvergenceAfterBad) {
  Expectation bad_convergence = EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .Times(5)
      .WillRepeatedly(Return(false));
  EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .After(bad_convergence)
      .WillOnce(Return(true));

  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status result, good_convergence = {6, 100, true, std::nullopt, std::nullopt};

  for (int i = 0; i < 6; ++i)
    result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);

  EXPECT_TRUE(CompareStatus(result, good_convergence));
  EXPECT_TRUE(test_checker.convergence_is_complete());
}

TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, BadConvergenceAfterGood) {

  auto delta = std::make_optional<double>(0.123);
  auto failed_index = std::make_optional<int>(5);

  Expectation good_convergence = EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .Times(5)
      .WillRepeatedly(Return(true));
  EXPECT_CALL(*checker_ptr, delta())
      .Times(5)
      .WillRepeatedly(::testing::DoDefault());
  EXPECT_CALL(*checker_ptr, failed_index())
      .Times(5)
      .WillRepeatedly(::testing::DoDefault());
  Expectation bad_convergence = EXPECT_CALL(*checker_ptr, CheckIfConverged(_,_))
      .After(good_convergence)
      .WillOnce(Return(false));
  EXPECT_CALL(*checker_ptr, delta())
      .After(bad_convergence)
      .WillOnce(Return(delta));
  EXPECT_CALL(*checker_ptr, failed_index())
      .After(bad_convergence)
      .WillOnce(Return(failed_index));

  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status result, expected = {6, 100, false, failed_index, delta};

  for (int i = 0; i < 6; ++i)
    result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);

  EXPECT_TRUE(CompareStatus(result, expected));
  EXPECT_FALSE(test_checker.convergence_is_complete());
}
//
TEST_F(ConvergenceFinalCheckerOrNMultiMomentTest, MaxIterationsReached) {

  auto delta = std::make_optional<double>(0.123);
  auto failed_index = std::make_optional<int>(5);

  ON_CALL(*checker_ptr, CheckIfConverged(_,_))
      .WillByDefault(Return(false));
  ON_CALL(*checker_ptr, delta())
      .WillByDefault(Return(delta));
  ON_CALL(*checker_ptr, failed_index())
      .WillByDefault(Return(failed_index));

  FinalMultiMomentChecker test_checker(std::move(checker_ptr));
  Status result, expected = {10, 10, true, failed_index, delta};

  test_checker.SetMaxIterations(10).SetIteration(9);

  result = test_checker.CheckFinalConvergence(moment_map_one, moment_map_two);

  EXPECT_TRUE(CompareStatus(result, expected));
  EXPECT_TRUE(test_checker.convergence_is_complete());
}

} // namespace

<|endoftext|>


<commit_before>#include <cstdint>
#include <vector>
#include <cstring>
#include <ctime>
#include "../src/mempool.h"
using namespace mp;

enum class FRAME_TYPE
{
    AUDIO,
    UNKNOWN
};

class Frame
{
public:
    Frame(int num_ch, FRAME_TYPE type)
    : num_channels_(num_ch),
      type_(type)
    {

    }

    ~Frame()
    {
        num_channels_ = 0;
        type_ = FRAME_TYPE::UNKNOWN;
    }

    int num_channels_;
    FRAME_TYPE type_;
    uint16_t buff[3000];
};

void usePool()
{
    std::stack<Frame*> s;
    MemPool<Frame> p;
    for(unsigned i = 0; i < 1000; i++)
    {
        for(unsigned j = 0; j < 1000; j++)
        {
            auto frame = p.create_raw(2, FRAME_TYPE::AUDIO);
            s.push(frame);
        }
        while(!s.empty())
        {
            auto frame = s.top();
            p.remove(frame);
            s.pop();
        }
    }
}

void noPool()
{
    std::stack<Frame*> s;
    for(unsigned i = 0; i < 1000; i++)
    {
        for(unsigned j = 0; j < 1000; j++)
        {
            s.push(new Frame(2, FRAME_TYPE::AUDIO));
        }

        while(!s.empty())
        {
            delete s.top();
            s.pop();
        }
    }
}

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printf("Usage: %s <pool|nopool|refcnt>\n", argv[0]);
        exit(1);
    }

    char* input = argv[1];
    if (strcmp(input, "pool") == 0)
    {
        usePool();
    }
    else if (strcmp(input, "nopool") == 0)
    {
        noPool();
    }
    else
    {
        printf("not implemented test for %s\n", input);
    }

    return (0);
}
<commit_msg>* Add test for shared_ptr allocations<commit_after>#include <cstdint>
#include <vector>
#include <cstring>
#include <ctime>
#include "../src/mempool.h"
using namespace mp;

enum class FRAME_TYPE
{
    AUDIO,
    UNKNOWN
};

class Frame
{
public:
    Frame(int num_ch, FRAME_TYPE type)
    : num_channels_(num_ch),
      type_(type)
    {

    }

    ~Frame()
    {
        num_channels_ = 0;
        type_ = FRAME_TYPE::UNKNOWN;
    }

    int num_channels_;
    FRAME_TYPE type_;
    uint16_t buff[32000];
};

void usePool()
{
    std::stack<Frame*> s;
    MemPool<Frame> p;
    for(unsigned i = 0; i < 1000; i++)
    {
        for(unsigned j = 0; j < 1000; j++)
        {
            auto frame = p.create_raw(2, FRAME_TYPE::AUDIO);
            s.push(frame);
        }
        while(!s.empty())
        {
            auto frame = s.top();
            p.remove(frame);
            s.pop();
        }
    }
}

void usePoolShared()
{
    MemPool<Frame> p;
    std::stack<std::shared_ptr<Frame>> s;
    for(unsigned i = 0; i < 1000; i++)
    {
        for(unsigned j = 0; j < 1000; j++)
        {
            auto frame = p.create_shared(2, FRAME_TYPE::AUDIO);
            s.push(frame);
        }

        while(!s.empty())
        {
            s.pop();
        }
    }
}

void noPool()
{
    std::stack<Frame*> s;
    for(unsigned i = 0; i < 1000; i++)
    {
        for(unsigned j = 0; j < 1000; j++)
        {
            s.push(new Frame(2, FRAME_TYPE::AUDIO));
        }

        while(!s.empty())
        {
            delete s.top();
            s.pop();
        }
    }
}

int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printf("Usage: %s <pool|nopool|poolshared>\n", argv[0]);
        exit(1);
    }

    char* input = argv[1];
    if (strcmp(input, "pool") == 0)
    {
        usePool();
    }
    else if (strcmp(input, "nopool") == 0)
    {
        noPool();
    }
    else if (strcmp(input, "poolshared") == 0)
    {
        usePoolShared();
    }
    else
    {
        printf("not implemented test for %s\n", input);
    }

    return (0);
}
<|endoftext|>


<commit_before>// See header file for why this is here
#ifdef MULTILOOKUPCOMPONENTMANAGER_H_

#include <utility>

#include "entity/managers/base/MultiLookupComponentManager.h"

template<typename Ti, typename T>
std::map<Ti,T> MultiLookupComponentManager<Ti,T>::getNullComponent()
{
	//Just an empty map
	std::map<Ti,T> empty;
	return empty;
}

template<typename Ti, typename T>
T MultiLookupComponentManager<Ti,T>::getComponent(Entity e, Ti type)
{
	//Get our current sub-components
	std::map<Ti, T> comp_map; //= getComponent(e);
	//Look for the one we're after
	typename std::map<Ti, T>::iterator comp_it = comp_map.find(type);

	if(comp_map.end() == comp_it)
	{
		//Not found, return our NULL-equivalent
		return getNullComponent();
	} else {
		//Return the specified sub-component
		return comp_it->second; //first is key, second is value
	}
}

template<typename Ti, typename T>
void MultiLookupComponentManager<Ti,T>::setComponent(Entity e, Ti type, T value)
{
	//Get our current components
	std::map<Ti, T> comp_map; //= getComponent(e);

	//Update the individual one to the specified value
	comp_map.insert(std::pair<Ti,T>(type, value));

	//Now update the whole thing
	//setComponent(e, comp_map);
}

#endif
<commit_msg>Fixed getComponent returning wrong NULL-equivalent<commit_after>// See header file for why this is here
#ifdef MULTILOOKUPCOMPONENTMANAGER_H_

#include <utility>

#include "entity/managers/base/MultiLookupComponentManager.h"

template<typename Ti, typename T>
std::map<Ti,T> MultiLookupComponentManager<Ti,T>::getNullComponent()
{
	//Just an empty map
	std::map<Ti,T> empty;
	return empty;
}

template<typename Ti, typename T>
T MultiLookupComponentManager<Ti,T>::getComponent(Entity e, Ti type)
{
	//Get our current sub-components
	std::map<Ti, T> comp_map; //= getComponent(e);
	//Look for the one we're after
	typename std::map<Ti, T>::iterator comp_it = comp_map.find(type);

	if(comp_map.end() == comp_it)
	{
		//Not found, return our NULL-equivalent
		return getNullSubComponent();
	} else {
		//Return the specified sub-component
		return comp_it->second; //first is key, second is value
	}
}

template<typename Ti, typename T>
void MultiLookupComponentManager<Ti,T>::setComponent(Entity e, Ti type, T value)
{
	//Get our current components
	std::map<Ti, T> comp_map; //= getComponent(e);

	//Update the individual one to the specified value
	comp_map.insert(std::pair<Ti,T>(type, value));

	//Now update the whole thing
	//setComponent(e, comp_map);
}

#endif
<|endoftext|>


<commit_before>/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/

#include "cppfindreferences.h"
#include "cppmodelmanagerinterface.h"
#include "cpptoolsconstants.h"

#include <texteditor/basetexteditor.h>
#include <find/searchresultwindow.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/filesearch.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>

#include <ASTVisitor.h>
#include <AST.h>
#include <Control.h>
#include <Literals.h>
#include <TranslationUnit.h>
#include <Symbols.h>
#include <Names.h>
#include <Scope.h>

#include <cplusplus/CppDocument.h>
#include <cplusplus/CppBindings.h>
#include <cplusplus/Overview.h>

#include <QtCore/QTime>
#include <QtCore/QtConcurrentRun>
#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <qtconcurrent/runextensions.h>

using namespace CppTools::Internal;
using namespace CPlusPlus;

CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelManager)
    : _modelManager(modelManager),
      _resultWindow(ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>())
{
    m_watcher.setPendingResultsLimit(1);
    connect(&m_watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
    connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
}

CppFindReferences::~CppFindReferences()
{
}

QList<int> CppFindReferences::references(Symbol *symbol,
                                         Document::Ptr doc,
                                         const Snapshot& snapshot) const
{
    Identifier *id = 0;
    if (Identifier *symbolId = symbol->identifier())
        id = doc->control()->findIdentifier(symbolId->chars(), symbolId->size());

    QList<int> references;

    if (! id)
        return references;

    TranslationUnit *translationUnit = doc->translationUnit();
    Q_ASSERT(translationUnit != 0);

    FindUsages process(doc, snapshot, /*future = */ 0);
    process.setGlobalNamespaceBinding(bind(doc, snapshot));
    references = process(symbol, id, translationUnit->ast());

    return references;
}

static void find_helper(QFutureInterface<Usage> &future,
                        const QMap<QString, QString> wl,
                        Snapshot snapshot,
                        Symbol *symbol)
{
    QTime tm;
    tm.start();

    Identifier *symbolId = symbol->identifier();
    Q_ASSERT(symbolId != 0);

    const QString sourceFile = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());

    QStringList files(sourceFile);

    if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
        foreach (const Document::Ptr &doc, snapshot) {
            if (doc->fileName() == sourceFile)
                continue;

            Control *control = doc->control();

            if (control->findIdentifier(symbolId->chars(), symbolId->size()))
                files.append(doc->fileName());
        }
    } else {
        files += snapshot.dependsOn(sourceFile);
    }

    files.removeDuplicates();

    //qDebug() << "done in:" << tm.elapsed() << "number of files to parse:" << files.size();

    future.setProgressRange(0, files.size());

    for (int i = 0; i < files.size(); ++i) {
        if (future.isPaused())
            future.waitForResume();

        if (future.isCanceled())
            break;

        const QString &fileName = files.at(i);
        future.setProgressValueAndText(i, QFileInfo(fileName).fileName());

        if (Document::Ptr previousDoc = snapshot.value(fileName)) {
            Control *control = previousDoc->control();
            Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size());
            if (! id)
                continue; // skip this document, it's not using symbolId.
        }

        QByteArray source;

        if (wl.contains(fileName))
            source = snapshot.preprocessedCode(wl.value(fileName), fileName);
        else {
            QFile file(fileName);
            if (! file.open(QFile::ReadOnly))
                continue;

            const QString contents = QTextStream(&file).readAll(); // ### FIXME
            source = snapshot.preprocessedCode(contents, fileName);
        }

        Document::Ptr doc = snapshot.documentFromSource(source, fileName);
        doc->tokenize();

        Control *control = doc->control();
        if (Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size())) {
            QTime tm;
            tm.start();
            doc->parse();

            //qDebug() << "***" << unit->fileName() << "parsed in:" << tm.elapsed();

            tm.start();
            doc->check();
            //qDebug() << "***" << unit->fileName() << "checked in:" << tm.elapsed();

            tm.start();

            FindUsages process(doc, snapshot, &future);
            process.setGlobalNamespaceBinding(bind(doc, snapshot));

            TranslationUnit *unit = doc->translationUnit();
            process(symbol, id, unit->ast());

            //qDebug() << "***" << unit->fileName() << "processed in:" << tm.elapsed();
        }
    }

    future.setProgressValue(files.size());
}

void CppFindReferences::findUsages(Symbol *symbol)
{
    Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly);

    connect(search, SIGNAL(activated(Find::SearchResultItem)),
            this, SLOT(openEditor(Find::SearchResultItem)));

    findAll_helper(symbol);
}

void CppFindReferences::renameUsages(Symbol *symbol)
{
    if (Identifier *id = symbol->identifier()) {
        const QString textToReplace = QString::fromUtf8(id->chars(), id->size());

        Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchAndReplace);
        _resultWindow->setTextToReplace(textToReplace);

        connect(search, SIGNAL(activated(Find::SearchResultItem)),
                this, SLOT(openEditor(Find::SearchResultItem)));

        connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
                SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));

        findAll_helper(symbol);
    }
}

void CppFindReferences::findAll_helper(Symbol *symbol)
{
    if (! (symbol && symbol->identifier()))
        return;

    _resultWindow->popup(true);

    const Snapshot snapshot = _modelManager->snapshot();
    const QMap<QString, QString> wl = _modelManager->workingCopy();

    Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();

    QFuture<Usage> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol);
    m_watcher.setFuture(result);

    Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching..."),
                                                              CppTools::Constants::TASK_SEARCH,
                                                              Core::ProgressManager::CloseOnSuccess);

    connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup()));
}

static void applyChanges(QTextDocument *doc, const QString &text, const QList<Find::SearchResultItem> &items)
{
    QList<QTextCursor> cursors;

    foreach (const Find::SearchResultItem &item, items) {
        const int blockNumber = item.lineNumber - 1;
        QTextCursor tc(doc->findBlockByNumber(blockNumber));
        tc.setPosition(tc.position() + item.searchTermStart);
        tc.setPosition(tc.position() + item.searchTermLength,
                       QTextCursor::KeepAnchor);
        cursors.append(tc);
    }

    foreach (QTextCursor tc, cursors)
        tc.insertText(text);
}

void CppFindReferences::onReplaceButtonClicked(const QString &text,
                                               const QList<Find::SearchResultItem> &items)
{
    Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));

    if (text.isEmpty())
        return;

    QHash<QString, QList<Find::SearchResultItem> > changes;

    foreach (const Find::SearchResultItem &item, items)
        changes[item.fileName].append(item);

    Core::EditorManager *editorManager = Core::EditorManager::instance();

    QHashIterator<QString, QList<Find::SearchResultItem> > it(changes);
    while (it.hasNext()) {
        it.next();

        const QString fileName = it.key();
        const QList<Find::SearchResultItem> items = it.value();

        const QList<Core::IEditor *> editors = editorManager->editorsForFileName(fileName);
        TextEditor::BaseTextEditor *textEditor = 0;
        foreach (Core::IEditor *editor, editors) {
            textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
            if (textEditor != 0)
                break;
        }

        if (textEditor != 0) {
            QTextCursor tc = textEditor->textCursor();
            tc.beginEditBlock();
            applyChanges(textEditor->document(), text, items);
            tc.endEditBlock();
        } else {
            QFile file(fileName);

            if (file.open(QFile::ReadOnly)) {
                QTextStream stream(&file);
                // ### set the encoding
                const QString plainText = stream.readAll();
                file.close();

                QTextDocument doc;
                doc.setPlainText(plainText);

                applyChanges(&doc, text, items);

                QFile newFile(fileName);
                if (newFile.open(QFile::WriteOnly)) {
                    QTextStream stream(&newFile);
                    // ### set the encoding
                    stream << doc.toPlainText();
                }
            }
        }
    }

    const QStringList fileNames = changes.keys();
    _modelManager->updateSourceFiles(fileNames);
    _resultWindow->hide();
}

void CppFindReferences::displayResult(int index)
{
    Usage result = m_watcher.future().resultAt(index);
    _resultWindow->addResult(result.path,
                             result.line,
                             result.lineText,
                             result.col,
                             result.len);
}

void CppFindReferences::searchFinished()
{
    emit changed();
}

void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{
    TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.searchTermStart);
}

<commit_msg>Paranoia check. Skip the change if we have another change with the same offset.<commit_after>/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
**
**************************************************************************/

#include "cppfindreferences.h"
#include "cppmodelmanagerinterface.h"
#include "cpptoolsconstants.h"

#include <texteditor/basetexteditor.h>
#include <find/searchresultwindow.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/filesearch.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>

#include <ASTVisitor.h>
#include <AST.h>
#include <Control.h>
#include <Literals.h>
#include <TranslationUnit.h>
#include <Symbols.h>
#include <Names.h>
#include <Scope.h>

#include <cplusplus/CppDocument.h>
#include <cplusplus/CppBindings.h>
#include <cplusplus/Overview.h>

#include <QtCore/QTime>
#include <QtCore/QtConcurrentRun>
#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <qtconcurrent/runextensions.h>

using namespace CppTools::Internal;
using namespace CPlusPlus;

CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelManager)
    : _modelManager(modelManager),
      _resultWindow(ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>())
{
    m_watcher.setPendingResultsLimit(1);
    connect(&m_watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int)));
    connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
}

CppFindReferences::~CppFindReferences()
{
}

QList<int> CppFindReferences::references(Symbol *symbol,
                                         Document::Ptr doc,
                                         const Snapshot& snapshot) const
{
    Identifier *id = 0;
    if (Identifier *symbolId = symbol->identifier())
        id = doc->control()->findIdentifier(symbolId->chars(), symbolId->size());

    QList<int> references;

    if (! id)
        return references;

    TranslationUnit *translationUnit = doc->translationUnit();
    Q_ASSERT(translationUnit != 0);

    FindUsages process(doc, snapshot, /*future = */ 0);
    process.setGlobalNamespaceBinding(bind(doc, snapshot));
    references = process(symbol, id, translationUnit->ast());

    return references;
}

static void find_helper(QFutureInterface<Usage> &future,
                        const QMap<QString, QString> wl,
                        Snapshot snapshot,
                        Symbol *symbol)
{
    QTime tm;
    tm.start();

    Identifier *symbolId = symbol->identifier();
    Q_ASSERT(symbolId != 0);

    const QString sourceFile = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());

    QStringList files(sourceFile);

    if (symbol->isClass() || symbol->isForwardClassDeclaration()) {
        foreach (const Document::Ptr &doc, snapshot) {
            if (doc->fileName() == sourceFile)
                continue;

            Control *control = doc->control();

            if (control->findIdentifier(symbolId->chars(), symbolId->size()))
                files.append(doc->fileName());
        }
    } else {
        files += snapshot.dependsOn(sourceFile);
    }

    files.removeDuplicates();

    //qDebug() << "done in:" << tm.elapsed() << "number of files to parse:" << files.size();

    future.setProgressRange(0, files.size());

    for (int i = 0; i < files.size(); ++i) {
        if (future.isPaused())
            future.waitForResume();

        if (future.isCanceled())
            break;

        const QString &fileName = files.at(i);
        future.setProgressValueAndText(i, QFileInfo(fileName).fileName());

        if (Document::Ptr previousDoc = snapshot.value(fileName)) {
            Control *control = previousDoc->control();
            Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size());
            if (! id)
                continue; // skip this document, it's not using symbolId.
        }

        QByteArray source;

        if (wl.contains(fileName))
            source = snapshot.preprocessedCode(wl.value(fileName), fileName);
        else {
            QFile file(fileName);
            if (! file.open(QFile::ReadOnly))
                continue;

            const QString contents = QTextStream(&file).readAll(); // ### FIXME
            source = snapshot.preprocessedCode(contents, fileName);
        }

        Document::Ptr doc = snapshot.documentFromSource(source, fileName);
        doc->tokenize();

        Control *control = doc->control();
        if (Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size())) {
            QTime tm;
            tm.start();
            doc->parse();

            //qDebug() << "***" << unit->fileName() << "parsed in:" << tm.elapsed();

            tm.start();
            doc->check();
            //qDebug() << "***" << unit->fileName() << "checked in:" << tm.elapsed();

            tm.start();

            FindUsages process(doc, snapshot, &future);
            process.setGlobalNamespaceBinding(bind(doc, snapshot));

            TranslationUnit *unit = doc->translationUnit();
            process(symbol, id, unit->ast());

            //qDebug() << "***" << unit->fileName() << "processed in:" << tm.elapsed();
        }
    }

    future.setProgressValue(files.size());
}

void CppFindReferences::findUsages(Symbol *symbol)
{
    Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchOnly);

    connect(search, SIGNAL(activated(Find::SearchResultItem)),
            this, SLOT(openEditor(Find::SearchResultItem)));

    findAll_helper(symbol);
}

void CppFindReferences::renameUsages(Symbol *symbol)
{
    if (Identifier *id = symbol->identifier()) {
        const QString textToReplace = QString::fromUtf8(id->chars(), id->size());

        Find::SearchResult *search = _resultWindow->startNewSearch(Find::SearchResultWindow::SearchAndReplace);
        _resultWindow->setTextToReplace(textToReplace);

        connect(search, SIGNAL(activated(Find::SearchResultItem)),
                this, SLOT(openEditor(Find::SearchResultItem)));

        connect(search, SIGNAL(replaceButtonClicked(QString,QList<Find::SearchResultItem>)),
                SLOT(onReplaceButtonClicked(QString,QList<Find::SearchResultItem>)));

        findAll_helper(symbol);
    }
}

void CppFindReferences::findAll_helper(Symbol *symbol)
{
    if (! (symbol && symbol->identifier()))
        return;

    _resultWindow->popup(true);

    const Snapshot snapshot = _modelManager->snapshot();
    const QMap<QString, QString> wl = _modelManager->workingCopy();

    Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();

    QFuture<Usage> result = QtConcurrent::run(&find_helper, wl, snapshot, symbol);
    m_watcher.setFuture(result);

    Core::FutureProgress *progress = progressManager->addTask(result, tr("Searching..."),
                                                              CppTools::Constants::TASK_SEARCH,
                                                              Core::ProgressManager::CloseOnSuccess);

    connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup()));
}

static void applyChanges(QTextDocument *doc, const QString &text, const QList<Find::SearchResultItem> &items)
{
    QList<QTextCursor> cursors;

    foreach (const Find::SearchResultItem &item, items) {
        const int blockNumber = item.lineNumber - 1;
        QTextCursor tc(doc->findBlockByNumber(blockNumber));

        const int cursorPosition = tc.position() + item.searchTermStart;

        int cursorIndex = 0;
        for (; cursorIndex < cursors.size(); ++cursorIndex) {
            const QTextCursor &tc = cursors.at(cursorIndex);

            if (tc.position() == cursorPosition)
                break;
        }

        if (cursorIndex != cursors.size())
            continue; // skip this change.

        tc.setPosition(cursorPosition);
        tc.setPosition(tc.position() + item.searchTermLength,
                       QTextCursor::KeepAnchor);
        cursors.append(tc);
    }

    foreach (QTextCursor tc, cursors)
        tc.insertText(text);
}

void CppFindReferences::onReplaceButtonClicked(const QString &text,
                                               const QList<Find::SearchResultItem> &items)
{
    Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));

    if (text.isEmpty())
        return;

    QHash<QString, QList<Find::SearchResultItem> > changes;

    foreach (const Find::SearchResultItem &item, items)
        changes[item.fileName].append(item);

    Core::EditorManager *editorManager = Core::EditorManager::instance();

    QHashIterator<QString, QList<Find::SearchResultItem> > it(changes);
    while (it.hasNext()) {
        it.next();

        const QString fileName = it.key();
        const QList<Find::SearchResultItem> items = it.value();

        const QList<Core::IEditor *> editors = editorManager->editorsForFileName(fileName);
        TextEditor::BaseTextEditor *textEditor = 0;
        foreach (Core::IEditor *editor, editors) {
            textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
            if (textEditor != 0)
                break;
        }

        if (textEditor != 0) {
            QTextCursor tc = textEditor->textCursor();
            tc.beginEditBlock();
            applyChanges(textEditor->document(), text, items);
            tc.endEditBlock();
        } else {
            QFile file(fileName);

            if (file.open(QFile::ReadOnly)) {
                QTextStream stream(&file);
                // ### set the encoding
                const QString plainText = stream.readAll();
                file.close();

                QTextDocument doc;
                doc.setPlainText(plainText);

                applyChanges(&doc, text, items);

                QFile newFile(fileName);
                if (newFile.open(QFile::WriteOnly)) {
                    QTextStream stream(&newFile);
                    // ### set the encoding
                    stream << doc.toPlainText();
                }
            }
        }
    }

    const QStringList fileNames = changes.keys();
    _modelManager->updateSourceFiles(fileNames);
    _resultWindow->hide();
}

void CppFindReferences::displayResult(int index)
{
    Usage result = m_watcher.future().resultAt(index);
    _resultWindow->addResult(result.path,
                             result.line,
                             result.lineText,
                             result.col,
                             result.len);
}

void CppFindReferences::searchFinished()
{
    emit changed();
}

void CppFindReferences::openEditor(const Find::SearchResultItem &item)
{
    TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.searchTermStart);
}

<|endoftext|>