<commit_before>// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp

#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <cstring>
#include <Nazara/Utility/Debug.hpp>

NzVertexDeclaration::NzVertexDeclaration() :
m_stride(0)
{
}

NzVertexDeclaration::NzVertexDeclaration(const NzVertexDeclaration& declaration) :
NzResource(),
m_stride(declaration.m_stride)
{
	std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1));
}

NzVertexDeclaration::~NzVertexDeclaration()
{
	NotifyDestroy();
}

void NzVertexDeclaration::DisableComponent(nzVertexComponent component)
{
	#ifdef NAZARA_DEBUG
	if (component > nzVertexComponent_Max)
	{
		NazaraError("Vertex component out of enum");
		return;
	}
	#endif

	#if NAZARA_UTILITY_SAFE
	if (component == nzVertexComponent_Unused)
	{
		NazaraError("Cannot disable \"unused\" component");
		return;
	}
	#endif

	Component& vertexComponent = m_components[component];
	if (vertexComponent.enabled)
	{
		vertexComponent.enabled = false;
		m_stride -= NzUtility::ComponentStride[vertexComponent.type];
	}
}

void NzVertexDeclaration::EnableComponent(nzVertexComponent component, nzComponentType type, unsigned int offset)
{
	#ifdef NAZARA_DEBUG
	if (component > nzVertexComponent_Max)
	{
		NazaraError("Vertex component out of enum");
		return;
	}
	#endif

	#if NAZARA_UTILITY_SAFE
	if (!IsTypeSupported(type))
	{
		NazaraError("Component type 0x" + NzString::Number(type, 16) + " is not supported by vertex declarations");
		return;
	}
	#endif

	if (component != nzVertexComponent_Unused)
	{
		Component& vertexComponent = m_components[component];
		if (vertexComponent.enabled)
			m_stride -= NzUtility::ComponentStride[vertexComponent.type];
		else
			vertexComponent.enabled = true;

		vertexComponent.offset = offset;
		vertexComponent.type = type;
	}

	m_stride += NzUtility::ComponentStride[type];
}

void NzVertexDeclaration::GetComponent(nzVertexComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const
{
	#ifdef NAZARA_DEBUG
	if (component > nzVertexComponent_Max)
	{
		NazaraError("Vertex component out of enum");
		return;
	}
	#endif

	#if NAZARA_UTILITY_SAFE
	if (component == nzVertexComponent_Unused)
	{
		NazaraError("Cannot get \"unused\" component");
		return;
	}
	#endif

	const Component& vertexComponent = m_components[component];

	if (enabled)
		*enabled = vertexComponent.enabled;

	if (type)
		*type = vertexComponent.type;

	if (offset)
		*offset = vertexComponent.offset;
}

unsigned int NzVertexDeclaration::GetStride() const
{
	return m_stride;
}

void NzVertexDeclaration::SetStride(unsigned int stride)
{
	m_stride = stride;
}

NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration)
{
	std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1));
	m_stride = declaration.m_stride;

	return *this;
}

NzVertexDeclaration* NzVertexDeclaration::Get(nzVertexLayout layout)
{
	#ifdef NAZARA_DEBUG
	if (layout > nzVertexLayout_Max)
	{
		NazaraError("Vertex layout out of enum");
		return nullptr;
	}
	#endif

	return &s_declarations[layout];
}

bool NzVertexDeclaration::IsTypeSupported(nzComponentType type)
{
	switch (type)
	{
		case nzComponentType_Color:
		case nzComponentType_Double1:
		case nzComponentType_Double2:
		case nzComponentType_Double3:
		case nzComponentType_Double4:
		case nzComponentType_Float1:
		case nzComponentType_Float2:
		case nzComponentType_Float3:
		case nzComponentType_Float4:
		case nzComponentType_Int1:
		case nzComponentType_Int2:
		case nzComponentType_Int3:
		case nzComponentType_Int4:
			return true;

		case nzComponentType_Quaternion:
			return false;
	}

	NazaraError("Component type not handled (0x" + NzString::Number(type, 16) + ')');
	return false;
}

bool NzVertexDeclaration::Initialize()
{
	try
	{
		NzErrorFlags flags(nzErrorFlag_Silent | nzErrorFlag_ThrowException);

		// Layout : Type
		NzVertexDeclaration* declaration;

		// nzVertexLayout_XY : NzVertexStruct_XY
		declaration = &s_declarations[nzVertexLayout_XY];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY, position));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY), "Invalid stride for declaration nzVertexLayout_XY");

		// nzVertexLayout_XY_Color : NzVertexStruct_XY_Color
		declaration = &s_declarations[nzVertexLayout_XY_Color];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_Color, position));
		declaration->EnableComponent(nzVertexComponent_Color,    nzComponentType_Color,  NzOffsetOf(NzVertexStruct_XY_Color, color));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_Color), "Invalid stride for declaration nzVertexLayout_XY_Color");

		// nzVertexLayout_XY_UV : NzVertexStruct_XY_UV
		declaration = &s_declarations[nzVertexLayout_XY_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, position));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_UV), "Invalid stride for declaration nzVertexLayout_XY_UV");

		// nzVertexLayout_XYZ : NzVertexStruct_XYZ
		declaration = &s_declarations[nzVertexLayout_XYZ];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ, position));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ");

		// nzVertexLayout_XYZ_Color : NzVertexStruct_XYZ_Color
		declaration = &s_declarations[nzVertexLayout_XYZ_Color_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Color, position));
		declaration->EnableComponent(nzVertexComponent_Color,    nzComponentType_Color,  NzOffsetOf(NzVertexStruct_XYZ_Color, color));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Color), "Invalid stride for declaration nzVertexLayout_XYZ_Color");

		// nzVertexLayout_XYZ_Color_UV : NzVertexStruct_XYZ_Color_UV
		declaration = &s_declarations[nzVertexLayout_XYZ_Color_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, position));
		declaration->EnableComponent(nzVertexComponent_Color,    nzComponentType_Color,  NzOffsetOf(NzVertexStruct_XYZ_Color_UV, color));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Color_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Color_UV");

		// nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position));
		declaration->EnableComponent(nzVertexComponent_Normal,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, normal));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal), "Invalid stride for declaration nzVertexLayout_XYZ_Normal");

		// nzVertexLayout_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal_UV
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, position));
		declaration->EnableComponent(nzVertexComponent_Normal,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, normal));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV");

		// nzVertexLayout_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV_Tangent
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, position));
		declaration->EnableComponent(nzVertexComponent_Normal,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, normal));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, uv));
		declaration->EnableComponent(nzVertexComponent_Tangent,  nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, tangent));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent");

		// nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning];
		declaration->EnableComponent(nzVertexComponent_Position,  nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, position));
		declaration->EnableComponent(nzVertexComponent_Normal,    nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, normal));
		declaration->EnableComponent(nzVertexComponent_TexCoord,  nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, uv));
		declaration->EnableComponent(nzVertexComponent_Tangent,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, tangent));
		declaration->EnableComponent(nzVertexComponent_Unused,    nzComponentType_Int1,   NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weightCount));
		declaration->EnableComponent(nzVertexComponent_Userdata0, nzComponentType_Float4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weights));
		declaration->EnableComponent(nzVertexComponent_Userdata1, nzComponentType_Int4,   NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, jointIndexes));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning");

		// nzVertexLayout_XYZ_UV : NzVertexStruct_XYZ_UV
		declaration = &s_declarations[nzVertexLayout_XYZ_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_UV, position));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_UV), "Invalid stride for declaration nzVertexLayout_XYZ_UV");

		// nzVertexLayout_Matrix4 : NzMatrix4f
		declaration = &s_declarations[nzVertexLayout_Matrix4];
		declaration->EnableComponent(nzVertexComponent_InstanceData0, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m11));
		declaration->EnableComponent(nzVertexComponent_InstanceData1, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m21));
		declaration->EnableComponent(nzVertexComponent_InstanceData2, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m31));
		declaration->EnableComponent(nzVertexComponent_InstanceData3, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m41));

		NazaraAssert(declaration->GetStride() == sizeof(NzMatrix4f), "Invalid stride for declaration nzVertexLayout_Matrix4");
	}
	catch (const std::exception& e)
	{
		NazaraError("Failed to initialize vertex declaration: " + NzString(e.what()));
		return false;
	}

	return true;
}

void NzVertexDeclaration::Uninitialize()
{
	// Rien à faire
}

NzVertexDeclaration NzVertexDeclaration::s_declarations[nzVertexLayout_Max+1];
<commit_msg>Fixed VertexLayout_XYZ_Color_UV declaration<commit_after>// Copyright (C) 2014 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp

#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/OffsetOf.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
#include <cstring>
#include <Nazara/Utility/Debug.hpp>

NzVertexDeclaration::NzVertexDeclaration() :
m_stride(0)
{
}

NzVertexDeclaration::NzVertexDeclaration(const NzVertexDeclaration& declaration) :
NzResource(),
m_stride(declaration.m_stride)
{
	std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1));
}

NzVertexDeclaration::~NzVertexDeclaration()
{
	NotifyDestroy();
}

void NzVertexDeclaration::DisableComponent(nzVertexComponent component)
{
	#ifdef NAZARA_DEBUG
	if (component > nzVertexComponent_Max)
	{
		NazaraError("Vertex component out of enum");
		return;
	}
	#endif

	#if NAZARA_UTILITY_SAFE
	if (component == nzVertexComponent_Unused)
	{
		NazaraError("Cannot disable \"unused\" component");
		return;
	}
	#endif

	Component& vertexComponent = m_components[component];
	if (vertexComponent.enabled)
	{
		vertexComponent.enabled = false;
		m_stride -= NzUtility::ComponentStride[vertexComponent.type];
	}
}

void NzVertexDeclaration::EnableComponent(nzVertexComponent component, nzComponentType type, unsigned int offset)
{
	#ifdef NAZARA_DEBUG
	if (component > nzVertexComponent_Max)
	{
		NazaraError("Vertex component out of enum");
		return;
	}
	#endif

	#if NAZARA_UTILITY_SAFE
	if (!IsTypeSupported(type))
	{
		NazaraError("Component type 0x" + NzString::Number(type, 16) + " is not supported by vertex declarations");
		return;
	}
	#endif

	if (component != nzVertexComponent_Unused)
	{
		Component& vertexComponent = m_components[component];
		if (vertexComponent.enabled)
			m_stride -= NzUtility::ComponentStride[vertexComponent.type];
		else
			vertexComponent.enabled = true;

		vertexComponent.offset = offset;
		vertexComponent.type = type;
	}

	m_stride += NzUtility::ComponentStride[type];
}

