text:
/*
 * Copyright (c) 2016-2018 Nicholas Corgan (n.corgan@gmail.com)
 *
 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
 * or copy at http://opensource.org/licenses/MIT)
 */

#include "../utils/misc.hpp"

#include "database_common.hpp"
#include "id_to_index.hpp"
#include "id_to_string.hpp"

#include <pkmn/config.hpp>

#include <boost/config.hpp>

#include <stdexcept>

namespace pkmn { namespace database {

    static pkmn::database::sptr _db;

    std::string game_index_to_name(
        int game_index
    )
    {
        static BOOST_CONSTEXPR const char* query =
            "SELECT name FROM version_names WHERE local_language_id=9 AND "
            "version_id=(SELECT version_id FROM version_game_indices WHERE "
            "game_index=?)";

        return pkmn::database::query_db_bind1<std::string, int>(
                   query, game_index
               );
    }

    int game_name_to_index(
        const std::string& game_name
    )
    {
        static BOOST_CONSTEXPR const char* query =
            "SELECT game_index FROM version_game_indices WHERE version_id="
            "(SELECT version_id FROM version_names WHERE name=?)";

        return pkmn::database::query_db_bind1<int, const std::string&>(
                   query, game_name
               );
    }

    /*
     * Calling the id_to_string and id_to_index functions is not ideal, but the logic in
     * those functions is complicated enough to warrant not duplicating code.
     */

    std::string item_index_to_name(
        int item_index,
        int game_id
    )
    {
        return pkmn::database::item_id_to_name(
                   pkmn::database::item_index_to_id(item_index, game_id),
                   pkmn::database::game_id_to_version_group(game_id)
               );
    }

    int item_name_to_index(
        const std::string& item_name,
        int game_id
    )
    {
        return pkmn::database::item_id_to_index(
                   pkmn::database::item_name_to_id(item_name),
                   game_id
               );
    }

    static PKMN_CONSTEXPR_OR_INLINE bool GAME_IS_SAPPHIRE(int game_id) {return (game_id == 8);}
    static PKMN_CONSTEXPR_OR_INLINE bool GAME_IS_RSE     (int game_id) {return (game_id >= 7 and game_id <= 9);}
    static PKMN_CONSTEXPR_OR_INLINE bool GAME_IS_E       (int game_id) {return (game_id == 9);}
    static PKMN_CONSTEXPR_OR_INLINE bool GAME_IS_DP      (int game_id) {return (game_id == 12 or game_id == 13);}
    static PKMN_CONSTEXPR_OR_INLINE bool GAME_IS_B2W2    (int game_id) {return (game_id == 21 or game_id == 22);}

    BOOST_STATIC_CONSTEXPR int COLOSSEUM = 19;

    std::string location_index_to_name(
        int location_index,
        int game_id
    )
    {
        std::string ret;

        if(game_is_gamecube(game_id))
        {
            static BOOST_CONSTEXPR const char* query =
                "SELECT name FROM location_names WHERE local_language_id=9 AND location_id=(SELECT "
                "location_id FROM gamecube_location_index_ranges WHERE range_start<=? AND "
                "colosseum=? ORDER BY range_start DESC)";

            ret = pkmn::database::query_db_bind2<std::string, int, int>(
                      query, location_index, ((game_id == COLOSSEUM) ? 1 : 0)
                  );
        }
        else
        {
            /*
             * Veekun's database stores location indices by generation, but some version
             * groups within a generation overlap indices. This solution isn't ideal, but
             * it's needed to work around how the database works.
             */
            if(GAME_IS_DP(game_id) and (location_index == 108))
            {
                ret = "Cafe";
            }
            else if(GAME_IS_B2W2(game_id) and (location_index == 36))
            {
                ret = "PWT";
            }
            else if((GAME_IS_SAPPHIRE(game_id) and (location_index == 486)) or
                    (GAME_IS_E(game_id) and (location_index == 197)))
            {
                ret = "Aqua Hideout";
            }
            else if(GAME_IS_RSE(game_id) and location_index == 87)
            {
                ret = "Ferry";
            }
            else
            {
                int generation = pkmn::database::game_id_to_generation(game_id);

                static BOOST_CONSTEXPR const char* query =
                    "SELECT name FROM location_names WHERE local_language_id=9 AND location_id="
                    "(SELECT location_id FROM location_game_indices WHERE game_index=? AND "
                    "generation_id=?)";

                ret = pkmn::database::query_db_bind2<std::string, int, int>(
                          query, location_index, generation
                      );
            }
        }

        return ret;
    }

    int location_name_to_index(
        const std::string& location_name,
        int game_id
    )
    {
        int ret = 0;

        std::string error_message = "Invalid location: ";
        error_message += location_name;

        if(game_is_gamecube(game_id))
        {
            static BOOST_CONSTEXPR const char* query =
                "SELECT max(range_start) FROM gamecube_location_index_ranges WHERE colosseum=? AND "
                "location_id=(SELECT location_id FROM location_names WHERE name=?)";

            ret = pkmn::database::query_db_bind2<int, int, const std::string&>(
                      query, ((game_id == COLOSSEUM) ? 1 : 0), location_name,
                      error_message
                  );

            /*
             * Even if the value is not in the gamecube_location_index_ranges table, it will
             * still return 0.
             */
            if(ret == 0)
            {
                throw std::invalid_argument(error_message);
            }
        }
        else
        {
            /*
             * Veekun's database stores location indices by generation, but some version
             * groups within a generation overlap indices. This solution isn't ideal, but
             * it's needed to work around how the database works.
             */
            if(GAME_IS_DP(game_id) and location_name == "Cafe")
            {
                ret = 108;
            }
            else if(GAME_IS_B2W2(game_id) and location_name == "PWT")
            {
                ret = 36;
            }
            else if(GAME_IS_SAPPHIRE(game_id) and location_name == "Aqua Hideout")
            {
                ret = 486;
            }
            else if(GAME_IS_E(game_id) and location_name == "Aqua Hideout")
            {
                ret = 197;
            }
            else if(GAME_IS_RSE(game_id) and location_name == "Ferry")
            {
                ret = 87;
            }
            else
            {
                int generation = pkmn::database::game_id_to_generation(game_id);

                static BOOST_CONSTEXPR const char* query =
                    "SELECT game_index FROM location_game_indices WHERE generation_id=? AND "
                    "location_id=(SELECT location_id FROM location_names WHERE name=?)";

                ret = pkmn::database::query_db_bind2<int, int, const std::string&>(
                          query, generation, location_name, error_message
                      );
            }
        }

        return ret;
    }

