<commit_before>#pragma once

#include "platform.hpp"

#include <exception>
#include <string>

#define xfatal(MSG)                                                     \
	do {                                                                \
		fputs((std::string(__FILE__) + ":" + std::to_string(__LINE__) + \
		       " in " + STX_FUNCTION + " : " + MSG)                     \
		          .c_str(),                                             \
		      stderr);                                                  \
		std::terminate();                                               \
	} while(false)

#define xfail(MSG)                                                   \
	do {                                                             \
		throw std::runtime_error(std::string(__FILE__) + ":" +       \
		                         std::to_string(__LINE__) + " in " + \
		                         STX_FUNCTION + " : " + MSG);        \
	} while(false)

#ifdef STX_DEBUG_TOOLS

#define xassert(TEST)                  \
	do {                               \
		if(!(TEST)) { xfatal(#TEST); } \
	} while(false)

#define xassertmsg(TEST, MSG)                \
	do {                                     \
		if(!(TEST)) { xfatal(#TEST + MSG); } \
	} while(false)

// These are intentionally not defined when the debug tools are off:
// they are only for debugging and should NEVER be in production code build
#define xhere() printf("%s:%i:\n", STX_FUNCTION, __LINE__)
#define xhere_class() printf("%s:%i: (%p)\n", STX_FUNCTION, __LINE__, this)

#else // defined(STX_DEBUG_TOOLS)

#define xassert(TEST) \
	do {              \
		if(TEST) {}   \
	} while(false) // The if is necessary to supress warnings
#define xassertmsg(TEST, MSG) \
	do {                      \
		if(TEST) {}           \
	} while(false)

#endif // defined(STX_DEBUG_TOOLS)

#if STX_DEBUG_TOOLS > 0

#include "logging.hpp"

namespace stx {

/// A class used for debugging which checks whether a returned value was
/// handled
template <typename T>
class important {
	T            m_value;
	mutable bool m_handled;

public:
	template <typename Tx>
	constexpr important(Tx&& val) : m_value(val), m_handled(false) {}

	~important() noexcept {
		if(!m_handled) {
			stx::warn(
			    "Unhandled important value! (important function result not "
			    "handled)");
		}
	}

	constexpr inline operator T() const noexcept {
		m_handled = true;
		return std::move(m_value);
	}
};

/// A class used for debugging which checks whether a returned value was
/// handled
template <typename T>
class asserted {
	T            m_value;
	mutable bool m_handled;

public:
	template <typename Tx>
	constexpr asserted(Tx&& val) : m_value(val), m_handled(false) {}

	~asserted() {
		if(!m_handled) {
			if(!m_value) {
				xfatal(
				    "Asserted return value was not handled and evaluates "
				    "to "
				    "false");
			} else {
				stx::warn(
				    "Unhandled important value! (important function result "
				    "not "
				    "handled)");
			}
		}
	}

	constexpr inline operator T() const noexcept {
		m_handled = true;
		return std::move(m_value);
	}
};

} // namespace stx

#define STX_RESULT_HANDLED(X) \
	{                         \
		if(X) {}              \
	}

#else // STX_DEBUG_TOOLS > 0

namespace stx {

template <typename T>
using important = T;

template <typename T>
using asserted = T;

} // namespace stx

#define STX_RESULT_HANDLED(X) \
	{ X }

#endif // STX_DEBUG_TOOLS > 0
<commit_msg>Fixed asserts in release mode<commit_after>#pragma once

#include "platform.hpp"

#include <exception>
#include <string>

#define xfatal(MSG)                                                     \
	do {                                                                \
		fputs((std::string(__FILE__) + ":" + std::to_string(__LINE__) + \
		       " in " + STX_FUNCTION + " : " + MSG)                     \
		          .c_str(),                                             \
		      stderr);                                                  \
		std::terminate();                                               \
	} while(false)

#define xfail(MSG)                                                   \
	do {                                                             \
		throw std::runtime_error(std::string(__FILE__) + ":" +       \
		                         std::to_string(__LINE__) + " in " + \
		                         STX_FUNCTION + " : " + MSG);        \
	} while(false)

#ifdef STX_DEBUG_TOOLS

#define xassert(TEST)                  \
	do {                               \
		if(!(TEST)) { xfatal(#TEST); } \
	} while(false)

#define xassertmsg(TEST, MSG)                \
	do {                                     \
		if(!(TEST)) { xfatal(#TEST + MSG); } \
	} while(false)

// These are intentionally not defined when the debug tools are off:
// they are only for debugging and should NEVER be in production code build
#define xhere() printf("%s:%i:\n", STX_FUNCTION, __LINE__)
#define xhere_class() printf("%s:%i: (%p)\n", STX_FUNCTION, __LINE__, this)

#else // defined(STX_DEBUG_TOOLS)

#define xassert(TEST) \
	do {              \
		if(TEST) {}   \
	} while(false) // The if is necessary to supress warnings
#define xassertmsg(TEST, MSG) \
	do {                      \
		if(TEST) {}           \
	} while(false)

#endif // defined(STX_DEBUG_TOOLS)

#if STX_DEBUG_TOOLS > 0

#include "logging.hpp"

namespace stx {

/// A class used for debugging which checks whether a returned value was
/// handled
template <typename T>
class important {
	T            m_value;
	mutable bool m_handled;

public:
	template <typename Tx>
	constexpr important(Tx&& val) : m_value(val), m_handled(false) {}

	~important() noexcept {
		if(!m_handled) {
			stx::warn(
			    "Unhandled important value! (important function result not "
			    "handled)");
		}
	}

	constexpr inline operator T() const noexcept {
		m_handled = true;
		return std::move(m_value);
	}
};

/// A class used for debugging which checks whether a returned value was
/// handled
template <typename T>
class asserted {
	T            m_value;
	mutable bool m_handled;

public:
	template <typename Tx>
	constexpr asserted(Tx&& val) : m_value(val), m_handled(false) {}

	~asserted() {
		if(!m_handled) {
			if(!m_value) {
				xfatal(
				    "Asserted return value was not handled and evaluates "
				    "to "
				    "false");
			} else {
				stx::warn(
				    "Unhandled important value! (important function result "
				    "not "
				    "handled)");
			}
		}
	}

	constexpr inline operator T() const noexcept {
		m_handled = true;
		return std::move(m_value);
	}
};

} // namespace stx

#define STX_RESULT_HANDLED(X) \
	{                         \
		if(X) {}              \
	}

#else // STX_DEBUG_TOOLS > 0

namespace stx {

template <typename T>
using important = T;

template <typename T>
using asserted = T;

} // namespace stx

#define STX_RESULT_HANDLED(X) \
	{ X; }

#endif // STX_DEBUG_TOOLS > 0
<|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you 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 .
 */
#ifndef INCLUDED_SVL_LSTNER_HXX
#define INCLUDED_SVL_LSTNER_HXX

#include <svl/svldllapi.h>
#include <tools/rtti.hxx>
#include <deque>

class SfxBroadcaster;
class SfxHint;

typedef std::deque<SfxBroadcaster*> SfxBroadcasterArr_Impl;

#define SFX_NOTIFY( rBC, rBCT, rHint, rHintT ) \
        Notify( rBC, rHint )

class SVL_DLLPUBLIC SfxListener
{
    SfxBroadcasterArr_Impl aBCs;

private:
    const SfxListener&  operator=(const SfxListener &); // n.i., ist verboten

public:
    TYPEINFO();

                        SfxListener();
                        SfxListener( const SfxListener &rCopy );
    virtual             ~SfxListener();

    void                StartListening( SfxBroadcaster& rBroadcaster, bool bPreventDups = false );
    void                EndListening( SfxBroadcaster& rBroadcaster, bool bAllDups = false );
    void                EndListeningAll();
    bool                IsListening( SfxBroadcaster& rBroadcaster ) const;

    sal_uInt16              GetBroadcasterCount() const
                        { return aBCs.size(); }
    SfxBroadcaster*     GetBroadcasterJOE( sal_uInt16 nNo ) const
                        { return aBCs[nNo]; }

    virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint );

#ifndef _NOTIFY_HXX
    void RemoveBroadcaster_Impl( SfxBroadcaster& rBC );
#endif
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>Bin crack, _NOTIFY_HXX is not defined anywhere anyway<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you 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 .
 */
#ifndef INCLUDED_SVL_LSTNER_HXX
#define INCLUDED_SVL_LSTNER_HXX

#include <svl/svldllapi.h>
#include <tools/rtti.hxx>
#include <deque>

class SfxBroadcaster;
class SfxHint;

typedef std::deque<SfxBroadcaster*> SfxBroadcasterArr_Impl;

#define SFX_NOTIFY( rBC, rBCT, rHint, rHintT ) \
        Notify( rBC, rHint )

class SVL_DLLPUBLIC SfxListener
{
    SfxBroadcasterArr_Impl aBCs;

private:
    const SfxListener&  operator=(const SfxListener &); // n.i., ist verboten

public:
    TYPEINFO();

                        SfxListener();
                        SfxListener( const SfxListener &rCopy );
    virtual             ~SfxListener();

    void                StartListening( SfxBroadcaster& rBroadcaster, bool bPreventDups = false );
    void                EndListening( SfxBroadcaster& rBroadcaster, bool bAllDups = false );
    void                EndListeningAll();
    bool                IsListening( SfxBroadcaster& rBroadcaster ) const;

    sal_uInt16              GetBroadcasterCount() const
                        { return aBCs.size(); }
    SfxBroadcaster*     GetBroadcasterJOE( sal_uInt16 nNo ) const
                        { return aBCs[nNo]; }

    virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint );

    void RemoveBroadcaster_Impl( SfxBroadcaster& rBC );
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>#include "Polygon3DDrawData.h"
#include "core/MapPos.h"
#include "geometry/PolygonGeometry.h"
#include "graphics/utils/GLContext.h"
#include "projections/Projection.h"
#include "projections/ProjectionSurface.h"
#include "styles/Polygon3DStyle.h"
#include "utils/Const.h"
#include "utils/GeomUtils.h"
#include "utils/Log.h"
#include "vectorelements/Polygon3D.h"

#include <cmath>
#include <cstdlib>
#include <numeric>

#include <tesselator.h>

namespace carto {

    Polygon3DDrawData::Polygon3DDrawData(const Polygon3D& polygon3D, const Polygon3DStyle& style, const Projection& projection, const ProjectionSurface& projectionSurface) :
        VectorElementDrawData(style.getColor()),
        _sideColor(GetPremultipliedColor(style.getSideColor())),
        _boundingBox(cglib::bbox3<double>::smallest()),
        _coords(),
        _normals(),
        _attribs()
    {
        const std::vector<MapPos>& poses = polygon3D.getGeometry()->getPoses();
        const std::vector<std::vector<MapPos> >& holes = polygon3D.getGeometry()->getHoles();
        float height = polygon3D.getHeight();

        // Create tesselator
        TESSalloc ma;
        ma.memalloc = [](void* userData, unsigned int size) { return malloc(size); };
        ma.memfree = [](void* userData, void* ptr) { free(ptr); };
        ma.extraVertices = 256;
        TESStesselator* tessPtr = tessNewTess(&ma);
        if (!tessPtr) {
            Log::Error("Polygon3DDrawData::Polygon3DDrawData: Failed to created tesselator!");
            return;
        }
        std::shared_ptr<TESStesselator> tess(tessPtr, tessDeleteTess);

        // Prepare polygon exterior
        std::vector<std::vector<MapPos> > ringsInternalPoses(1 + holes.size());
        ringsInternalPoses[0].reserve(poses.size());

        std::vector<double> posesArray(poses.size() * 3);
        for (std::size_t i = 0; i < poses.size(); i++) {
            MapPos pos = poses[i];
            pos.setZ(height);
            MapPos internalPos = projection.toInternal(pos);
            posesArray[i * 3 + 0] = internalPos.getX();
            posesArray[i * 3 + 1] = internalPos.getY();
            posesArray[i * 3 + 2] = internalPos.getZ();
            ringsInternalPoses[0].push_back(internalPos);
        }
        tessAddContour(tess.get(), 3, posesArray.data(), sizeof(double) * 3, static_cast<unsigned int>(poses.size()));

        // Prepare polygon holes
        std::vector<std::vector<double> > holesArray(holes.size());
        for (std::size_t n = 0; n < holes.size(); n++) {
            const std::vector<MapPos>& hole = holes[n];
            std::vector<double>& holeArray = holesArray[n];
            holeArray.resize(hole.size() * 3);
            for (std::size_t i = 0; i < hole.size(); i++) {
                MapPos pos = hole[i];
                pos.setZ(height);
                MapPos internalPos = projection.toInternal(pos);
                holeArray[i * 3 + 0] = internalPos.getX();
                holeArray[i * 3 + 1] = internalPos.getY();
                holeArray[i * 3 + 2] = internalPos.getZ();
                ringsInternalPoses[n + 1].push_back(internalPos);
            }
            tessAddContour(tess.get(), 3, holeArray.data(), sizeof(double) * 3, static_cast<unsigned int>(hole.size()));
        }

        // Triangulate
        double normal[3] = { 0, 0, 1 };
        if (!tessTesselate(tess.get(), TESS_WINDING_ODD, TESS_POLYGONS, 3, 3, normal)) {
            Log::Error("Polygon3DDrawData::Polygon3DDrawData: Failed to triangulate 3d polygon!");
            return;
        }
        const double* roofCoords = tessGetVertices(tess.get());
        const int* roofElements = tessGetElements(tess.get());
        std::size_t roofVertexCount = tessGetVertexCount(tess.get());
        std::size_t roofElementCount = tessGetElementCount(tess.get());

        // Do projection-surface based tesselation
        std::vector<MapPos> roofInternalPoses;
        roofInternalPoses.reserve(roofVertexCount);
        for (std::size_t i = 0; i < roofVertexCount; i++) {
            roofInternalPoses.emplace_back(roofCoords[i * 3 + 0], roofCoords[i * 3 + 1], roofCoords[i * 3 + 2]);
        }
        std::vector<unsigned int> roofIndices;
        roofIndices.reserve(roofElementCount * 3);
        for (std::size_t i = 0; i < roofElementCount * 3; i += 3) {
            unsigned int i0 = roofElements[i + 0];
            unsigned int i1 = roofElements[i + 1];
            unsigned int i2 = roofElements[i + 2];
            if (i0 != TESS_UNDEF && i1 != TESS_UNDEF && i2 != TESS_UNDEF) {
                projectionSurface.tesselateTriangle(i0, i1, i2, roofIndices, roofInternalPoses);
            }
        }

        // Tesselate rings
        for (std::vector<MapPos>& ringInternalPoses : ringsInternalPoses) {
            std::vector<MapPos> tesselatedPoses;
            tesselatedPoses.reserve(ringInternalPoses.size());
            for (std::size_t i = 0; i < ringInternalPoses.size(); i++) {
                if (!tesselatedPoses.empty()) {
                    tesselatedPoses.pop_back();
                }
                projectionSurface.tesselateSegment(ringInternalPoses[i], ringInternalPoses[(i + 1) % ringInternalPoses.size()], tesselatedPoses);
            }
            std::swap(ringInternalPoses, tesselatedPoses);
        }

        // Reserve space for roof and sides
        std::size_t edgeVertexCount = std::accumulate(ringsInternalPoses.begin(), ringsInternalPoses.end(), std::size_t(0), [](std::size_t count, const std::vector<MapPos>& ringInternalPoses) { return count + ringInternalPoses.size(); });
        _coords.reserve(roofIndices.size() + edgeVertexCount * 6);
        _normals.reserve(roofIndices.size() + edgeVertexCount * 6);

        // Convert triangulator output to coord array
        for (std::size_t i = 0; i < roofIndices.size(); i++) {
            std::size_t index = roofIndices[i];
            _coords.push_back(projectionSurface.calculatePosition(roofInternalPoses[index]));
            _normals.push_back(cglib::vec3<float>::convert(projectionSurface.calculateNormal(roofInternalPoses[index])));
            _attribs.push_back(1);
        }

        // Calculate sides
        for (std::size_t n = 0; n < ringsInternalPoses.size(); n++) {
            const std::vector<MapPos>& ringInternalPoses = ringsInternalPoses[n];

            // Calculate vertex orientation of the polygon
            bool clockWise = GeomUtils::IsConcavePolygonClockwise(ringInternalPoses);
            // If calculating a whole, reverse the direction
            bool flipOrder = (n > 0 ? !clockWise : clockWise);

            for (std::size_t j = 1; j < ringInternalPoses.size(); j++) {
                const MapPos& internalPos0 = ringInternalPoses[(flipOrder ? j : j - 1)];
                const MapPos& internalPos1 = ringInternalPoses[(flipOrder ? j - 1 : j)];
                cglib::vec3<double> p0r = projectionSurface.calculatePosition(internalPos0);
                cglib::vec3<double> p1r = projectionSurface.calculatePosition(internalPos1);
                cglib::vec3<double> p0b = projectionSurface.calculatePosition(MapPos(internalPos0.getX(), internalPos0.getY(), 0));
                cglib::vec3<double> p1b = projectionSurface.calculatePosition(MapPos(internalPos1.getX(), internalPos1.getY(), 0));

                // Add coordinates for 2 triangles
                _coords.push_back(p0r);
                _coords.push_back(p0b);
                _coords.push_back(p1r);
                _coords.push_back(p0b);
                _coords.push_back(p1b);
                _coords.push_back(p1r);

                // Calculate side normal
                cglib::vec3<double> normal = projectionSurface.calculateNormal(internalPos0);
                cglib::vec3<double> sideVec = projectionSurface.calculateVector(internalPos0, internalPos1 - internalPos0);
                cglib::vec3<float> sideNormal = cglib::vec3<float>::convert(cglib::unit(cglib::vector_product(sideVec, normal)));

                // Add normal for each vertex
                for (int k = 0; k < 6; k++) {
                    _normals.push_back(sideNormal);
                    _attribs.push_back(0);
                }
            }
        }

        // Update bounding box based on calculated coordinates
        _boundingBox.add(_coords.begin(), _coords.end());

        // Do sanity check on the size
        if (_coords.size() > GLContext::MAX_VERTEXBUFFER_SIZE) {
            Log::Error("Polygon3DDrawData::Polygon3DDrawData: Maximum buffer size exceeded, 3d polygon can't be drawn");
        }
    }

    Polygon3DDrawData::~Polygon3DDrawData() {
    }

    const Color& Polygon3DDrawData::getSideColor() const {
        return _sideColor;
    }

    const cglib::bbox3<double>& Polygon3DDrawData::getBoundingBox() const {
        return _boundingBox;
    }

    const std::vector<cglib::vec3<double> >& Polygon3DDrawData::getCoords() const {
        return _coords;
    }

    const std::vector<cglib::vec3<float> >& Polygon3DDrawData::getNormals() const {
        return _normals;
    }

    const std::vector<unsigned char>& Polygon3DDrawData::getAttribs() const {
        return _attribs;
    }

    void Polygon3DDrawData::offsetHorizontally(double offset) {
        for (cglib::vec3<double>& pos : _coords) {
            pos(0) += offset;
        }
        setIsOffset(true);
    }

}
<commit_msg>Missing reserve<commit_after>#include "Polygon3DDrawData.h"
#include "core/MapPos.h"
#include "geometry/PolygonGeometry.h"
#include "graphics/utils/GLContext.h"
#include "projections/Projection.h"
#include "projections/ProjectionSurface.h"
#include "styles/Polygon3DStyle.h"
#include "utils/Const.h"
#include "utils/GeomUtils.h"
#include "utils/Log.h"
#include "vectorelements/Polygon3D.h"

#include <cmath>
#include <cstdlib>
#include <numeric>

#include <tesselator.h>

namespace carto {

    Polygon3DDrawData::Polygon3DDrawData(const Polygon3D& polygon3D, const Polygon3DStyle& style, const Projection& projection, const ProjectionSurface& projectionSurface) :
        VectorElementDrawData(style.getColor()),
        _sideColor(GetPremultipliedColor(style.getSideColor())),
        _boundingBox(cglib::bbox3<double>::smallest()),
        _coords(),
        _normals(),
        _attribs()
    {
        const std::vector<MapPos>& poses = polygon3D.getGeometry()->getPoses();
        const std::vector<std::vector<MapPos> >& holes = polygon3D.getGeometry()->getHoles();
        float height = polygon3D.getHeight();

        // Create tesselator
        TESSalloc ma;
        ma.memalloc = [](void* userData, unsigned int size) { return malloc(size); };
        ma.memfree = [](void* userData, void* ptr) { free(ptr); };
        ma.extraVertices = 256;
        TESStesselator* tessPtr = tessNewTess(&ma);
        if (!tessPtr) {
            Log::Error("Polygon3DDrawData::Polygon3DDrawData: Failed to created tesselator!");
            return;
        }
        std::shared_ptr<TESStesselator> tess(tessPtr, tessDeleteTess);

        // Prepare polygon exterior
        std::vector<std::vector<MapPos> > ringsInternalPoses(1 + holes.size());
        ringsInternalPoses[0].reserve(poses.size());

        std::vector<double> posesArray(poses.size() * 3);
        for (std::size_t i = 0; i < poses.size(); i++) {
            MapPos pos = poses[i];
            pos.setZ(height);
            MapPos internalPos = projection.toInternal(pos);
            posesArray[i * 3 + 0] = internalPos.getX();
            posesArray[i * 3 + 1] = internalPos.getY();
            posesArray[i * 3 + 2] = internalPos.getZ();
            ringsInternalPoses[0].push_back(internalPos);
        }
        tessAddContour(tess.get(), 3, posesArray.data(), sizeof(double) * 3, static_cast<unsigned int>(poses.size()));

        // Prepare polygon holes
        std::vector<std::vector<double> > holesArray(holes.size());
        for (std::size_t n = 0; n < holes.size(); n++) {
            const std::vector<MapPos>& hole = holes[n];
            std::vector<double>& holeArray = holesArray[n];
            holeArray.resize(hole.size() * 3);
            for (std::size_t i = 0; i < hole.size(); i++) {
                MapPos pos = hole[i];
                pos.setZ(height);
                MapPos internalPos = projection.toInternal(pos);
                holeArray[i * 3 + 0] = internalPos.getX();
                holeArray[i * 3 + 1] = internalPos.getY();
                holeArray[i * 3 + 2] = internalPos.getZ();
                ringsInternalPoses[n + 1].push_back(internalPos);
            }
            tessAddContour(tess.get(), 3, holeArray.data(), sizeof(double) * 3, static_cast<unsigned int>(hole.size()));
        }

        // Triangulate
        double normal[3] = { 0, 0, 1 };
        if (!tessTesselate(tess.get(), TESS_WINDING_ODD, TESS_POLYGONS, 3, 3, normal)) {
            Log::Error("Polygon3DDrawData::Polygon3DDrawData: Failed to triangulate 3d polygon!");
            return;
        }
        const double* roofCoords = tessGetVertices(tess.get());
        const int* roofElements = tessGetElements(tess.get());
        std::size_t roofVertexCount = tessGetVertexCount(tess.get());
        std::size_t roofElementCount = tessGetElementCount(tess.get());

        // Do projection-surface based tesselation
        std::vector<MapPos> roofInternalPoses;
        roofInternalPoses.reserve(roofVertexCount);
        for (std::size_t i = 0; i < roofVertexCount; i++) {
            roofInternalPoses.emplace_back(roofCoords[i * 3 + 0], roofCoords[i * 3 + 1], roofCoords[i * 3 + 2]);
        }
        std::vector<unsigned int> roofIndices;
        roofIndices.reserve(roofElementCount * 3);
        for (std::size_t i = 0; i < roofElementCount * 3; i += 3) {
            unsigned int i0 = roofElements[i + 0];
            unsigned int i1 = roofElements[i + 1];
            unsigned int i2 = roofElements[i + 2];
            if (i0 != TESS_UNDEF && i1 != TESS_UNDEF && i2 != TESS_UNDEF) {
                projectionSurface.tesselateTriangle(i0, i1, i2, roofIndices, roofInternalPoses);
            }
        }

        // Tesselate rings
        for (std::vector<MapPos>& ringInternalPoses : ringsInternalPoses) {
            std::vector<MapPos> tesselatedPoses;
            tesselatedPoses.reserve(ringInternalPoses.size());
            for (std::size_t i = 0; i < ringInternalPoses.size(); i++) {
                if (!tesselatedPoses.empty()) {
                    tesselatedPoses.pop_back();
                }
                projectionSurface.tesselateSegment(ringInternalPoses[i], ringInternalPoses[(i + 1) % ringInternalPoses.size()], tesselatedPoses);
            }
            std::swap(ringInternalPoses, tesselatedPoses);
        }

        // Reserve space for roof and sides
        std::size_t edgeVertexCount = std::accumulate(ringsInternalPoses.begin(), ringsInternalPoses.end(), std::size_t(0), [](std::size_t count, const std::vector<MapPos>& ringInternalPoses) { return count + ringInternalPoses.size(); });
        _coords.reserve(roofIndices.size() + edgeVertexCount * 6);
        _normals.reserve(roofIndices.size() + edgeVertexCount * 6);
        _attribs.reserve(roofIndices.size() + edgeVertexCount * 6);

        // Convert triangulator output to coord array
        for (std::size_t i = 0; i < roofIndices.size(); i++) {
            std::size_t index = roofIndices[i];
            _coords.push_back(projectionSurface.calculatePosition(roofInternalPoses[index]));
            _normals.push_back(cglib::vec3<float>::convert(projectionSurface.calculateNormal(roofInternalPoses[index])));
            _attribs.push_back(1);
        }

        // Calculate sides
        for (std::size_t n = 0; n < ringsInternalPoses.size(); n++) {
            const std::vector<MapPos>& ringInternalPoses = ringsInternalPoses[n];

            // Calculate vertex orientation of the polygon
            bool clockWise = GeomUtils::IsConcavePolygonClockwise(ringInternalPoses);
            // If calculating a whole, reverse the direction
            bool flipOrder = (n > 0 ? !clockWise : clockWise);

            for (std::size_t j = 1; j < ringInternalPoses.size(); j++) {
                const MapPos& internalPos0 = ringInternalPoses[(flipOrder ? j : j - 1)];
                const MapPos& internalPos1 = ringInternalPoses[(flipOrder ? j - 1 : j)];
                cglib::vec3<double> p0r = projectionSurface.calculatePosition(internalPos0);
                cglib::vec3<double> p1r = projectionSurface.calculatePosition(internalPos1);
                cglib::vec3<double> p0b = projectionSurface.calculatePosition(MapPos(internalPos0.getX(), internalPos0.getY(), 0));
                cglib::vec3<double> p1b = projectionSurface.calculatePosition(MapPos(internalPos1.getX(), internalPos1.getY(), 0));

                // Add coordinates for 2 triangles
                _coords.push_back(p0r);
                _coords.push_back(p0b);
                _coords.push_back(p1r);
                _coords.push_back(p0b);
                _coords.push_back(p1b);
                _coords.push_back(p1r);

                // Calculate side normal
                cglib::vec3<double> normal = projectionSurface.calculateNormal(internalPos0);
                cglib::vec3<double> sideVec = projectionSurface.calculateVector(internalPos0, internalPos1 - internalPos0);
                cglib::vec3<float> sideNormal = cglib::vec3<float>::convert(cglib::unit(cglib::vector_product(sideVec, normal)));

                // Add normal for each vertex
                for (int k = 0; k < 6; k++) {
                    _normals.push_back(sideNormal);
                    _attribs.push_back(0);
                }
            }
        }

        // Update bounding box based on calculated coordinates
        _boundingBox.add(_coords.begin(), _coords.end());

        // Do sanity check on the size
        if (_coords.size() > GLContext::MAX_VERTEXBUFFER_SIZE) {
            Log::Error("Polygon3DDrawData::Polygon3DDrawData: Maximum buffer size exceeded, 3d polygon can't be drawn");
        }
    }

    Polygon3DDrawData::~Polygon3DDrawData() {
    }

    const Color& Polygon3DDrawData::getSideColor() const {
        return _sideColor;
    }

    const cglib::bbox3<double>& Polygon3DDrawData::getBoundingBox() const {
        return _boundingBox;
    }

    const std::vector<cglib::vec3<double> >& Polygon3DDrawData::getCoords() const {
        return _coords;
    }

    const std::vector<cglib::vec3<float> >& Polygon3DDrawData::getNormals() const {
        return _normals;
    }

    const std::vector<unsigned char>& Polygon3DDrawData::getAttribs() const {
        return _attribs;
    }

    void Polygon3DDrawData::offsetHorizontally(double offset) {
        for (cglib::vec3<double>& pos : _coords) {
            pos(0) += offset;
        }
        setIsOffset(true);
    }

}
<|endoftext|>


<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#if defined(GRID_RENDERER)

// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/grid/grid_rasterizer.hpp>
#include <mapnik/grid/grid_renderer.hpp>
#include <mapnik/grid/grid_renderer_base.hpp>
#include <mapnik/grid/grid.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/vertex_converters.hpp>
#include <mapnik/vertex_processor.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp>

#pragma GCC diagnostic push
#include <mapnik/warning_ignore_agg.hpp>
#include "agg_rasterizer_scanline_aa.h"
#include "agg_renderer_scanline.h"
#include "agg_scanline_bin.h"
#include "agg_conv_stroke.h"
#include "agg_conv_dash.h"
#pragma GCC diagnostic pop

// stl
#include <string>

namespace mapnik {

template <typename T>
void grid_renderer<T>::process(line_pattern_symbolizer const& sym,
                               mapnik::feature_impl & feature,
                               proj_transform const& prj_trans)
{
    std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_);
    if (filename.empty()) return;
    std::shared_ptr<mapnik::marker const> mark = marker_cache::instance().find(filename, true);
    if (mark->is<mapnik::marker_null>()) return;

    if (!mark->is<mapnik::marker_rgba8>())
    {
        MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: Only images (not '" << filename << "') are supported in the line_pattern_symbolizer";
        return;
    }

    value_bool clip = get<value_bool, keys::clip>(sym, feature, common_.vars_);
    value_double offset = get<value_double, keys::offset>(sym, feature, common_.vars_);
    value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
    value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);

    using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;
    using color_type = typename grid_renderer_base_type::pixfmt_type::color_type;
    using renderer_type = agg::renderer_scanline_bin_solid<grid_renderer_base_type>;

    agg::scanline_bin sl;

    grid_rendering_buffer buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_);
    pixfmt_type pixf(buf);

    grid_renderer_base_type renb(pixf);
    renderer_type ren(renb);

    ras_ptr->reset();

    std::size_t stroke_width = mark->width();

    agg::trans_affine tr;
    auto transform = get_optional<transform_type>(sym, keys::geometry_transform);
    if (transform)
    {
        evaluate_transform(tr, feature, common_.vars_, *transform, common_.scale_factor_);
    }

    box2d<double> clipping_extent = common_.query_extent_;
    if (clip)
    {
        double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
        double pixels = std::ceil(std::max(stroke_width / 2.0 + std::fabs(offset),
                                          (std::fabs(offset) * offset_converter_default_threshold)));
        double padding = pad_per_pixel * pixels * common_.scale_factor_;

        clipping_extent.pad(padding);
    }

    // to avoid the complexity of using an agg pattern filter instead
    // we create a line_symbolizer in order to fake the pattern
    line_symbolizer line;
    put<value_double>(line, keys::stroke_width, value_double(stroke_width));
    // TODO: really should pass the offset to the fake line too, but
    // this wasn't present in the previous version and makes the test
    // fail - in this case, probably the test should be updated.
    //put<value_double>(line, keys::offset, value_double(offset));
    put<value_double>(line, keys::simplify_tolerance, value_double(simplify_tolerance));
    put<value_double>(line, keys::smooth, value_double(smooth));

    using vertex_converter_type = vertex_converter<clip_line_tag, transform_tag,
                                                   affine_transform_tag,
                                                   simplify_tag,smooth_tag,
                                                   offset_transform_tag,stroke_tag>;
    vertex_converter_type converter(clipping_extent,line,common_.t_,prj_trans,tr,feature,common_.vars_,common_.scale_factor_);
    if (clip) converter.set<clip_line_tag>();
    converter.set<transform_tag>(); // always transform
    if (std::fabs(offset) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
    converter.set<affine_transform_tag>(); // optional affine transform
    if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
    if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
    converter.set<stroke_tag>(); //always stroke
    using apply_vertex_converter_type = detail::apply_vertex_converter<vertex_converter_type,grid_rasterizer>;
    using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
    apply_vertex_converter_type apply(converter, *ras_ptr);
    mapnik::util::apply_visitor(vertex_processor_type(apply),feature.get_geometry());

    // render id
    ren.color(color_type(feature.id()));
    agg::render_scanlines(*ras_ptr, sl, ren);

    // add feature properties to grid cache
    pixmap_.add_feature(feature);

}

template void grid_renderer<grid>::process(line_pattern_symbolizer const&,
                                           mapnik::feature_impl &,
                                           proj_transform const&);

}

#endif
<commit_msg>Polygon pattern on line geometries for Grid backend<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#if defined(GRID_RENDERER)

// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/grid/grid_rasterizer.hpp>
#include <mapnik/grid/grid_renderer.hpp>
#include <mapnik/grid/grid_renderer_base.hpp>
#include <mapnik/grid/grid.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/vertex_converters.hpp>
#include <mapnik/vertex_processor.hpp>
#include <mapnik/parse_path.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp>

#pragma GCC diagnostic push
#include <mapnik/warning_ignore_agg.hpp>
#include "agg_rasterizer_scanline_aa.h"
#include "agg_renderer_scanline.h"
#include "agg_scanline_bin.h"
#include "agg_conv_stroke.h"
#include "agg_conv_dash.h"
#pragma GCC diagnostic pop

// stl
#include <string>

namespace mapnik {

template <typename T>
void grid_renderer<T>::process(line_pattern_symbolizer const& sym,
                               mapnik::feature_impl & feature,
                               proj_transform const& prj_trans)
{
    std::string filename = get<std::string, keys::file>(sym, feature, common_.vars_);
    if (filename.empty()) return;
    std::shared_ptr<mapnik::marker const> mark = marker_cache::instance().find(filename, true);
    if (mark->is<mapnik::marker_null>()) return;

    if (!mark->is<mapnik::marker_rgba8>())
    {
        MAPNIK_LOG_DEBUG(agg_renderer) << "agg_renderer: Only images (not '" << filename << "') are supported in the line_pattern_symbolizer";
        return;
    }

    value_bool clip = get<value_bool, keys::clip>(sym, feature, common_.vars_);
    value_double offset = get<value_double, keys::offset>(sym, feature, common_.vars_);
    value_double simplify_tolerance = get<value_double, keys::simplify_tolerance>(sym, feature, common_.vars_);
    value_double smooth = get<value_double, keys::smooth>(sym, feature, common_.vars_);

    using pixfmt_type = typename grid_renderer_base_type::pixfmt_type;
    using color_type = typename grid_renderer_base_type::pixfmt_type::color_type;
    using renderer_type = agg::renderer_scanline_bin_solid<grid_renderer_base_type>;

    agg::scanline_bin sl;

    grid_rendering_buffer buf(pixmap_.raw_data(), common_.width_, common_.height_, common_.width_);
    pixfmt_type pixf(buf);

    grid_renderer_base_type renb(pixf);
    renderer_type ren(renb);

    ras_ptr->reset();

    line_pattern_enum pattern = get<line_pattern_enum, keys::line_pattern>(sym, feature, common_.vars_);
    std::size_t stroke_width = (pattern == LINE_PATTERN_WARP) ? mark->width() :
        get<value_double, keys::stroke_width>(sym, feature, common_.vars_);

    agg::trans_affine tr;
    auto transform = get_optional<transform_type>(sym, keys::geometry_transform);
    if (transform)
    {
        evaluate_transform(tr, feature, common_.vars_, *transform, common_.scale_factor_);
    }

    box2d<double> clipping_extent = common_.query_extent_;
    if (clip)
    {
        double pad_per_pixel = static_cast<double>(common_.query_extent_.width()/common_.width_);
        double pixels = std::ceil(std::max(stroke_width / 2.0 + std::fabs(offset),
                                          (std::fabs(offset) * offset_converter_default_threshold)));
        double padding = pad_per_pixel * pixels * common_.scale_factor_;

        clipping_extent.pad(padding);
    }

    // to avoid the complexity of using an agg pattern filter instead
    // we create a line_symbolizer in order to fake the pattern
    line_symbolizer line;
    put<value_double>(line, keys::stroke_width, value_double(stroke_width));
    // TODO: really should pass the offset to the fake line too, but
    // this wasn't present in the previous version and makes the test
    // fail - in this case, probably the test should be updated.
    //put<value_double>(line, keys::offset, value_double(offset));
    put<value_double>(line, keys::simplify_tolerance, value_double(simplify_tolerance));
    put<value_double>(line, keys::smooth, value_double(smooth));

    using vertex_converter_type = vertex_converter<clip_line_tag, transform_tag,
                                                   affine_transform_tag,
                                                   simplify_tag,smooth_tag,
                                                   offset_transform_tag,stroke_tag>;
    vertex_converter_type converter(clipping_extent,line,common_.t_,prj_trans,tr,feature,common_.vars_,common_.scale_factor_);
    if (clip) converter.set<clip_line_tag>();
    converter.set<transform_tag>(); // always transform
    if (std::fabs(offset) > 0.0) converter.set<offset_transform_tag>(); // parallel offset
    converter.set<affine_transform_tag>(); // optional affine transform
    if (simplify_tolerance > 0.0) converter.set<simplify_tag>(); // optional simplify converter
    if (smooth > 0.0) converter.set<smooth_tag>(); // optional smooth converter
    converter.set<stroke_tag>(); //always stroke
    using apply_vertex_converter_type = detail::apply_vertex_converter<vertex_converter_type,grid_rasterizer>;
    using vertex_processor_type = geometry::vertex_processor<apply_vertex_converter_type>;
    apply_vertex_converter_type apply(converter, *ras_ptr);
    mapnik::util::apply_visitor(vertex_processor_type(apply),feature.get_geometry());

    // render id
    ren.color(color_type(feature.id()));
    agg::render_scanlines(*ras_ptr, sl, ren);

    // add feature properties to grid cache
    pixmap_.add_feature(feature);

}

template void grid_renderer<grid>::process(line_pattern_symbolizer const&,
                                           mapnik::feature_impl &,
                                           proj_transform const&);

}

#endif
<|endoftext|>


<commit_before>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
***************************************************************************/

#include <QtGui>
#include "mediaplayer.h"

int main (int argc, char *argv[])
{
    Q_INIT_RESOURCE(mediaplayer);
    QApplication app(argc, argv);
    app.setApplicationName("Media Player");
    app.setOrganizationName("Qt");
    app.setQuitOnLastWindowClosed(true);

    QString fileString = app.arguments().value(1);

    bool hasSmallScreen =
#ifdef Q_OS_SYMBIAN
        /* On Symbian, we always want fullscreen. One reason is that it's not
         * possible to launch any demos from the fluidlauncher due to a
         * limitation in the emulator. */
        true
#else
        false
#endif
    ;

    const QStringList args(app.arguments());
    for (int i = 0; i < args.count(); ++i) {
        if (args.at(i) == QLatin1String("-small-screen"))
            hasSmallScreen = true;
    }

    MediaPlayer player(fileString, hasSmallScreen);

    if (hasSmallScreen)
        player.showMaximized();
    else
        player.show();

    return app.exec();
}

<commit_msg>Ensure we can handle file names on the cmdline too.<commit_after>/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
***************************************************************************/

#include <QtGui>
#include "mediaplayer.h"

int main (int argc, char *argv[])
{
    Q_INIT_RESOURCE(mediaplayer);
    QApplication app(argc, argv);
    app.setApplicationName("Media Player");
    app.setOrganizationName("Qt");
    app.setQuitOnLastWindowClosed(true);

    bool hasSmallScreen =
#ifdef Q_OS_SYMBIAN
        /* On Symbian, we always want fullscreen. One reason is that it's not
         * possible to launch any demos from the fluidlauncher due to a
         * limitation in the emulator. */
        true
#else
        false
#endif
    ;

    QString fileString;
    const QStringList args(app.arguments());
    /* We have a minor problem here, we accept two arguments, both are
     * optional:
     * - A file name
     * - the option "-small-screen", so let's try to cope with that.
     */
    for (int i = 0; i < args.count(); ++i) {
        const QString &at = args.at(i);

        if (at == QLatin1String("-small-screen"))
            hasSmallScreen = true;
        else if (i > 0) // We don't want the app name.
            fileString = at;
    }

    MediaPlayer player(fileString, hasSmallScreen);

    if (hasSmallScreen)
        player.showMaximized();
    else
        player.show();

    return app.exec();
}

<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/hwpf/fapi2/include/target_types.H $                */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 * @file target_types.H
 * @brief definitions for fapi2 target types
 */

#ifndef __FAPI2_TARGET_TYPES__
#define __FAPI2_TARGET_TYPES__
#include <stdint.h>

/// FAPI namespace
namespace fapi2
{
///
/// @enum fapi::TargetType
/// @brief Types, kinds, of targets
/// @note TYPE_NONE is used to represent empty/NULL targets in lists
/// or tables. TYPE_ALL is used to pass targets to methods which
/// can act generally on any type of target
///

/// Target Kind
enum TargetType : uint64_t
{
    TARGET_TYPE_NONE          = 0x0000000000000000, ///< No type
    TARGET_TYPE_SYSTEM        = 0x0000000000000001, ///< System type
    TARGET_TYPE_DIMM          = 0x0000000000000002, ///< DIMM type
    TARGET_TYPE_PROC_CHIP     = 0x0000000000000004, ///< Processor type
    TARGET_TYPE_MEMBUF_CHIP   = 0x0000000000000008, ///< Membuf type
    TARGET_TYPE_EX            = 0x0000000000000010, ///< EX - 2x Core, L2, L3 - can be deconfigured
    TARGET_TYPE_MBA           = 0x0000000000000020, ///< MBA type
    TARGET_TYPE_MCS           = 0x0000000000000040, ///< MCS type
    TARGET_TYPE_XBUS          = 0x0000000000000080, ///< XBUS type
    TARGET_TYPE_ABUS          = 0x0000000000000100, ///< ABUS type
    TARGET_TYPE_L4            = 0x0000000000000200, ///< L4 type
    TARGET_TYPE_CORE          = 0x0000000000000400, ///< Core
    TARGET_TYPE_EQ            = 0x0000000000000800, ///< EQ - 4x core, 2x L2, 2x L3 - can be deconfigured
    TARGET_TYPE_MCA           = 0x0000000000001000, ///< MCA type
    TARGET_TYPE_MCBIST        = 0x0000000000002000, ///< MCBIST type
    TARGET_TYPE_MI            = 0x0000000000004000, ///< MI Memory Interface (Cumulus)
    TARGET_TYPE_CAPP          = 0x0000000000008000, ///< CAPP target
    TARGET_TYPE_DMI           = 0x0000000000010000, ///< DMI type
    TARGET_TYPE_OBUS          = 0x0000000000020000, ///< OBUS type
    TARGET_TYPE_OBUS_BRICK    = 0x0000000000040000, ///< OBUS BRICK type
    TARGET_TYPE_SBE           = 0x0000000000080000, ///< SBE type
    TARGET_TYPE_PPE           = 0x0000000000100000, ///< PPE type
    TARGET_TYPE_PERV          = 0x0000000000200000, ///< Pervasive type
    TARGET_TYPE_PEC           = 0x0000000000400000, ///< PEC type
    TARGET_TYPE_PHB           = 0x0000000000800000, ///< PHB type
    TARGET_TYPE_MC            = 0x0000000001000000, ///< MC type
    TARGET_TYPE_OMI           = 0x0000000002000000, ///< OMI type
    TARGET_TYPE_OMIC          = 0x0000000004000000, ///< OMIC type
    TARGET_TYPE_MCC           = 0x0000000008000000, ///< MCC type
    TARGET_TYPE_OCMB_CHIP     = 0x0000000010000000, ///< OCMB type
    TARGET_TYPE_MEM_PORT      = 0x0000000020000000, ///< MEM_PORT type
    TARGET_TYPE_NMMU          = 0x0000000040000000, ///< NEST MMU type
    TARGET_TYPE_RESERVED      = 0x0000000080000000, ///< Reserved for Cronus (Z)
    TARGET_TYPE_PAU           = 0x0000000100000000, ///< PAU type
    TARGET_TYPE_IOHS          = 0x0000000200000000, ///< IOHS type
    TARGET_TYPE_FC            = 0x0000000400000000, ///< Fused Core type
    TARGET_TYPE_PMIC          = 0x0000000800000000, ///< PMIC type
    TARGET_TYPE_PAUC          = 0x0000001000000000, ///< PAUC type
    TARGET_TYPE_MULTICAST     = 0x8000000000000000, ///< MULTICAST type
    TARGET_TYPE_ALL           = 0x7FFFFFFFFFFFFFFF, ///< Any/All types
    TARGET_TYPE_ALL_MC        = 0xFFFFFFFFFFFFFFFF, ///< Any/All types + Multicast

    // Compound target types
    TARGET_TYPE_CHIPS         = TARGET_TYPE_PROC_CHIP |
                                TARGET_TYPE_MEMBUF_CHIP |
                                TARGET_TYPE_OCMB_CHIP,

    TARGET_TYPE_CHIPLETS      = TARGET_TYPE_EX            |
                                TARGET_TYPE_MBA           |
                                TARGET_TYPE_MCS           |
                                TARGET_TYPE_XBUS          |
                                TARGET_TYPE_ABUS          |
                                TARGET_TYPE_L4            |
                                TARGET_TYPE_CORE          |
                                TARGET_TYPE_EQ            |
                                TARGET_TYPE_MCA           |
                                TARGET_TYPE_MCBIST        |
                                TARGET_TYPE_MI            |
                                TARGET_TYPE_DMI           |
                                TARGET_TYPE_OBUS          |
                                TARGET_TYPE_OBUS_BRICK    |
                                TARGET_TYPE_SBE           |
                                TARGET_TYPE_PPE           |
                                TARGET_TYPE_PERV          |
                                TARGET_TYPE_PEC           |
                                TARGET_TYPE_PHB           |
                                TARGET_TYPE_MC            |
                                TARGET_TYPE_OMI           |
                                TARGET_TYPE_OMIC          |
                                TARGET_TYPE_MCC           |
                                TARGET_TYPE_MEM_PORT      |
                                TARGET_TYPE_NMMU          |
                                TARGET_TYPE_PAU           |
                                TARGET_TYPE_IOHS          |
                                TARGET_TYPE_FC            |
                                TARGET_TYPE_PAUC,

    TARGET_TYPE_MULTICASTABLE = TARGET_TYPE_CORE   |
                                TARGET_TYPE_EQ     |
                                TARGET_TYPE_MCBIST |
                                TARGET_TYPE_OBUS   |
                                TARGET_TYPE_PERV   |
                                TARGET_TYPE_PEC,

    // Mappings to target types found in the error xml files
    TARGET_TYPE_EX_CHIPLET    = TARGET_TYPE_EX,
    TARGET_TYPE_MBA_CHIPLET   = TARGET_TYPE_MBA,
    TARGET_TYPE_MCS_CHIPLET   = TARGET_TYPE_MCS,
    TARGET_TYPE_XBUS_ENDPOINT = TARGET_TYPE_XBUS,
    TARGET_TYPE_ABUS_ENDPOINT = TARGET_TYPE_ABUS,
};

///
/// Target filter 64-bit
/// Declare the enumeration size so that target.H will compile without chip specific filter.
/// When users want to use an enumeration value then they can include the chip specific
/// target_filters.H, which would have the enumerator list of values.
///
enum TargetFilter : uint64_t;

// attributeOverride tool requires x86.nfp compile
#ifndef CONTEXT_x86_nfp
/// @cond
    constexpr TargetType operator|(TargetType x, TargetType y)
{
    return static_cast<TargetType>(static_cast<uint64_t>(x) |
                                   static_cast<uint64_t>(y));
}
#endif

template<uint64_t V>
class bitCount
{
    public:
        // Don't use enums, too hard to compare
        static const uint8_t count = bitCount < (V >> 1) >::count + (V & 1);
};

template<>
class bitCount<0>
{
    public:
        static const uint8_t count = 0;
};
/// @endcond

}

#endif
<commit_msg>update TARGET_TYPE_MULTICASTABLE<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/hwpf/fapi2/include/target_types.H $                */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2012,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 * @file target_types.H
 * @brief definitions for fapi2 target types
 */

#ifndef __FAPI2_TARGET_TYPES__
#define __FAPI2_TARGET_TYPES__
#include <stdint.h>

/// FAPI namespace
namespace fapi2
{
///
/// @enum fapi::TargetType
/// @brief Types, kinds, of targets
/// @note TYPE_NONE is used to represent empty/NULL targets in lists
/// or tables. TYPE_ALL is used to pass targets to methods which
/// can act generally on any type of target
///

/// Target Kind
enum TargetType : uint64_t
{
    TARGET_TYPE_NONE          = 0x0000000000000000, ///< No type
    TARGET_TYPE_SYSTEM        = 0x0000000000000001, ///< System type
    TARGET_TYPE_DIMM          = 0x0000000000000002, ///< DIMM type
    TARGET_TYPE_PROC_CHIP     = 0x0000000000000004, ///< Processor type
    TARGET_TYPE_MEMBUF_CHIP   = 0x0000000000000008, ///< Membuf type
    TARGET_TYPE_EX            = 0x0000000000000010, ///< EX - 2x Core, L2, L3 - can be deconfigured
    TARGET_TYPE_MBA           = 0x0000000000000020, ///< MBA type
    TARGET_TYPE_MCS           = 0x0000000000000040, ///< MCS type
    TARGET_TYPE_XBUS          = 0x0000000000000080, ///< XBUS type
    TARGET_TYPE_ABUS          = 0x0000000000000100, ///< ABUS type
    TARGET_TYPE_L4            = 0x0000000000000200, ///< L4 type
    TARGET_TYPE_CORE          = 0x0000000000000400, ///< Core
    TARGET_TYPE_EQ            = 0x0000000000000800, ///< EQ - 4x core, 2x L2, 2x L3 - can be deconfigured
    TARGET_TYPE_MCA           = 0x0000000000001000, ///< MCA type
    TARGET_TYPE_MCBIST        = 0x0000000000002000, ///< MCBIST type
    TARGET_TYPE_MI            = 0x0000000000004000, ///< MI Memory Interface (Cumulus)
    TARGET_TYPE_CAPP          = 0x0000000000008000, ///< CAPP target
    TARGET_TYPE_DMI           = 0x0000000000010000, ///< DMI type
    TARGET_TYPE_OBUS          = 0x0000000000020000, ///< OBUS type
    TARGET_TYPE_OBUS_BRICK    = 0x0000000000040000, ///< OBUS BRICK type
    TARGET_TYPE_SBE           = 0x0000000000080000, ///< SBE type
    TARGET_TYPE_PPE           = 0x0000000000100000, ///< PPE type
    TARGET_TYPE_PERV          = 0x0000000000200000, ///< Pervasive type
    TARGET_TYPE_PEC           = 0x0000000000400000, ///< PEC type
    TARGET_TYPE_PHB           = 0x0000000000800000, ///< PHB type
    TARGET_TYPE_MC            = 0x0000000001000000, ///< MC type
    TARGET_TYPE_OMI           = 0x0000000002000000, ///< OMI type
    TARGET_TYPE_OMIC          = 0x0000000004000000, ///< OMIC type
    TARGET_TYPE_MCC           = 0x0000000008000000, ///< MCC type
    TARGET_TYPE_OCMB_CHIP     = 0x0000000010000000, ///< OCMB type
    TARGET_TYPE_MEM_PORT      = 0x0000000020000000, ///< MEM_PORT type
    TARGET_TYPE_NMMU          = 0x0000000040000000, ///< NEST MMU type
    TARGET_TYPE_RESERVED      = 0x0000000080000000, ///< Reserved for Cronus (Z)
    TARGET_TYPE_PAU           = 0x0000000100000000, ///< PAU type
    TARGET_TYPE_IOHS          = 0x0000000200000000, ///< IOHS type
    TARGET_TYPE_FC            = 0x0000000400000000, ///< Fused Core type
    TARGET_TYPE_PMIC          = 0x0000000800000000, ///< PMIC type
    TARGET_TYPE_PAUC          = 0x0000001000000000, ///< PAUC type
    TARGET_TYPE_MULTICAST     = 0x8000000000000000, ///< MULTICAST type
    TARGET_TYPE_ALL           = 0x7FFFFFFFFFFFFFFF, ///< Any/All types
    TARGET_TYPE_ALL_MC        = 0xFFFFFFFFFFFFFFFF, ///< Any/All types + Multicast

    // Compound target types
    TARGET_TYPE_CHIPS         = TARGET_TYPE_PROC_CHIP |
                                TARGET_TYPE_MEMBUF_CHIP |
                                TARGET_TYPE_OCMB_CHIP,

    TARGET_TYPE_CHIPLETS      = TARGET_TYPE_EX            |
                                TARGET_TYPE_MBA           |
                                TARGET_TYPE_MCS           |
                                TARGET_TYPE_XBUS          |
                                TARGET_TYPE_ABUS          |
                                TARGET_TYPE_L4            |
                                TARGET_TYPE_CORE          |
                                TARGET_TYPE_EQ            |
                                TARGET_TYPE_MCA           |
                                TARGET_TYPE_MCBIST        |
                                TARGET_TYPE_MI            |
                                TARGET_TYPE_DMI           |
                                TARGET_TYPE_OBUS          |
                                TARGET_TYPE_OBUS_BRICK    |
                                TARGET_TYPE_SBE           |
                                TARGET_TYPE_PPE           |
                                TARGET_TYPE_PERV          |
                                TARGET_TYPE_PEC           |
                                TARGET_TYPE_PHB           |
                                TARGET_TYPE_MC            |
                                TARGET_TYPE_OMI           |
                                TARGET_TYPE_OMIC          |
                                TARGET_TYPE_MCC           |
                                TARGET_TYPE_MEM_PORT      |
                                TARGET_TYPE_NMMU          |
                                TARGET_TYPE_PAU           |
                                TARGET_TYPE_IOHS          |
                                TARGET_TYPE_FC            |
                                TARGET_TYPE_PAUC,

    TARGET_TYPE_MULTICASTABLE = TARGET_TYPE_CORE   |
                                TARGET_TYPE_EQ     |
                                TARGET_TYPE_IOHS   |
                                TARGET_TYPE_MC     |
                                TARGET_TYPE_PAUC   |
                                TARGET_TYPE_PEC    |
                                TARGET_TYPE_PERV,

    // Mappings to target types found in the error xml files
    TARGET_TYPE_EX_CHIPLET    = TARGET_TYPE_EX,
    TARGET_TYPE_MBA_CHIPLET   = TARGET_TYPE_MBA,
    TARGET_TYPE_MCS_CHIPLET   = TARGET_TYPE_MCS,
    TARGET_TYPE_XBUS_ENDPOINT = TARGET_TYPE_XBUS,
    TARGET_TYPE_ABUS_ENDPOINT = TARGET_TYPE_ABUS,
};

///
/// Target filter 64-bit
/// Declare the enumeration size so that target.H will compile without chip specific filter.
/// When users want to use an enumeration value then they can include the chip specific
/// target_filters.H, which would have the enumerator list of values.
///
enum TargetFilter : uint64_t;

// attributeOverride tool requires x86.nfp compile
#ifndef CONTEXT_x86_nfp
/// @cond
    constexpr TargetType operator|(TargetType x, TargetType y)
{
    return static_cast<TargetType>(static_cast<uint64_t>(x) |
                                   static_cast<uint64_t>(y));
}
#endif

template<uint64_t V>
class bitCount
{
    public:
        // Don't use enums, too hard to compare
        static const uint8_t count = bitCount < (V >> 1) >::count + (V & 1);
};

template<>
class bitCount<0>
{
    public:
        static const uint8_t count = 0;
};
/// @endcond

}

#endif
<|endoftext|>


<commit_before>// Copyright 2019 The Pigweed Authors
//
// 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
//
//     https://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 "pw_unit_test/framework.h"

#include <cstring>

namespace pw::unit_test {

void RegisterEventHandler(EventHandler* event_handler) {
  internal::Framework::Get().RegisterEventHandler(event_handler);
}

namespace internal {

// Singleton instance of the unit test framework class.
Framework Framework::framework_;

// Linked list of all test cases in the test executable. This is static as it is
// populated using static initialization.
TestInfo* Framework::tests_ = nullptr;

void Framework::RegisterTest(TestInfo* new_test) {
  // If the test list is empty, set new_test as the first test.
  if (tests_ == nullptr) {
    tests_ = new_test;
    return;
  }

  // Append the test case to the end of the test list.
  TestInfo* info = tests_;
  for (; info->next() != nullptr; info = info->next()) {
  }
  info->set_next(new_test);
}

int Framework::RunAllTests() {
  run_tests_summary_.passed_tests = 0;
  run_tests_summary_.failed_tests = 0;

  if (event_handler_ != nullptr) {
    event_handler_->RunAllTestsStart();
  }
  for (const TestInfo* test = tests_; test != nullptr; test = test->next()) {
    if (test->enabled()) {
      test->run();
    } else {
      event_handler_->TestCaseDisabled(test->test_case());
    }
  }
  if (event_handler_ != nullptr) {
    event_handler_->RunAllTestsEnd(run_tests_summary_);
  }
  return exit_status_;
}

void Framework::StartTest(const TestInfo& test) {
  current_test_ = &test;
  current_result_ = TestResult::kSuccess;

  if (event_handler_ != nullptr) {
    event_handler_->TestCaseStart(test.test_case());
  }
}

void Framework::EndCurrentTest() {
  switch (current_result_) {
    case TestResult::kSuccess:
      run_tests_summary_.passed_tests++;
      break;
    case TestResult::kFailure:
      run_tests_summary_.failed_tests++;
      break;
  }

  if (event_handler_ != nullptr) {
    event_handler_->TestCaseEnd(current_test_->test_case(), current_result_);
  }

  current_test_ = nullptr;
}

void Framework::ExpectationResult(const char* expression,
                                  const char* evaluated_expression,
                                  int line,
                                  bool success) {
  if (!success) {
    current_result_ = TestResult::kFailure;
    exit_status_ = 1;
  }

  if (event_handler_ == nullptr) {
    return;
  }

  TestExpectation expectation = {
      .expression = expression,
      .evaluated_expression = evaluated_expression,
      .line_number = line,
      .success = success,
  };

  event_handler_->TestCaseExpect(current_test_->test_case(), expectation);
}

bool TestInfo::enabled() const {
  constexpr size_t kStringSize = sizeof("DISABLED_") - 1;
  return std::strncmp("DISABLED_", test_case().test_name, kStringSize) != 0 &&
         std::strncmp("DISABLED_", test_case().suite_name, kStringSize) != 0;
}

}  // namespace internal
}  // namespace pw::unit_test
<commit_msg>Remove nested namespace in pw_unit_test<commit_after>// Copyright 2019 The Pigweed Authors
//
// 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
//
//     https://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 "pw_unit_test/framework.h"

#include <cstring>

namespace pw {
namespace unit_test {

void RegisterEventHandler(EventHandler* event_handler) {
  internal::Framework::Get().RegisterEventHandler(event_handler);
}

namespace internal {

// Singleton instance of the unit test framework class.
Framework Framework::framework_;

// Linked list of all test cases in the test executable. This is static as it is
// populated using static initialization.
TestInfo* Framework::tests_ = nullptr;

void Framework::RegisterTest(TestInfo* new_test) {
  // If the test list is empty, set new_test as the first test.
  if (tests_ == nullptr) {
    tests_ = new_test;
    return;
  }

  // Append the test case to the end of the test list.
  TestInfo* info = tests_;
  for (; info->next() != nullptr; info = info->next()) {
  }
  info->set_next(new_test);
}

int Framework::RunAllTests() {
  run_tests_summary_.passed_tests = 0;
  run_tests_summary_.failed_tests = 0;

  if (event_handler_ != nullptr) {
    event_handler_->RunAllTestsStart();
  }
  for (const TestInfo* test = tests_; test != nullptr; test = test->next()) {
    if (test->enabled()) {
      test->run();
    } else {
      event_handler_->TestCaseDisabled(test->test_case());
    }
  }
  if (event_handler_ != nullptr) {
    event_handler_->RunAllTestsEnd(run_tests_summary_);
  }
  return exit_status_;
}

void Framework::StartTest(const TestInfo& test) {
  current_test_ = &test;
  current_result_ = TestResult::kSuccess;

  if (event_handler_ != nullptr) {
    event_handler_->TestCaseStart(test.test_case());
  }
}

void Framework::EndCurrentTest() {
  switch (current_result_) {
    case TestResult::kSuccess:
      run_tests_summary_.passed_tests++;
      break;
    case TestResult::kFailure:
      run_tests_summary_.failed_tests++;
      break;
  }

  if (event_handler_ != nullptr) {
    event_handler_->TestCaseEnd(current_test_->test_case(), current_result_);
  }

  current_test_ = nullptr;
}

void Framework::ExpectationResult(const char* expression,
                                  const char* evaluated_expression,
                                  int line,
                                  bool success) {
  if (!success) {
    current_result_ = TestResult::kFailure;
    exit_status_ = 1;
  }

  if (event_handler_ == nullptr) {
    return;
  }

  TestExpectation expectation = {
      .expression = expression,
      .evaluated_expression = evaluated_expression,
      .line_number = line,
      .success = success,
  };

  event_handler_->TestCaseExpect(current_test_->test_case(), expectation);
}

bool TestInfo::enabled() const {
  constexpr size_t kStringSize = sizeof("DISABLED_") - 1;
  return std::strncmp("DISABLED_", test_case().test_name, kStringSize) != 0 &&
         std::strncmp("DISABLED_", test_case().suite_name, kStringSize) != 0;
}

}  // namespace internal
}  // namespace unit_test
}  // namespace pw
<|endoftext|>


<commit_before>/* $Id$ */

/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/**
 * >> Flat structure representing a TPC seed <<
 *
 * To be used in the online and offline calibration schema.
 *
 *
 * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
 *
 **************************************************************************/

#include "AliFlatTPCseed.h"
#include "AliTPCseed.h"
#include "AliHLTTPCTransform.h"
#include "Riostream.h"

void AliFlatTPCseed::SetFromTPCseed( const AliTPCseed *p )
{
  // initialise from AliTPCseed

  Reset();
  if( !p ) return;
  fParam.SetExternalTrackParam(  p );
  fLabel = p->GetLabel();
  for( Int_t irow=159; irow>=0; irow-- ){
    if( p->GetClusterPointer(irow) ) AddCluster( p->GetClusterPointer(irow), p->GetTrackPointConst(irow) );
  }
}

void AliFlatTPCseed::GetTPCseed( AliTPCseed *p ) const
{
   // write to AliTPCseed
  if( !p ) return;
  p->Reset();

  AliTPCseed seed;

  fParam.GetExternalTrackParam( seed );
  seed.SetLabel(fLabel);
  seed.SetNumberOfClusters(fNTPCClusters);

  AliTPCclusterMI * clusters = new AliTPCclusterMI[fNTPCClusters];

  const AliFlatTPCCluster *flatClusters = reinterpret_cast< const AliFlatTPCCluster* >( fContent );

  for( Int_t ic=0; ic<fNTPCClusters; ic++){
    const AliFlatTPCCluster &flatCluster = flatClusters[ic];
    int sec = flatCluster.GetSector();
    int row = flatCluster.GetPadRow();
    if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
    if( row<160 ){
      flatCluster.GetTPCCluster( &(clusters[ic]), seed.GetTrackPoint(row) );
      seed.SetClusterPointer( row , &(clusters[ic]) );
    }
  }
  new (p) AliTPCseed( seed, kTRUE ); // true means that p creates its own cluster objects
  delete [] clusters;
}
<commit_msg>fix bug in setting of TPC clusters in flatTPCseed convertor<commit_after>/* $Id$ */

/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/**
 * >> Flat structure representing a TPC seed <<
 *
 * To be used in the online and offline calibration schema.
 *
 *
 * Primary Authors : Sergey Gorbunov, Jochen Thaeder, Chiara Zampolli
 *
 **************************************************************************/

#include "AliFlatTPCseed.h"
#include "AliTPCseed.h"
#include "AliHLTTPCTransform.h"
#include "Riostream.h"

void AliFlatTPCseed::SetFromTPCseed( const AliTPCseed *p )
{
  // initialise from AliTPCseed

  Reset();
  if( !p ) return;
  fParam.SetExternalTrackParam(  p );
  fLabel = p->GetLabel();
  for( Int_t irow=0; irow<160; irow++ ){
    if( p->GetClusterPointer(irow) ) AddCluster( p->GetClusterPointer(irow), p->GetTrackPointConst(irow) );
  }
}

void AliFlatTPCseed::GetTPCseed( AliTPCseed *p ) const
{
   // write to AliTPCseed
  if( !p ) return;
  p->Reset();

  AliTPCseed seed;

  fParam.GetExternalTrackParam( seed );
  seed.SetLabel(fLabel);
  seed.SetNumberOfClusters(fNTPCClusters);

  AliTPCclusterMI * clusters = new AliTPCclusterMI[fNTPCClusters];

  const AliFlatTPCCluster *flatClusters = reinterpret_cast< const AliFlatTPCCluster* >( fContent );

  for( Int_t ic=0; ic<fNTPCClusters; ic++){
    const AliFlatTPCCluster &flatCluster = flatClusters[ic];
    int sec = flatCluster.GetSector();
    int row = flatCluster.GetPadRow();
    if(sec >= 36) row = row + AliHLTTPCTransform::GetNRowLow();
    if( row<160 ){
      flatCluster.GetTPCCluster( &(clusters[ic]), seed.GetTrackPoint(row) );
      seed.SetClusterPointer( row , &(clusters[ic]) );
    }
  }
  new (p) AliTPCseed( seed, kTRUE ); // true means that p creates its own cluster objects
  delete [] clusters;
}
<|endoftext|>


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

#ifndef _WLDCRD_HXX
#include <wldcrd.hxx>
#endif

/*************************************************************************
|*
|*    WildCard::Match()
|*
|*    Beschreibung      WLDCRD.SDW
|*    Ersterstellung    MA 19.06.91
|*    Letzte Aenderung  MA 03.07.91
|*
*************************************************************************/

/* Diese Methode ueberprueft, ob die Wilde Karte in pWild mit dem String
 * in pStr matscht.
 * Vertragen sich die beiden, so wird 1 zurueckgegeben, sonst 0.
 *
 * ein '*' in pWild bedeutet n beliebige Zeichen, mit n>=0
 * ein '?' in pWild bedeutet genau ein beliebiges Zeichen
 *
 */

USHORT WildCard::ImpMatch( const char *pWild, const char *pStr ) const
{
    int    pos=0;
    int    flag=0;

    while ( *pWild || flag )
    {
        switch (*pWild)
        {
            case '?':
                if ( *pStr == '\0' )
                    return 0;
                break;

            default:
                if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
                    pWild++;
                if ( *pWild != *pStr )
                    if ( !pos )
                        return 0;
                    else
                        pWild += pos;
                else
                    break;          // ACHTUNG laeuft unter bestimmten
                                    // Umstaenden in den nachsten case rein!!
            case '*':
                while ( *pWild == '*' )
                    pWild++;
                if ( *pWild == '\0' )
                    return 1;
                flag = 1;
                pos  = 0;
                if ( *pStr == '\0' )
                    return ( *pWild == '\0' );
                while ( *pStr && *pStr != *pWild )
                {
                    if ( *pWild == '?' ) {
                        pWild++;
                        while ( *pWild == '*' )
                            pWild++;
                    }
                    pStr++;
                    if ( *pStr == '\0' )
                        return ( *pWild == '\0' );
                }
                break;
        }
        if ( *pWild != '\0' )
            pWild++;
        if ( *pStr != '\0' )
            pStr++;
        else
            flag = 0;
        if ( flag )
            pos--;
    }
    return ( *pStr == '\0' ) && ( *pWild == '\0' );
}

/*************************************************************************
|*
|*    WildCard::Matches()
|*
|*    Beschreibung      WLDCRD.SDW
|*    Ersterstellung    MA 19.06.91
|*    Letzte Aenderung  TH 02.02.96
|*
*************************************************************************/

BOOL WildCard::Matches( const String& rString ) const
{
    ByteString aTmpWild = aWildString;
    ByteString aString(rString, osl_getThreadTextEncoding());

    USHORT  nSepPos;

    if ( cSepSymbol != '\0' )
    {
        while ( (nSepPos = aTmpWild.Search( cSepSymbol )) != STRING_NOTFOUND )
        {
            // alle getrennten WildCard's pruefen
            if ( ImpMatch( aTmpWild.Copy( 0, nSepPos ).GetBuffer(), aString.GetBuffer() ) )
                return TRUE;
            aTmpWild.Erase( 0, nSepPos + 1 ); // Trennsymbol entfernen
        }
        // und noch den hinter dem letzen Trennsymbol bzw. den einzigen
    }

    if ( ImpMatch( aTmpWild.GetBuffer(), aString.GetBuffer() ) )
        return TRUE;
    else
        return FALSE;
}
<commit_msg>INTEGRATION: CWS pchfix02 (1.2.120); FILE MERGED 2006/09/01 17:54:51 kaib 1.2.120.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: wldcrd.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 00:54:37 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_tools.hxx"

#ifndef _WLDCRD_HXX
#include <wldcrd.hxx>
#endif

/*************************************************************************
|*
|*    WildCard::Match()
|*
|*    Beschreibung      WLDCRD.SDW
|*    Ersterstellung    MA 19.06.91
|*    Letzte Aenderung  MA 03.07.91
|*
*************************************************************************/

/* Diese Methode ueberprueft, ob die Wilde Karte in pWild mit dem String
 * in pStr matscht.
 * Vertragen sich die beiden, so wird 1 zurueckgegeben, sonst 0.
 *
 * ein '*' in pWild bedeutet n beliebige Zeichen, mit n>=0
 * ein '?' in pWild bedeutet genau ein beliebiges Zeichen
 *
 */

USHORT WildCard::ImpMatch( const char *pWild, const char *pStr ) const
{
    int    pos=0;
    int    flag=0;

    while ( *pWild || flag )
    {
        switch (*pWild)
        {
            case '?':
                if ( *pStr == '\0' )
                    return 0;
                break;

            default:
                if ( (*pWild == '\\') && ((*(pWild+1)=='?') || (*(pWild+1) == '*')) )
                    pWild++;
                if ( *pWild != *pStr )
                    if ( !pos )
                        return 0;
                    else
                        pWild += pos;
                else
                    break;          // ACHTUNG laeuft unter bestimmten
                                    // Umstaenden in den nachsten case rein!!
            case '*':
                while ( *pWild == '*' )
                    pWild++;
                if ( *pWild == '\0' )
                    return 1;
                flag = 1;
                pos  = 0;
                if ( *pStr == '\0' )
                    return ( *pWild == '\0' );
                while ( *pStr && *pStr != *pWild )
                {
                    if ( *pWild == '?' ) {
                        pWild++;
                        while ( *pWild == '*' )
                            pWild++;
                    }
                    pStr++;
                    if ( *pStr == '\0' )
                        return ( *pWild == '\0' );
                }
                break;
        }
        if ( *pWild != '\0' )
            pWild++;
        if ( *pStr != '\0' )
            pStr++;
        else
            flag = 0;
        if ( flag )
            pos--;
    }
    return ( *pStr == '\0' ) && ( *pWild == '\0' );
}

/*************************************************************************
|*
|*    WildCard::Matches()
|*
|*    Beschreibung      WLDCRD.SDW
|*    Ersterstellung    MA 19.06.91
|*    Letzte Aenderung  TH 02.02.96
|*
*************************************************************************/

BOOL WildCard::Matches( const String& rString ) const
{
    ByteString aTmpWild = aWildString;
    ByteString aString(rString, osl_getThreadTextEncoding());

    USHORT  nSepPos;

    if ( cSepSymbol != '\0' )
    {
        while ( (nSepPos = aTmpWild.Search( cSepSymbol )) != STRING_NOTFOUND )
        {
            // alle getrennten WildCard's pruefen
            if ( ImpMatch( aTmpWild.Copy( 0, nSepPos ).GetBuffer(), aString.GetBuffer() ) )
                return TRUE;
            aTmpWild.Erase( 0, nSepPos + 1 ); // Trennsymbol entfernen
        }
        // und noch den hinter dem letzen Trennsymbol bzw. den einzigen
    }

    if ( ImpMatch( aTmpWild.GetBuffer(), aString.GetBuffer() ) )
        return TRUE;
    else
        return FALSE;
}
<|endoftext|>