void NzVertexDeclaration::GetComponent(nzVertexComponent component, bool* enabled, nzComponentType* type, unsigned int* offset) const
{
	#ifdef NAZARA_DEBUG
	if (component > nzVertexComponent_Max)
	{
		NazaraError("Vertex component out of enum");
		return;
	}
	#endif

	#if NAZARA_UTILITY_SAFE
	if (component == nzVertexComponent_Unused)
	{
		NazaraError("Cannot get \"unused\" component");
		return;
	}
	#endif

	const Component& vertexComponent = m_components[component];

	if (enabled)
		*enabled = vertexComponent.enabled;

	if (type)
		*type = vertexComponent.type;

	if (offset)
		*offset = vertexComponent.offset;
}

unsigned int NzVertexDeclaration::GetStride() const
{
	return m_stride;
}

void NzVertexDeclaration::SetStride(unsigned int stride)
{
	m_stride = stride;
}

NzVertexDeclaration& NzVertexDeclaration::operator=(const NzVertexDeclaration& declaration)
{
	std::memcpy(m_components, declaration.m_components, sizeof(Component)*(nzVertexComponent_Max+1));
	m_stride = declaration.m_stride;

	return *this;
}

NzVertexDeclaration* NzVertexDeclaration::Get(nzVertexLayout layout)
{
	#ifdef NAZARA_DEBUG
	if (layout > nzVertexLayout_Max)
	{
		NazaraError("Vertex layout out of enum");
		return nullptr;
	}
	#endif

	return &s_declarations[layout];
}

bool NzVertexDeclaration::IsTypeSupported(nzComponentType type)
{
	switch (type)
	{
		case nzComponentType_Color:
		case nzComponentType_Double1:
		case nzComponentType_Double2:
		case nzComponentType_Double3:
		case nzComponentType_Double4:
		case nzComponentType_Float1:
		case nzComponentType_Float2:
		case nzComponentType_Float3:
		case nzComponentType_Float4:
		case nzComponentType_Int1:
		case nzComponentType_Int2:
		case nzComponentType_Int3:
		case nzComponentType_Int4:
			return true;

		case nzComponentType_Quaternion:
			return false;
	}

	NazaraError("Component type not handled (0x" + NzString::Number(type, 16) + ')');
	return false;
}

bool NzVertexDeclaration::Initialize()
{
	try
	{
		NzErrorFlags flags(nzErrorFlag_Silent | nzErrorFlag_ThrowException);

		// Layout : Type
		NzVertexDeclaration* declaration;

		// nzVertexLayout_XY : NzVertexStruct_XY
		declaration = &s_declarations[nzVertexLayout_XY];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY, position));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY), "Invalid stride for declaration nzVertexLayout_XY");

		// nzVertexLayout_XY_Color : NzVertexStruct_XY_Color
		declaration = &s_declarations[nzVertexLayout_XY_Color];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_Color, position));
		declaration->EnableComponent(nzVertexComponent_Color,    nzComponentType_Color,  NzOffsetOf(NzVertexStruct_XY_Color, color));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_Color), "Invalid stride for declaration nzVertexLayout_XY_Color");

		// nzVertexLayout_XY_UV : NzVertexStruct_XY_UV
		declaration = &s_declarations[nzVertexLayout_XY_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, position));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XY_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XY_UV), "Invalid stride for declaration nzVertexLayout_XY_UV");

		// nzVertexLayout_XYZ : NzVertexStruct_XYZ
		declaration = &s_declarations[nzVertexLayout_XYZ];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ, position));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ), "Invalid stride for declaration nzVertexLayout_XYZ");

		// nzVertexLayout_XYZ_Color : NzVertexStruct_XYZ_Color
		declaration = &s_declarations[nzVertexLayout_XYZ_Color];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Color, position));
		declaration->EnableComponent(nzVertexComponent_Color,    nzComponentType_Color,  NzOffsetOf(NzVertexStruct_XYZ_Color, color));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Color), "Invalid stride for declaration nzVertexLayout_XYZ_Color");

		// nzVertexLayout_XYZ_Color_UV : NzVertexStruct_XYZ_Color_UV
		declaration = &s_declarations[nzVertexLayout_XYZ_Color_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, position));
		declaration->EnableComponent(nzVertexComponent_Color,    nzComponentType_Color,  NzOffsetOf(NzVertexStruct_XYZ_Color_UV, color));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Color_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Color_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Color_UV");

		// nzVertexLayout_XYZ_Normal : NzVertexStruct_XYZ_Normal
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, position));
		declaration->EnableComponent(nzVertexComponent_Normal,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal, normal));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal), "Invalid stride for declaration nzVertexLayout_XYZ_Normal");

		// nzVertexLayout_XYZ_Normal_UV : NzVertexStruct_XYZ_Normal_UV
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, position));
		declaration->EnableComponent(nzVertexComponent_Normal,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, normal));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV");

		// nzVertexLayout_XYZ_Normal_UV_Tangent : NzVertexStruct_XYZ_Normal_UV_Tangent
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, position));
		declaration->EnableComponent(nzVertexComponent_Normal,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, normal));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, uv));
		declaration->EnableComponent(nzVertexComponent_Tangent,  nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent, tangent));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent");

		// nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning : NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning
		declaration = &s_declarations[nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning];
		declaration->EnableComponent(nzVertexComponent_Position,  nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, position));
		declaration->EnableComponent(nzVertexComponent_Normal,    nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, normal));
		declaration->EnableComponent(nzVertexComponent_TexCoord,  nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, uv));
		declaration->EnableComponent(nzVertexComponent_Tangent,   nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, tangent));
		declaration->EnableComponent(nzVertexComponent_Unused,    nzComponentType_Int1,   NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weightCount));
		declaration->EnableComponent(nzVertexComponent_Userdata0, nzComponentType_Float4, NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, weights));
		declaration->EnableComponent(nzVertexComponent_Userdata1, nzComponentType_Int4,   NzOffsetOf(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning, jointIndexes));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_Normal_UV_Tangent_Skinning), "Invalid stride for declaration nzVertexLayout_XYZ_Normal_UV_Tangent_Skinning");

		// nzVertexLayout_XYZ_UV : NzVertexStruct_XYZ_UV
		declaration = &s_declarations[nzVertexLayout_XYZ_UV];
		declaration->EnableComponent(nzVertexComponent_Position, nzComponentType_Float3, NzOffsetOf(NzVertexStruct_XYZ_UV, position));
		declaration->EnableComponent(nzVertexComponent_TexCoord, nzComponentType_Float2, NzOffsetOf(NzVertexStruct_XYZ_UV, uv));

		NazaraAssert(declaration->GetStride() == sizeof(NzVertexStruct_XYZ_UV), "Invalid stride for declaration nzVertexLayout_XYZ_UV");

		// nzVertexLayout_Matrix4 : NzMatrix4f
		declaration = &s_declarations[nzVertexLayout_Matrix4];
		declaration->EnableComponent(nzVertexComponent_InstanceData0, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m11));
		declaration->EnableComponent(nzVertexComponent_InstanceData1, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m21));
		declaration->EnableComponent(nzVertexComponent_InstanceData2, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m31));
		declaration->EnableComponent(nzVertexComponent_InstanceData3, nzComponentType_Float4, NzOffsetOf(NzMatrix4f, m41));

		NazaraAssert(declaration->GetStride() == sizeof(NzMatrix4f), "Invalid stride for declaration nzVertexLayout_Matrix4");
	}
	catch (const std::exception& e)
	{
		NazaraError("Failed to initialize vertex declaration: " + NzString(e.what()));
		return false;
	}

	return true;
}

void NzVertexDeclaration::Uninitialize()
{
	// Rien à faire
}

NzVertexDeclaration NzVertexDeclaration::s_declarations[nzVertexLayout_Max+1];
<|endoftext|>


<commit_before>// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <fcntl.h>

#include <iostream>
#include <set>
#include <string>

#include "dart/runtime/include/dart_api.h"
#include "lib/ftl/arraysize.h"
#include "lib/ftl/command_line.h"
#include "lib/ftl/files/directory.h"
#include "lib/ftl/files/eintr_wrapper.h"
#include "lib/ftl/files/file_descriptor.h"
#include "lib/ftl/files/file.h"
#include "lib/ftl/files/symlink.h"
#include "lib/ftl/files/unique_fd.h"
#include "lib/ftl/logging.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/file_loader/file_loader.h"

extern "C" {
extern const uint8_t kDartVmIsolateSnapshotBuffer[];
extern const uint8_t kDartIsolateSnapshotBuffer[];
}

namespace {

using tonic::ToDart;

constexpr char kHelp[] = "help";
constexpr char kPackages[] = "packages";
constexpr char kSnapshot[] = "snapshot";
constexpr char kDepfile[] = "depfile";
constexpr char kBuildOutput[] = "build-output";

const char* kDartArgs[] = {
    // clang-format off
    "--enable_mirrors=false",
    "--load_deferred_eagerly=true",
    "--conditional_directives",
    // TODO(chinmaygarde): The experimental interpreter for iOS device targets
    // does not support all these flags. The build process uses its own version
    // of this snapshotter. Till support for all these flags is added, make
    // sure the snapshotter does not error out on unrecognized flags.
    "--ignore-unrecognized-flags",
    // clang-format on
};

void Usage() {
  std::cerr
      << "Usage: sky_snapshot --" << kPackages << "=PACKAGES" << std::endl
      << "                  [ --" << kSnapshot << "=OUTPUT_SNAPSHOT ]"
      << std::endl
      << "                  [ --" << kDepfile << "=DEPFILE ]" << std::endl
      << "                  [ --" << kBuildOutput << "=BUILD_OUTPUT ]"
      << std::endl
      << std::endl
      << "                        MAIN_DART" << std::endl
      << " * PACKAGES is the '.packages' file that defines where to find Dart "
         "packages."
      << std::endl
      << " * OUTPUT_SNAPSHOT is the file to write the snapshot into."
      << std::endl
      << " * DEPFILE is the file into which to write the '.d' depedendency "
         "information into."
      << std::endl
      << " * BUILD_OUTPUT determines the target name used in the " << std::endl
      << "   DEPFILE. (Required if DEPFILE is provided.) " << std::endl;
}

class DartScope {
 public:
  DartScope(Dart_Isolate isolate) {
    Dart_EnterIsolate(isolate);
    Dart_EnterScope();
  }