    std::string nature_index_to_name(
        int nature_index,
        bool increment_error_message
    )
    {
        static BOOST_CONSTEXPR const char* query =
            "SELECT name FROM nature_names WHERE local_language_id=9 "
            "AND nature_id=(SELECT id FROM natures WHERE game_index=?)";

        std::string error_message = "Invalid nature: ";
        error_message += std::to_string(
            increment_error_message ? (nature_index + 1) : nature_index
        );

        return pkmn::database::query_db_bind1<std::string, int>(
                   query,
                   nature_index,
                   error_message
               );
    }

    int nature_name_to_index(
        const std::string& nature_name
    )
    {
        static BOOST_CONSTEXPR const char* query =
            "SELECT game_index FROM natures WHERE id="
            "(SELECT nature_id FROM nature_names WHERE name=?)";

        std::string error_message = "Invalid nature: ";
        error_message += nature_name;

        return pkmn::database::query_db_bind1<int, const std::string&>(
                   query,
                   nature_name,
                   error_message
               );
    }

}}

max_stars_repo_name: ncorgan/libpkmn

max_issues_repo_name: PMArkive/libpkmn

max_forks_repo_name: PMArkive/libpkmn


text:
//  Copyright Neil Groves 2009. Use, modification and
//  distribution is subject to the Boost Software License, Version
//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//
//
// For more information, see http://www.boost.org/libs/range/
//
#ifndef BOOST_RANGE_ALGORITHM_ROTATE_HPP_INCLUDED
#define BOOST_RANGE_ALGORITHM_ROTATE_HPP_INCLUDED

#include <boost/concept_check.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/concepts.hpp>
#include <algorithm>

namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost
{
    namespace range
    {

/// \brief template function rotate
///
/// range-based version of the rotate std algorithm
///
/// \pre Rng meets the requirements for a Forward range
template<class ForwardRange>
inline ForwardRange& rotate(ForwardRange& rng,
    BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type middle)
{
    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
    std::rotate(mars_boost::begin(rng), middle, mars_boost::end(rng));
    return rng;
}

/// \overload
template<class ForwardRange>
inline const ForwardRange& rotate(const ForwardRange& rng,
    BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type middle)
{
    BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
    std::rotate(mars_boost::begin(rng), middle, mars_boost::end(rng));
    return rng;
}

    } // namespace range
    using range::rotate;
} // namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost

#endif // include guard

ext: hpp

max_stars_repo_name: jonetomtom/mars

max_issues_repo_name: wblzu/mars

max_forks_repo_name: pengjinning/mars


text:
#include "scope_axis_direction_predicate.h"

#include "geometry_component.h"
#include "geometry_core/scope.h"
#include "geometry_system.h"
#include "math_lib/radians.h"
#include "procedural_object_system.h"

#include <boost/qvm/vec_operations.hpp>

#include <cmath>
#include <sstream>

namespace pagoda
{
ScopeAxisDirectionPredicate::ScopeAxisDirectionPredicate(ProceduralObjectSystemPtr objectSystem, char scopeAxis,
                                                         const Vec3F& direction, const Degrees<float>& tolerance)
    : ProceduralObjectPredicate(objectSystem),
      m_scopeAxis(scopeAxis),
      m_direction(normalized(direction)),
      m_tolerance(tolerance)
{
	m_geometrySystem = objectSystem->GetComponentSystem<GeometrySystem>();
}

ScopeAxisDirectionPredicate::~ScopeAxisDirectionPredicate() {}

bool ScopeAxisDirectionPredicate::operator()(const ProceduralObjectPtr object)
{
	auto geometryComponent = m_geometrySystem->GetComponentAs<GeometryComponent>(object);
	if (geometryComponent == nullptr)
	{
		return false;
	}
	Scope scope = geometryComponent->GetScope();
	Vec3F axis = scope.GetAxis(m_scopeAxis);

	auto angle = std::acos(boost::qvm::dot(axis, m_direction));
	if (angle <= static_cast<float>(Radians<float>(m_tolerance)))
	{
		return true;
	}

	return false;
}

std::string ScopeAxisDirectionPredicate::ToString()
{
	std::stringstream ss;
	ss << "ScopeAxisDirectionPredicate. axis: " << m_scopeAxis << " direction: " << m_direction
	   << " tolerance: " << static_cast<float>(m_tolerance);
	return ss.str();
}
}  // namespace pagoda

ext: cpp

max_stars_repo_name: diegoarjz/selector

max_issues_repo_name: diegoarjz/selector

max_forks_repo_name: diegoarjz/selector


text:
// Copyright (c) 2008 Joseph Gauterin, Niels Dekker
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap.

#include <boost/utility/swap.hpp>
#define BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>

//Put test class in the global namespace
#include "./swap_test_class.hpp"

#include <algorithm> //for std::copy and std::equal
#include <cstddef> //for std::size_t

//Provide swap function in both the namespace of swap_test_class
//(which is the global namespace), and the std namespace.
//It's common to provide a swap function for a class in both
//namespaces. Scott Meyers recommends doing so: Effective C++,
//Third Edition, item 25, "Consider support for a non-throwing swap".
void swap(swap_test_class& left, swap_test_class& right)
{
  left.swap(right);
}

namespace std
{
  template <>
  void swap(swap_test_class& left, swap_test_class& right)
  {
    left.swap(right);
  }
}

int test_main(int, char*[])
{
  const std::size_t first_dimension = 3;
  const std::size_t second_dimension = 4;
  const std::size_t number_of_elements = first_dimension * second_dimension;

  swap_test_class array1[first_dimension][second_dimension];
  swap_test_class array2[first_dimension][second_dimension];

  swap_test_class* const ptr1 = array1[0];
  swap_test_class* const ptr2 = array2[0];

  for (std::size_t i = 0; i < number_of_elements; ++i)
  {
    ptr1[i].set_data( static_cast<int>(i) );
    ptr2[i].set_data( static_cast<int>(i + number_of_elements) );
  }

  boost::swap(array1, array2);

  for (std::size_t i = 0; i < number_of_elements; ++i)
  {
    BOOST_CHECK_EQUAL(ptr1[i].get_data(), static_cast<int>(i + number_of_elements) );
    BOOST_CHECK_EQUAL(ptr2[i].get_data(), static_cast<int>(i) );
  }

  BOOST_CHECK_EQUAL(swap_test_class::swap_count(), number_of_elements);
  BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0);

  return 0;
}

max_stars_repo_name: randolphwong/mcsema

max_issues_repo_name: randolphwong/mcsema

max_forks_repo_name: randolphwong/mcsema


text:
#include <CGAL/Simple_cartesian.h>
#include <CGAL/K_neighbor_search.h>
#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Search_traits_3.h>
#include <CGAL/Timer.h>

#include <iostream>
#include <fstream>

#include <boost/lexical_cast.hpp>

typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Search_traits_3<K> TreeTraits_3;
typedef K::Point_3 Point_3;
typedef CGAL::Euclidean_distance<TreeTraits_3> Distance;
typedef CGAL::Sliding_midpoint<TreeTraits_3> Splitter;
typedef CGAL::Orthogonal_k_neighbor_search<TreeTraits_3,Distance,Splitter> Neighbor_search_3;
typedef Neighbor_search_3::Tree Tree_3;
typedef CGAL::Timer Timer;

typedef std::vector<Point_3> Points;

void read(Points& points, char* argv)
{
  int d, n;
  double x,y,z;
#if 0
  std::ifstream data(argv);
  data >> d >> n;
  assert(d == 3);
  points.reserve(n);
  while(data >> p){
    points.push_back(p);
  }
  data.close();

#else
 std::ifstream data(argv, std::ios::in | std::ios::binary);
  CGAL::IO::set_binary_mode(data);
  CGAL::read(data,d);
  CGAL::read(data,n);

  points.reserve(n);
  for(int i=0; i < n; i++){
    CGAL::read(data,x);
    CGAL::read(data,y);
    CGAL::read(data,z);
    points.push_back(Point_3(x,y,z));
  }
#endif
  data.close();
}

int main(int argc,char *argv[])
{
  Points query_points_3, data_points_3;

  Point_3 p;
  Timer t;

  read(data_points_3, argv[1]);
  read(query_points_3, argv[2]);

  int runs = (argc>3) ? boost::lexical_cast<int>(argv[3]) : 1;
  std::cerr << "runs = "  << runs <<std::endl;

  int bucketsize = (argc>4) ? boost::lexical_cast<int>(argv[4]) : 10;
  std::cerr << "bucketsize = "  << bucketsize <<std::endl;

  int NN_number = (argc>5) ? boost::lexical_cast<int>(argv[5]) : 10;
  std::cerr << "k = "  << NN_number <<std::endl;

  t.start();
  // Insert data points in the tree
  Tree_3 tree(data_points_3.begin(), data_points_3.end(),Splitter(bucketsize));
  tree.build();
  t.stop();
  std::cerr << "build " << t.time() << " sec\n";
  int items=0,leafs=0,internals=0;
  Points result(NN_number);
  tree.statistics(std::cerr);
  double sum=0;
  bool dump = true;

  for(int i = 0 ; i<runs; ++i){

    for(Points::iterator it = query_points_3.begin(); it != query_points_3.end(); ++it) {
      // Initialize the search structure, and search all NN_number neighbors
       t.reset();t.start();
      Neighbor_search_3 search(tree, *it, NN_number);
       t.stop();
      int i=0;
      for (Neighbor_search_3::iterator it = search.begin(); it != search.end();it++, i++) {
        result[i] = it->first;
        if(dump){
          std::cerr << result[i].x()<<" "<<result[i].y()<<" "<<result[i].z()<< std::endl;
        }
      }
      dump = false;
       sum += t.time();
       items+=search.items_visited();
       leafs+=search.leafs_visited();
       internals+=search.internals_visited();
    }

  }

  std::cerr << items <<" items\n";
  std::cerr << leafs <<" leaf\n";
  std::cerr << internals <<" internals visited\n";

  std::cerr<<std::endl << "total: " << sum << " sec\n";
  if(runs>1){
    std::cerr << "average: " << sum/runs << " sec\n";
  }
    std::cerr << "done\n";
  return 0;
}

max_stars_repo_name: ffteja/cgal

max_issues_repo_name: ffteja/cgal

max_forks_repo_name: ffteja/cgal


text:
/**************************************************************
 *
 * 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
 *
 * 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.
 *
 *************************************************************/

#ifndef _CHARTVIEWIMPL_HXX
#define _CHARTVIEWIMPL_HXX

#include "chartview/ExplicitValueProvider.hxx"
#include "ServiceMacros.hxx"
#include <cppuhelper/implbase9.hxx>
#include <cppuhelper/interfacecontainer.hxx>

// header for class SfxListener
#include <svl/lstner.hxx>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/util/XModeChangeBroadcaster.hpp>
#include <com/sun/star/util/XUpdatable.hpp>

#include <vector>
#include <boost/shared_ptr.hpp>

class SdrPage;

//.............................................................................
namespace chart
{
//.............................................................................

class VCoordinateSystem;
class DrawModelWrapper;
class SeriesPlotterContainer;

//-----------------------------------------------------------------------------
/** The ChartView is responsible to manage the generation of Drawing Objects
for visualization on a given OutputDevice. The ChartModel is responsible to notify changes to the view.
The view than changes to state dirty. The view can be updated with call 'update'.

The View is not responsible to handle single user events (that is instead done by the ChartWindow).
*/

class ChartView : public ::cppu::WeakImplHelper9<
	::com::sun::star::lang::XInitialization
		, ::com::sun::star::lang::XServiceInfo
        , ::com::sun::star::datatransfer::XTransferable
        ,::com::sun::star::lang::XUnoTunnel
		//::com::sun::star::lang::XComponent ???
		//::com::sun::star::uno::XWeak			// implemented by WeakImplHelper(optional interface)
		//::com::sun::star::uno::XInterface		// implemented by WeakImplHelper(optional interface)
		//::com::sun::star::lang::XTypeProvider	// implemented by WeakImplHelper
        ,::com::sun::star::util::XModifyListener
        ,::com::sun::star::util::XModeChangeBroadcaster
        ,::com::sun::star::util::XUpdatable
        ,::com::sun::star::beans::XPropertySet
        ,::com::sun::star::lang::XMultiServiceFactory
		>
        , public ExplicitValueProvider
        , private SfxListener
{
public:
    ChartView(::com::sun::star::uno::Reference<
			   ::com::sun::star::uno::XComponentContext > const & xContext);
	virtual ~ChartView();

    // ___lang::XServiceInfo___
	APPHELPER_XSERVICEINFO_DECL()
	APPHELPER_SERVICE_FACTORY_HELPER(ChartView)

	// ___lang::XInitialization___
    virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
                throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // ___ExplicitValueProvider___
    virtual sal_Bool getExplicitValuesForAxis(
        ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > xAxis
        , ExplicitScaleData&  rExplicitScale
        , ExplicitIncrementData& rExplicitIncrement );
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >
        getShapeForCID( const rtl::OUString& rObjectCID );

    virtual ::com::sun::star::awt::Rectangle getRectangleOfObject( const rtl::OUString& rObjectCID, bool bSnapRect=false );

    virtual ::com::sun::star::awt::Rectangle getDiagramRectangleExcludingAxes();

    ::boost::shared_ptr< DrawModelWrapper > getDrawModelWrapper();

    // ___XTransferable___
    virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
                throw (::com::sun::star::datatransfer::UnsupportedFlavorException
                     , ::com::sun::star::io::IOException
                     , ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors(  )
                throw (::com::sun::star::uno::RuntimeException);
    virtual ::sal_Bool SAL_CALL isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
                throw (::com::sun::star::uno::RuntimeException);

    //-------------------------------------------------------------------------------------
	// ::com::sun::star::util::XEventListener (base of XCloseListener and XModifyListener)
	//-------------------------------------------------------------------------------------
	virtual void SAL_CALL
		disposing( const ::com::sun::star::lang::EventObject& Source )
							throw (::com::sun::star::uno::RuntimeException);

    //-----------------------------------------------------------------
    // ::com::sun::star::util::XModifyListener
    //-----------------------------------------------------------------
    virtual void SAL_CALL modified(
        const ::com::sun::star::lang::EventObject& aEvent )
        throw (::com::sun::star::uno::RuntimeException);

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

    //-----------------------------------------------------------------
    // ::com::sun::star::util::XModeChangeBroadcaster
    //-----------------------------------------------------------------

    virtual void SAL_CALL addModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addModeChangeApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeApproveListener >& _rxListener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeModeChangeApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeApproveListener >& _rxListener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);

    //-----------------------------------------------------------------
    // ::com::sun::star::util::XUpdatable
    //-----------------------------------------------------------------
    virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException);

