<commit_before>// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// 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 "SurgSim/Collision/TriangleMeshTriangleMeshDcdContact.h"

#include "SurgSim/Collision/CollisionPair.h"
#include "SurgSim/Collision/Representation.h"
#include "SurgSim/DataStructures/TriangleMesh.h"
#include "SurgSim/DataStructures/TriangleMeshBase.h"
#include "SurgSim/Math/Geometry.h"
#include "SurgSim/Math/MeshShape.h"
#include "SurgSim/Math/RigidTransform.h"

using SurgSim::DataStructures::TriangleMesh;
using SurgSim::DataStructures::TriangleMeshBase;
using SurgSim::Math::MeshShape;
using SurgSim::Math::RigidTransform3d;
using SurgSim::Math::Vector3d;

namespace SurgSim
{
namespace Collision
{

TriangleMeshTriangleMeshDcdContact::TriangleMeshTriangleMeshDcdContact()
{
}

std::pair<int,int> TriangleMeshTriangleMeshDcdContact::getShapeTypes()
{
	return std::pair<int,int>(SurgSim::Math::SHAPE_TYPE_MESH, SurgSim::Math::SHAPE_TYPE_MESH);
}

#ifdef SURGSIM_DEBUG_TRIANGLETRIANGLECONTACT

static void assertIsCoplanar(const Vector3d& triangle0, const Vector3d& triangle1, const Vector3d& triangle2,
					   const Vector3d& point)
{
	SURGSIM_ASSERT(abs((triangle2 - triangle0).dot((triangle1 - triangle0).cross(point - triangle2)))
				   < SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Coplanarity failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", pt " << point.transpose();
}

static void assertIsConstrained(const Vector3d& point,
								const Vector3d& triangle0,
								const Vector3d& triangle1,
								const Vector3d& triangle2,
								const Vector3d& normal)
{
	Vector3d barycentricCoordinate;

	SurgSim::Math::barycentricCoordinates(point, triangle0, triangle1, triangle2, normal, &barycentricCoordinate);

	SURGSIM_ASSERT(barycentricCoordinate.x() >= -SurgSim::Math::Geometry::ScalarEpsilon
				   && barycentricCoordinate.x() <= 1.0 + SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Constrained failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", n " << normal.transpose() << ", pt " << point.transpose();
	SURGSIM_ASSERT(barycentricCoordinate.y() >= -SurgSim::Math::Geometry::ScalarEpsilon
				   && barycentricCoordinate.y() <= 1.0 + SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Constrained failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", n " << normal.transpose() << ", pt " << point.transpose();
	SURGSIM_ASSERT(barycentricCoordinate.z() >= -SurgSim::Math::Geometry::ScalarEpsilon
				   && barycentricCoordinate.z() <= 1.0 + SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Constrained failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", n " << normal.transpose() << ", pt " << point.transpose();
}

static void assertIsCorrectNormalAndDepth(const Vector3d& normal,
										  double penetrationDepth,
										  const Vector3d& triangleA0,
										  const Vector3d& triangleA1,
										  const Vector3d& triangleA2,
										  const Vector3d& triangleB0,
										  const Vector3d& triangleB1,
										  const Vector3d& triangleB2)
{
	Vector3d correction = normal * (penetrationDepth + 2 * SurgSim::Math::Geometry::DistanceEpsilon);

	Vector3d temp1, temp2;
	double expectedDistance = SurgSim::Math::distanceTriangleTriangle(
		(Vector3d)(triangleA0 + correction), (Vector3d)(triangleA1 + correction), (Vector3d)(triangleA2 + correction),
		triangleB0, triangleB1, triangleB2,
		&temp1, &temp2);

	SURGSIM_ASSERT(expectedDistance > 0.0)
		<< "Normal and depth failed with: "
		<< "calcD " << expectedDistance << ", n " << normal.transpose() << ", d " << penetrationDepth
		<< ", a0 " << triangleA0.transpose() << ", a1 " << triangleA1.transpose() << ", a2 " << triangleA2.transpose()
		<< ", b0 " << triangleB0.transpose() << ", b1 " << triangleB1.transpose() << ", b2 " << triangleB2.transpose();
	SURGSIM_ASSERT(expectedDistance <= 2.1 * SurgSim::Math::Geometry::DistanceEpsilon)
		<< "Normal and depth failed with: "
		<< "calcD " << expectedDistance << ", n " << normal.transpose() << ", d " << penetrationDepth
		<< ", a0 " << triangleA0.transpose() << ", a1 " << triangleA1.transpose() << ", a2 " << triangleA2.transpose()
		<< ", b0 " << triangleB0.transpose() << ", b1 " << triangleB1.transpose() << ", b2 " << triangleB2.transpose();
}

#endif // SURGSIM_DEBUG_TRIANGLETRIANGLECONTACT

void TriangleMeshTriangleMeshDcdContact::doCalculateContact(std::shared_ptr<CollisionPair> pair)
{
	std::shared_ptr<Representation> representationMeshA = pair->getFirst();
	std::shared_ptr<Representation> representationMeshB = pair->getSecond();

	std::shared_ptr<TriangleMesh> collisionMeshA =
		std::static_pointer_cast<MeshShape>(representationMeshA->getShape())->getMesh();
	std::shared_ptr<TriangleMesh> collisionMeshB =
		std::static_pointer_cast<MeshShape>(representationMeshB->getShape())->getMesh();

	RigidTransform3d globalCoordinatesFromMeshACoordinates = representationMeshA->getPose();
	RigidTransform3d globalCoordinatesFromMeshBCoordinates = representationMeshB->getPose();

	RigidTransform3d meshBCoordinatesFromGlobalCoordinates = globalCoordinatesFromMeshBCoordinates.inverse();
	RigidTransform3d meshBCoordinatesFromMeshACoordinates = meshBCoordinatesFromGlobalCoordinates
															* globalCoordinatesFromMeshACoordinates;

	double depth = 0.0;
	Vector3d normal;
	Vector3d penetrationPointA, penetrationPointB;

	for (size_t i = 0; i < collisionMeshA->getNumTriangles(); ++i)
	{
		// The triangleA vertices.
		const Vector3d& triangleA0InLocalB = meshBCoordinatesFromMeshACoordinates *
			collisionMeshA->getVertexPosition(collisionMeshA->getTriangle(i).verticesId[0]);
		const Vector3d& triangleA1InLocalB = meshBCoordinatesFromMeshACoordinates *
			collisionMeshA->getVertexPosition(collisionMeshA->getTriangle(i).verticesId[1]);
		const Vector3d& triangleA2InLocalB = meshBCoordinatesFromMeshACoordinates *
			collisionMeshA->getVertexPosition(collisionMeshA->getTriangle(i).verticesId[2]);

		const Vector3d& normalAInLocalB = meshBCoordinatesFromMeshACoordinates.linear() * collisionMeshA->getNormal(i);
		if (normalAInLocalB.isZero())
		{
			continue;
		}

		for (size_t j = 0; j < collisionMeshB->getNumTriangles(); ++j)
		{
			const Vector3d& normalB = collisionMeshB->getNormal(j);
			if (normalB.isZero())
			{
				continue;
			}

			// The triangleB vertices.
			const Vector3d& triangleB0 =
				collisionMeshB->getVertexPosition(collisionMeshB->getTriangle(j).verticesId[0]);
			const Vector3d& triangleB1 =
				collisionMeshB->getVertexPosition(collisionMeshB->getTriangle(j).verticesId[1]);
			const Vector3d& triangleB2 =
				collisionMeshB->getVertexPosition(collisionMeshB->getTriangle(j).verticesId[2]);

			// Check if the triangles intersect.
			if (SurgSim::Math::calculateContactTriangleTriangle(triangleA0InLocalB, triangleA1InLocalB,
																triangleA2InLocalB,
																triangleB0, triangleB1, triangleB2,
																normalAInLocalB, normalB, &depth,
																&penetrationPointA, &penetrationPointB,
																&normal))
			{
#ifdef SURGSIM_DEBUG_TRIANGLETRIANGLECONTACT
				assertIsCoplanar(triangleA0InLocalB, triangleA1InLocalB, triangleA2InLocalB, penetrationPointA);
				assertIsCoplanar(triangleB0, triangleB1, triangleB2, penetrationPointB);

				assertIsConstrained(
					penetrationPointA, triangleA0InLocalB, triangleA1InLocalB, triangleA2InLocalB, normalAInLocalB);
				assertIsConstrained(penetrationPointB, triangleB0, triangleB1, triangleB2, normalB);

				assertIsCorrectNormalAndDepth(normal, depth, triangleA0InLocalB, triangleA1InLocalB, triangleA2InLocalB,
					triangleB0, triangleB1, triangleB2);
#endif

				// Create the contact.
				std::pair<Location, Location> penetrationPoints;
				penetrationPoints.first.globalPosition.setValue(globalCoordinatesFromMeshBCoordinates
																* penetrationPointA);
				penetrationPoints.second.globalPosition.setValue(globalCoordinatesFromMeshBCoordinates
																 * penetrationPointB);

				pair->addContact(std::abs(depth), globalCoordinatesFromMeshBCoordinates.linear() * normal,
								 penetrationPoints);
			}
		}
	}
}

}; // namespace Collision
}; // namespace SurgSim
<commit_msg>TriangleMeshTriangleMeshDcdContact, add documentation<commit_after>// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// 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 "SurgSim/Collision/TriangleMeshTriangleMeshDcdContact.h"

#include "SurgSim/Collision/CollisionPair.h"
#include "SurgSim/Collision/Representation.h"
#include "SurgSim/DataStructures/TriangleMesh.h"
#include "SurgSim/DataStructures/TriangleMeshBase.h"
#include "SurgSim/Math/Geometry.h"
#include "SurgSim/Math/MeshShape.h"
#include "SurgSim/Math/RigidTransform.h"

using SurgSim::DataStructures::TriangleMesh;
using SurgSim::DataStructures::TriangleMeshBase;
using SurgSim::Math::MeshShape;
using SurgSim::Math::RigidTransform3d;
using SurgSim::Math::Vector3d;

namespace SurgSim
{
namespace Collision
{

TriangleMeshTriangleMeshDcdContact::TriangleMeshTriangleMeshDcdContact()
{
}

std::pair<int,int> TriangleMeshTriangleMeshDcdContact::getShapeTypes()
{
	return std::pair<int,int>(SurgSim::Math::SHAPE_TYPE_MESH, SurgSim::Math::SHAPE_TYPE_MESH);
}

namespace
{

/// Asserts the points are coplanar, and prints debug output on the failing condition.
/// \param triangle0, triangle1, triangle2 the vertices of the triangle
/// \param point the point to compare against
/// \throws If the points are not coplanar
void assertIsCoplanar(const Vector3d& triangle0,
					  const Vector3d& triangle1,
					  const Vector3d& triangle2,
					  const Vector3d& point)
{
	SURGSIM_ASSERT(abs((triangle2 - triangle0).dot((triangle1 - triangle0).cross(point - triangle2)))
				   < SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Coplanar assertion failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", pt " << point.transpose();
}

/// Asserts the point is inside the triangle, and prints debug output on the failing condition.
/// \param point the point to compare against
/// \param triangle0, triangle1, triangle2 the vertices of the triangle
/// \param normal the unit normal of the triangle
/// \throws If the point is not inside the triangle
void assertIsPointInsideTriangle(const Vector3d& point,
								 const Vector3d& triangle0,
								 const Vector3d& triangle1,
								 const Vector3d& triangle2,
								 const Vector3d& normal)
{
	Vector3d barycentricCoordinate;

	SurgSim::Math::barycentricCoordinates(point, triangle0, triangle1, triangle2, normal, &barycentricCoordinate);

	SURGSIM_ASSERT(barycentricCoordinate.x() >= -SurgSim::Math::Geometry::ScalarEpsilon
				   && barycentricCoordinate.x() <= 1.0 + SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Point inside triangle assertion failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", n " << normal.transpose() << ", pt " << point.transpose();
	SURGSIM_ASSERT(barycentricCoordinate.y() >= -SurgSim::Math::Geometry::ScalarEpsilon
				   && barycentricCoordinate.y() <= 1.0 + SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Point inside triangle assertion failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", n " << normal.transpose() << ", pt " << point.transpose();
	SURGSIM_ASSERT(barycentricCoordinate.z() >= -SurgSim::Math::Geometry::ScalarEpsilon
				   && barycentricCoordinate.z() <= 1.0 + SurgSim::Math::Geometry::ScalarEpsilon)
		<< "Point inside triangle assertion failed with: "
		<< "t0 " << triangle0.transpose() << ", t1 " << triangle1.transpose() << ", t2 " << triangle2.transpose()
		<< ", n " << normal.transpose() << ", pt " << point.transpose();
}

/// Asserts the provided normal and depth minimally resolve the interpenetration of the two triangles, and prints debug
/// output on the failing condition.
/// \param normal the unit normal in the direction to resolve the penetration
/// \param penetrationDepth the depth of penetration to check
/// \param triangleA0, triangleA1, triangleA2 the vertices of the first triangle
/// \param triangleB0, triangleB1, triangleB2 the vertices of the second triangle
/// \throws If the normal and depth do not minimally resolve the interpenetration of the two triangles
void assertIsCorrectNormalAndDepth(const Vector3d& normal,
								   double penetrationDepth,
								   const Vector3d& triangleA0,
								   const Vector3d& triangleA1,
								   const Vector3d& triangleA2,
								   const Vector3d& triangleB0,
								   const Vector3d& triangleB1,
								   const Vector3d& triangleB2)
{
	Vector3d correction = normal * (penetrationDepth + 2 * SurgSim::Math::Geometry::DistanceEpsilon);

	Vector3d temp1, temp2;
	double expectedDistance = SurgSim::Math::distanceTriangleTriangle(
		(Vector3d)(triangleA0 + correction), (Vector3d)(triangleA1 + correction), (Vector3d)(triangleA2 + correction),
		triangleB0, triangleB1, triangleB2,
		&temp1, &temp2);

	SURGSIM_ASSERT(expectedDistance > 0.0)
		<< "Correct normal and depth assertion failed with: "
		<< "calcD " << expectedDistance << ", n " << normal.transpose() << ", d " << penetrationDepth
		<< ", a0 " << triangleA0.transpose() << ", a1 " << triangleA1.transpose() << ", a2 " << triangleA2.transpose()
		<< ", b0 " << triangleB0.transpose() << ", b1 " << triangleB1.transpose() << ", b2 " << triangleB2.transpose();
	SURGSIM_ASSERT(expectedDistance <= 2.1 * SurgSim::Math::Geometry::DistanceEpsilon)
		<< "Correct normal and depth assertion failed with: "
		<< "calcD " << expectedDistance << ", n " << normal.transpose() << ", d " << penetrationDepth
		<< ", a0 " << triangleA0.transpose() << ", a1 " << triangleA1.transpose() << ", a2 " << triangleA2.transpose()
		<< ", b0 " << triangleB0.transpose() << ", b1 " << triangleB1.transpose() << ", b2 " << triangleB2.transpose();
}

}

void TriangleMeshTriangleMeshDcdContact::doCalculateContact(std::shared_ptr<CollisionPair> pair)
{
	std::shared_ptr<Representation> representationMeshA = pair->getFirst();
	std::shared_ptr<Representation> representationMeshB = pair->getSecond();

	std::shared_ptr<TriangleMesh> collisionMeshA =
		std::static_pointer_cast<MeshShape>(representationMeshA->getShape())->getMesh();
	std::shared_ptr<TriangleMesh> collisionMeshB =
		std::static_pointer_cast<MeshShape>(representationMeshB->getShape())->getMesh();

	RigidTransform3d globalCoordinatesFromMeshACoordinates = representationMeshA->getPose();
	RigidTransform3d globalCoordinatesFromMeshBCoordinates = representationMeshB->getPose();

	RigidTransform3d meshBCoordinatesFromGlobalCoordinates = globalCoordinatesFromMeshBCoordinates.inverse();
	RigidTransform3d meshBCoordinatesFromMeshACoordinates = meshBCoordinatesFromGlobalCoordinates
															* globalCoordinatesFromMeshACoordinates;

	double depth = 0.0;
	Vector3d normal;
	Vector3d penetrationPointA, penetrationPointB;

	for (size_t i = 0; i < collisionMeshA->getNumTriangles(); ++i)
	{
		// The triangleA vertices.
		const Vector3d& triangleA0InLocalB = meshBCoordinatesFromMeshACoordinates *
			collisionMeshA->getVertexPosition(collisionMeshA->getTriangle(i).verticesId[0]);
		const Vector3d& triangleA1InLocalB = meshBCoordinatesFromMeshACoordinates *
			collisionMeshA->getVertexPosition(collisionMeshA->getTriangle(i).verticesId[1]);
		const Vector3d& triangleA2InLocalB = meshBCoordinatesFromMeshACoordinates *
			collisionMeshA->getVertexPosition(collisionMeshA->getTriangle(i).verticesId[2]);

		const Vector3d& normalAInLocalB = meshBCoordinatesFromMeshACoordinates.linear() * collisionMeshA->getNormal(i);
		if (normalAInLocalB.isZero())
		{
			continue;
		}

		for (size_t j = 0; j < collisionMeshB->getNumTriangles(); ++j)
		{
			const Vector3d& normalB = collisionMeshB->getNormal(j);
			if (normalB.isZero())
			{
				continue;
			}

			// The triangleB vertices.
			const Vector3d& triangleB0 =
				collisionMeshB->getVertexPosition(collisionMeshB->getTriangle(j).verticesId[0]);
			const Vector3d& triangleB1 =
				collisionMeshB->getVertexPosition(collisionMeshB->getTriangle(j).verticesId[1]);
			const Vector3d& triangleB2 =
				collisionMeshB->getVertexPosition(collisionMeshB->getTriangle(j).verticesId[2]);

			// Check if the triangles intersect.
			if (SurgSim::Math::calculateContactTriangleTriangle(triangleA0InLocalB, triangleA1InLocalB,
																triangleA2InLocalB,
																triangleB0, triangleB1, triangleB2,
																normalAInLocalB, normalB, &depth,
																&penetrationPointA, &penetrationPointB,
																&normal))
			{
#ifdef SURGSIM_DEBUG_TRIANGLETRIANGLECONTACT
				assertIsCoplanar(triangleA0InLocalB, triangleA1InLocalB, triangleA2InLocalB, penetrationPointA);
				assertIsCoplanar(triangleB0, triangleB1, triangleB2, penetrationPointB);

				assertIsPointInsideTriangle(
					penetrationPointA, triangleA0InLocalB, triangleA1InLocalB, triangleA2InLocalB, normalAInLocalB);
				assertIsPointInsideTriangle(penetrationPointB, triangleB0, triangleB1, triangleB2, normalB);

				assertIsCorrectNormalAndDepth(normal, depth, triangleA0InLocalB, triangleA1InLocalB, triangleA2InLocalB,
					triangleB0, triangleB1, triangleB2);
#endif

				// Create the contact.
				std::pair<Location, Location> penetrationPoints;
				penetrationPoints.first.globalPosition.setValue(globalCoordinatesFromMeshBCoordinates
																* penetrationPointA);
				penetrationPoints.second.globalPosition.setValue(globalCoordinatesFromMeshBCoordinates
																 * penetrationPointB);

				pair->addContact(std::abs(depth), globalCoordinatesFromMeshBCoordinates.linear() * normal,
								 penetrationPoints);
			}
		}
	}
}

}; // namespace Collision
}; // namespace SurgSim
<|endoftext|>


<commit_before>#include "Log.h"
#include <iostream>

namespace spdlog
{
	namespace sinks
	{

		template <class Mutex>
		class stdout_sink_no_debug : public base_sink<Mutex>
		{
			using MyType = stdout_sink_no_debug<Mutex>;
		public:
			stdout_sink_no_debug() {}
			static std::shared_ptr<MyType> instance()
			{
				static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
				return instance;
			}

			void _sink_it(const details::log_msg& msg) override
			{
				if (msg.level >= level::info) {
					fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stdout);
					flush();
				}
			}

			void flush() override
			{
				fflush(stdout);
			}
		};

		typedef stdout_sink_no_debug<details::null_mutex> stdout_sink_no_debug_st;
		typedef stdout_sink_no_debug<std::mutex> stdout_sink_no_debug_mt; // ̰߳ȫ
	}
}

CLog::CLog() {

    try {
        std::vector<spdlog::sink_ptr> sinks;
        sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
        sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_mt>("logfile", "txt", 0, 0));
        auto combined_logger = std::make_shared<spdlog::logger>("log", begin(sinks), end(sinks));
        combined_logger->flush_on(spdlog::level::err); // trigger flush if the log severity is error or higher
        spdlog::register_logger(combined_logger);

        //[%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
        spd::set_pattern("[%H:%M:%S %e] [%L] [%t] %v");
		spd::set_level(spd::level::debug);
    } catch (const spdlog::spdlog_ex& ex) {
        std::cout << "Log failed: " << ex.what() << std::endl;
    }

}

CLog::~CLog() {
    // Under VisualStudio, this must be called before main finishes to workaround a known VS issue
    spdlog::drop_all();
}

CLog nono;
<commit_msg>flush_on debug<commit_after>#include "Log.h"
#include <iostream>

namespace spdlog
{
	namespace sinks
	{

		template <class Mutex>
		class stdout_sink_no_debug : public base_sink<Mutex>
		{
			using MyType = stdout_sink_no_debug<Mutex>;
		public:
			stdout_sink_no_debug() {}
			static std::shared_ptr<MyType> instance()
			{
				static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
				return instance;
			}

			void _sink_it(const details::log_msg& msg) override
			{
				if (msg.level >= level::info) {
					fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stdout);
					flush();
				}
			}

			void flush() override
			{
				fflush(stdout);
			}
		};

		typedef stdout_sink_no_debug<details::null_mutex> stdout_sink_no_debug_st;
		typedef stdout_sink_no_debug<std::mutex> stdout_sink_no_debug_mt; // ̰߳ȫ
	}
}

CLog::CLog() {

    try {
        std::vector<spdlog::sink_ptr> sinks;
        sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
        sinks.push_back(std::make_shared<spdlog::sinks::daily_file_sink_mt>("logfile", "txt", 0, 0));
        auto combined_logger = std::make_shared<spdlog::logger>("log", begin(sinks), end(sinks));
        combined_logger->flush_on(spdlog::level::debug); // trigger flush if the log severity is debug or higher
        spdlog::register_logger(combined_logger);

        //[%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
        spd::set_pattern("[%H:%M:%S %e] [%L] [%t] %v");
		spd::set_level(spd::level::debug);
    } catch (const spdlog::spdlog_ex& ex) {
        std::cout << "Log failed: " << ex.what() << std::endl;
    }

}

CLog::~CLog() {
    // Under VisualStudio, this must be called before main finishes to workaround a known VS issue
    spdlog::drop_all();
}

CLog nono;
<|endoftext|>


<commit_before>#include "CPU.h"

short CPU::opcode0x07() {
	byte bit = AF.hi & 0x80;
	AF.hi <<= 1;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(CARRY_FLAG);;
	}
	if (AF.hi == 0x0) {
		raiseFlag(ZERO_FLAG);
    }

    return 4;
}

short CPU::opcode0x0F() {
	byte bitZero = AF.hi & 0x01;
	AF.hi >>= 1;

	clearFlags();
	if (bitZero == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (AF.hi == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}

    return 4;
}

short CPU::opcode0x17() {
	byte lastBit = AF.hi & 0x80;
	AF.hi <<= 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(&AF.hi, 0);
	} else {
		clearBit(&AF.hi, 0);
	}

	clearFlags();
	if (lastBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (AF.hi == 0) {
		raiseFlag(ZERO_FLAG);
	}
    return 4;
}// RLA

short CPU::opcode0x1F() {
	byte firstBit = AF.hi & 0x01;
	AF.hi >>= 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(&AF.hi, 7);
	} else {
		clearBit(&AF.hi, 7);
	}

	clearFlags();
	if (firstBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	return 4;
}// RR A

void CPU::rlc8bitRegister(byte * reg) {
	byte bit= *reg & 0x80;
	*reg <<= 1;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (*reg == 0x00) {
		raiseFlag(ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x00() {
    rlc8bitRegister(&BC.hi);
    return 8;
}// RLC B

short CPU::extendedOpcode0x01() {
    rlc8bitRegister(&BC.low);
    return 8;
}// RLC C

short CPU::extendedOpcode0x02() {
    rlc8bitRegister(&DE.hi);
    return 8;
}// RLC D

short CPU::extendedOpcode0x03() {
    rlc8bitRegister(&DE.low);
    return 8;
}// RLC E

short CPU::extendedOpcode0x04() {
    rlc8bitRegister(&HL.hi);
    return 8;
}// RLC H

short CPU::extendedOpcode0x05() {
    rlc8bitRegister(&HL.low);
    return 8;
}// RLC L

short CPU::extendedOpcode0x06() {
	byte reg = memory->read(HL.value) ;
	rlc8bitRegister(&reg);
	memory->write(HL.value, reg);

	return 16;
}// RLC (HL)

short CPU::extendedOpcode0x07() {
    rlc8bitRegister(&AF.hi);
    return 8;
}// RLC A

void CPU::rrc8bitRegister(byte *reg) {
	byte zeroBit = *reg & 0x01;
	*reg = *reg >> 1;

	clearFlags();
	if (zeroBit == 0x01) {
		raiseFlag(CARRY_FLAG);
	}
	if (*reg == 0) {
		raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x08() {
    rrc8bitRegister(&BC.hi);
    return 8;
}// RRC B

short CPU::extendedOpcode0x09() {
    rrc8bitRegister(&BC.low);
    return 8;
}// RRC C

short CPU::extendedOpcode0x0A() {
    rrc8bitRegister(&DE.hi);
    return 8;
}// RRC D

short CPU::extendedOpcode0x0B() {
    rrc8bitRegister(&DE.low);
    return 8;
}// RRC E

short CPU::extendedOpcode0x0C() {
    rrc8bitRegister(&HL.hi);
    return 8;
}// RRC H

short CPU::extendedOpcode0x0D() {
    rrc8bitRegister(&HL.low);
    return 8;
}// RRC L

short CPU::extendedOpcode0x0E() {
	byte reg = memory->read(HL.value) ;
	rrc8bitRegister(&reg);
	memory->write(HL.value, reg);
    return 16;
}// RRC (HL)

short CPU::extendedOpcode0x0F() {
	byte bit = AF.hi & 0x01;
	AF.hi >>= 1;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}

	if (AF.hi == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}

    return 8;
}// RRC A

void CPU::rl8bitRegister(byte *reg) {
	byte lastBit = *reg & 0x80;
	*reg <<= 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(&AF.hi, 7);
	} else {
		clearBit(&AF.hi, 7);
	}

	clearFlags();
	if (lastBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (AF.hi == 0) {
		raiseFlag(ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x10() {
    rl8bitRegister(&BC.hi);
    return 8;
}// rl B

short CPU::extendedOpcode0x11() {
    rl8bitRegister(&BC.low);
    return 8;
}// rl C

short CPU::extendedOpcode0x12() {
    rl8bitRegister(&DE.hi);
    return 8;
}// rl D

short CPU::extendedOpcode0x13() {
    rl8bitRegister(&DE.low);
    return 8;
}// rl E

short CPU::extendedOpcode0x14() {
    rl8bitRegister(&HL.hi);
    return 8;
}// rl H

short CPU::extendedOpcode0x15() {
    rl8bitRegister(&HL.low);
    return 8;
}// rl L

short CPU::extendedOpcode0x16() {
	byte reg = memory->read(HL.value);
	rl8bitRegister(&reg);
	memory->write(HL.value, reg);
    return 16;
}// rl (HL)

short CPU::extendedOpcode0x17() {

	byte bit = AF.hi & 0x80;

	byte carry = checkFlag(Flag::CARRY_FLAG) ? 0x01 : 0x00;
	AF.hi <<= carry;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(CARRY_FLAG);;
	}

	if (AF.hi == 0x0) {
		raiseFlag(ZERO_FLAG);
	}

	return 8;
}

void CPU::rr8bitRegister(byte *reg) {
	byte zeroBit = *reg & 0x01;
	*reg = *reg >> 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(reg, 7);
	} else {
		clearBit(reg, 7);
	}

	clearFlags();
	if (zeroBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (*reg == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x18() {
    rr8bitRegister(&BC.hi);
    return 8;
}// rr B

short CPU::extendedOpcode0x19() {
    rr8bitRegister(&BC.low);
    return 8;
}// rr C

short CPU::extendedOpcode0x1A() {
    rr8bitRegister(&DE.hi);
    return 8;
}// rr D

short CPU::extendedOpcode0x1B() {
    rr8bitRegister(&DE.hi);
    return 8;
}// rr E

short CPU::extendedOpcode0x1C() {
    rr8bitRegister(&HL.hi);
    return 8;
}// rr H

short CPU::extendedOpcode0x1D() {
    rr8bitRegister(&HL.low);
    return 8;
}// rr L

short CPU::extendedOpcode0x1E() {
	byte reg = memory->read(HL.value);
	rr8bitRegister(&reg);
    memory->write(HL.value, reg);
    return 16;
}// rr (HL)

short CPU::extendedOpcode0x1F() {
    rr8bitRegister(&AF.hi);
    return 8;
}// rr A

void CPU::sla8bitRegister(byte *reg) {
	byte lastBit = *reg & 0x80;
	*reg <<= 1;

	clearFlags();
	if (lastBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
    if ( *reg == 0 ) {
        raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x20() {
    sla8bitRegister(&BC.hi);
    return 8;
}// sla B

short CPU::extendedOpcode0x21() {
    sla8bitRegister(&BC.low);
    return 8;
}// sla C

short CPU::extendedOpcode0x22() {
    sla8bitRegister(&DE.hi);
    return 8;
}// sla D

short CPU::extendedOpcode0x23() {
    sla8bitRegister(&DE.low);
    return 8;
}// sla E

short CPU::extendedOpcode0x24() {
    sla8bitRegister(&HL.hi);
    return 8;
}// sla H

short CPU::extendedOpcode0x25() {
    sla8bitRegister(&HL.low);
    return 8;
}// sla L

short CPU::extendedOpcode0x26() {
    byte reg = memory->read(HL.value);
	sla8bitRegister(&reg);
    memory->write(HL.value, reg);
    return 16;
}// sla (HL)

short CPU::extendedOpcode0x27() {
    sla8bitRegister(&AF.hi);
    return 8;
}// sla A

void CPU::sra8bitRegister(byte * reg) {
	byte firstBit = *reg & 0x01;
	byte lastBit = *reg & 0x80;

	*reg >>= 1;

	if (lastBit == 0x01) {
		setBit(reg, 7);
	} else {
		clearBit(reg, 7);
	}

	clearFlags();
	if (firstBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (*reg == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x28() {
    sra8bitRegister(&BC.hi);
    return 8;
}// sra B

short CPU::extendedOpcode0x29() {
    sra8bitRegister(&BC.low);
    return 8;
}// sra C

short CPU::extendedOpcode0x2A() {
    sra8bitRegister(&DE.hi);
    return 8;
}// sra D

short CPU::extendedOpcode0x2B() {
    sra8bitRegister(&DE.low);
    return 8;
}// sra E

short CPU::extendedOpcode0x2C() {
    sra8bitRegister(&HL.hi);
    return 8;
}// sra H

short CPU::extendedOpcode0x2D(){
    sra8bitRegister(&HL.low);
    return 8;
}// sra L

short CPU::extendedOpcode0x2E() {
    byte data = memory->read(HL.value);
	sra8bitRegister(&data);
	memory->write(HL.value, data);
    return 16;
}// sra (HL)

short CPU::extendedOpcode0x2F() {
    sra8bitRegister(&AF.hi);
    return 8;
}// sra A

void CPU::swap8bitRegister(byte * reg) {
	clearFlags();

	*reg = (((*reg & 0xF0) >> 4) | ((*reg & 0x0F) << 4));

	if ( *reg == 0 ) {
        raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x30() {
    swap8bitRegister(&BC.hi);
    return 8;
}// swap B

short CPU::extendedOpcode0x31() {
    swap8bitRegister(&BC.low);
    return 8;
}// swap C

short CPU::extendedOpcode0x32() {
    swap8bitRegister(&DE.hi);
    return 8;
}// swap D

short CPU::extendedOpcode0x33() {
    swap8bitRegister(&DE.low);
    return 8;
}// swap E

short CPU::extendedOpcode0x34() {
    swap8bitRegister(&HL.hi);
    return 8;
}// swap H

short CPU::extendedOpcode0x35() {
    swap8bitRegister(&HL.low);
    return 8;
}// swap L

short CPU::extendedOpcode0x36() {
	clearFlags();
    byte data = memory->read(HL.value);
	data = (((data & 0xF0) >> 4) | ((data & 0x0F) << 4));

	if ( data == 0 ) {
        raiseFlag(ZERO_FLAG);
    }

    memory->write(HL.value, data);
    return 16;
}// swap (HL)

short CPU::extendedOpcode0x37() {
    swap8bitRegister(&AF.hi);
    return 8;
}// swap A

void CPU::srl8bitRegister(byte *reg) {
	byte firstBit = *reg & 0x01;
	*reg >>= 1;

	clearBit(reg, 7);

	clearFlags();
	if (firstBit == 0x01) {
        raiseFlag(CARRY_FLAG);
    }
	if (*reg == 0) {
        raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x38() {
    srl8bitRegister(&BC.hi);
    return 8;
}// SRL B

short CPU::extendedOpcode0x39() {
    srl8bitRegister(&BC.low);
    return 8;
}// SRL C

short CPU::extendedOpcode0x3A() {
    srl8bitRegister(&DE.hi);
    return 8;
}// SRL D

short CPU::extendedOpcode0x3B() {
    srl8bitRegister(&DE.low);
    return 8;
}// SRL E

short CPU::extendedOpcode0x3C() {
    srl8bitRegister(&HL.hi);
    return 8;
}// SRL H

short CPU::extendedOpcode0x3D() {
    srl8bitRegister(&HL.low);
    return 8;
}// SRL L

short CPU::extendedOpcode0x3E() {
    byte data = memory->read(HL.value);
	srl8bitRegister(&data);
	memory->write(HL.value, data);
    return 16;
}// SRL (HL)

short CPU::extendedOpcode0x3F() {
    srl8bitRegister(&AF.hi);
    return 8;
}// SRL A
<commit_msg>Fix RR e instruction<commit_after>#include "CPU.h"

short CPU::opcode0x07() {
	byte bit = AF.hi & 0x80;
	AF.hi <<= 1;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(CARRY_FLAG);;
	}
	if (AF.hi == 0x0) {
		raiseFlag(ZERO_FLAG);
    }

    return 4;
}

short CPU::opcode0x0F() {
	byte bitZero = AF.hi & 0x01;
	AF.hi >>= 1;

	clearFlags();
	if (bitZero == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (AF.hi == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}

    return 4;
}

short CPU::opcode0x17() {
	byte lastBit = AF.hi & 0x80;
	AF.hi <<= 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(&AF.hi, 0);
	} else {
		clearBit(&AF.hi, 0);
	}

	clearFlags();
	if (lastBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (AF.hi == 0) {
		raiseFlag(ZERO_FLAG);
	}
    return 4;
}// RLA

short CPU::opcode0x1F() {
	byte firstBit = AF.hi & 0x01;
	AF.hi >>= 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(&AF.hi, 7);
	} else {
		clearBit(&AF.hi, 7);
	}

	clearFlags();
	if (firstBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	return 4;
}// RR A

void CPU::rlc8bitRegister(byte * reg) {
	byte bit= *reg & 0x80;
	*reg <<= 1;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (*reg == 0x00) {
		raiseFlag(ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x00() {
    rlc8bitRegister(&BC.hi);
    return 8;
}// RLC B

short CPU::extendedOpcode0x01() {
    rlc8bitRegister(&BC.low);
    return 8;
}// RLC C

short CPU::extendedOpcode0x02() {
    rlc8bitRegister(&DE.hi);
    return 8;
}// RLC D

short CPU::extendedOpcode0x03() {
    rlc8bitRegister(&DE.low);
    return 8;
}// RLC E

short CPU::extendedOpcode0x04() {
    rlc8bitRegister(&HL.hi);
    return 8;
}// RLC H

short CPU::extendedOpcode0x05() {
    rlc8bitRegister(&HL.low);
    return 8;
}// RLC L

short CPU::extendedOpcode0x06() {
	byte reg = memory->read(HL.value) ;
	rlc8bitRegister(&reg);
	memory->write(HL.value, reg);

	return 16;
}// RLC (HL)

short CPU::extendedOpcode0x07() {
    rlc8bitRegister(&AF.hi);
    return 8;
}// RLC A

void CPU::rrc8bitRegister(byte *reg) {
	byte zeroBit = *reg & 0x01;
	*reg = *reg >> 1;

	clearFlags();
	if (zeroBit == 0x01) {
		raiseFlag(CARRY_FLAG);
	}
	if (*reg == 0) {
		raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x08() {
    rrc8bitRegister(&BC.hi);
    return 8;
}// RRC B

short CPU::extendedOpcode0x09() {
    rrc8bitRegister(&BC.low);
    return 8;
}// RRC C

short CPU::extendedOpcode0x0A() {
    rrc8bitRegister(&DE.hi);
    return 8;
}// RRC D

short CPU::extendedOpcode0x0B() {
    rrc8bitRegister(&DE.low);
    return 8;
}// RRC E

short CPU::extendedOpcode0x0C() {
    rrc8bitRegister(&HL.hi);
    return 8;
}// RRC H

short CPU::extendedOpcode0x0D() {
    rrc8bitRegister(&HL.low);
    return 8;
}// RRC L

short CPU::extendedOpcode0x0E() {
	byte reg = memory->read(HL.value) ;
	rrc8bitRegister(&reg);
	memory->write(HL.value, reg);
    return 16;
}// RRC (HL)

short CPU::extendedOpcode0x0F() {
	byte bit = AF.hi & 0x01;
	AF.hi >>= 1;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}

	if (AF.hi == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}

    return 8;
}// RRC A

void CPU::rl8bitRegister(byte *reg) {
	byte lastBit = *reg & 0x80;
	*reg <<= 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(&AF.hi, 7);
	} else {
		clearBit(&AF.hi, 7);
	}

	clearFlags();
	if (lastBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (AF.hi == 0) {
		raiseFlag(ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x10() {
    rl8bitRegister(&BC.hi);
    return 8;
}// rl B

short CPU::extendedOpcode0x11() {
    rl8bitRegister(&BC.low);
    return 8;
}// rl C

short CPU::extendedOpcode0x12() {
    rl8bitRegister(&DE.hi);
    return 8;
}// rl D

short CPU::extendedOpcode0x13() {
    rl8bitRegister(&DE.low);
    return 8;
}// rl E

short CPU::extendedOpcode0x14() {
    rl8bitRegister(&HL.hi);
    return 8;
}// rl H

short CPU::extendedOpcode0x15() {
    rl8bitRegister(&HL.low);
    return 8;
}// rl L

short CPU::extendedOpcode0x16() {
	byte reg = memory->read(HL.value);
	rl8bitRegister(&reg);
	memory->write(HL.value, reg);
    return 16;
}// rl (HL)

short CPU::extendedOpcode0x17() {

	byte bit = AF.hi & 0x80;

	byte carry = checkFlag(Flag::CARRY_FLAG) ? 0x01 : 0x00;
	AF.hi <<= carry;

	clearFlags();
	if (bit == 0x01) {
		raiseFlag(CARRY_FLAG);;
	}

	if (AF.hi == 0x0) {
		raiseFlag(ZERO_FLAG);
	}

	return 8;
}

void CPU::rr8bitRegister(byte *reg) {
	byte zeroBit = *reg & 0x01;
	*reg = *reg >> 1;

	if (checkFlag(Flag::CARRY_FLAG)) {
		setBit(reg, 7);
	} else {
		clearBit(reg, 7);
	}

	clearFlags();
	if (zeroBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (*reg == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x18() {
    rr8bitRegister(&BC.hi);
    return 8;
}// rr B

short CPU::extendedOpcode0x19() {
    rr8bitRegister(&BC.low);
    return 8;
}// rr C

short CPU::extendedOpcode0x1A() {
    rr8bitRegister(&DE.hi);
    return 8;
}// rr D

short CPU::extendedOpcode0x1B() {
    rr8bitRegister(&DE.low);
    return 8;
}// rr E

short CPU::extendedOpcode0x1C() {
    rr8bitRegister(&HL.hi);
    return 8;
}// rr H

short CPU::extendedOpcode0x1D() {
    rr8bitRegister(&HL.low);
    return 8;
}// rr L

short CPU::extendedOpcode0x1E() {
	byte reg = memory->read(HL.value);
	rr8bitRegister(&reg);
    memory->write(HL.value, reg);
    return 16;
}// rr (HL)

short CPU::extendedOpcode0x1F() {
    rr8bitRegister(&AF.hi);
    return 8;
}// rr A

void CPU::sla8bitRegister(byte *reg) {
	byte lastBit = *reg & 0x80;
	*reg <<= 1;

	clearFlags();
	if (lastBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
    if ( *reg == 0 ) {
        raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x20() {
    sla8bitRegister(&BC.hi);
    return 8;
}// sla B

short CPU::extendedOpcode0x21() {
    sla8bitRegister(&BC.low);
    return 8;
}// sla C

short CPU::extendedOpcode0x22() {
    sla8bitRegister(&DE.hi);
    return 8;
}// sla D

short CPU::extendedOpcode0x23() {
    sla8bitRegister(&DE.low);
    return 8;
}// sla E

short CPU::extendedOpcode0x24() {
    sla8bitRegister(&HL.hi);
    return 8;
}// sla H

short CPU::extendedOpcode0x25() {
    sla8bitRegister(&HL.low);
    return 8;
}// sla L

short CPU::extendedOpcode0x26() {
    byte reg = memory->read(HL.value);
	sla8bitRegister(&reg);
    memory->write(HL.value, reg);
    return 16;
}// sla (HL)

short CPU::extendedOpcode0x27() {
    sla8bitRegister(&AF.hi);
    return 8;
}// sla A

void CPU::sra8bitRegister(byte * reg) {
	byte firstBit = *reg & 0x01;
	byte lastBit = *reg & 0x80;

	*reg >>= 1;

	if (lastBit == 0x01) {
		setBit(reg, 7);
	} else {
		clearBit(reg, 7);
	}

	clearFlags();
	if (firstBit == 0x01) {
		raiseFlag(Flag::CARRY_FLAG);
	}
	if (*reg == 0x00) {
		raiseFlag(Flag::ZERO_FLAG);
	}
}

short CPU::extendedOpcode0x28() {
    sra8bitRegister(&BC.hi);
    return 8;
}// sra B

short CPU::extendedOpcode0x29() {
    sra8bitRegister(&BC.low);
    return 8;
}// sra C

short CPU::extendedOpcode0x2A() {
    sra8bitRegister(&DE.hi);
    return 8;
}// sra D

short CPU::extendedOpcode0x2B() {
    sra8bitRegister(&DE.low);
    return 8;
}// sra E

short CPU::extendedOpcode0x2C() {
    sra8bitRegister(&HL.hi);
    return 8;
}// sra H

short CPU::extendedOpcode0x2D(){
    sra8bitRegister(&HL.low);
    return 8;
}// sra L

short CPU::extendedOpcode0x2E() {
    byte data = memory->read(HL.value);
	sra8bitRegister(&data);
	memory->write(HL.value, data);
    return 16;
}// sra (HL)

short CPU::extendedOpcode0x2F() {
    sra8bitRegister(&AF.hi);
    return 8;
}// sra A

void CPU::swap8bitRegister(byte * reg) {
	clearFlags();

	*reg = (((*reg & 0xF0) >> 4) | ((*reg & 0x0F) << 4));

	if ( *reg == 0 ) {
        raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x30() {
    swap8bitRegister(&BC.hi);
    return 8;
}// swap B

short CPU::extendedOpcode0x31() {
    swap8bitRegister(&BC.low);
    return 8;
}// swap C

short CPU::extendedOpcode0x32() {
    swap8bitRegister(&DE.hi);
    return 8;
}// swap D

short CPU::extendedOpcode0x33() {
    swap8bitRegister(&DE.low);
    return 8;
}// swap E

short CPU::extendedOpcode0x34() {
    swap8bitRegister(&HL.hi);
    return 8;
}// swap H

short CPU::extendedOpcode0x35() {
    swap8bitRegister(&HL.low);
    return 8;
}// swap L

short CPU::extendedOpcode0x36() {
	clearFlags();
    byte data = memory->read(HL.value);
	data = (((data & 0xF0) >> 4) | ((data & 0x0F) << 4));

	if ( data == 0 ) {
        raiseFlag(ZERO_FLAG);
    }

    memory->write(HL.value, data);
    return 16;
}// swap (HL)

short CPU::extendedOpcode0x37() {
    swap8bitRegister(&AF.hi);
    return 8;
}// swap A

void CPU::srl8bitRegister(byte *reg) {
	byte firstBit = *reg & 0x01;
	*reg >>= 1;

	clearBit(reg, 7);

	clearFlags();
	if (firstBit == 0x01) {
        raiseFlag(CARRY_FLAG);
    }
	if (*reg == 0) {
        raiseFlag(ZERO_FLAG);
    }
}

short CPU::extendedOpcode0x38() {
    srl8bitRegister(&BC.hi);
    return 8;
}// SRL B

short CPU::extendedOpcode0x39() {
    srl8bitRegister(&BC.low);
    return 8;
}// SRL C

short CPU::extendedOpcode0x3A() {
    srl8bitRegister(&DE.hi);
    return 8;
}// SRL D

short CPU::extendedOpcode0x3B() {
    srl8bitRegister(&DE.low);
    return 8;
}// SRL E

short CPU::extendedOpcode0x3C() {
    srl8bitRegister(&HL.hi);
    return 8;
}// SRL H

short CPU::extendedOpcode0x3D() {
    srl8bitRegister(&HL.low);
    return 8;
}// SRL L

short CPU::extendedOpcode0x3E() {
    byte data = memory->read(HL.value);
	srl8bitRegister(&data);
	memory->write(HL.value, data);
    return 16;
}// SRL (HL)

short CPU::extendedOpcode0x3F() {
    srl8bitRegister(&AF.hi);
    return 8;
}// SRL A
<|endoftext|>


<commit_before>#include "stdafx.h"
#include "core/core.h"
#include "platform/dispatch.h"

#ifdef ENABLE_AUTO_TESTS
#include "platform/linux/test.h"
#endif

int main(int argc, char *argv[])
{
	Platform::init();
	std::string file_name;

	auto ram_saver = [&](const u8* data, u32 size)
	{
		std::ofstream to_save(file_name + "_ram", std::ios_base::trunc);
		to_save.write(reinterpret_cast<const char*>(data), size * sizeof(u8));
	};

	auto rtc_saver = [&](std::chrono::seconds epoch, const u8* data, u32 size)
	{
		std::ofstream to_save(file_name + "_rtc", std::ios_base::trunc);
		to_save << epoch.count();
		to_save.write(reinterpret_cast<const char*>(data), size * sizeof(u8));
	};

	Core emu_core;

#ifndef ENABLE_AUTO_TESTS
	Platform::Audio audio_post;
	Platform::Gui gui(3*160, 3*144, "GBE");
	Platform::Renderer renderer(gui.get_display());

	external_callbacks endpoints;

	endpoints.save_ram = function<void(const u8*, u32)>(ram_saver);
	endpoints.save_rtc = function<void(std::chrono::seconds, const u8*, u32)>(rtc_saver);
	endpoints.audio_control = make_function(&Platform::Audio::dummy, &audio_post);
	endpoints.swap_sample_buffer = make_function(&Platform::Audio::swap_buffers, &audio_post);
	endpoints.update_input = make_function(&Platform::Gui::input_handler, &gui);
	endpoints.draw_frame = make_function(&Platform::Renderer::vblank_handler, &renderer);
#else
	Platform::Gui gui(3*160, 3*140, "GBE");
	Platform::Renderer renderer(gui.get_display());
	Tester tester;
	external_callbacks endpoints;

	tester.attach_renderer(make_function(&Platform::Renderer::vblank_handler, &renderer));

	endpoints.save_ram = function<void(const u8*, u32)>(ram_saver);
	endpoints.save_rtc = function<void(std::chrono::seconds, const u8*, u32)>(rtc_saver);
	endpoints.audio_control = make_function(&Tester::audio_dummy_ctrl, &tester);
	endpoints.swap_sample_buffer = make_function(&Tester::audio_dummy_swap, &tester);
	endpoints.update_input = make_function(&Tester::input_stub, &tester);
	endpoints.draw_frame = make_function(&Tester::render_stub, &tester);
#endif

	emu_core.attach_callbacks(endpoints);

#ifndef ENABLE_AUTO_TESTS
	while (true)
	{
		std::cout << "Insert cartrige path:\n";
		std::cin >> file_name;

		std::ifstream rom(file_name);

		if (rom.is_open())
		{
			std::ifstream ram(file_name + "_ram"), rtc(file_name + "_rtc");

			emu_core.load_cartrige(rom, ram, rtc);
			std::string cart_name = emu_core.get_cart_name();
			gui.set_window_title(cart_name);

			std::cout << "Cartrige loaded!\n";
			break;
		}

		std::cout << "Failed to load cartrige!\n";
	}

#else
	std::ifstream rom(argv[1]);

	if (rom.is_open())
	{
		std::ifstream ram(file_name + "_ram"), rtc(file_name + "_rtc");
		emu_core.load_cartrige(rom, ram, rtc);
	}
#endif

	emu_core.run();
	return 0;
}
<commit_msg>fix for tester GUI<commit_after>#include "stdafx.h"
#include "core/core.h"
#include "platform/dispatch.h"

#ifdef ENABLE_AUTO_TESTS
#include "platform/linux/test.h"
#endif

int main(int argc, char *argv[])
{
	Platform::init();
	std::string file_name;

	auto ram_saver = [&](const u8* data, u32 size)
	{
		std::ofstream to_save(file_name + "_ram", std::ios_base::trunc);
		to_save.write(reinterpret_cast<const char*>(data), size * sizeof(u8));
	};

	auto rtc_saver = [&](std::chrono::seconds epoch, const u8* data, u32 size)
	{
		std::ofstream to_save(file_name + "_rtc", std::ios_base::trunc);
		to_save << epoch.count();
		to_save.write(reinterpret_cast<const char*>(data), size * sizeof(u8));
	};

	Core emu_core;

#ifndef ENABLE_AUTO_TESTS
	Platform::Audio audio_post;
	Platform::Gui gui(3*160, 3*144, "GBE");
	Platform::Renderer renderer(gui.get_display());

	external_callbacks endpoints;

	endpoints.save_ram = function<void(const u8*, u32)>(ram_saver);
	endpoints.save_rtc = function<void(std::chrono::seconds, const u8*, u32)>(rtc_saver);
	endpoints.audio_control = make_function(&Platform::Audio::dummy, &audio_post);
	endpoints.swap_sample_buffer = make_function(&Platform::Audio::swap_buffers, &audio_post);
	endpoints.update_input = make_function(&Platform::Gui::input_handler, &gui);
	endpoints.draw_frame = make_function(&Platform::Renderer::vblank_handler, &renderer);
#else
	Platform::Gui gui(3*160, 3*144, "GBE");
	Platform::Renderer renderer(gui.get_display());
	Tester tester;
	external_callbacks endpoints;

	tester.attach_renderer(make_function(&Platform::Renderer::vblank_handler, &renderer));

	endpoints.save_ram = function<void(const u8*, u32)>(ram_saver);
	endpoints.save_rtc = function<void(std::chrono::seconds, const u8*, u32)>(rtc_saver);
	endpoints.audio_control = make_function(&Tester::audio_dummy_ctrl, &tester);
	endpoints.swap_sample_buffer = make_function(&Tester::audio_dummy_swap, &tester);
	endpoints.update_input = make_function(&Tester::input_stub, &tester);
	endpoints.draw_frame = make_function(&Tester::render_stub, &tester);
#endif

	emu_core.attach_callbacks(endpoints);

#ifndef ENABLE_AUTO_TESTS
	while (true)
	{
		std::cout << "Insert cartrige path:\n";
		std::cin >> file_name;

		std::ifstream rom(file_name);

		if (rom.is_open())
		{
			std::ifstream ram(file_name + "_ram"), rtc(file_name + "_rtc");

			emu_core.load_cartrige(rom, ram, rtc);
			std::string cart_name = emu_core.get_cart_name();
			gui.set_window_title(cart_name);

			std::cout << "Cartrige loaded!\n";
			break;
		}

		std::cout << "Failed to load cartrige!\n";
	}

#else
	std::ifstream rom(argv[1]);

	if (rom.is_open())
	{
		std::ifstream ram(file_name + "_ram"), rtc(file_name + "_rtc");
		emu_core.load_cartrige(rom, ram, rtc);
	}
#endif

	emu_core.run();
	return 0;
}
<|endoftext|>


<commit_before><commit_msg>Fixed build warnings in x86<commit_after><|endoftext|>


<commit_before><commit_msg>Fixed to make compile.<commit_after><|endoftext|>


<commit_before><commit_msg>Bugfix<commit_after><|endoftext|>


<commit_before>// Copyright (c) 2011 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 "webkit/glue/webpreferences.h"

#include <unicode/uchar.h>

#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webkit_glue.h"

using WebKit::WebNetworkStateNotifier;
using WebKit::WebRuntimeFeatures;
using WebKit::WebSettings;
using WebKit::WebString;
using WebKit::WebURL;
using WebKit::WebView;

WebPreferences::WebPreferences()
    : standard_font_family(ASCIIToUTF16("Times New Roman")),
      fixed_font_family(ASCIIToUTF16("Courier New")),
      serif_font_family(ASCIIToUTF16("Times New Roman")),
      sans_serif_font_family(ASCIIToUTF16("Arial")),
      cursive_font_family(ASCIIToUTF16("Script")),
      fantasy_font_family(),  // Not sure what to use on Windows.
      default_font_size(16),
      default_fixed_font_size(13),
      minimum_font_size(0),
      minimum_logical_font_size(6),
      default_encoding("ISO-8859-1"),
      javascript_enabled(true),
      web_security_enabled(true),
      javascript_can_open_windows_automatically(true),
      loads_images_automatically(true),
      plugins_enabled(true),
      dom_paste_enabled(false),  // enables execCommand("paste")
      developer_extras_enabled(false),  // Requires extra work by embedder
      site_specific_quirks_enabled(false),
      shrinks_standalone_images_to_fit(true),
      uses_universal_detector(false),  // Disabled: page cycler regression
      text_areas_are_resizable(true),
      java_enabled(true),
      allow_scripts_to_close_windows(false),
      uses_page_cache(false),
      remote_fonts_enabled(true),
      javascript_can_access_clipboard(false),
      xss_auditor_enabled(false),
      dns_prefetching_enabled(true),
      local_storage_enabled(false),
      databases_enabled(false),
      application_cache_enabled(false),
      tabs_to_links(true),
      caret_browsing_enabled(false),
      hyperlink_auditing_enabled(true),
      is_online(true),
      user_style_sheet_enabled(false),
      author_and_user_styles_enabled(true),
      frame_flattening_enabled(false),
      allow_universal_access_from_file_urls(false),
      allow_file_access_from_file_urls(false),
      webaudio_enabled(false),
      experimental_webgl_enabled(false),
      gl_multisampling_enabled(true),
      show_composited_layer_borders(false),
      show_composited_layer_tree(false),
      show_fps_counter(false),
      asynchronous_spell_checking_enabled(true),
      accelerated_compositing_enabled(false),
      force_compositing_mode(false),
      allow_webui_compositing(false),
      composite_to_texture_enabled(false),
      accelerated_layers_enabled(false),
      accelerated_video_enabled(false),
      accelerated_2d_canvas_enabled(false),
      accelerated_drawing_enabled(false),
      accelerated_plugins_enabled(false),
      memory_info_enabled(false),
      interactive_form_validation_enabled(true),
      fullscreen_enabled(false),
      allow_displaying_insecure_content(true),
      allow_running_insecure_content(false),
      should_print_backgrounds(false),
      enable_scroll_animator(false),
      hixie76_websocket_protocol_enabled(false) {
}

WebPreferences::~WebPreferences() {
}

namespace {

void setStandardFontFamilyWrapper(WebSettings* settings,
                                  const string16& font,
                                  UScriptCode script) {
  settings->setStandardFontFamily(font, script);
}

void setFixedFontFamilyWrapper(WebSettings* settings,
                               const string16& font,
                               UScriptCode script) {
  settings->setFixedFontFamily(font, script);
}

void setSerifFontFamilyWrapper(WebSettings* settings,
                               const string16& font,
                               UScriptCode script) {
  settings->setSerifFontFamily(font, script);
}

void setSansSerifFontFamilyWrapper(WebSettings* settings,
                                   const string16& font,
                                   UScriptCode script) {
  settings->setSansSerifFontFamily(font, script);
}

void setCursiveFontFamilyWrapper(WebSettings* settings,
                                 const string16& font,
                                 UScriptCode script) {
  settings->setCursiveFontFamily(font, script);
}

void setFantasyFontFamilyWrapper(WebSettings* settings,
                                 const string16& font,
                                 UScriptCode script) {
  settings->setFantasyFontFamily(font, script);
}

typedef void (*SetFontFamilyWrapper)(
    WebKit::WebSettings*, const string16&, UScriptCode);

void ApplyFontsFromMap(const WebPreferences::ScriptFontFamilyMap& map,
                       SetFontFamilyWrapper setter,
                       WebSettings* settings) {
  for (WebPreferences::ScriptFontFamilyMap::const_iterator it = map.begin();
       it != map.end(); ++it) {
    int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
    if (script >= 0 && script < USCRIPT_CODE_LIMIT)
      (*setter)(settings, it->second, (UScriptCode) script);
  }
}

}  // namespace

void WebPreferences::Apply(WebView* web_view) const {
  WebSettings* settings = web_view->settings();
  settings->setStandardFontFamily(standard_font_family);
  settings->setFixedFontFamily(fixed_font_family);
  settings->setSerifFontFamily(serif_font_family);
  settings->setSansSerifFontFamily(sans_serif_font_family);
  settings->setCursiveFontFamily(cursive_font_family);
  settings->setFantasyFontFamily(fantasy_font_family);
  ApplyFontsFromMap(standard_font_family_map, setStandardFontFamilyWrapper,
                    settings);
  ApplyFontsFromMap(fixed_font_family_map, setFixedFontFamilyWrapper, settings);
  ApplyFontsFromMap(serif_font_family_map, setSerifFontFamilyWrapper, settings);
  ApplyFontsFromMap(sans_serif_font_family_map, setSansSerifFontFamilyWrapper,
                    settings);
  ApplyFontsFromMap(cursive_font_family_map, setCursiveFontFamilyWrapper,
                    settings);
  ApplyFontsFromMap(fantasy_font_family_map, setFantasyFontFamilyWrapper,
                    settings);
  settings->setDefaultFontSize(default_font_size);
  settings->setDefaultFixedFontSize(default_fixed_font_size);
  settings->setMinimumFontSize(minimum_font_size);
  settings->setMinimumLogicalFontSize(minimum_logical_font_size);
  settings->setDefaultTextEncodingName(ASCIIToUTF16(default_encoding));
  settings->setJavaScriptEnabled(javascript_enabled);
  settings->setWebSecurityEnabled(web_security_enabled);
  settings->setJavaScriptCanOpenWindowsAutomatically(
      javascript_can_open_windows_automatically);
  settings->setLoadsImagesAutomatically(loads_images_automatically);
  settings->setPluginsEnabled(plugins_enabled);
  settings->setDOMPasteAllowed(dom_paste_enabled);
  settings->setDeveloperExtrasEnabled(developer_extras_enabled);
  settings->setNeedsSiteSpecificQuirks(site_specific_quirks_enabled);
  settings->setShrinksStandaloneImagesToFit(shrinks_standalone_images_to_fit);
  settings->setUsesEncodingDetector(uses_universal_detector);
  settings->setTextAreasAreResizable(text_areas_are_resizable);
  settings->setAllowScriptsToCloseWindows(allow_scripts_to_close_windows);
  if (user_style_sheet_enabled)
    settings->setUserStyleSheetLocation(user_style_sheet_location);
  else
    settings->setUserStyleSheetLocation(WebURL());
  settings->setAuthorAndUserStylesEnabled(author_and_user_styles_enabled);
  settings->setUsesPageCache(uses_page_cache);
  settings->setDownloadableBinaryFontsEnabled(remote_fonts_enabled);
  settings->setJavaScriptCanAccessClipboard(javascript_can_access_clipboard);
  settings->setXSSAuditorEnabled(xss_auditor_enabled);
  settings->setDNSPrefetchingEnabled(dns_prefetching_enabled);
  settings->setLocalStorageEnabled(local_storage_enabled);
  WebRuntimeFeatures::enableDatabase(
      WebRuntimeFeatures::isDatabaseEnabled() || databases_enabled);
  settings->setOfflineWebApplicationCacheEnabled(application_cache_enabled);
  settings->setCaretBrowsingEnabled(caret_browsing_enabled);
  settings->setHyperlinkAuditingEnabled(hyperlink_auditing_enabled);

  // This setting affects the behavior of links in an editable region:
  // clicking the link should select it rather than navigate to it.
  // Safari uses the same default. It is unlikley an embedder would want to
  // change this, since it would break existing rich text editors.
  settings->setEditableLinkBehaviorNeverLive();

  settings->setFrameFlatteningEnabled(frame_flattening_enabled);

  settings->setFontRenderingModeNormal();
  settings->setJavaEnabled(java_enabled);

  // Turn this on to cause WebCore to paint the resize corner for us.
  settings->setShouldPaintCustomScrollbars(true);

  // By default, allow_universal_access_from_file_urls is set to false and thus
  // we mitigate attacks from local HTML files by not granting file:// URLs
  // universal access. Only test shell will enable this.
  settings->setAllowUniversalAccessFromFileURLs(
      allow_universal_access_from_file_urls);
  settings->setAllowFileAccessFromFileURLs(allow_file_access_from_file_urls);

  // We prevent WebKit from checking if it needs to add a "text direction"
  // submenu to a context menu. it is not only because we don't need the result
  // but also because it cause a possible crash in Editor::hasBidiSelection().
  settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded();

  // Enable the web audio API if requested on the command line.
  settings->setWebAudioEnabled(webaudio_enabled);

  // Enable experimental WebGL support if requested on command line
  // and support is compiled in.
  settings->setExperimentalWebGLEnabled(experimental_webgl_enabled);

  // Disable GL multisampling if requested on command line.
  settings->setOpenGLMultisamplingEnabled(gl_multisampling_enabled);

  // Display colored borders around composited render layers if requested
  // on command line.
  settings->setShowDebugBorders(show_composited_layer_borders);

  // Display an FPS indicator if requested on the command line.
  settings->setShowFPSCounter(show_fps_counter);

  // Display the current compositor tree as overlay if requested on
  // the command line
  settings->setShowPlatformLayerTree(show_composited_layer_tree);

  // Enable gpu-accelerated compositing if requested on the command line.
  settings->setAcceleratedCompositingEnabled(accelerated_compositing_enabled);

  // Always enter compositing if requested on the command line.
  settings->setForceCompositingMode(force_compositing_mode);

  // Enable composite to offscreen texture if requested on the command line.
  settings->setCompositeToTextureEnabled(composite_to_texture_enabled);

  // Enable gpu-accelerated 2d canvas if requested on the command line.
  settings->setAccelerated2dCanvasEnabled(accelerated_2d_canvas_enabled);

  // Enable gpu-accelerated drawing if requested on the command line.
  settings->setAcceleratedDrawingEnabled(accelerated_drawing_enabled);

  // Enabling accelerated layers from the command line enabled accelerated
  // 3D CSS, Video, and Animations.
  settings->setAcceleratedCompositingFor3DTransformsEnabled(
      accelerated_layers_enabled);
  settings->setAcceleratedCompositingForVideoEnabled(
      accelerated_video_enabled);
  settings->setAcceleratedCompositingForAnimationEnabled(
      accelerated_layers_enabled);

  // Enabling accelerated plugins if specified from the command line.
  settings->setAcceleratedCompositingForPluginsEnabled(
      accelerated_plugins_enabled);

  // WebGL and accelerated 2D canvas are always gpu composited.
  settings->setAcceleratedCompositingForCanvasEnabled(
      experimental_webgl_enabled || accelerated_2d_canvas_enabled);

  // Enable memory info reporting to page if requested on the command line.
  settings->setMemoryInfoEnabled(memory_info_enabled);

  settings->setAsynchronousSpellCheckingEnabled(
      asynchronous_spell_checking_enabled);

  for (WebInspectorPreferences::const_iterator it = inspector_settings.begin();
       it != inspector_settings.end(); ++it)
    web_view->setInspectorSetting(WebString::fromUTF8(it->first),
                                  WebString::fromUTF8(it->second));

  // Tabs to link is not part of the settings. WebCore calls
  // ChromeClient::tabsToLinks which is part of the glue code.
  web_view->setTabsToLinks(tabs_to_links);

  settings->setInteractiveFormValidationEnabled(
      interactive_form_validation_enabled);

  settings->setFullScreenEnabled(fullscreen_enabled);
  settings->setAllowDisplayOfInsecureContent(allow_displaying_insecure_content);
  settings->setAllowRunningOfInsecureContent(allow_running_insecure_content);
  settings->setShouldPrintBackgrounds(should_print_backgrounds);
  settings->setEnableScrollAnimator(enable_scroll_animator);
  settings->setHixie76WebSocketProtocolEnabled(
      hixie76_websocket_protocol_enabled);

  WebNetworkStateNotifier::setOnLine(is_online);
}
<commit_msg>This function no longer does anything.  Remove the caller so we can delete the function.  andersca tells me this comment is wrong and that this setting doesn't actually affect the resize corner.<commit_after>// Copyright (c) 2011 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 "webkit/glue/webpreferences.h"

#include <unicode/uchar.h>

#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRuntimeFeatures.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "webkit/glue/webkit_glue.h"

using WebKit::WebNetworkStateNotifier;
using WebKit::WebRuntimeFeatures;
using WebKit::WebSettings;
using WebKit::WebString;
using WebKit::WebURL;
using WebKit::WebView;

WebPreferences::WebPreferences()
    : standard_font_family(ASCIIToUTF16("Times New Roman")),
      fixed_font_family(ASCIIToUTF16("Courier New")),
      serif_font_family(ASCIIToUTF16("Times New Roman")),
      sans_serif_font_family(ASCIIToUTF16("Arial")),
      cursive_font_family(ASCIIToUTF16("Script")),
      fantasy_font_family(),  // Not sure what to use on Windows.
      default_font_size(16),
      default_fixed_font_size(13),
      minimum_font_size(0),
      minimum_logical_font_size(6),
      default_encoding("ISO-8859-1"),
      javascript_enabled(true),
      web_security_enabled(true),
      javascript_can_open_windows_automatically(true),
      loads_images_automatically(true),
      plugins_enabled(true),
      dom_paste_enabled(false),  // enables execCommand("paste")
      developer_extras_enabled(false),  // Requires extra work by embedder
      site_specific_quirks_enabled(false),
      shrinks_standalone_images_to_fit(true),
      uses_universal_detector(false),  // Disabled: page cycler regression
      text_areas_are_resizable(true),
      java_enabled(true),
      allow_scripts_to_close_windows(false),
      uses_page_cache(false),
      remote_fonts_enabled(true),
      javascript_can_access_clipboard(false),
      xss_auditor_enabled(false),
      dns_prefetching_enabled(true),
      local_storage_enabled(false),
      databases_enabled(false),
      application_cache_enabled(false),
      tabs_to_links(true),
      caret_browsing_enabled(false),
      hyperlink_auditing_enabled(true),
      is_online(true),
      user_style_sheet_enabled(false),
      author_and_user_styles_enabled(true),
      frame_flattening_enabled(false),
      allow_universal_access_from_file_urls(false),
      allow_file_access_from_file_urls(false),
      webaudio_enabled(false),
      experimental_webgl_enabled(false),
      gl_multisampling_enabled(true),
      show_composited_layer_borders(false),
      show_composited_layer_tree(false),
      show_fps_counter(false),
      asynchronous_spell_checking_enabled(true),
      accelerated_compositing_enabled(false),
      force_compositing_mode(false),
      allow_webui_compositing(false),
      composite_to_texture_enabled(false),
      accelerated_layers_enabled(false),
      accelerated_video_enabled(false),
      accelerated_2d_canvas_enabled(false),
      accelerated_drawing_enabled(false),
      accelerated_plugins_enabled(false),
      memory_info_enabled(false),
      interactive_form_validation_enabled(true),
      fullscreen_enabled(false),
      allow_displaying_insecure_content(true),
      allow_running_insecure_content(false),
      should_print_backgrounds(false),
      enable_scroll_animator(false),
      hixie76_websocket_protocol_enabled(false) {
}

WebPreferences::~WebPreferences() {
}

namespace {

void setStandardFontFamilyWrapper(WebSettings* settings,
                                  const string16& font,
                                  UScriptCode script) {
  settings->setStandardFontFamily(font, script);
}

void setFixedFontFamilyWrapper(WebSettings* settings,
                               const string16& font,
                               UScriptCode script) {
  settings->setFixedFontFamily(font, script);
}

void setSerifFontFamilyWrapper(WebSettings* settings,
                               const string16& font,
                               UScriptCode script) {
  settings->setSerifFontFamily(font, script);
}

void setSansSerifFontFamilyWrapper(WebSettings* settings,
                                   const string16& font,
                                   UScriptCode script) {
  settings->setSansSerifFontFamily(font, script);
}

void setCursiveFontFamilyWrapper(WebSettings* settings,
                                 const string16& font,
                                 UScriptCode script) {
  settings->setCursiveFontFamily(font, script);
}

void setFantasyFontFamilyWrapper(WebSettings* settings,
                                 const string16& font,
                                 UScriptCode script) {
  settings->setFantasyFontFamily(font, script);
}

typedef void (*SetFontFamilyWrapper)(
    WebKit::WebSettings*, const string16&, UScriptCode);

void ApplyFontsFromMap(const WebPreferences::ScriptFontFamilyMap& map,
                       SetFontFamilyWrapper setter,
                       WebSettings* settings) {
  for (WebPreferences::ScriptFontFamilyMap::const_iterator it = map.begin();
       it != map.end(); ++it) {
    int32 script = u_getPropertyValueEnum(UCHAR_SCRIPT, (it->first).c_str());
    if (script >= 0 && script < USCRIPT_CODE_LIMIT)
      (*setter)(settings, it->second, (UScriptCode) script);
  }
}

}  // namespace

void WebPreferences::Apply(WebView* web_view) const {
  WebSettings* settings = web_view->settings();
  settings->setStandardFontFamily(standard_font_family);
  settings->setFixedFontFamily(fixed_font_family);
  settings->setSerifFontFamily(serif_font_family);
  settings->setSansSerifFontFamily(sans_serif_font_family);
  settings->setCursiveFontFamily(cursive_font_family);
  settings->setFantasyFontFamily(fantasy_font_family);
  ApplyFontsFromMap(standard_font_family_map, setStandardFontFamilyWrapper,
                    settings);
  ApplyFontsFromMap(fixed_font_family_map, setFixedFontFamilyWrapper, settings);
  ApplyFontsFromMap(serif_font_family_map, setSerifFontFamilyWrapper, settings);
  ApplyFontsFromMap(sans_serif_font_family_map, setSansSerifFontFamilyWrapper,
                    settings);
  ApplyFontsFromMap(cursive_font_family_map, setCursiveFontFamilyWrapper,
                    settings);
  ApplyFontsFromMap(fantasy_font_family_map, setFantasyFontFamilyWrapper,
                    settings);
  settings->setDefaultFontSize(default_font_size);
  settings->setDefaultFixedFontSize(default_fixed_font_size);
  settings->setMinimumFontSize(minimum_font_size);
  settings->setMinimumLogicalFontSize(minimum_logical_font_size);
  settings->setDefaultTextEncodingName(ASCIIToUTF16(default_encoding));
  settings->setJavaScriptEnabled(javascript_enabled);
  settings->setWebSecurityEnabled(web_security_enabled);
  settings->setJavaScriptCanOpenWindowsAutomatically(
      javascript_can_open_windows_automatically);
  settings->setLoadsImagesAutomatically(loads_images_automatically);
  settings->setPluginsEnabled(plugins_enabled);
  settings->setDOMPasteAllowed(dom_paste_enabled);
  settings->setDeveloperExtrasEnabled(developer_extras_enabled);
  settings->setNeedsSiteSpecificQuirks(site_specific_quirks_enabled);
  settings->setShrinksStandaloneImagesToFit(shrinks_standalone_images_to_fit);
  settings->setUsesEncodingDetector(uses_universal_detector);
  settings->setTextAreasAreResizable(text_areas_are_resizable);
  settings->setAllowScriptsToCloseWindows(allow_scripts_to_close_windows);
  if (user_style_sheet_enabled)
    settings->setUserStyleSheetLocation(user_style_sheet_location);
  else
    settings->setUserStyleSheetLocation(WebURL());
  settings->setAuthorAndUserStylesEnabled(author_and_user_styles_enabled);
  settings->setUsesPageCache(uses_page_cache);
  settings->setDownloadableBinaryFontsEnabled(remote_fonts_enabled);
  settings->setJavaScriptCanAccessClipboard(javascript_can_access_clipboard);
  settings->setXSSAuditorEnabled(xss_auditor_enabled);
  settings->setDNSPrefetchingEnabled(dns_prefetching_enabled);
  settings->setLocalStorageEnabled(local_storage_enabled);
  WebRuntimeFeatures::enableDatabase(
      WebRuntimeFeatures::isDatabaseEnabled() || databases_enabled);
  settings->setOfflineWebApplicationCacheEnabled(application_cache_enabled);
  settings->setCaretBrowsingEnabled(caret_browsing_enabled);
  settings->setHyperlinkAuditingEnabled(hyperlink_auditing_enabled);

  // This setting affects the behavior of links in an editable region:
  // clicking the link should select it rather than navigate to it.
  // Safari uses the same default. It is unlikley an embedder would want to
  // change this, since it would break existing rich text editors.
  settings->setEditableLinkBehaviorNeverLive();

  settings->setFrameFlatteningEnabled(frame_flattening_enabled);

  settings->setFontRenderingModeNormal();
  settings->setJavaEnabled(java_enabled);

  // By default, allow_universal_access_from_file_urls is set to false and thus
  // we mitigate attacks from local HTML files by not granting file:// URLs
  // universal access. Only test shell will enable this.
  settings->setAllowUniversalAccessFromFileURLs(
      allow_universal_access_from_file_urls);
  settings->setAllowFileAccessFromFileURLs(allow_file_access_from_file_urls);

  // We prevent WebKit from checking if it needs to add a "text direction"
  // submenu to a context menu. it is not only because we don't need the result
  // but also because it cause a possible crash in Editor::hasBidiSelection().
  settings->setTextDirectionSubmenuInclusionBehaviorNeverIncluded();

  // Enable the web audio API if requested on the command line.
  settings->setWebAudioEnabled(webaudio_enabled);

  // Enable experimental WebGL support if requested on command line
  // and support is compiled in.
  settings->setExperimentalWebGLEnabled(experimental_webgl_enabled);

  // Disable GL multisampling if requested on command line.
  settings->setOpenGLMultisamplingEnabled(gl_multisampling_enabled);

  // Display colored borders around composited render layers if requested
  // on command line.
  settings->setShowDebugBorders(show_composited_layer_borders);

  // Display an FPS indicator if requested on the command line.
  settings->setShowFPSCounter(show_fps_counter);

  // Display the current compositor tree as overlay if requested on
  // the command line
  settings->setShowPlatformLayerTree(show_composited_layer_tree);

  // Enable gpu-accelerated compositing if requested on the command line.
  settings->setAcceleratedCompositingEnabled(accelerated_compositing_enabled);

  // Always enter compositing if requested on the command line.
  settings->setForceCompositingMode(force_compositing_mode);

  // Enable composite to offscreen texture if requested on the command line.
  settings->setCompositeToTextureEnabled(composite_to_texture_enabled);

  // Enable gpu-accelerated 2d canvas if requested on the command line.
  settings->setAccelerated2dCanvasEnabled(accelerated_2d_canvas_enabled);

  // Enable gpu-accelerated drawing if requested on the command line.
  settings->setAcceleratedDrawingEnabled(accelerated_drawing_enabled);

  // Enabling accelerated layers from the command line enabled accelerated
  // 3D CSS, Video, and Animations.
  settings->setAcceleratedCompositingFor3DTransformsEnabled(
      accelerated_layers_enabled);
  settings->setAcceleratedCompositingForVideoEnabled(
      accelerated_video_enabled);
  settings->setAcceleratedCompositingForAnimationEnabled(
      accelerated_layers_enabled);

  // Enabling accelerated plugins if specified from the command line.
  settings->setAcceleratedCompositingForPluginsEnabled(
      accelerated_plugins_enabled);

  // WebGL and accelerated 2D canvas are always gpu composited.
  settings->setAcceleratedCompositingForCanvasEnabled(
      experimental_webgl_enabled || accelerated_2d_canvas_enabled);

  // Enable memory info reporting to page if requested on the command line.
  settings->setMemoryInfoEnabled(memory_info_enabled);

  settings->setAsynchronousSpellCheckingEnabled(
      asynchronous_spell_checking_enabled);

  for (WebInspectorPreferences::const_iterator it = inspector_settings.begin();
       it != inspector_settings.end(); ++it)
    web_view->setInspectorSetting(WebString::fromUTF8(it->first),
                                  WebString::fromUTF8(it->second));

  // Tabs to link is not part of the settings. WebCore calls
  // ChromeClient::tabsToLinks which is part of the glue code.
  web_view->setTabsToLinks(tabs_to_links);

  settings->setInteractiveFormValidationEnabled(
      interactive_form_validation_enabled);

  settings->setFullScreenEnabled(fullscreen_enabled);
  settings->setAllowDisplayOfInsecureContent(allow_displaying_insecure_content);
  settings->setAllowRunningOfInsecureContent(allow_running_insecure_content);
  settings->setShouldPrintBackgrounds(should_print_backgrounds);
  settings->setEnableScrollAnimator(enable_scroll_animator);
  settings->setHixie76WebSocketProtocolEnabled(
      hixie76_websocket_protocol_enabled);

  WebNetworkStateNotifier::setOnLine(is_online);
}
<|endoftext|>


<commit_before>//===- PrintSCC.cpp - Enumerate SCCs in some key graphs -------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file provides passes to print out SCCs in a CFG or a CallGraph.
// Normally, you would not use these passes; instead, you would use the
// scc_iterator directly to enumerate SCCs and process them in some way.  These
// passes serve three purposes:
//
// (1) As a reference for how to use the scc_iterator.
// (2) To print out the SCCs for a CFG or a CallGraph:
//       analyze -print-cfg-sccs            to print the SCCs in each CFG of a module.
//       analyze -print-cfg-sccs -stats     to print the #SCCs and the maximum SCC size.
//       analyze -print-cfg-sccs -debug > /dev/null to watch the algorithm in action.
//
//     and similarly:
//       analyze -print-callgraph-sccs [-stats] [-debug] to print SCCs in the CallGraph
//
// (3) To test the scc_iterator.
//
//===----------------------------------------------------------------------===//

#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SCCIterator.h"
using namespace llvm;

namespace {
  struct CFGSCC : public FunctionPass {
    static char ID;  // Pass identification, replacement for typeid
    CFGSCC() : FunctionPass(ID) {}
    bool runOnFunction(Function& func);

    void print(raw_ostream &O, const Module* = 0) const { }

    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }
  };

  struct CallGraphSCC : public ModulePass {
    static char ID;  // Pass identification, replacement for typeid
    CallGraphSCC() : ModulePass(ID) {}

    // run - Print out SCCs in the call graph for the specified module.
    bool runOnModule(Module &M);

    void print(raw_ostream &O, const Module* = 0) const { }

    // getAnalysisUsage - This pass requires the CallGraph.
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
      AU.addRequired<CallGraph>();
    }
  };

  char CFGSCC::ID = 0;
  RegisterPass<CFGSCC>
  Y("print-cfg-sccs", "Print SCCs of each function CFG");

  char CallGraphSCC::ID = 0;
  RegisterPass<CallGraphSCC>
  Z("print-callgraph-sccs", "Print SCCs of the Call Graph");
}

bool CFGSCC::runOnFunction(Function &F) {
  unsigned sccNum = 0;
  outs() << "SCCs for Function " << F.getName() << " in PostOrder:";
  for (scc_iterator<Function*> SCCI = scc_begin(&F),
         E = scc_end(&F); SCCI != E; ++SCCI) {
    std::vector<BasicBlock*> &nextSCC = *SCCI;
    outs() << "\nSCC #" << ++sccNum << " : ";
    for (std::vector<BasicBlock*>::const_iterator I = nextSCC.begin(),
           E = nextSCC.end(); I != E; ++I)
      outs() << (*I)->getName() << ", ";
    if (nextSCC.size() == 1 && SCCI.hasLoop())
      outs() << " (Has self-loop).";
  }
  outs() << "\n";

  return true;
}

// run - Print out SCCs in the call graph for the specified module.
bool CallGraphSCC::runOnModule(Module &M) {
  CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot();
  unsigned sccNum = 0;
  outs() << "SCCs for the program in PostOrder:";
  for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode),
         E = scc_end(rootNode); SCCI != E; ++SCCI) {
    const std::vector<CallGraphNode*> &nextSCC = *SCCI;
    outs() << "\nSCC #" << ++sccNum << " : ";
    for (std::vector<CallGraphNode*>::const_iterator I = nextSCC.begin(),
           E = nextSCC.end(); I != E; ++I)
      outs() << ((*I)->getFunction() ? (*I)->getFunction()->getNameStr()
                 : std::string("external node")) << ", ";
    if (nextSCC.size() == 1 && SCCI.hasLoop())
      outs() << " (Has self-loop).";
  }
  outs() << "\n";

  return true;
}
<commit_msg>Minor cleanups to follow the common convention for pass registration variables.<commit_after>//===- PrintSCC.cpp - Enumerate SCCs in some key graphs -------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file provides passes to print out SCCs in a CFG or a CallGraph.
// Normally, you would not use these passes; instead, you would use the
// scc_iterator directly to enumerate SCCs and process them in some way.  These
// passes serve three purposes:
//
// (1) As a reference for how to use the scc_iterator.
// (2) To print out the SCCs for a CFG or a CallGraph:
//       analyze -print-cfg-sccs            to print the SCCs in each CFG of a module.
//       analyze -print-cfg-sccs -stats     to print the #SCCs and the maximum SCC size.
//       analyze -print-cfg-sccs -debug > /dev/null to watch the algorithm in action.
//
//     and similarly:
//       analyze -print-callgraph-sccs [-stats] [-debug] to print SCCs in the CallGraph
//
// (3) To test the scc_iterator.
//
//===----------------------------------------------------------------------===//

#include "llvm/Pass.h"
#include "llvm/Module.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SCCIterator.h"
using namespace llvm;

namespace {
  struct CFGSCC : public FunctionPass {
    static char ID;  // Pass identification, replacement for typeid
    CFGSCC() : FunctionPass(ID) {}
    bool runOnFunction(Function& func);

    void print(raw_ostream &O, const Module* = 0) const { }

    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }
  };

  struct CallGraphSCC : public ModulePass {
    static char ID;  // Pass identification, replacement for typeid
    CallGraphSCC() : ModulePass(ID) {}

    // run - Print out SCCs in the call graph for the specified module.
    bool runOnModule(Module &M);

    void print(raw_ostream &O, const Module* = 0) const { }

    // getAnalysisUsage - This pass requires the CallGraph.
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
      AU.addRequired<CallGraph>();
    }
  };
}

char CFGSCC::ID = 0;
static RegisterPass<CFGSCC>
Y("print-cfg-sccs", "Print SCCs of each function CFG");

char CallGraphSCC::ID = 0;
static RegisterPass<CallGraphSCC>
Z("print-callgraph-sccs", "Print SCCs of the Call Graph");

bool CFGSCC::runOnFunction(Function &F) {
  unsigned sccNum = 0;
  outs() << "SCCs for Function " << F.getName() << " in PostOrder:";
  for (scc_iterator<Function*> SCCI = scc_begin(&F),
         E = scc_end(&F); SCCI != E; ++SCCI) {
    std::vector<BasicBlock*> &nextSCC = *SCCI;
    outs() << "\nSCC #" << ++sccNum << " : ";
    for (std::vector<BasicBlock*>::const_iterator I = nextSCC.begin(),
           E = nextSCC.end(); I != E; ++I)
      outs() << (*I)->getName() << ", ";
    if (nextSCC.size() == 1 && SCCI.hasLoop())
      outs() << " (Has self-loop).";
  }
  outs() << "\n";

  return true;
}

// run - Print out SCCs in the call graph for the specified module.
bool CallGraphSCC::runOnModule(Module &M) {
  CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot();
  unsigned sccNum = 0;
  outs() << "SCCs for the program in PostOrder:";
  for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode),
         E = scc_end(rootNode); SCCI != E; ++SCCI) {
    const std::vector<CallGraphNode*> &nextSCC = *SCCI;
    outs() << "\nSCC #" << ++sccNum << " : ";
    for (std::vector<CallGraphNode*>::const_iterator I = nextSCC.begin(),
           E = nextSCC.end(); I != E; ++I)
      outs() << ((*I)->getFunction() ? (*I)->getFunction()->getNameStr()
                 : std::string("external node")) << ", ";
    if (nextSCC.size() == 1 && SCCI.hasLoop())
      outs() << " (Has self-loop).";
  }
  outs() << "\n";

  return true;
}
<|endoftext|>


<commit_before>/*
** Copyright 2014 Merethis
**
** This file is part of Centreon Broker.
**
** Centreon Broker is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License version 2
** as published by the Free Software Foundation.
**
** Centreon Broker is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Centreon Broker. If not, see
** <http://www.gnu.org/licenses/>.
*/

#ifndef CCB_BAM_BOOL_VALUE_HH
#  define CCB_BAM_BOOL_VALUE_HH

#  include "com/centreon/broker/bam/computable.hh"
#  include "com/centreon/broker/namespace.hh"

CCB_BEGIN()

namespace        bam {
  /**
   *  @class bool_value bool_value.hh "com/centreon/broker/bam/bool_value.hh"
   *  @brief Computable boolean value.
   *
   *  This class abstracts a boolean value that can get computed.
   */
  class          bool_value : public computable {
  public:
                 bool_value();
                 bool_value(bool_value const& right);
                 ~bool_value();
    bool_value&  operator=(bool_value const& right);
    virtual bool value_hard() = 0;
    virtual bool value_soft() = 0;
  };
}

CCB_END()

#endif // !CCB_BAM_BOOL_VALUE_HH
<commit_msg>BAM: make bool_value inheritable (virtual destructor).<commit_after>/*
** Copyright 2014 Merethis
**
** This file is part of Centreon Broker.
**
** Centreon Broker is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License version 2
** as published by the Free Software Foundation.
**
** Centreon Broker is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Centreon Broker. If not, see
** <http://www.gnu.org/licenses/>.
*/

#ifndef CCB_BAM_BOOL_VALUE_HH
#  define CCB_BAM_BOOL_VALUE_HH

#  include "com/centreon/broker/bam/computable.hh"
#  include "com/centreon/broker/namespace.hh"

CCB_BEGIN()

namespace        bam {
  /**
   *  @class bool_value bool_value.hh "com/centreon/broker/bam/bool_value.hh"
   *  @brief Computable boolean value.
   *
   *  This class abstracts a boolean value that can get computed.
   */
  class          bool_value : public computable {
  public:
                 bool_value();
                 bool_value(bool_value const& right);
    virtual      ~bool_value();
    bool_value&  operator=(bool_value const& right);
    virtual bool value_hard() = 0;
    virtual bool value_soft() = 0;
  };
}

CCB_END()

#endif // !CCB_BAM_BOOL_VALUE_HH
<|endoftext|>


<commit_before>/*-------------------------------------------------------------------------
 *
 * mapper_seq_scan.cpp
 * file description
 *
 * Copyright(c) 2015, CMU
 *
 * /peloton/src/backend/bridge/dml/mapper/mapper_seq_scan.cpp
 *
 *-------------------------------------------------------------------------
 */

#include "backend/bridge/dml/mapper/mapper.h"

namespace peloton {
namespace bridge {

//===--------------------------------------------------------------------===//
// Seq Scan
//===--------------------------------------------------------------------===//

/**
 * @brief Convert a Postgres LockRow into a Peloton Node.
 *
 *    currently, we just ignore the lock step, and return the
 *    underlying node
 *
 * @return Pointer to the constructed AbstractPlanNode.
 *
 */
planner::AbstractPlanNode* PlanTransformer::TransformLockRows(
    const LockRowsState* lr_plan_state) {
  assert(nodeTag(lr_plan_state) == T_LockRowsState);

  LOG_INFO("Handle LockRows");

  /* get the underlying plan */
  PlanState* outer_plan_state = outerPlanState(lr_plan_state);

  return PlanTransformer::TransformPlan(outer_plan_state);
}

}  // namespace bridge
}  // namespace peloton
<commit_msg>minor fix<commit_after>/*-------------------------------------------------------------------------
 *
 * mapper_seq_scan.cpp
 * file description
 *
 * Copyright(c) 2015, CMU
 *
 * /peloton/src/backend/bridge/dml/mapper/mapper_seq_scan.cpp
 *
 *-------------------------------------------------------------------------
 */

#include "backend/bridge/dml/mapper/mapper.h"

namespace peloton {
namespace bridge {

//===--------------------------------------------------------------------===//
// Seq Scan
//===--------------------------------------------------------------------===//

/**
 * @brief Convert a Postgres LockRow into a Peloton Node.
 *
 *    currently, we just ignore the lock step, and return the
 *    underlying node
 *
 * @return Pointer to the constructed AbstractPlanNode.
 *
 */
planner::AbstractPlanNode* PlanTransformer::TransformLockRows(
    const LockRowsState* lr_plan_state) {
  assert(nodeTag(lr_plan_state) == T_LockRowsState);

  LOG_INFO("Handle LockRows");

  /* get the underlying plan */
  PlanState* outer_plan_state = outerPlanState(lr_plan_state);

  TransformOptions options = kDefaultOptions;
  options.use_projInfo = false;

  return PlanTransformer::TransformPlan(outer_plan_state, options);
}

}  // namespace bridge
}  // namespace peloton
<|endoftext|>


<commit_before><commit_msg>QHexPainter: Restore default font before paint a new line<commit_after><|endoftext|>


<commit_before>// Implementación de las funciones de la librería "bluetooth"
#include <arduino.h>
#include "bluetooth.h"
#include "pendiente.h"
#include "sensor.h"

#define INTERRUPCION_BT 4

int modo = 1; // Modo de funcionamiento del sistema
// Variables que controlan la comunicación
char c = ' ';
static char saludo = 'D';
static char fin = '%';
static char coma = ',';

//----------------------------------------
// Función de interrupción cuando llega un comando, y lo interpreta
void leeDatos(){
  while(Serial1.available() > 0){
    c = Serial1.read();
  }
  switch(c){
    case '0':
      modo = 0;
      break;
    case '1':
      modo = 1;
      break;
    case '2':
      modo = 2;
      break;
    case 's':
      modo = 0;
      break;
    default:
      break;
  }
}
//----------------------------------------

// Configura los parámetros de la transmisión serie
void configurarBT(){
  Serial1.begin(38400);
  attachInterrupt(INTERRUPCION_BT, leeDatos, CHANGE);
}
// Envía los datos vía bluetooth
void envioDatos(){
  Serial1.write(saludo);
  Serial1.write(int(anguloX));
  Serial1.write(coma);
  Serial1.write(temperatura);
  Serial1.write(coma);
  Serial1.write(aceleracion);
  Serial1.write(fin);
}

<commit_msg>Update bluetooth.cpp<commit_after>// Implementación de las funciones de la librería "bluetooth"
#include <arduino.h>
#include "bluetooth.h"
#include "pendiente.h"
#include "sensor.h"

#define INTERRUPCION_BT 4 // Número de la interrupción (pin 19)

int modo = 0; // Modo de funcionamiento del sistema
// Variables que controlan la comunicación
char c = ' ';
static char saludo = 'D';
static char fin = '%';
static char coma = ',';

//----------------------------------------
// Función de interrupción cuando llega un comando, y lo interpreta
void leeDatos(){
  while(Serial1.available() > 0){
    c = Serial1.read();
  }
  switch(c){
    case '0':
      modo = 0;
      break;
    case '1':
      modo = 1;
      break;
    case '2':
      modo = 2;
      break;
    case 's':
      modo = 0;
      break;
    default:
      break;
  }
}
//----------------------------------------

// Configura los parámetros de la transmisión serie
void configurarBT(){
  Serial1.begin(38400);
  attachInterrupt(INTERRUPCION_BT, leeDatos, CHANGE);
}
// Envía los datos vía bluetooth
void envioDatos(){
  Serial1.write(saludo);
  Serial1.write(coma);
  Serial1.write(int(anguloX));
  Serial1.write(coma);
  Serial1.write(temperatura);
  Serial1.write(coma);
  Serial1.write(aceleracion);
  Serial1.write(fin);
}

<|endoftext|>


<commit_before>#include <stdio.h>
#include <errno.h>

#include "osal.h"

#include "syscalls_cpp.hpp"

/**
 *
 */
#ifdef __cplusplus
extern "C" {
#endif
void _exit(int status){
   (void) status;
   osalSysHalt("Unrealized");
   while(TRUE){}
}
#ifdef __cplusplus
}
#endif

/**
 *
 */
#ifdef __cplusplus
extern "C" {
#endif
pid_t _getpid(void){
   return 1;
}
#ifdef __cplusplus
}
#endif

/**
 *
 */
#undef errno
extern int errno;
#ifdef __cplusplus
extern "C" {
#endif
int _kill(int pid, int sig) {
  (void)pid;
  (void)sig;
  errno = EINVAL;
  return -1;
}
#ifdef __cplusplus
}
#endif

/**
 *
 */
#ifdef __cplusplus
extern "C" {
#endif
void _open_r(void){
  return;
}
#ifdef __cplusplus
}
#endif

/**
 *
 */
#ifdef __cplusplus
extern "C" {
#endif
  void __cxa_pure_virtual() {
    osalSysHalt("Pure virtual function call.");
  }
#ifdef __cplusplus
}
#endif
<commit_msg>[CPP wrappers] Syscalls cleanup.<commit_after>#include <stdio.h>
#include <errno.h>

#include "osal.h"

#include "syscalls_cpp.hpp"

#ifdef __cplusplus
extern "C" {
#endif

void _exit(int status){
   (void) status;
   osalSysHalt("Unrealized");
   while(TRUE){}
}

pid_t _getpid(void){
   return 1;
}

#undef errno
extern int errno;
int _kill(int pid, int sig) {
  (void)pid;
  (void)sig;
  errno = EINVAL;
  return -1;
}

void _open_r(void){
  return;
}

void __cxa_pure_virtual() {
  osalSysHalt("Pure virtual function call.");
}

#ifdef __cplusplus
}
#endif
<|endoftext|>


<commit_before><commit_msg>fix(preproc): Reduced the number of the temporary tokens<commit_after><|endoftext|>