  ~DartScope() {
    Dart_ExitScope();
    Dart_ExitIsolate();
  }
};

void InitDartVM() {
  FTL_CHECK(Dart_SetVMFlags(arraysize(kDartArgs), kDartArgs));
  char* error = Dart_Initialize(
      kDartVmIsolateSnapshotBuffer, nullptr, nullptr, nullptr, nullptr, nullptr,
      nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
  if (error)
    FTL_LOG(FATAL) << error;
}

Dart_Isolate CreateDartIsolate() {
  FTL_CHECK(kDartIsolateSnapshotBuffer);
  char* error = nullptr;
  Dart_Isolate isolate =
      Dart_CreateIsolate("dart:snapshot", "main", kDartIsolateSnapshotBuffer,
                         nullptr, nullptr, &error);
  FTL_CHECK(isolate) << error;
  Dart_ExitIsolate();
  return isolate;
}

tonic::FileLoader* g_loader = nullptr;

tonic::FileLoader& GetLoader() {
  if (!g_loader)
    g_loader = new tonic::FileLoader();
  return *g_loader;
}

Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
                             Dart_Handle library,
                             Dart_Handle url) {
  FTL_CHECK(Dart_IsLibrary(library));
  FTL_CHECK(Dart_IsString(url));
  tonic::FileLoader& loader = GetLoader();
  if (tag == Dart_kCanonicalizeUrl)
    return loader.CanonicalizeURL(library, url);
  if (tag == Dart_kImportTag)
    return loader.Import(url);
  if (tag == Dart_kSourceTag)
    return loader.Source(library, url);
  return Dart_NewApiError("Unknown library tag.");
}

std::vector<char> CreateSnapshot() {
  uint8_t* buffer = nullptr;
  intptr_t size = 0;
  DART_CHECK_VALID(Dart_CreateScriptSnapshot(&buffer, &size));
  const char* begin = reinterpret_cast<const char*>(buffer);
  return std::vector<char>(begin, begin + size);
}

bool WriteDepfile(const std::string& path,
                  const std::string& build_output,
                  const std::set<std::string>& deps) {
  std::string current_directory = files::GetCurrentDirectory();
  std::string output = build_output + ":";
  for (const auto& dep : deps) {
    std::string file = dep;
    FTL_DCHECK(!file.empty());
    if (file[0] != '/')
      file = current_directory + "/" + file;

    std::string resolved_file;
    if (files::ReadSymbolicLink(file, &resolved_file)) {
      output += " " + resolved_file;
    } else {
      output += " " + file;
    }
  }
  return files::WriteFile(path, output.data(), output.size());
}

int CreateSnapshot(const ftl::CommandLine& command_line) {
  if (command_line.HasOption(kHelp, nullptr)) {
    Usage();
    return 0;
  }

  if (command_line.positional_args().empty()) {
    Usage();
    return 1;
  }

  std::string packages;
  if (!command_line.GetOptionValue(kPackages, &packages)) {
    std::cerr << "error: Need --" << kPackages << std::endl;
    return 1;
  }

  std::vector<std::string> args = command_line.positional_args();
  if (args.size() != 1) {
    std::cerr << "error: Need one position argument. Got " << args.size() << "."
              << std::endl;
    return 1;
  }

  std::string main_dart = args[0];

  std::string snapshot;
  if (!command_line.GetOptionValue(kSnapshot, &snapshot)) {
    std::cerr << "error: Need --" << kSnapshot << "." << std::endl;
    return 1;
  }

  std::string depfile;
  std::string build_output;
  if (command_line.GetOptionValue(kDepfile, &depfile) &&
      !command_line.GetOptionValue(kBuildOutput, &build_output)) {
    std::cerr << "error: Need --" << kBuildOutput << " if --" << kDepfile
              << " is specified." << std::endl;
    return 1;
  }

  InitDartVM();

  tonic::FileLoader& loader = GetLoader();
  if (!loader.LoadPackagesMap(packages))
    return 1;

  Dart_Isolate isolate = CreateDartIsolate();
  FTL_CHECK(isolate) << "Failed to create isolate.";

  DartScope scope(isolate);

  DART_CHECK_VALID(Dart_SetLibraryTagHandler(HandleLibraryTag));
  DART_CHECK_VALID(Dart_LoadScript(ToDart(main_dart), Dart_Null(),
                                   ToDart(loader.Fetch(main_dart)), 0, 0));

  std::vector<char> snapshot_blob = CreateSnapshot();

  if (!snapshot.empty() &&
      !files::WriteFile(snapshot, snapshot_blob.data(), snapshot_blob.size())) {
    std::cerr << "error: Failed to write snapshot to '" << snapshot << "'."
              << std::endl;
    return 1;
  }

  if (!depfile.empty() &&
      !WriteDepfile(depfile, build_output, loader.dependencies())) {
    std::cerr << "error: Failed to write depfile to '" << depfile << "'."
              << std::endl;
    return 1;
  }

  return 0;
}

}  // namespace

int main(int argc, const char* argv[]) {
  return CreateSnapshot(ftl::CommandLineFromArgcArgv(argc, argv));
}
<commit_msg>Attempt to fix build<commit_after>// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <fcntl.h>

#include <iostream>
#include <set>
#include <string>

#include "dart/runtime/include/dart_api.h"
#include "lib/ftl/arraysize.h"
#include "lib/ftl/command_line.h"
#include "lib/ftl/files/directory.h"
#include "lib/ftl/files/eintr_wrapper.h"
#include "lib/ftl/files/file_descriptor.h"
#include "lib/ftl/files/file.h"
#include "lib/ftl/files/symlink.h"
#include "lib/ftl/files/unique_fd.h"
#include "lib/ftl/logging.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/file_loader/file_loader.h"

extern "C" {
extern const uint8_t kDartVmIsolateSnapshotBuffer[];
extern const uint8_t kDartIsolateSnapshotBuffer[];
}

namespace {

using tonic::ToDart;

constexpr char kHelp[] = "help";
constexpr char kPackages[] = "packages";
constexpr char kSnapshot[] = "snapshot";
constexpr char kDepfile[] = "depfile";
constexpr char kBuildOutput[] = "build-output";

const char* kDartArgs[] = {
    // clang-format off
    "--enable_mirrors=false",
    "--load_deferred_eagerly=true",
    "--conditional_directives",
    // TODO(chinmaygarde): The experimental interpreter for iOS device targets
    // does not support all these flags. The build process uses its own version
    // of this snapshotter. Till support for all these flags is added, make
    // sure the snapshotter does not error out on unrecognized flags.
    "--ignore-unrecognized-flags",
    // clang-format on
};

void Usage() {
  std::cerr
      << "Usage: sky_snapshot --" << kPackages << "=PACKAGES" << std::endl
      << "                  [ --" << kSnapshot << "=OUTPUT_SNAPSHOT ]"
      << std::endl
      << "                  [ --" << kDepfile << "=DEPFILE ]" << std::endl
      << "                  [ --" << kBuildOutput << "=BUILD_OUTPUT ]"
      << std::endl
      << std::endl
      << "                        MAIN_DART" << std::endl
      << " * PACKAGES is the '.packages' file that defines where to find Dart "
         "packages."
      << std::endl
      << " * OUTPUT_SNAPSHOT is the file to write the snapshot into."
      << std::endl
      << " * DEPFILE is the file into which to write the '.d' depedendency "
         "information into."
      << std::endl
      << " * BUILD_OUTPUT determines the target name used in the " << std::endl
      << "   DEPFILE. (Required if DEPFILE is provided.) " << std::endl;
}

class DartScope {
 public:
  DartScope(Dart_Isolate isolate) {
    Dart_EnterIsolate(isolate);
    Dart_EnterScope();
  }

  ~DartScope() {
    Dart_ExitScope();
    Dart_ExitIsolate();
  }
};

void InitDartVM() {
  FTL_CHECK(Dart_SetVMFlags(arraysize(kDartArgs), kDartArgs));
  char* error = Dart_Initialize(
      kDartVmIsolateSnapshotBuffer, nullptr, nullptr, nullptr, nullptr, nullptr,
      nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
  if (error)
    FTL_LOG(FATAL) << error;
}

Dart_Isolate CreateDartIsolate() {
  char* error = nullptr;
  Dart_Isolate isolate =
      Dart_CreateIsolate("dart:snapshot", "main", kDartIsolateSnapshotBuffer,
                         nullptr, nullptr, &error);
  FTL_CHECK(isolate) << error;
  Dart_ExitIsolate();
  return isolate;
}

tonic::FileLoader* g_loader = nullptr;

tonic::FileLoader& GetLoader() {
  if (!g_loader)
    g_loader = new tonic::FileLoader();
  return *g_loader;
}

Dart_Handle HandleLibraryTag(Dart_LibraryTag tag,
                             Dart_Handle library,
                             Dart_Handle url) {
  FTL_CHECK(Dart_IsLibrary(library));
  FTL_CHECK(Dart_IsString(url));
  tonic::FileLoader& loader = GetLoader();
  if (tag == Dart_kCanonicalizeUrl)
    return loader.CanonicalizeURL(library, url);
  if (tag == Dart_kImportTag)
    return loader.Import(url);
  if (tag == Dart_kSourceTag)
    return loader.Source(library, url);
  return Dart_NewApiError("Unknown library tag.");
}

std::vector<char> CreateSnapshot() {
  uint8_t* buffer = nullptr;
  intptr_t size = 0;
  DART_CHECK_VALID(Dart_CreateScriptSnapshot(&buffer, &size));
  const char* begin = reinterpret_cast<const char*>(buffer);
  return std::vector<char>(begin, begin + size);
}

bool WriteDepfile(const std::string& path,
                  const std::string& build_output,
                  const std::set<std::string>& deps) {
  std::string current_directory = files::GetCurrentDirectory();
  std::string output = build_output + ":";
  for (const auto& dep : deps) {
    std::string file = dep;
    FTL_DCHECK(!file.empty());
    if (file[0] != '/')
      file = current_directory + "/" + file;

    std::string resolved_file;
    if (files::ReadSymbolicLink(file, &resolved_file)) {
      output += " " + resolved_file;
    } else {
      output += " " + file;
    }
  }
  return files::WriteFile(path, output.data(), output.size());
}

int CreateSnapshot(const ftl::CommandLine& command_line) {
  if (command_line.HasOption(kHelp, nullptr)) {
    Usage();
    return 0;
  }

  if (command_line.positional_args().empty()) {
    Usage();
    return 1;
  }

  std::string packages;
  if (!command_line.GetOptionValue(kPackages, &packages)) {
    std::cerr << "error: Need --" << kPackages << std::endl;
    return 1;
  }

  std::vector<std::string> args = command_line.positional_args();
  if (args.size() != 1) {
    std::cerr << "error: Need one position argument. Got " << args.size() << "."
              << std::endl;
    return 1;
  }

  std::string main_dart = args[0];

  std::string snapshot;
  if (!command_line.GetOptionValue(kSnapshot, &snapshot)) {
    std::cerr << "error: Need --" << kSnapshot << "." << std::endl;
    return 1;
  }

  std::string depfile;
  std::string build_output;
  if (command_line.GetOptionValue(kDepfile, &depfile) &&
      !command_line.GetOptionValue(kBuildOutput, &build_output)) {
    std::cerr << "error: Need --" << kBuildOutput << " if --" << kDepfile
              << " is specified." << std::endl;
    return 1;
  }

  InitDartVM();

  tonic::FileLoader& loader = GetLoader();
  if (!loader.LoadPackagesMap(packages))
    return 1;

  Dart_Isolate isolate = CreateDartIsolate();
  FTL_CHECK(isolate) << "Failed to create isolate.";

  DartScope scope(isolate);

  DART_CHECK_VALID(Dart_SetLibraryTagHandler(HandleLibraryTag));
  DART_CHECK_VALID(Dart_LoadScript(ToDart(main_dart), Dart_Null(),
                                   ToDart(loader.Fetch(main_dart)), 0, 0));

  std::vector<char> snapshot_blob = CreateSnapshot();

  if (!snapshot.empty() &&
      !files::WriteFile(snapshot, snapshot_blob.data(), snapshot_blob.size())) {
    std::cerr << "error: Failed to write snapshot to '" << snapshot << "'."
              << std::endl;
    return 1;
  }

  if (!depfile.empty() &&
      !WriteDepfile(depfile, build_output, loader.dependencies())) {
    std::cerr << "error: Failed to write depfile to '" << depfile << "'."
              << std::endl;
    return 1;
  }

  return 0;
}

}  // namespace

int main(int argc, const char* argv[]) {
  return CreateSnapshot(ftl::CommandLineFromArgcArgv(argc, argv));
}
<|endoftext|>


<commit_before>//
// RemotePhotoTool - remote camera control software
// Copyright (C) 2008-2014 Michael Fink
//
/// \file ImageFileManager.hpp Image file manager
//
#pragma once

// includes
#include "AppSettings.hpp"

/// image file manager image type
enum T_enImageType
{
   imageTypeNormal = 0, ///< normal image
   imageTypeHDR = 1,    ///< image of a HDR bracketing series
   imageTypePano = 2,   ///< image of a panorama take
   imageTypeHDRPano = 3,   ///< image of a HDR panorama bracketing series
   imageTypeTimelapse = 4,    ///< image of a timelapse series
   imageTypePhotostack = 5,   ///< image of a photostack series
};

/// image file manager
class ImageFileManager
{
public:
   /// ctor
   ImageFileManager(AppSettings& settings);