    //-----------------------------------------------------------------
    // ::com::sun::star::beans::XPropertySet
    //-----------------------------------------------------------------
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);

    //-----------------------------------------------------------------
    // ::com::sun::star::lang::XMultiServiceFactory
    //-----------------------------------------------------------------
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier )
        throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments(
        const ::rtl::OUString& ServiceSpecifier, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments )
        throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames() throw (::com::sun::star::uno::RuntimeException);

    // for ExplicitValueProvider
    // ____ XUnoTunnel ___
    virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier )
            throw (::com::sun::star::uno::RuntimeException);

private: //methods
    ChartView();

    void createShapes();
    void getMetaFile( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream
                      , bool bUseHighContrast );
    SdrPage* getSdrPage();

    void impl_setChartModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel );
    void impl_deleteCoordinateSystems();
    void impl_notifyModeChangeListener( const rtl::OUString& rNewMode );

    void impl_refreshAddIn();
    bool impl_AddInDrawsAllByItself();

    void impl_updateView();

    ::com::sun::star::awt::Rectangle impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlotterContainer
        , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes>& xDiagramPlusAxes_Shapes
        , const ::com::sun::star::awt::Point& rAvailablePos
        , const ::com::sun::star::awt::Size& rAvailableSize
        , const ::com::sun::star::awt::Size& rPageSize
        , bool bUseFixedInnerSize
        , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape>& xDiagram_MarkHandles );

private: //member
    ::osl::Mutex m_aMutex;

	::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>
			m_xCC;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
            m_xChartModel;

	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>
			m_xShapeFactory;
	::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage>
			m_xDrawPage;

    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xDashTable;
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xGradientTable;
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xHatchTable;
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xBitmapTable;
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xTransGradientTable;
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xMarkerTable;

    ::boost::shared_ptr< DrawModelWrapper > m_pDrawModelWrapper;

    std::vector< VCoordinateSystem* > m_aVCooSysList;

    ::cppu::OMultiTypeInterfaceContainerHelper
                        m_aListenerContainer;

    bool volatile       m_bViewDirty; //states whether the view needs to be rebuild
    bool volatile       m_bInViewUpdate;
    bool volatile       m_bViewUpdatePending;
    bool volatile		m_bRefreshAddIn;

    //better performance for big data
    ::com::sun::star::awt::Size m_aPageResolution;
    bool m_bPointsWereSkipped;

    //#i75867# poor quality of ole's alternative view with 3D scenes and zoomfactors besides 100%
    sal_Int32 m_nScaleXNumerator;
    sal_Int32 m_nScaleXDenominator;
    sal_Int32 m_nScaleYNumerator;
    sal_Int32 m_nScaleYDenominator;

    sal_Bool m_bSdrViewIsInEditMode;

    ::com::sun::star::awt::Rectangle m_aResultingDiagramRectangleExcludingAxes;
};

//.............................................................................
} //namespace chart
//.............................................................................

#endif

ext: hxx

max_stars_repo_name: Grosskopf/openoffice

max_issues_repo_name: Grosskopf/openoffice

max_forks_repo_name: Grosskopf/openoffice


text:
////////////////////////////////////////////////////////////////////////////////
//  Copyright (c) 2007-2015 Hartmut Kaiser
//  Copyright (c) 2008-2009 Chirag Dekate, Anshul Tandon
//  Copyright (c) 2012-2013 Thomas Heller
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#ifndef HPX_RUNTIME_THREADS_TOPOLOGY_HPP
#define HPX_RUNTIME_THREADS_TOPOLOGY_HPP

#include <hpx/config.hpp>
#include <hpx/exception_fwd.hpp>
#include <hpx/runtime/naming_fwd.hpp>
#include <hpx/runtime/threads/cpu_mask.hpp>

#include <boost/thread/thread.hpp>

#include <cstddef>
#include <iosfwd>
#include <utility>

#if defined(HPX_HAVE_HWLOC)
#include <hpx/error_code.hpp>

#include <cstddef>
#include <string>
#include <vector>
#endif

namespace hpx { namespace threads
{
    struct HPX_EXPORT topology
    {
        virtual ~topology() {}

        virtual std::size_t get_pu_number(
            std::size_t num_thread
          , error_code& ec = throws
            ) const = 0;

        /// \brief Return the NUMA node number of the processing unit the
        ///        given thread is running on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual std::size_t get_numa_node_number(std::size_t num_thread,
            error_code& ec = throws) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit available to the application.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_cref_type get_machine_affinity_mask(
            error_code& ec = throws) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit available to the service threads in the
        ///        application.
        ///
        /// \param used_processing_units [in] This is the mask of processing
        ///                   units which are not available for service threads.
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_type get_service_affinity_mask(
            mask_cref_type used_processing_units, error_code& ec = throws) const;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit available to the given thread inside
        ///        the socket it is running on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_cref_type get_socket_affinity_mask(std::size_t num_thread,
            bool numa_sensitive, error_code& ec = throws) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit available to the given thread inside
        ///        the NUMA domain it is running on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_cref_type get_numa_node_affinity_mask(std::size_t num_thread,
            bool numa_sensitive, error_code& ec = throws) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit associated with the given NUMA node.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_type get_numa_node_affinity_mask_from_numa_node(
            std::size_t num_node) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit available to the given thread inside
        ///        the core it is running on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_cref_type get_core_affinity_mask(std::size_t num_thread,
            bool numa_sensitive, error_code& ec = throws) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit available to the given thread.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_cref_type get_thread_affinity_mask(std::size_t num_thread,
            bool numa_sensitive = false, error_code& ec = throws) const = 0;

        /// \brief Use the given bit mask to set the affinity of the given
        ///        thread. Each set bit corresponds to a processing unit the
        ///        thread will be allowed to run on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        ///
        /// \note  Use this function on systems where the affinity must be
        ///        set from outside the thread itself.
        virtual void set_thread_affinity_mask(boost::thread& t,
            mask_cref_type mask, error_code& ec = throws) const = 0;

        /// \brief Use the given bit mask to set the affinity of the given
        ///        thread. Each set bit corresponds to a processing unit the
        ///        thread will be allowed to run on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        ///
        /// \note  Use this function on systems where the affinity must be
        ///        set from inside the thread itself.
        virtual void set_thread_affinity_mask(mask_cref_type mask,
            error_code& ec = throws) const = 0;

        /// \brief Return a bit mask where each set bit corresponds to a
        ///        processing unit co-located with the memory the given
        ///        address is currently allocated on.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual mask_type get_thread_affinity_mask_from_lva(
            naming::address_type, error_code& ec = throws) const = 0;

        /// \brief Prints the \param m to os in a human readable form
        virtual void print_affinity_mask(std::ostream& os,
            std::size_t num_thread, mask_type const& m) const = 0;

        /// \brief Reduce thread priority of the current thread.
        ///
        /// \param ec         [in,out] this represents the error status on exit,
        ///                   if this is pre-initialized to \a hpx#throws
        ///                   the function will throw on error instead.
        virtual bool reduce_thread_priority(error_code& ec = throws) const;

        /// \brief Return the number of available NUMA domains
        virtual std::size_t get_number_of_sockets() const = 0;

        /// \brief Return the number of available NUMA domains
        virtual std::size_t get_number_of_numa_nodes() const = 0;

        /// \brief Return the number of available cores
        virtual std::size_t get_number_of_cores() const = 0;

        /// \brief Return the number of available hardware processing units
        virtual std::size_t get_number_of_pus() const = 0;

        /// \brief Return number of cores in given numa domain
        virtual std::size_t get_number_of_numa_node_cores(std::size_t numa) const = 0;

        /// \brief Return number of processing units in a given numa domain
        virtual std::size_t get_number_of_numa_node_pus(std::size_t numa) const = 0;

        /// \brief Return number of processing units in a given socket
        virtual std::size_t get_number_of_socket_pus(std::size_t socket) const = 0;

        /// \brief Return number of processing units in given core
        virtual std::size_t get_number_of_core_pus(std::size_t core) const = 0;

        virtual std::size_t get_core_number(std::size_t num_thread,
            error_code& ec = throws) const = 0;

        virtual mask_type get_cpubind_mask(error_code& ec = throws) const = 0;
        virtual mask_type get_cpubind_mask(boost::thread & handle,
            error_code& ec = throws) const = 0;

        virtual void write_to_log() const = 0;

        /// This is equivalent to malloc(), except that it tries to allocate
        /// page-aligned memory from the OS.
        virtual void* allocate(std::size_t len) const = 0;

        /// Free memory that was previously allocated by allocate
        virtual void deallocate(void* addr, std::size_t len) const = 0;
    };

    HPX_API_EXPORT std::size_t hardware_concurrency();

    HPX_API_EXPORT topology const& get_topology();

#if defined(HPX_HAVE_HWLOC)
    HPX_API_EXPORT void parse_affinity_options(std::string const& spec,
        std::vector<mask_type>& affinities,
        std::size_t used_cores,
        std::size_t max_cores,
        std::size_t num_threads,
        std::vector<std::size_t>& num_pus,
        error_code& ec = throws);

    // backwards compatibility helper
    inline void parse_affinity_options(std::string const& spec,
        std::vector<mask_type>& affinities, error_code& ec = throws)
    {
        std::vector<std::size_t> num_pus;
        parse_affinity_options(spec, affinities, 1, 1, affinities.size(),
            num_pus, ec);
    }
#endif

    /// \endcond
}}

#endif /*HPX_RUNTIME_THREADS_TOPOLOGY_HPP*/

max_stars_repo_name: brycelelbach/hpx

max_issues_repo_name: brycelelbach/hpx

max_forks_repo_name: brycelelbach/hpx


text:
//=======================================================================
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/graph_archetypes.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <boost/concept/assert.hpp>

int main(int,char*[])
{
  using namespace boost;
  // Check filtered_graph
  {
    typedef adjacency_list<vecS, vecS, directedS,
      no_property, property<edge_residual_capacity_t, long> > Graph;
    typedef property_map<Graph, edge_residual_capacity_t>::type ResCapMap;
    typedef filtered_graph<Graph, is_residual_edge<ResCapMap> > ResGraph;
    typedef graph_traits<ResGraph>::edge_descriptor Edge;

    BOOST_CONCEPT_ASSERT(( VertexListGraphConcept<ResGraph> ));
    BOOST_CONCEPT_ASSERT(( EdgeListGraphConcept<ResGraph> ));
    BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept<ResGraph> ));
    BOOST_CONCEPT_ASSERT(( AdjacencyGraphConcept<ResGraph> ));
    BOOST_CONCEPT_ASSERT(( PropertyGraphConcept<ResGraph, Edge,
      edge_residual_capacity_t> ));
  }
  // Check filtered_graph with bidirectional adjacency_list
  {
    typedef adjacency_list<vecS, vecS, bidirectionalS,
      no_property, property<edge_residual_capacity_t, long> > Graph;
    typedef property_map<Graph, edge_residual_capacity_t>::type ResCapMap;
    typedef filtered_graph<Graph, is_residual_edge<ResCapMap> > ResGraph;
    BOOST_CONCEPT_ASSERT(( BidirectionalGraphConcept<ResGraph> ));
  }
  // Check filtered_graph with undirected adjacency_list
  {
    typedef adjacency_list<vecS, vecS, undirectedS,
      no_property, property<edge_residual_capacity_t, long> > Graph;
    typedef property_map<Graph, edge_residual_capacity_t>::type ResCapMap;
    typedef filtered_graph<Graph, is_residual_edge<ResCapMap> > ResGraph;
    BOOST_CONCEPT_ASSERT(( BidirectionalGraphConcept<ResGraph> ));
  }
  return 0;
}


text:
// Copyright (C) 2012  Davis E. King (davis@dlib.net)
// License: Boost Software License   See LICENSE.txt for the full license.

#include <dlib/svm.h>

#include "tester.h"

namespace
{

    using namespace test;
    using namespace dlib;
    using namespace std;

    logger dlog("test.active_learning");

// ----------------------------------------------------------------------------------------