   /// returns next filename for given image type
   CString NextFilename(T_enImageType enImageType, bool bStartNewSeries = false);

private:
   /// adds current date to path
   void AddCurrentDate(CString& cszPath);

   /// adds image type path
   void AddImageTypePath(CString& cszPath, T_enImageType enImageType, bool bStartNewSeries);

   /// formats numbered image path
   void FormatNumberedImagePath(const CString& cszPath, CString& cszSubfolder, bool bStartNewSeries);

   /// finds last used filename image index
   void FindLastUsedFilename();

private:
   /// app settings (copy)
   AppSettings m_settings;

   /// next image index
   unsigned int m_uiNextImageIndex;
};
<commit_msg>using T_enImageType from Logic project<commit_after>//
// RemotePhotoTool - remote camera control software
// Copyright (C) 2008-2016 Michael Fink
//
/// \file ImageFileManager.hpp Image file manager
//
#pragma once

// includes
#include "AppSettings.hpp"
#include "ImageType.hpp"

/// image file manager
class ImageFileManager
{
public:
   /// ctor
   ImageFileManager(AppSettings& settings);

   /// returns next filename for given image type
   CString NextFilename(T_enImageType enImageType, bool bStartNewSeries = false);

private:
   /// adds current date to path
   void AddCurrentDate(CString& cszPath);

   /// adds image type path
   void AddImageTypePath(CString& cszPath, T_enImageType enImageType, bool bStartNewSeries);

   /// formats numbered image path
   void FormatNumberedImagePath(const CString& cszPath, CString& cszSubfolder, bool bStartNewSeries);

   /// finds last used filename image index
   void FindLastUsedFilename();

private:
   /// app settings (copy)
   AppSettings m_settings;

   /// next image index
   unsigned int m_uiNextImageIndex;
};
<|endoftext|>


<commit_before>#ifndef GENERIC_INTEGER_SEQUENCE_HPP
# define GENERIC_INTEGER_SEQUENCE_HPP
# pragma once

#include <cstddef>

namespace generic
{

template <typename T, T ...Is>
struct integer_sequence
{
  static_assert(::std::is_integral<T>{} &&
    !::std::is_same<typename ::std::decay<T>::type, bool>{},
    "T must be integral and not bool");

  static constexpr ::std::size_t size() noexcept { return sizeof...(Is); }
};

template <::std::size_t ...Is>
using index_sequence = integer_sequence<::std::size_t, Is...>;

namespace detail
{

template<typename, typename, typename> struct catenate_indices;

template <typename T, T ...Is, T ...Js>
struct catenate_indices<T, integer_sequence<T, Is...>, integer_sequence<T, Js...> >
{
  using type = integer_sequence<T, Is..., Js...>;
};

template <typename T, T, T, typename = void>
struct expand_indices;

template <typename T, T A, T B>
struct expand_indices<T, A, B, typename ::std::enable_if<A == B>::type>
{
  using type = integer_sequence<T, A>;
};

template <typename T, T A, T B>
struct expand_indices<T, A, B, typename ::std::enable_if<A != B>::type>
{
  static_assert(A < B, "A > B");
  using type = typename catenate_indices<T,
    typename expand_indices<T, A, (A + B) / 2>::type,
    typename expand_indices<T, (A + B) / 2 + 1, B>::type
  >::type;
};

}

template <std::size_t ...Is>
using index_sequence = integer_sequence<::std::size_t, Is...>;

template <typename T, T N>
struct make_integer_sequence :
  ::std::conditional<bool(N),
    detail::expand_indices<T, 0, N - 1>,
    integer_sequence<T>
  >
{
};

template <::std::size_t N>
using make_index_sequence = make_integer_sequence<::std::size_t, N>;

template <typename ...T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;

template <typename T, T A, T B>
struct make_integer_range : detail::expand_indices<T, A, B - 1>::type {};

template <typename T, T A>
struct make_integer_range<T, A, A> : integer_sequence<T> {};

template <::std::size_t A, ::std::size_t B>
using make_index_range = make_integer_range<::std::size_t, A, B>;

}

#endif // GENERIC_INTEGER_SEQUENCE_HPP
<commit_msg>some fixes<commit_after>#ifndef GENERIC_INTEGER_SEQUENCE_HPP
# define GENERIC_INTEGER_SEQUENCE_HPP
# pragma once

#include <cstddef>

namespace generic
{

template <typename T, T ...Is>
struct integer_sequence
{
  static_assert(::std::is_integral<T>{} &&
    !::std::is_same<typename ::std::decay<T>::type, bool>{},
    "T must be integral and not bool");

  static constexpr ::std::size_t size() noexcept { return sizeof...(Is); }
};

template <::std::size_t ...Is>
using index_sequence = integer_sequence<::std::size_t, Is...>;

namespace detail
{

template<typename, typename, typename> struct catenate_indices;

template <typename T, T ...Is, T ...Js>
struct catenate_indices<T, integer_sequence<T, Is...>, integer_sequence<T, Js...> >
{
  using type = integer_sequence<T, Is..., Js...>;
};

template <typename T, T, T, typename = void>
struct expand_indices;

template <typename T, T A, T B>
struct expand_indices<T, A, B, typename ::std::enable_if<A == B>::type>
{
  using type = integer_sequence<T, A>;
};

template <typename T, T A, T B>
struct expand_indices<T, A, B, typename ::std::enable_if<A != B>::type>
{
  static_assert(A < B, "A > B");
  using type = typename catenate_indices<T,
    typename expand_indices<T, A, (A + B) / 2>::type,
    typename expand_indices<T, (A + B) / 2 + 1, B>::type
  >::type;
};

}

template <std::size_t ...Is>
using index_sequence = integer_sequence<::std::size_t, Is...>;

template <typename T, T N>
struct make_integer_sequence :
  ::std::conditional<bool(N),
    detail::expand_indices<T, 0, N - 1>,
    integer_sequence<T>
  >
{
};

template <::std::size_t N>
using make_index_sequence = make_integer_sequence<::std::size_t, N>;

template <typename ...T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;

template <typename T, T A, T B>
struct make_integer_range : detail::expand_indices<T, A, B - 1>::type {};

template <typename T, T A>
struct make_integer_range<T, A, A> : integer_sequence<T> {};

template <::std::size_t A, ::std::size_t B>
using make_index_range = make_integer_range<decltype(A), A, B>;

}

#endif // GENERIC_INTEGER_SEQUENCE_HPP
<|endoftext|>


<commit_before>/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "oat.h"
#include "utils.h"

#include <zlib.h>

namespace art {

const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' };
const uint8_t OatHeader::kOatVersion[] = { '0', '1', '0', '\0' };

OatHeader::OatHeader() {
  memset(this, 0, sizeof(*this));
}

OatHeader::OatHeader(InstructionSet instruction_set,
                     const InstructionSetFeatures& instruction_set_features,
                     const std::vector<const DexFile*>* dex_files,
                     uint32_t image_file_location_oat_checksum,
                     uint32_t image_file_location_oat_data_begin,
                     const std::string& image_file_location) {
  memcpy(magic_, kOatMagic, sizeof(kOatMagic));
  memcpy(version_, kOatVersion, sizeof(kOatVersion));

  adler32_checksum_ = adler32(0L, Z_NULL, 0);

  CHECK_NE(instruction_set, kNone);
  instruction_set_ = instruction_set;
  UpdateChecksum(&instruction_set_, sizeof(instruction_set_));

  instruction_set_features_ = instruction_set_features;
  UpdateChecksum(&instruction_set_features_, sizeof(instruction_set_features_));

  dex_file_count_ = dex_files->size();
  UpdateChecksum(&dex_file_count_, sizeof(dex_file_count_));

  image_file_location_oat_checksum_ = image_file_location_oat_checksum;
  UpdateChecksum(&image_file_location_oat_checksum_, sizeof(image_file_location_oat_checksum_));

  CHECK(IsAligned<kPageSize>(image_file_location_oat_data_begin));
  image_file_location_oat_data_begin_ = image_file_location_oat_data_begin;
  UpdateChecksum(&image_file_location_oat_data_begin_, sizeof(image_file_location_oat_data_begin_));

  image_file_location_size_ = image_file_location.size();
  UpdateChecksum(&image_file_location_size_, sizeof(image_file_location_size_));
  UpdateChecksum(image_file_location.data(), image_file_location_size_);

  executable_offset_ = 0;
  interpreter_to_interpreter_bridge_offset_ = 0;
  interpreter_to_compiled_code_bridge_offset_ = 0;
  jni_dlsym_lookup_offset_ = 0;
  portable_imt_conflict_trampoline_offset_ = 0;
  portable_resolution_trampoline_offset_ = 0;
  portable_to_interpreter_bridge_offset_ = 0;
  quick_imt_conflict_trampoline_offset_ = 0;
  quick_resolution_trampoline_offset_ = 0;
  quick_to_interpreter_bridge_offset_ = 0;
}

bool OatHeader::IsValid() const {
  if (memcmp(magic_, kOatMagic, sizeof(kOatMagic)) != 0) {
    return false;
  }
  if (memcmp(version_, kOatVersion, sizeof(kOatVersion)) != 0) {
    return false;
  }
  return true;
}

const char* OatHeader::GetMagic() const {
  CHECK(IsValid());
  return reinterpret_cast<const char*>(magic_);
}

uint32_t OatHeader::GetChecksum() const {
  CHECK(IsValid());
  return adler32_checksum_;
}

void OatHeader::UpdateChecksum(const void* data, size_t length) {
  DCHECK(IsValid());
  const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
  adler32_checksum_ = adler32(adler32_checksum_, bytes, length);
}

InstructionSet OatHeader::GetInstructionSet() const {
  CHECK(IsValid());
  return instruction_set_;
}

const InstructionSetFeatures& OatHeader::GetInstructionSetFeatures() const {
  CHECK(IsValid());
  return instruction_set_features_;
}

uint32_t OatHeader::GetExecutableOffset() const {
  DCHECK(IsValid());
  DCHECK_ALIGNED(executable_offset_, kPageSize);
  CHECK_GT(executable_offset_, sizeof(OatHeader));
  return executable_offset_;
}

void OatHeader::SetExecutableOffset(uint32_t executable_offset) {
  DCHECK_ALIGNED(executable_offset, kPageSize);
  CHECK_GT(executable_offset, sizeof(OatHeader));
  DCHECK(IsValid());
  DCHECK_EQ(executable_offset_, 0U);

  executable_offset_ = executable_offset;
  UpdateChecksum(&executable_offset_, sizeof(executable_offset));
}

const void* OatHeader::GetInterpreterToInterpreterBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetInterpreterToInterpreterBridgeOffset();
}

uint32_t OatHeader::GetInterpreterToInterpreterBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(interpreter_to_interpreter_bridge_offset_, executable_offset_);
  return interpreter_to_interpreter_bridge_offset_;
}

void OatHeader::SetInterpreterToInterpreterBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= executable_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(interpreter_to_interpreter_bridge_offset_, 0U) << offset;

  interpreter_to_interpreter_bridge_offset_ = offset;
  UpdateChecksum(&interpreter_to_interpreter_bridge_offset_, sizeof(offset));
}

const void* OatHeader::GetInterpreterToCompiledCodeBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetInterpreterToCompiledCodeBridgeOffset();
}

uint32_t OatHeader::GetInterpreterToCompiledCodeBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(interpreter_to_compiled_code_bridge_offset_, interpreter_to_interpreter_bridge_offset_);
  return interpreter_to_compiled_code_bridge_offset_;
}

void OatHeader::SetInterpreterToCompiledCodeBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= interpreter_to_interpreter_bridge_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(interpreter_to_compiled_code_bridge_offset_, 0U) << offset;

  interpreter_to_compiled_code_bridge_offset_ = offset;
  UpdateChecksum(&interpreter_to_compiled_code_bridge_offset_, sizeof(offset));
}

const void* OatHeader::GetJniDlsymLookup() const {
  return reinterpret_cast<const uint8_t*>(this) + GetJniDlsymLookupOffset();
}

uint32_t OatHeader::GetJniDlsymLookupOffset() const {
  DCHECK(IsValid());
  CHECK_GE(jni_dlsym_lookup_offset_, interpreter_to_compiled_code_bridge_offset_);
  return jni_dlsym_lookup_offset_;
}

void OatHeader::SetJniDlsymLookupOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= interpreter_to_compiled_code_bridge_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(jni_dlsym_lookup_offset_, 0U) << offset;

  jni_dlsym_lookup_offset_ = offset;
  UpdateChecksum(&jni_dlsym_lookup_offset_, sizeof(offset));
}

const void* OatHeader::GetPortableImtConflictTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetPortableImtConflictTrampolineOffset();
}

uint32_t OatHeader::GetPortableImtConflictTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(portable_imt_conflict_trampoline_offset_, jni_dlsym_lookup_offset_);
  return portable_imt_conflict_trampoline_offset_;
}

void OatHeader::SetPortableImtConflictTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= jni_dlsym_lookup_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(portable_imt_conflict_trampoline_offset_, 0U) << offset;

  portable_imt_conflict_trampoline_offset_ = offset;
  UpdateChecksum(&portable_imt_conflict_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetPortableResolutionTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetPortableResolutionTrampolineOffset();
}

uint32_t OatHeader::GetPortableResolutionTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(portable_resolution_trampoline_offset_, portable_imt_conflict_trampoline_offset_);
  return portable_resolution_trampoline_offset_;
}

void OatHeader::SetPortableResolutionTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= portable_imt_conflict_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(portable_resolution_trampoline_offset_, 0U) << offset;

  portable_resolution_trampoline_offset_ = offset;
  UpdateChecksum(&portable_resolution_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetPortableToInterpreterBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetPortableToInterpreterBridgeOffset();
}

uint32_t OatHeader::GetPortableToInterpreterBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(portable_to_interpreter_bridge_offset_, portable_resolution_trampoline_offset_);
  return portable_to_interpreter_bridge_offset_;
}

void OatHeader::SetPortableToInterpreterBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= portable_resolution_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(portable_to_interpreter_bridge_offset_, 0U) << offset;

  portable_to_interpreter_bridge_offset_ = offset;
  UpdateChecksum(&portable_to_interpreter_bridge_offset_, sizeof(offset));
}

const void* OatHeader::GetQuickImtConflictTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetQuickImtConflictTrampolineOffset();
}

uint32_t OatHeader::GetQuickImtConflictTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(quick_imt_conflict_trampoline_offset_, portable_to_interpreter_bridge_offset_);
  return quick_imt_conflict_trampoline_offset_;
}

void OatHeader::SetQuickImtConflictTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= portable_to_interpreter_bridge_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(quick_imt_conflict_trampoline_offset_, 0U) << offset;

  quick_imt_conflict_trampoline_offset_ = offset;
  UpdateChecksum(&quick_imt_conflict_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetQuickResolutionTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetQuickResolutionTrampolineOffset();
}

uint32_t OatHeader::GetQuickResolutionTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(quick_resolution_trampoline_offset_, quick_imt_conflict_trampoline_offset_);
  return quick_resolution_trampoline_offset_;
}

void OatHeader::SetQuickResolutionTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= quick_imt_conflict_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(quick_resolution_trampoline_offset_, 0U) << offset;

  quick_resolution_trampoline_offset_ = offset;
  UpdateChecksum(&quick_resolution_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetQuickToInterpreterBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetQuickToInterpreterBridgeOffset();
}

uint32_t OatHeader::GetQuickToInterpreterBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(quick_to_interpreter_bridge_offset_, quick_resolution_trampoline_offset_);
  return quick_to_interpreter_bridge_offset_;
}

void OatHeader::SetQuickToInterpreterBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= quick_resolution_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(quick_to_interpreter_bridge_offset_, 0U) << offset;

  quick_to_interpreter_bridge_offset_ = offset;
  UpdateChecksum(&quick_to_interpreter_bridge_offset_, sizeof(offset));
}

uint32_t OatHeader::GetImageFileLocationOatChecksum() const {
  CHECK(IsValid());
  return image_file_location_oat_checksum_;
}

uint32_t OatHeader::GetImageFileLocationOatDataBegin() const {
  CHECK(IsValid());
  return image_file_location_oat_data_begin_;
}

uint32_t OatHeader::GetImageFileLocationSize() const {
  CHECK(IsValid());
  return image_file_location_size_;
}

const uint8_t* OatHeader::GetImageFileLocationData() const {
  CHECK(IsValid());
  return image_file_location_data_;
}

std::string OatHeader::GetImageFileLocation() const {
  CHECK(IsValid());
  return std::string(reinterpret_cast<const char*>(GetImageFileLocationData()),
                     GetImageFileLocationSize());
}

OatMethodOffsets::OatMethodOffsets()
  : code_offset_(0),
    frame_size_in_bytes_(0),
    core_spill_mask_(0),
    fp_spill_mask_(0),
    mapping_table_offset_(0),
    vmap_table_offset_(0),
    gc_map_offset_(0)
{}

OatMethodOffsets::OatMethodOffsets(uint32_t code_offset,
                                   uint32_t frame_size_in_bytes,
                                   uint32_t core_spill_mask,
                                   uint32_t fp_spill_mask,
                                   uint32_t mapping_table_offset,
                                   uint32_t vmap_table_offset,
                                   uint32_t gc_map_offset
                                   )
  : code_offset_(code_offset),
    frame_size_in_bytes_(frame_size_in_bytes),
    core_spill_mask_(core_spill_mask),
    fp_spill_mask_(fp_spill_mask),
    mapping_table_offset_(mapping_table_offset),
    vmap_table_offset_(vmap_table_offset),
    gc_map_offset_(gc_map_offset)
{}

OatMethodOffsets::~OatMethodOffsets() {}

}  // namespace art
<commit_msg>am 03fc1e06: am 3a13ba4a: am 5da37787: Turn up oat version to 11<commit_after>/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "oat.h"
#include "utils.h"

#include <zlib.h>