    typedef matrix<double, 0, 1> sample_type;
    typedef radial_basis_kernel<sample_type> kernel_type;

// ----------------------------------------------------------------------------------------

    void make_dataset (
        std::vector<sample_type>& samples,
        std::vector<double>& labels
    )
    {
        for (int r = -10; r <= 10; ++r)
        {
            for (int c = -10; c <= 10; ++c)
            {
                sample_type samp(2);
                samp(0) = r;
                samp(1) = c;
                samples.push_back(samp);

                // if this point is less than 10 from the origin
                if (sqrt((double)r*r + c*c) <= 8)
                    labels.push_back(+1);
                else
                    labels.push_back(-1);

            }
        }

        vector_normalizer<sample_type> normalizer;
        normalizer.train(samples);
        for (unsigned long i = 0; i < samples.size(); ++i)
            samples[i] = normalizer(samples[i]);

        randomize_samples(samples, labels);

        /*
        cout << "samples.size(): " << samples.size() << endl;
        cout << "num +1 samples: "<< sum(mat(labels) > 0) << endl;
        cout << "num -1 samples: "<< sum(mat(labels) < 0) << endl;
        */

        empirical_kernel_map<kernel_type> ekm;
        ekm.load(kernel_type(0.15), samples);
        for (unsigned long i = 0; i < samples.size(); ++i)
            samples[i] = ekm.project(samples[i]);

        //cout << "dims: "<< ekm.out_vector_size() << endl;
    }

// ----------------------------------------------------------------------------------------

    double test_rank_unlabeled_training_samples (
        const std::vector<sample_type>& samples,
        const std::vector<double>& labels,
        active_learning_mode mode,
        int iterations,
        bool pick_front
    )
    {
        matrix<double,2,1> s;
        s = sum(mat(labels) > 0), sum(mat(labels) < 0);
        s /= labels.size();

        svm_c_linear_dcd_trainer<linear_kernel<sample_type> > trainer;
        trainer.set_c(25);

        const unsigned long initial_size = 1;
        std::vector<sample_type> tsamples(samples.begin(), samples.begin()+initial_size);
        std::vector<double> tlabels(labels.begin(), labels.begin()+initial_size);

        decision_function<linear_kernel<sample_type> > df;

        double random_score = 0;
        double active_learning_score = 0;
        for (int i = 0; i < iterations; ++i)
        {
            print_spinner();
            random_subset_selector<sample_type> sss = randomly_subsample(samples,50,i);
            random_subset_selector<double> ssl = randomly_subsample(labels,50,i);
            std::vector<unsigned long> results;

            results = rank_unlabeled_training_samples(trainer, tsamples, tlabels, sss, mode);

            const unsigned long idx = pick_front ? results.front() : results.back();
            tsamples.push_back(sss[idx]);
            tlabels.push_back(ssl[idx]);

            df = trainer.train(tsamples, tlabels);
            //cout << "tsamples.size(): " << tsamples.size() << endl;
            const unsigned long num = tsamples.size();
            const double active = test_binary_decision_function(df, samples, labels)*s;
            //cout << "test: "<< active;
            df = trainer.train(randomly_subsample(samples,num,i), randomly_subsample(labels,num,i));
            const double random = test_binary_decision_function(df, samples, labels)*s;
            //cout << "test: "<< random << endl;

            active_learning_score += active;
            random_score += random;

            //cout << "\n\n***********\n\n" << flush;
        }

        dlog << LINFO << "pick_front: " << pick_front << "   mode: "<< mode;
        dlog << LINFO << "active_learning_score: "<< active_learning_score;
        dlog << LINFO << "random_score:          "<< random_score;
        return active_learning_score / random_score;
    }

// ----------------------------------------------------------------------------------------

    class test_active_learning : public tester
    {
    public:
        test_active_learning (
        ) :
            tester ("test_active_learning",
                "Runs tests on the active learning components.")
        {}

        void perform_test (
        )
        {
            std::vector<sample_type> samples;
            std::vector<double> labels;
            print_spinner();
            make_dataset(samples, labels);
            dlog << LINFO << "samples.size(): "<< samples.size();

            // When we pick the best/front ranked element then the active learning method
            // shouldn't do much worse than random selection (and often much better).
            DLIB_TEST(test_rank_unlabeled_training_samples(samples, labels, max_min_margin, 25, true) >= 0.97);
            DLIB_TEST(test_rank_unlabeled_training_samples(samples, labels, ratio_margin, 25, true) >= 0.96);
            // However, picking the worst ranked element should do way worse than random
            // selection.
            DLIB_TEST(test_rank_unlabeled_training_samples(samples, labels, max_min_margin, 25, false) < 0.8);
            DLIB_TEST(test_rank_unlabeled_training_samples(samples, labels, ratio_margin, 25, false) < 0.8);
        }
    } a;

}

max_stars_repo_name: yatonon/dlib-face

max_issues_repo_name: lwneal/tfasts

max_forks_repo_name: lwneal/tfasts


text:
#include <JCDT_Lib/internal/util/case.h>
#include "JCDT_Lib/internal/lookup/DirectorySymbol.h"
#include "JCDT_Lib/internal/lookup/PathSymbol.h"
#include "JCDT_Lib/internal/lookup/DirectoryEntry.h"
#include "JCDT_Lib/internal/lookup/DirectoryTable.h"
#include "JCDT_Lib/internal/lookup/FileSymbol.h"
#include "JCDT_Lib/internal/lookup/BindingSymbolTable.h"
#include <JCDT_Lib/internal/util/CharOperation.h>
#include <boost/filesystem/operations.hpp>

namespace Jikes { // Open namespace Jikes block

	BindingSymbolTable* DirectorySymbol::Table()
	{
		return table ? table : table = new BindingSymbolTable(101);
	}

	FileSymbol* DirectorySymbol::FindFileSymbol(const NameSymbol* name_symbol)
	{
		return table ? table->FindFileSymbol(name_symbol)
			: (FileSymbol*)NULL;
	}

	FileSymbol* DirectorySymbol::InsertFileSymbol(const NameSymbol* name_symbol)
	{
		return Table()->InsertFileSymbol(name_symbol);
	}

	void DirectorySymbol::InsertFileSymbol(FileSymbol* file_symbol)
	{
		return Table()->InsertFileSymbol(file_symbol);
	}

	DirectorySymbol* DirectorySymbol::InsertDirectorySymbol(const NameSymbol* name_symbol,
		bool source_dir)
	{
		DirectorySymbol* subdirectory_symbol =
			Table()->InsertDirectorySymbol(name_symbol, this,
				source_dir && source_dir_only);
		subdirectories.Next() = subdirectory_symbol;
		return subdirectory_symbol;
	}

	DirectorySymbol* DirectorySymbol::FindDirectorySymbol(const NameSymbol* name_symbol)
	{
		return table ? table->FindDirectorySymbol(name_symbol)
			: (DirectorySymbol*)NULL;
	}

	PathSymbol* DirectorySymbol::PathSym()
	{
		PathSymbol* temp = PathSymbol::PathCast(owner);// PathSymbol* temp = owner->PathCast();
		return  temp ? (PathSymbol*)owner
			: ((DirectorySymbol*)owner)->PathSym();
	}

	bool DirectorySymbol::IsZip() { return PathSym()->IsZip(); }

#ifdef WIN32_FILE_SYSTEM
	DirectoryEntry* DirectorySymbol::FindCaseInsensitiveEntry(char* name, unsigned length)
	{
		return entries ? entries->FindCaseInsensitiveEntry(name, length)
			: (DirectoryEntry*)NULL;
	}

	void DirectorySymbol::InsertEntry(char* name, unsigned length)
	{
		assert(entries);

		DirectoryEntry* entry = entries->InsertEntry(this, name, length);
		entries->InsertCaseInsensitiveEntry(entry);
	}
#endif // WIN32_FILE_SYSTEM

	DirectorySymbol::DirectorySymbol(const NameSymbol* name_symbol_,
		Symbol* owner_, bool source_dir_only_)
		: owner(owner_)
		, name_symbol(name_symbol_)
		, mtime(0)
		, table(NULL)
		, entries(NULL)
		, directory_name()
		, source_dir_only(source_dir_only_)
	{
		Symbol::_kind = _DIRECTORY;
	}

	DirectoryEntry* DirectorySymbol::FindEntry(char* name, unsigned len)
	{
		DirectoryEntry* find_it = nullptr;
		if(entries) {
			find_it = entries->FindEntry(name, len);
			if (find_it) {
				return find_it;
			}
		}
		else{
			entries = new DirectoryTable();
		}
		auto _w_dir = DirectoryNameString();
		_w_dir += string(name,name + len);
		using namespace boost::filesystem;
		auto file =  path(CharOperation::ConvertUtf8ToUnicode(_w_dir));
		boost::system::error_code ec;
		if (!exists(file,ec)) {
			return nullptr;
		}

		bool is_java = false;
		auto _ext = file.extension().wstring();
		if (_ext == L".java") {
			is_java = true;
		}
		else if (_ext == L".class") {
		}
		else {
			return nullptr;
		}

		auto _clean_name = file.filename().string();
		DirectoryEntry* entry =
			entries->InsertEntry(this, _clean_name.c_str(), _clean_name.size());
		if (!is_java)
			entries->InsertCaseInsensitiveEntry(entry);

		return entry;
	}

	DirectorySymbol::~DirectorySymbol()
	{

		delete entries;
		delete table;
	}

	void DirectorySymbol::SetDirectoryName()
	{
		//PathSymbol* path_symbol = owner->PathCast();
		PathSymbol* path_symbol = PathSymbol::PathCast(owner);
		if (path_symbol)
		{
			auto __utf_name_string = Utf8NameString();
			if (__utf_name_string ==  ".")
			{
				directory_name.swap(__utf_name_string);
			}
			else
			{
				auto directory_name_length = path_symbol->Utf8NameLength();
				auto _name = path_symbol->Utf8Name();
				directory_name.assign(_name, _name + directory_name_length);

			}
		}
		else
		{
			DirectorySymbol* owner_directory = DirectorySymbol::DirectoryCast(owner);  // DirectorySymbol* owner_directory = owner->DirectoryCast();

			if (Name()[NameLength() - 1] == U_SLASH ||
				strcmp(owner_directory->DirectoryName(), ".") == 0)
			{
				// An absolute file name, or is the owner "." ?
				directory_name = Utf8NameString();
			}
			else
			{
				int owner_length = owner_directory->DirectoryNameLength();
				auto owner_name = owner_directory->DirectoryName();
				auto directory_name_length = owner_length + Utf8NameLength() +
					(owner_name[owner_length - 1] != U_SLASH ? 1 : 0); // +1: '/'

				auto __utf_name_string = Utf8NameString();
				directory_name.assign(owner_name, owner_name + owner_length);

				if (owner_name[owner_length - 1] != U_SLASH)
					directory_name.append(StringConstant::U8S_SL);
				directory_name += __utf_name_string;
			}
		}

	}

	void DirectorySymbol::ResetDirectory()
	{
		delete entries;
		entries = NULL;
		ReadDirectory();
	}

	void DirectorySymbol::ReadDirectory()
	{
		assert(!IsZip());
		if (!entries){
			entries = new DirectoryTable();
			using namespace boost::filesystem;
			auto _w_dir =   CharOperation::ConvertUtf8ToUnicode(DirectoryNameString());
			boost::system::error_code ec;
			if(!is_directory(_w_dir , ec)){
				return;
			}
			directory_iterator end;
			for (directory_iterator pos(_w_dir); pos != end; ++pos) {
				if (is_directory(*pos, ec) == false) {
					path file(*pos);
					bool is_java = false;
					auto _ext = file.extension().wstring();
					if (_ext == L".java"){
						is_java = true;
					}
					else if (_ext == L".class") {
					}
					else{
						continue;
					}
					auto _clean_name =  file.filename().string();
					DirectoryEntry* entry =
						entries->InsertEntry(this, _clean_name.c_str(), _clean_name.size());
					if (!is_java)
						entries->InsertCaseInsensitiveEntry(entry);
				}
			}
		}
	}

} // Close namespace Jikes block

max_stars_repo_name: kuafuwang/JCDT

max_issues_repo_name: kuafuwang/JCDT

max_forks_repo_name: kuafuwang/JCDT


text:
//
// Copyright (c) 2015-2020 CNRS INRIA
//

#include "pinocchio/parsers/urdf.hpp"
#include "pinocchio/bindings/python/parsers/urdf.hpp"

#include <boost/python.hpp>

namespace pinocchio
{
  namespace python
  {

    namespace bp = boost::python;

#ifdef PINOCCHIO_WITH_URDFDOM

    GeometryModel
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type)
    {
      GeometryModel geometry_model;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model);

      return geometry_model;
    }

    GeometryModel &
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      GeometryModel & geometry_model)
    {
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model);
      return geometry_model;
    }

    GeometryModel
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      const std::vector<std::string> & package_dirs)
    {
      GeometryModel geometry_model;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dirs);

      return geometry_model;
    }

    GeometryModel &
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      GeometryModel & geometry_model,
                      const std::vector<std::string> & package_dirs)
    {
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dirs);

      return geometry_model;
    }

    GeometryModel
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      const std::string & package_dir)
    {
      GeometryModel geometry_model;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dir);

      return geometry_model;
    }

    GeometryModel &
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      GeometryModel & geometry_model,
                      const std::string & package_dir)
    {
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dir);

      return geometry_model;
    }