namespace art {

const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' };
const uint8_t OatHeader::kOatVersion[] = { '0', '1', '1', '\0' };

OatHeader::OatHeader() {
  memset(this, 0, sizeof(*this));
}

OatHeader::OatHeader(InstructionSet instruction_set,
                     const InstructionSetFeatures& instruction_set_features,
                     const std::vector<const DexFile*>* dex_files,
                     uint32_t image_file_location_oat_checksum,
                     uint32_t image_file_location_oat_data_begin,
                     const std::string& image_file_location) {
  memcpy(magic_, kOatMagic, sizeof(kOatMagic));
  memcpy(version_, kOatVersion, sizeof(kOatVersion));

  adler32_checksum_ = adler32(0L, Z_NULL, 0);

  CHECK_NE(instruction_set, kNone);
  instruction_set_ = instruction_set;
  UpdateChecksum(&instruction_set_, sizeof(instruction_set_));

  instruction_set_features_ = instruction_set_features;
  UpdateChecksum(&instruction_set_features_, sizeof(instruction_set_features_));

  dex_file_count_ = dex_files->size();
  UpdateChecksum(&dex_file_count_, sizeof(dex_file_count_));

  image_file_location_oat_checksum_ = image_file_location_oat_checksum;
  UpdateChecksum(&image_file_location_oat_checksum_, sizeof(image_file_location_oat_checksum_));

  CHECK(IsAligned<kPageSize>(image_file_location_oat_data_begin));
  image_file_location_oat_data_begin_ = image_file_location_oat_data_begin;
  UpdateChecksum(&image_file_location_oat_data_begin_, sizeof(image_file_location_oat_data_begin_));

  image_file_location_size_ = image_file_location.size();
  UpdateChecksum(&image_file_location_size_, sizeof(image_file_location_size_));
  UpdateChecksum(image_file_location.data(), image_file_location_size_);

  executable_offset_ = 0;
  interpreter_to_interpreter_bridge_offset_ = 0;
  interpreter_to_compiled_code_bridge_offset_ = 0;
  jni_dlsym_lookup_offset_ = 0;
  portable_imt_conflict_trampoline_offset_ = 0;
  portable_resolution_trampoline_offset_ = 0;
  portable_to_interpreter_bridge_offset_ = 0;
  quick_imt_conflict_trampoline_offset_ = 0;
  quick_resolution_trampoline_offset_ = 0;
  quick_to_interpreter_bridge_offset_ = 0;
}

bool OatHeader::IsValid() const {
  if (memcmp(magic_, kOatMagic, sizeof(kOatMagic)) != 0) {
    return false;
  }
  if (memcmp(version_, kOatVersion, sizeof(kOatVersion)) != 0) {
    return false;
  }
  return true;
}

const char* OatHeader::GetMagic() const {
  CHECK(IsValid());
  return reinterpret_cast<const char*>(magic_);
}

uint32_t OatHeader::GetChecksum() const {
  CHECK(IsValid());
  return adler32_checksum_;
}

void OatHeader::UpdateChecksum(const void* data, size_t length) {
  DCHECK(IsValid());
  const uint8_t* bytes = reinterpret_cast<const uint8_t*>(data);
  adler32_checksum_ = adler32(adler32_checksum_, bytes, length);
}

InstructionSet OatHeader::GetInstructionSet() const {
  CHECK(IsValid());
  return instruction_set_;
}

const InstructionSetFeatures& OatHeader::GetInstructionSetFeatures() const {
  CHECK(IsValid());
  return instruction_set_features_;
}

uint32_t OatHeader::GetExecutableOffset() const {
  DCHECK(IsValid());
  DCHECK_ALIGNED(executable_offset_, kPageSize);
  CHECK_GT(executable_offset_, sizeof(OatHeader));
  return executable_offset_;
}

void OatHeader::SetExecutableOffset(uint32_t executable_offset) {
  DCHECK_ALIGNED(executable_offset, kPageSize);
  CHECK_GT(executable_offset, sizeof(OatHeader));
  DCHECK(IsValid());
  DCHECK_EQ(executable_offset_, 0U);

  executable_offset_ = executable_offset;
  UpdateChecksum(&executable_offset_, sizeof(executable_offset));
}

const void* OatHeader::GetInterpreterToInterpreterBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetInterpreterToInterpreterBridgeOffset();
}

uint32_t OatHeader::GetInterpreterToInterpreterBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(interpreter_to_interpreter_bridge_offset_, executable_offset_);
  return interpreter_to_interpreter_bridge_offset_;
}

void OatHeader::SetInterpreterToInterpreterBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= executable_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(interpreter_to_interpreter_bridge_offset_, 0U) << offset;

  interpreter_to_interpreter_bridge_offset_ = offset;
  UpdateChecksum(&interpreter_to_interpreter_bridge_offset_, sizeof(offset));
}

const void* OatHeader::GetInterpreterToCompiledCodeBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetInterpreterToCompiledCodeBridgeOffset();
}

uint32_t OatHeader::GetInterpreterToCompiledCodeBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(interpreter_to_compiled_code_bridge_offset_, interpreter_to_interpreter_bridge_offset_);
  return interpreter_to_compiled_code_bridge_offset_;
}

void OatHeader::SetInterpreterToCompiledCodeBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= interpreter_to_interpreter_bridge_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(interpreter_to_compiled_code_bridge_offset_, 0U) << offset;

  interpreter_to_compiled_code_bridge_offset_ = offset;
  UpdateChecksum(&interpreter_to_compiled_code_bridge_offset_, sizeof(offset));
}

const void* OatHeader::GetJniDlsymLookup() const {
  return reinterpret_cast<const uint8_t*>(this) + GetJniDlsymLookupOffset();
}

uint32_t OatHeader::GetJniDlsymLookupOffset() const {
  DCHECK(IsValid());
  CHECK_GE(jni_dlsym_lookup_offset_, interpreter_to_compiled_code_bridge_offset_);
  return jni_dlsym_lookup_offset_;
}

void OatHeader::SetJniDlsymLookupOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= interpreter_to_compiled_code_bridge_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(jni_dlsym_lookup_offset_, 0U) << offset;

  jni_dlsym_lookup_offset_ = offset;
  UpdateChecksum(&jni_dlsym_lookup_offset_, sizeof(offset));
}

const void* OatHeader::GetPortableImtConflictTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetPortableImtConflictTrampolineOffset();
}

uint32_t OatHeader::GetPortableImtConflictTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(portable_imt_conflict_trampoline_offset_, jni_dlsym_lookup_offset_);
  return portable_imt_conflict_trampoline_offset_;
}

void OatHeader::SetPortableImtConflictTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= jni_dlsym_lookup_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(portable_imt_conflict_trampoline_offset_, 0U) << offset;

  portable_imt_conflict_trampoline_offset_ = offset;
  UpdateChecksum(&portable_imt_conflict_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetPortableResolutionTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetPortableResolutionTrampolineOffset();
}

uint32_t OatHeader::GetPortableResolutionTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(portable_resolution_trampoline_offset_, portable_imt_conflict_trampoline_offset_);
  return portable_resolution_trampoline_offset_;
}

void OatHeader::SetPortableResolutionTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= portable_imt_conflict_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(portable_resolution_trampoline_offset_, 0U) << offset;

  portable_resolution_trampoline_offset_ = offset;
  UpdateChecksum(&portable_resolution_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetPortableToInterpreterBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetPortableToInterpreterBridgeOffset();
}

uint32_t OatHeader::GetPortableToInterpreterBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(portable_to_interpreter_bridge_offset_, portable_resolution_trampoline_offset_);
  return portable_to_interpreter_bridge_offset_;
}

void OatHeader::SetPortableToInterpreterBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= portable_resolution_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(portable_to_interpreter_bridge_offset_, 0U) << offset;

  portable_to_interpreter_bridge_offset_ = offset;
  UpdateChecksum(&portable_to_interpreter_bridge_offset_, sizeof(offset));
}

const void* OatHeader::GetQuickImtConflictTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetQuickImtConflictTrampolineOffset();
}

uint32_t OatHeader::GetQuickImtConflictTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(quick_imt_conflict_trampoline_offset_, portable_to_interpreter_bridge_offset_);
  return quick_imt_conflict_trampoline_offset_;
}

void OatHeader::SetQuickImtConflictTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= portable_to_interpreter_bridge_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(quick_imt_conflict_trampoline_offset_, 0U) << offset;

  quick_imt_conflict_trampoline_offset_ = offset;
  UpdateChecksum(&quick_imt_conflict_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetQuickResolutionTrampoline() const {
  return reinterpret_cast<const uint8_t*>(this) + GetQuickResolutionTrampolineOffset();
}

uint32_t OatHeader::GetQuickResolutionTrampolineOffset() const {
  DCHECK(IsValid());
  CHECK_GE(quick_resolution_trampoline_offset_, quick_imt_conflict_trampoline_offset_);
  return quick_resolution_trampoline_offset_;
}

void OatHeader::SetQuickResolutionTrampolineOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= quick_imt_conflict_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(quick_resolution_trampoline_offset_, 0U) << offset;

  quick_resolution_trampoline_offset_ = offset;
  UpdateChecksum(&quick_resolution_trampoline_offset_, sizeof(offset));
}

const void* OatHeader::GetQuickToInterpreterBridge() const {
  return reinterpret_cast<const uint8_t*>(this) + GetQuickToInterpreterBridgeOffset();
}

uint32_t OatHeader::GetQuickToInterpreterBridgeOffset() const {
  DCHECK(IsValid());
  CHECK_GE(quick_to_interpreter_bridge_offset_, quick_resolution_trampoline_offset_);
  return quick_to_interpreter_bridge_offset_;
}

void OatHeader::SetQuickToInterpreterBridgeOffset(uint32_t offset) {
  CHECK(offset == 0 || offset >= quick_resolution_trampoline_offset_);
  DCHECK(IsValid());
  DCHECK_EQ(quick_to_interpreter_bridge_offset_, 0U) << offset;

  quick_to_interpreter_bridge_offset_ = offset;
  UpdateChecksum(&quick_to_interpreter_bridge_offset_, sizeof(offset));
}

uint32_t OatHeader::GetImageFileLocationOatChecksum() const {
  CHECK(IsValid());
  return image_file_location_oat_checksum_;
}

uint32_t OatHeader::GetImageFileLocationOatDataBegin() const {
  CHECK(IsValid());
  return image_file_location_oat_data_begin_;
}

uint32_t OatHeader::GetImageFileLocationSize() const {
  CHECK(IsValid());
  return image_file_location_size_;
}

const uint8_t* OatHeader::GetImageFileLocationData() const {
  CHECK(IsValid());
  return image_file_location_data_;
}

std::string OatHeader::GetImageFileLocation() const {
  CHECK(IsValid());
  return std::string(reinterpret_cast<const char*>(GetImageFileLocationData()),
                     GetImageFileLocationSize());
}

OatMethodOffsets::OatMethodOffsets()
  : code_offset_(0),
    frame_size_in_bytes_(0),
    core_spill_mask_(0),
    fp_spill_mask_(0),
    mapping_table_offset_(0),
    vmap_table_offset_(0),
    gc_map_offset_(0)
{}

OatMethodOffsets::OatMethodOffsets(uint32_t code_offset,
                                   uint32_t frame_size_in_bytes,
                                   uint32_t core_spill_mask,
                                   uint32_t fp_spill_mask,
                                   uint32_t mapping_table_offset,
                                   uint32_t vmap_table_offset,
                                   uint32_t gc_map_offset
                                   )
  : code_offset_(code_offset),
    frame_size_in_bytes_(frame_size_in_bytes),
    core_spill_mask_(core_spill_mask),
    fp_spill_mask_(fp_spill_mask),
    mapping_table_offset_(mapping_table_offset),
    vmap_table_offset_(vmap_table_offset),
    gc_map_offset_(gc_map_offset)
{}

OatMethodOffsets::~OatMethodOffsets() {}

}  // namespace art
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: zforscan.hxx,v $
 *
 *  $Revision: 1.20 $
 *
 *  last change: $Author: rt $ $Date: 2005-10-21 11:46:30 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _ZFORSCAN_HXX
#define _ZFORSCAN_HXX

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _DATE_HXX //autogen
#include <tools/date.hxx>
#endif
#ifndef _LANG_HXX //autogen
#include <tools/lang.hxx>
#endif
#ifndef _TOOLS_COLOR_HXX
#include <tools/color.hxx>
#endif