#ifdef PINOCCHIO_WITH_HPP_FCL
    GeometryModel
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      const fcl::MeshLoaderPtr & meshLoader)
    {
      std::vector<std::string> hints;
      GeometryModel geometry_model;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,hints,meshLoader);

      return geometry_model;
    }

    GeometryModel &
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      GeometryModel & geometry_model,
                      const fcl::MeshLoaderPtr & meshLoader)
    {
      std::vector<std::string> hints;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,hints,meshLoader);

      return geometry_model;
    }

    GeometryModel
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      const std::vector<std::string> & package_dirs,
                      const fcl::MeshLoaderPtr & meshLoader)
    {
      GeometryModel geometry_model;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dirs,meshLoader);

      return geometry_model;
    }

    GeometryModel &
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      GeometryModel & geometry_model,
                      const std::vector<std::string> & package_dirs,
                      const fcl::MeshLoaderPtr & meshLoader)
    {
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dirs,meshLoader);

      return geometry_model;
    }

    GeometryModel
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      const std::string & package_dir,
                      const fcl::MeshLoaderPtr & meshLoader)
    {
      GeometryModel geometry_model;
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dir,meshLoader);

      return geometry_model;
    }

    GeometryModel &
    buildGeomFromUrdf(const Model & model,
                      const std::string & filename,
                      const GeometryType type,
                      GeometryModel & geometry_model,
                      const std::string & package_dir,
                      const fcl::MeshLoaderPtr & meshLoader)
    {
      pinocchio::urdf::buildGeom(model,filename,type,geometry_model,package_dir,meshLoader);

      return geometry_model;
    }

#endif // #ifdef PINOCCHIO_WITH_HPP_FCL
#endif

    void exposeURDFGeometry()
    {

#ifdef PINOCCHIO_WITH_URDFDOM

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType, const std::vector<std::string> &)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","package_dirs"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "return a GeometryModel containing either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL).\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tpackage_dirs: vector of paths pointing to the folders containing the model of the robot\n"
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel & (*) (const Model &, const std::string &, const GeometryType, GeometryModel &, const std::vector<std::string> &)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","geom_model","package_dirs"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "and store either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL) in the geom_model given as input.\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tgeom_model: reference where to store the parsed information\n"
              "\tpackage_dirs: vector of paths pointing to the folders containing the model of the robot\n",
              bp::return_internal_reference<4>()
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "return a GeometryModel containing either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL).\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "Note:\n"
              "This function does not take any hint concerning the location of the meshes of the robot."
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel & (*) (const Model &, const std::string &, const GeometryType, GeometryModel &)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","geom_model"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "and store either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL) in the geom_model given as input.\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tgeom_model: reference where to store the parsed information\n"
              "Note:\n"
              "This function does not take any hint concerning the location of the meshes of the robot.",
              bp::return_internal_reference<4>()
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType, const std::string &)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","package_dir"  ),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "return a GeometryModel containing either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL).\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tpackage_dir: path pointing to the folder containing the meshes of the robot\n"
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel & (*) (const Model &, const std::string &, const GeometryType, GeometryModel &, const std::string &)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","geom_model","package_dir"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "and store either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL) in the geom_model given as input.\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tgeom_model: reference where to store the parsed information\n"
              "\tpackage_dir: path pointing to the folder containing the meshes of the robot\n",
              bp::return_internal_reference<4>()
              );

#ifdef PINOCCHIO_WITH_HPP_FCL

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType, const std::vector<std::string> &, const fcl::MeshLoaderPtr&)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","package_dirs","mesh_loader"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "return a GeometryModel containing either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL).\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tpackage_dirs: vector of paths pointing to the folders containing the model of the robot\n"
              "\tmesh_loader: an hpp-fcl mesh loader (to load only once the related geometries)."
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel & (*) (const Model &, const std::string &, const GeometryType, GeometryModel &, const std::vector<std::string> &, const fcl::MeshLoaderPtr&)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","geom_model","package_dirs","mesh_loader"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "and store either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL) in the geom_model given as input.\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tgeom_model: reference where to store the parsed information\n"
              "\tpackage_dirs: vector of paths pointing to the folders containing the model of the robot\n"
              "\tmesh_loader: an hpp-fcl mesh loader (to load only once the related geometries).",
              bp::return_internal_reference<4>()
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType, const std::string &, const fcl::MeshLoaderPtr&)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","package_dir","mesh_loader"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "return a GeometryModel containing either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL).\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tpackage_dir: path pointing to the folder containing the meshes of the robot\n"
              "\tmesh_loader: an hpp-fcl mesh loader (to load only once the related geometries)."
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel & (*) (const Model &, const std::string &, const GeometryType, GeometryModel &, const std::string &, const fcl::MeshLoaderPtr&)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","geom_model","package_dir","mesh_loader"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "and store either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL) in the geom_model given as input.\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tgeom_model: reference where to store the parsed information\n"
              "\tpackage_dir: path pointing to the folder containing the meshes of the robot\n"
              "\tmesh_loader: an hpp-fcl mesh loader (to load only once the related geometries).",
              bp::return_internal_reference<4>()
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel (*) (const Model &, const std::string &, const GeometryType, const fcl::MeshLoaderPtr&)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","mesh_loader"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "return a GeometryModel containing either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL).\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tmesh_loader: an hpp-fcl mesh loader (to load only once the related geometries).\n"
              "Note:\n"
              "This function does not take any hint concerning the location of the meshes of the robot."
              );

      bp::def("buildGeomFromUrdf",
              static_cast <GeometryModel & (*) (const Model &, const std::string &, const GeometryType, GeometryModel &, const fcl::MeshLoaderPtr&)> (pinocchio::python::buildGeomFromUrdf),
              bp::args("model","urdf_filename","geom_type","geom_model","mesh_loader"),
              "Parse the URDF file given as input looking for the geometry of the given input model and\n"
              "and store either the collision geometries (GeometryType.COLLISION) or the visual geometries (GeometryType.VISUAL) in the geom_model given as input.\n"
              "Parameters:\n"
              "\tmodel: model of the robot\n"
              "\turdf_filename: path to the URDF file containing the model of the robot\n"
              "\tgeom_type: type of geometry to extract from the URDF file (either the VISUAL for display or the COLLISION for collision detection).\n"
              "\tgeom_model: reference where to store the parsed information\n"
              "\tmesh_loader: an hpp-fcl mesh loader (to load only once the related geometries).\n"
              "Note:\n"
              "This function does not take any hint concerning the location of the meshes of the robot.",
              bp::return_internal_reference<4>()
              );

#endif // #ifdef PINOCCHIO_WITH_HPP_FCL
#endif // #ifdef PINOCCHIO_WITH_URDFDOM
    }
  }
}