#ifndef INCLUDED_SVTOOLS_NFKEYTAB_HXX
#include "nfkeytab.hxx"
#endif

class SvNumberFormatter;
struct ImpSvNumberformatInfo;

const size_t NF_MAX_FORMAT_SYMBOLS   = 100;
const size_t NF_MAX_DEFAULT_COLORS   = 10;

// Hack: nThousand==1000 => "Default" occurs in format string
const USHORT FLAG_STANDARD_IN_FORMAT = 1000;

class ImpSvNumberformatScan
{
public:

    ImpSvNumberformatScan( SvNumberFormatter* pFormatter );
    ~ImpSvNumberformatScan();
    void ChangeIntl();                          // tauscht Keywords aus

    void ChangeNullDate(USHORT nDay, USHORT nMonth, USHORT nYear);
                                                // tauscht Referenzdatum aus
    void ChangeStandardPrec(short nPrec);       // tauscht Standardprecision aus

    xub_StrLen ScanFormat( String& rString, String& rComment ); // Aufruf der Scan-Analyse

    void CopyInfo(ImpSvNumberformatInfo* pInfo,
                     USHORT nAnz);              // Kopiert die FormatInfo
    USHORT GetAnzResStrings() const             { return nAnzResStrings; }

    const CharClass& GetChrCls() const          { return *pFormatter->GetCharClass(); }
    const LocaleDataWrapper& GetLoc() const     { return *pFormatter->GetLocaleData(); }
    CalendarWrapper& GetCal() const             { return *pFormatter->GetCalendar(); }

    const String* GetKeywords() const
        {
            if ( bKeywordsNeedInit )
                InitKeywords();
            return sKeyword;
        }
    // Keywords used in output like TRUE and FALSE
    const String& GetSpecialKeyword( NfKeywordIndex eIdx ) const
        {
            if ( !sKeyword[eIdx].Len() )
                InitSpecialKeyword( eIdx );
            return sKeyword[eIdx];
        }
    const String& GetTrueString() const     { return GetSpecialKeyword( NF_KEY_TRUE ); }
    const String& GetFalseString() const    { return GetSpecialKeyword( NF_KEY_FALSE ); }
    const String& GetColorString() const    { return GetKeywords()[NF_KEY_COLOR]; }
    const String& GetRedString() const      { return GetKeywords()[NF_KEY_RED]; }
    const String& GetBooleanString() const  { return GetKeywords()[NF_KEY_BOOLEAN]; }
    const String& GetErrorString() const    { return sErrStr; }

    Date* GetNullDate() const                   { return pNullDate; }
    const String& GetStandardName() const
        {
            if ( bKeywordsNeedInit )
                InitKeywords();
            return sNameStandardFormat;
        }
    short GetStandardPrec() const               { return nStandardPrec; }
    const Color& GetRedColor() const            { return StandardColor[4]; }
    Color* GetColor(String& sStr);          // Setzt Hauptfarben oder
                                                // definierte Farben

    // the compatibility currency symbol for old automatic currency formats
    const String& GetCurSymbol() const
        {
            if ( bCompatCurNeedInit )
                InitCompatCur();
            return sCurSymbol;
        }

    // the compatibility currency abbreviation for CCC format code
    const String& GetCurAbbrev() const
        {
            if ( bCompatCurNeedInit )
                InitCompatCur();
            return sCurAbbrev;
        }

    // the compatibility currency symbol upper case for old automatic currency formats
    const String& GetCurString() const
        {
            if ( bCompatCurNeedInit )
                InitCompatCur();
            return sCurString;
        }

    void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
            BOOL bSystemToSystem = FALSE )
    {
        bConvertMode = TRUE;
        eNewLnge = eNewLge;
        eTmpLnge = eTmpLge;
        bConvertSystemToSystem = bSystemToSystem;
    }
    void SetConvertMode(BOOL bMode) { bConvertMode = bMode; }
                                                // Veraendert nur die Bool-Variable
                                                // (zum temporaeren Unterbrechen des
                                                // Convert-Modus)
    const BOOL GetConvertMode()     { return bConvertMode; }
    const LanguageType GetNewLnge() { return eNewLnge; }
                                                // Lesezugriff auf ConvertMode
                                                // und Konvertierungsland/Spr.
    const LanguageType GetTmpLnge() { return eTmpLnge; }
                                                // Lesezugriff auf
                                                // und Ausgangsland/Spr.

                                                /// get Thai T speciality
    BYTE GetNatNumModifier() const      { return nNatNumModifier; }
                                                /// set Thai T speciality
    void SetNatNumModifier( BYTE n )    { nNatNumModifier = n; }

    SvNumberFormatter* GetNumberformatter() { return pFormatter; }
                                                // Zugriff auf Formatierer
                                                // (fuer zformat.cxx)

private:                            // ---- privater Teil
    NfKeywordTable sKeyword;                    // Schluesselworte der Syntax
    Color StandardColor[NF_MAX_DEFAULT_COLORS];
                                                // Array der Standardfarben
    Date* pNullDate;                            // 30Dec1899
    String sNameStandardFormat;             // "Standard"
    short nStandardPrec;                        // default Precision fuer Standardformat (2)
    SvNumberFormatter* pFormatter;              // Pointer auf die Formatliste

    String sStrArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Symbole
    short nTypeArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Infos
                                                // externe Infos:
    USHORT nAnzResStrings;                      // Anzahl der Ergebnissymbole
#if !(defined SOLARIS && defined X86)
    short eScannedType;                         // Typ gemaess Scan
#else
    int eScannedType;                           // wg. Optimierung
#endif
    BOOL bThousand;                             // Mit Tausenderpunkt
    USHORT nThousand;                           // Zaehlt ....-Folgen
    USHORT nCntPre;                             // Zaehlt Vorkommastellen
    USHORT nCntPost;                            // Zaehlt Nachkommastellen
    USHORT nCntExp;                             // Zaehlt Exp.Stellen, AM/PM
                                                // interne Infos:
    USHORT nAnzStrings;                         // Anzahl der Symbole
    USHORT nRepPos;                             // Position eines '*'
    USHORT nExpPos;                             // interne Position des E
    USHORT nBlankPos;                           // interne Position des Blank
    short nDecPos;                              // interne Pos. des ,
    BOOL bExp;                                  // wird bei Lesen des E gesetzt
    BOOL bFrac;                                 // wird bei Lesen des / gesetzt
    BOOL bBlank;                                // wird bei ' '(Fraction) ges.
    BOOL bDecSep;                               // Wird beim ersten , gesetzt
    mutable BOOL bKeywordsNeedInit;             // Locale dependent keywords need to be initialized
    mutable BOOL bCompatCurNeedInit;            // Locale dependent compatibility currency need to be initialized
    String sCurSymbol;                          // Currency symbol for compatibility format codes
    String sCurString;                          // Currency symbol in upper case
    String sCurAbbrev;                          // Currency abbreviation
    String sErrStr;                             // String fuer Fehlerausgaben

    BOOL bConvertMode;                          // Wird im Convert-Mode gesetzt
                                                // Land/Sprache, in die der
    LanguageType eNewLnge;                      // gescannte String konvertiert
                                                // wird (fuer Excel Filter)
                                                // Land/Sprache, aus der der
    LanguageType eTmpLnge;                      // gescannte String konvertiert
                                                // wird (fuer Excel Filter)
    BOOL bConvertSystemToSystem;                // Whether the conversion is
                                                // from one system locale to
                                                // another system locale (in
                                                // this case the automatic
                                                // currency symbol is converted
                                                // too).

    xub_StrLen nCurrPos;                        // Position des Waehrungssymbols

    BYTE nNatNumModifier;                       // Thai T speciality

    void InitKeywords() const;
    void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
    void InitCompatCur() const;

#ifdef _ZFORSCAN_CXX                // ----- private Methoden -----
    void SetDependentKeywords();
                                                // Setzt die Sprachabh. Keyw.
    void SkipStrings(USHORT& i,xub_StrLen& nPos);// Ueberspringt StringSymbole
    USHORT PreviousKeyword(USHORT i);           // Gibt Index des vorangeh.
                                                // Schluesselworts oder 0
    USHORT NextKeyword(USHORT i);               // Gibt Index des naechsten
                                                // Schluesselworts oder 0
    sal_Unicode PreviousChar(USHORT i);             // Gibt letzten Buchstaben
                                                // vor der Position,
                                                // skipt EMPTY, STRING, STAR, BLANK
    sal_Unicode NextChar(USHORT i);                 // Gibt ersten Buchst. danach
    short PreviousType( USHORT i );             // Gibt Typ vor Position,
                                                // skipt EMPTY
    BOOL IsLastBlankBeforeFrac(USHORT i);       // True <=> es kommt kein ' '
                                                // mehr bis zum '/'
    void Reset();                               // Reset aller Variablen
                                                // vor Analysestart
    short GetKeyWord( const String& sSymbol,    // determine keyword at nPos
        xub_StrLen nPos );                      // return 0 <=> not found

    inline BOOL IsAmbiguousE( short nKey )      // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
        {
            return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
                (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
        }

    // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
    BOOL Is100SecZero( USHORT i, BOOL bHadDecSep );

    short Next_Symbol(const String& rStr,
                        xub_StrLen& nPos,
                      String& sSymbol);       // Naechstes Symbol
    xub_StrLen Symbol_Division(const String& rString);// lexikalische Voranalyse
    xub_StrLen ScanType(const String& rString); // Analyse des Formattyps
    xub_StrLen FinalScan( String& rString, String& rComment );  // Endanalyse mit Vorgabe
                                                // des Typs
    // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
    int FinalScanGetCalendar( xub_StrLen& nPos, USHORT& i, USHORT& nAnzResStrings );

    static inline BOOL StringEqualsChar( const String& rStr, sal_Unicode ch )
        { return rStr.GetChar(0) == ch && rStr.Len() == 1; }
        // Yes, for efficiency get the character first and then compare length
        // because in most places where this is used the string is one char.

    // remove "..." and \... quotes from rStr, return how many chars removed
    static xub_StrLen RemoveQuotes( String& rStr );

#endif //_ZFORSCAN_CXX
};

#endif  // _ZFORSCAN_HXX
<commit_msg>INTEGRATION: CWS internatiodel (1.20.102); FILE MERGED 2006/02/10 19:32:09 er 1.20.102.1: #i52115# move LangIDs and ISO conversion from tools to i18npool; introduce class MsLangId and libi18nisolang<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: zforscan.hxx,v $
 *
 *  $Revision: 1.21 $
 *
 *  last change: $Author: vg $ $Date: 2006-04-07 16:04:05 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _ZFORSCAN_HXX
#define _ZFORSCAN_HXX

#ifndef _STRING_HXX //autogen
#include <tools/string.hxx>
#endif
#ifndef _DATE_HXX //autogen
#include <tools/date.hxx>
#endif
#ifndef INCLUDED_I18NPOOL_LANG_H
#include <i18npool/lang.h>
#endif
#ifndef _TOOLS_COLOR_HXX
#include <tools/color.hxx>
#endif

#ifndef INCLUDED_SVTOOLS_NFKEYTAB_HXX
#include "nfkeytab.hxx"
#endif

class SvNumberFormatter;
struct ImpSvNumberformatInfo;

const size_t NF_MAX_FORMAT_SYMBOLS   = 100;
const size_t NF_MAX_DEFAULT_COLORS   = 10;

// Hack: nThousand==1000 => "Default" occurs in format string
const USHORT FLAG_STANDARD_IN_FORMAT = 1000;

class ImpSvNumberformatScan
{
public:

    ImpSvNumberformatScan( SvNumberFormatter* pFormatter );
    ~ImpSvNumberformatScan();
    void ChangeIntl();                          // tauscht Keywords aus

    void ChangeNullDate(USHORT nDay, USHORT nMonth, USHORT nYear);
                                                // tauscht Referenzdatum aus
    void ChangeStandardPrec(short nPrec);       // tauscht Standardprecision aus

    xub_StrLen ScanFormat( String& rString, String& rComment ); // Aufruf der Scan-Analyse

    void CopyInfo(ImpSvNumberformatInfo* pInfo,
                     USHORT nAnz);              // Kopiert die FormatInfo
    USHORT GetAnzResStrings() const             { return nAnzResStrings; }

    const CharClass& GetChrCls() const          { return *pFormatter->GetCharClass(); }
    const LocaleDataWrapper& GetLoc() const     { return *pFormatter->GetLocaleData(); }
    CalendarWrapper& GetCal() const             { return *pFormatter->GetCalendar(); }

    const String* GetKeywords() const
        {
            if ( bKeywordsNeedInit )
                InitKeywords();
            return sKeyword;
        }
    // Keywords used in output like TRUE and FALSE
    const String& GetSpecialKeyword( NfKeywordIndex eIdx ) const
        {
            if ( !sKeyword[eIdx].Len() )
                InitSpecialKeyword( eIdx );
            return sKeyword[eIdx];
        }
    const String& GetTrueString() const     { return GetSpecialKeyword( NF_KEY_TRUE ); }
    const String& GetFalseString() const    { return GetSpecialKeyword( NF_KEY_FALSE ); }
    const String& GetColorString() const    { return GetKeywords()[NF_KEY_COLOR]; }
    const String& GetRedString() const      { return GetKeywords()[NF_KEY_RED]; }
    const String& GetBooleanString() const  { return GetKeywords()[NF_KEY_BOOLEAN]; }
    const String& GetErrorString() const    { return sErrStr; }

    Date* GetNullDate() const                   { return pNullDate; }
    const String& GetStandardName() const
        {
            if ( bKeywordsNeedInit )
                InitKeywords();
            return sNameStandardFormat;
        }
    short GetStandardPrec() const               { return nStandardPrec; }
    const Color& GetRedColor() const            { return StandardColor[4]; }
    Color* GetColor(String& sStr);          // Setzt Hauptfarben oder
                                                // definierte Farben

    // the compatibility currency symbol for old automatic currency formats
    const String& GetCurSymbol() const
        {
            if ( bCompatCurNeedInit )
                InitCompatCur();
            return sCurSymbol;
        }

    // the compatibility currency abbreviation for CCC format code
    const String& GetCurAbbrev() const
        {
            if ( bCompatCurNeedInit )
                InitCompatCur();
            return sCurAbbrev;
        }

    // the compatibility currency symbol upper case for old automatic currency formats
    const String& GetCurString() const
        {
            if ( bCompatCurNeedInit )
                InitCompatCur();
            return sCurString;
        }

    void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge,
            BOOL bSystemToSystem = FALSE )
    {
        bConvertMode = TRUE;
        eNewLnge = eNewLge;
        eTmpLnge = eTmpLge;
        bConvertSystemToSystem = bSystemToSystem;
    }
    void SetConvertMode(BOOL bMode) { bConvertMode = bMode; }
                                                // Veraendert nur die Bool-Variable
                                                // (zum temporaeren Unterbrechen des
                                                // Convert-Modus)
    const BOOL GetConvertMode()     { return bConvertMode; }
    const LanguageType GetNewLnge() { return eNewLnge; }
                                                // Lesezugriff auf ConvertMode
                                                // und Konvertierungsland/Spr.
    const LanguageType GetTmpLnge() { return eTmpLnge; }
                                                // Lesezugriff auf
                                                // und Ausgangsland/Spr.

                                                /// get Thai T speciality
    BYTE GetNatNumModifier() const      { return nNatNumModifier; }
                                                /// set Thai T speciality
    void SetNatNumModifier( BYTE n )    { nNatNumModifier = n; }

    SvNumberFormatter* GetNumberformatter() { return pFormatter; }
                                                // Zugriff auf Formatierer
                                                // (fuer zformat.cxx)

private:                            // ---- privater Teil
    NfKeywordTable sKeyword;                    // Schluesselworte der Syntax
    Color StandardColor[NF_MAX_DEFAULT_COLORS];
                                                // Array der Standardfarben
    Date* pNullDate;                            // 30Dec1899
    String sNameStandardFormat;             // "Standard"
    short nStandardPrec;                        // default Precision fuer Standardformat (2)
    SvNumberFormatter* pFormatter;              // Pointer auf die Formatliste

    String sStrArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Symbole
    short nTypeArray[NF_MAX_FORMAT_SYMBOLS];    // Array der Infos
                                                // externe Infos:
    USHORT nAnzResStrings;                      // Anzahl der Ergebnissymbole
#if !(defined SOLARIS && defined X86)
    short eScannedType;                         // Typ gemaess Scan
#else
    int eScannedType;                           // wg. Optimierung
#endif
    BOOL bThousand;                             // Mit Tausenderpunkt
    USHORT nThousand;                           // Zaehlt ....-Folgen
    USHORT nCntPre;                             // Zaehlt Vorkommastellen
    USHORT nCntPost;                            // Zaehlt Nachkommastellen
    USHORT nCntExp;                             // Zaehlt Exp.Stellen, AM/PM
                                                // interne Infos:
    USHORT nAnzStrings;                         // Anzahl der Symbole
    USHORT nRepPos;                             // Position eines '*'
    USHORT nExpPos;                             // interne Position des E
    USHORT nBlankPos;                           // interne Position des Blank
    short nDecPos;                              // interne Pos. des ,
    BOOL bExp;                                  // wird bei Lesen des E gesetzt
    BOOL bFrac;                                 // wird bei Lesen des / gesetzt
    BOOL bBlank;                                // wird bei ' '(Fraction) ges.
    BOOL bDecSep;                               // Wird beim ersten , gesetzt
    mutable BOOL bKeywordsNeedInit;             // Locale dependent keywords need to be initialized
    mutable BOOL bCompatCurNeedInit;            // Locale dependent compatibility currency need to be initialized
    String sCurSymbol;                          // Currency symbol for compatibility format codes
    String sCurString;                          // Currency symbol in upper case
    String sCurAbbrev;                          // Currency abbreviation
    String sErrStr;                             // String fuer Fehlerausgaben

    BOOL bConvertMode;                          // Wird im Convert-Mode gesetzt
                                                // Land/Sprache, in die der
    LanguageType eNewLnge;                      // gescannte String konvertiert
                                                // wird (fuer Excel Filter)
                                                // Land/Sprache, aus der der
    LanguageType eTmpLnge;                      // gescannte String konvertiert
                                                // wird (fuer Excel Filter)
    BOOL bConvertSystemToSystem;                // Whether the conversion is
                                                // from one system locale to
                                                // another system locale (in
                                                // this case the automatic
                                                // currency symbol is converted
                                                // too).

    xub_StrLen nCurrPos;                        // Position des Waehrungssymbols

    BYTE nNatNumModifier;                       // Thai T speciality

    void InitKeywords() const;
    void InitSpecialKeyword( NfKeywordIndex eIdx ) const;
    void InitCompatCur() const;

#ifdef _ZFORSCAN_CXX                // ----- private Methoden -----
    void SetDependentKeywords();
                                                // Setzt die Sprachabh. Keyw.
    void SkipStrings(USHORT& i,xub_StrLen& nPos);// Ueberspringt StringSymbole
    USHORT PreviousKeyword(USHORT i);           // Gibt Index des vorangeh.
                                                // Schluesselworts oder 0
    USHORT NextKeyword(USHORT i);               // Gibt Index des naechsten
                                                // Schluesselworts oder 0
    sal_Unicode PreviousChar(USHORT i);             // Gibt letzten Buchstaben
                                                // vor der Position,
                                                // skipt EMPTY, STRING, STAR, BLANK
    sal_Unicode NextChar(USHORT i);                 // Gibt ersten Buchst. danach
    short PreviousType( USHORT i );             // Gibt Typ vor Position,
                                                // skipt EMPTY
    BOOL IsLastBlankBeforeFrac(USHORT i);       // True <=> es kommt kein ' '
                                                // mehr bis zum '/'
    void Reset();                               // Reset aller Variablen
                                                // vor Analysestart
    short GetKeyWord( const String& sSymbol,    // determine keyword at nPos
        xub_StrLen nPos );                      // return 0 <=> not found

    inline BOOL IsAmbiguousE( short nKey )      // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC
        {
            return (nKey == NF_KEY_EC || nKey == NF_KEY_E) &&
                (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]);
        }

    // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan()
    BOOL Is100SecZero( USHORT i, BOOL bHadDecSep );

    short Next_Symbol(const String& rStr,
                        xub_StrLen& nPos,
                      String& sSymbol);       // Naechstes Symbol
    xub_StrLen Symbol_Division(const String& rString);// lexikalische Voranalyse
    xub_StrLen ScanType(const String& rString); // Analyse des Formattyps
    xub_StrLen FinalScan( String& rString, String& rComment );  // Endanalyse mit Vorgabe
                                                // des Typs
    // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found
    int FinalScanGetCalendar( xub_StrLen& nPos, USHORT& i, USHORT& nAnzResStrings );

    static inline BOOL StringEqualsChar( const String& rStr, sal_Unicode ch )
        { return rStr.GetChar(0) == ch && rStr.Len() == 1; }
        // Yes, for efficiency get the character first and then compare length
        // because in most places where this is used the string is one char.

    // remove "..." and \... quotes from rStr, return how many chars removed
    static xub_StrLen RemoveQuotes( String& rStr );

#endif //_ZFORSCAN_CXX
};

#endif  // _ZFORSCAN_HXX
<|endoftext|>


<commit_before><commit_msg>fdo#81231 Make this macro work again<commit_after><|endoftext|>