text:
//==================================================================================================
/*!

  Copyright 2016 NumScale SAS

  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
//==================================================================================================
#include <boost/simd/constant/ratio.hpp>
#include <scalar_test.hpp>

STF_CASE_TPL( "Check constant behavior for ratio", STF_NUMERIC_TYPES)
{
  using boost::simd::Ratio;

  STF_EXPR_IS   ( (Ratio<T,7,21>()  ) , T         );
  STF_IEEE_EQUAL( (Ratio<T,7,21>()  ) , T(7./21.) );

  STF_EXPR_IS   ( (Ratio<T,7>()  ) , T    );
  STF_IEEE_EQUAL( (Ratio<T,7>()  ) , T(7) );
}


text:
#ifndef OPENCV_RGBD_GRAPH_NODE_H
#define OPENCV_RGBD_GRAPH_NODE_H

#include <map>
#include <unordered_map>

#include "opencv2/core/affine.hpp"
#if defined(HAVE_EIGEN)
#include <Eigen/Core>
#include <Eigen/Geometry>
#include "opencv2/core/eigen.hpp"
#endif

#if defined(CERES_FOUND)
#include <ceres/ceres.h>
#endif

namespace cv
{
namespace kinfu
{
/*! \class GraphNode
 *  \brief Defines a node/variable that is optimizable in a posegraph
 *
 *  Detailed description
 */
#if defined(HAVE_EIGEN)
struct Pose3d
{
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW

    Eigen::Vector3d t;
    Eigen::Quaterniond r;

    Pose3d()
    {
        t.setZero();
        r.setIdentity();
    };
    Pose3d(const Eigen::Matrix3d& rotation, const Eigen::Vector3d& translation)
        : t(translation), r(Eigen::Quaterniond(rotation))
    {
        normalizeRotation();
    }

    Pose3d(const Matx33d& rotation, const Vec3d& translation)
    {
        Eigen::Matrix3d R;
        cv2eigen(rotation, R);
        cv2eigen(translation, t);
        r = Eigen::Quaterniond(R);
        normalizeRotation();
    }

    explicit Pose3d(const Matx44f& pose)
    {
        Matx33d rotation(pose.val[0], pose.val[1], pose.val[2], pose.val[4], pose.val[5],
                         pose.val[6], pose.val[8], pose.val[9], pose.val[10]);
        Vec3d translation(pose.val[3], pose.val[7], pose.val[11]);
        Pose3d(rotation, translation);
    }

    // NOTE: Eigen overloads quaternion multiplication appropriately
    inline Pose3d operator*(const Pose3d& otherPose) const
    {
        Pose3d out(*this);
        out.t += r * otherPose.t;
        out.r *= otherPose.r;
        out.normalizeRotation();
        return out;
    }

    inline Pose3d& operator*=(const Pose3d& otherPose)
    {
        t += otherPose.t;
        r *= otherPose.r;
        normalizeRotation();
        return *this;
    }

    inline Pose3d inverse() const
    {
        Pose3d out;
        out.r = r.conjugate();
        out.t = out.r * (t * -1.0);
        return out;
    }

    inline void normalizeRotation()
    {
        if (r.w() < 0)
            r.coeffs() *= -1.0;
        r.normalize();
    }
};
#endif

struct PoseGraphNode
{
   public:
    explicit PoseGraphNode(int _nodeId, const Affine3f& _pose)
        : nodeId(_nodeId), isFixed(false), pose(_pose)
    {
#if defined(HAVE_EIGEN)
        se3Pose = Pose3d(_pose.rotation(), _pose.translation());
#endif
    }
    virtual ~PoseGraphNode() = default;

    int getId() const { return nodeId; }
    inline Affine3f getPose() const
    {
        return pose;
    }
    void setPose(const Affine3f& _pose)
    {
        pose = _pose;
#if defined(HAVE_EIGEN)
        se3Pose = Pose3d(pose.rotation(), pose.translation());
#endif
    }
#if defined(HAVE_EIGEN)
    void setPose(const Pose3d& _pose)
    {
        se3Pose = _pose;
        const Eigen::Matrix3d& rotation    = se3Pose.r.toRotationMatrix();
        const Eigen::Vector3d& translation = se3Pose.t;
        Matx33d rot;
        Vec3d trans;
        eigen2cv(rotation, rot);
        eigen2cv(translation, trans);
        Affine3d poseMatrix(rot, trans);
        pose = poseMatrix;
    }
#endif
    void setFixed(bool val = true) { isFixed = val; }
    bool isPoseFixed() const { return isFixed; }

   public:
    int nodeId;
    bool isFixed;
    Affine3f pose;
#if defined(HAVE_EIGEN)
    Pose3d se3Pose;
#endif
};

/*! \class PoseGraphEdge
 *  \brief Defines the constraints between two PoseGraphNodes
 *
 *  Detailed description
 */
struct PoseGraphEdge
{
   public:
    PoseGraphEdge(int _sourceNodeId, int _targetNodeId, const Affine3f& _transformation,
                  const Matx66f& _information = Matx66f::eye())
        : sourceNodeId(_sourceNodeId),
          targetNodeId(_targetNodeId),
          transformation(_transformation),
          information(_information)
    {
    }
    virtual ~PoseGraphEdge() = default;

    int getSourceNodeId() const { return sourceNodeId; }
    int getTargetNodeId() const { return targetNodeId; }

    bool operator==(const PoseGraphEdge& edge)
    {
        if ((edge.getSourceNodeId() == sourceNodeId && edge.getTargetNodeId() == targetNodeId) ||
            (edge.getSourceNodeId() == targetNodeId && edge.getTargetNodeId() == sourceNodeId))
            return true;
        return false;
    }

   public:
    int sourceNodeId;
    int targetNodeId;
    Affine3f transformation;
    Matx66f information;
};

//! @brief Reference: A tutorial on SE(3) transformation parameterizations and on-manifold
//! optimization Jose Luis Blanco Compactly represents the jacobian of the SE3 generator
// clang-format off
/* static const std::array<Matx44f, 6> generatorJacobian = { */
/*     // alpha */
/*     Matx44f(0, 0,  0, 0, */
/*             0, 0, -1, 0, */
/*             0, 1,  0, 0, */
/*             0, 0,  0, 0), */
/*     // beta */
/*     Matx44f( 0, 0, 1, 0, */
/*              0, 0, 0, 0, */
/*             -1, 0, 0, 0, */
/*              0, 0, 0, 0), */
/*     // gamma */
/*     Matx44f(0, -1, 0, 0, */
/*             1,  0, 0, 0, */
/*             0,  0, 0, 0, */
/*             0,  0, 0, 0), */
/*     // x */
/*     Matx44f(0, 0, 0, 1, */
/*             0, 0, 0, 0, */
/*             0, 0, 0, 0, */
/*             0, 0, 0, 0), */
/*     // y */
/*     Matx44f(0, 0, 0, 0, */
/*             0, 0, 0, 1, */
/*             0, 0, 0, 0, */
/*             0, 0, 0, 0), */
/*     // z */
/*     Matx44f(0, 0, 0, 0, */
/*             0, 0, 0, 0, */
/*             0, 0, 0, 1, */
/*             0, 0, 0, 0) */
/* }; */
// clang-format on

class PoseGraph
{
   public:
    typedef std::vector<PoseGraphNode> NodeVector;
    typedef std::vector<PoseGraphEdge> EdgeVector;

    explicit PoseGraph(){};
    virtual ~PoseGraph() = default;

    //! PoseGraph can be copied/cloned
    PoseGraph(const PoseGraph&) = default;
    PoseGraph& operator=(const PoseGraph&) = default;

    void addNode(const PoseGraphNode& node) { nodes.push_back(node); }
    void addEdge(const PoseGraphEdge& edge) { edges.push_back(edge); }

    bool nodeExists(int nodeId) const
    {
        return std::find_if(nodes.begin(), nodes.end(), [nodeId](const PoseGraphNode& currNode) {
                   return currNode.getId() == nodeId;
               }) != nodes.end();
    }

    bool isValid() const;

    int getNumNodes() const { return int(nodes.size()); }
    int getNumEdges() const { return int(edges.size()); }

   public:
    NodeVector nodes;
    EdgeVector edges;
};

namespace Optimizer
{
void optimize(PoseGraph& poseGraph);

#if defined(CERES_FOUND)
void createOptimizationProblem(PoseGraph& poseGraph, ceres::Problem& problem);

//! Error Functor required for Ceres to obtain an auto differentiable cost function
class Pose3dErrorFunctor
{
   public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
    Pose3dErrorFunctor(const Pose3d& _poseMeasurement, const Matx66d& _sqrtInformation)
        : poseMeasurement(_poseMeasurement)
    {
        cv2eigen(_sqrtInformation, sqrtInfo);
    }
    Pose3dErrorFunctor(const Pose3d& _poseMeasurement,
                       const Eigen::Matrix<double, 6, 6>& _sqrtInformation)
        : poseMeasurement(_poseMeasurement), sqrtInfo(_sqrtInformation)
    {
    }

    template<typename T>
    bool operator()(const T* const _pSourceTrans, const T* const _pSourceQuat,
                    const T* const _pTargetTrans, const T* const _pTargetQuat, T* _pResidual) const
    {
        Eigen::Map<const Eigen::Matrix<T, 3, 1>> sourceTrans(_pSourceTrans);
        Eigen::Map<const Eigen::Matrix<T, 3, 1>> targetTrans(_pTargetTrans);
        Eigen::Map<const Eigen::Quaternion<T>> sourceQuat(_pSourceQuat);
        Eigen::Map<const Eigen::Quaternion<T>> targetQuat(_pTargetQuat);
        Eigen::Map<Eigen::Matrix<T, 6, 1>> residual(_pResidual);

        Eigen::Quaternion<T> targetQuatInv = targetQuat.conjugate();

        Eigen::Quaternion<T> relativeQuat    = targetQuatInv * sourceQuat;
        Eigen::Matrix<T, 3, 1> relativeTrans = targetQuatInv * (targetTrans - sourceTrans);

        //! Definition should actually be relativeQuat * poseMeasurement.r.conjugate()
        Eigen::Quaternion<T> deltaRot =
            poseMeasurement.r.template cast<T>() * relativeQuat.conjugate();

        residual.template block<3, 1>(0, 0) = relativeTrans - poseMeasurement.t.template cast<T>();
        residual.template block<3, 1>(3, 0) = T(2.0) * deltaRot.vec();

        residual.applyOnTheLeft(sqrtInfo.template cast<T>());

        return true;
    }

    static ceres::CostFunction* create(const Pose3d& _poseMeasurement,
                                       const Matx66f& _sqrtInformation)
    {
        return new ceres::AutoDiffCostFunction<Pose3dErrorFunctor, 6, 3, 4, 3, 4>(
            new Pose3dErrorFunctor(_poseMeasurement, _sqrtInformation));
    }

   private:
    const Pose3d poseMeasurement;
    Eigen::Matrix<double, 6, 6> sqrtInfo;
};
#endif

}  // namespace Optimizer

}  // namespace kinfu
}  // namespace cv
#endif /* ifndef OPENCV_RGBD_GRAPH_NODE_H */

ext: hpp


text:
//  Copyright (c) 2007-2012 Hartmut Kaiser
//
//  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)

#if !defined(HPX_PARCELSET_SHMEM_ACCEPTOR_NOV_25_2012_0710PM)
#define HPX_PARCELSET_SHMEM_ACCEPTOR_NOV_25_2012_0710PM

#include <hpx/hpx_fwd.hpp>
#include <hpx/runtime/parcelset/shmem/interprocess_errors.hpp>
#include <hpx/runtime/parcelset/shmem/message.hpp>
#include <hpx/runtime/parcelset/shmem/data_window.hpp>
#include <hpx/util/io_service_pool.hpp>

#include <boost/asio/basic_io_object.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/static_assert.hpp>
#include <boost/system/system_error.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/scope_exit.hpp>
#include <boost/atomic.hpp>

#include <boost/interprocess/ipc/message_queue.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace parcelset { namespace shmem
{
    ///////////////////////////////////////////////////////////////////////////
    //
    struct basic_acceptor_options
    {
        template <typename T>
        struct option
        {
            option(T const& num) : val_(num) {}
            T val_;
        };

        typedef option<std::size_t> msg_num;
        typedef option<bool> manage;
    };

    ///////////////////////////////////////////////////////////////////////////
    template <typename Service>
    class basic_acceptor
      : public boost::asio::basic_io_object<Service>,
        public basic_acceptor_options
    {
    public:
        explicit basic_acceptor(boost::asio::io_service &io_service)
          : boost::asio::basic_io_object<Service>(io_service)
        {
        }

        void open(boost::system::error_code &ec = boost::system::throws)
        {
            this->service.open(this->implementation, ec);
        }

        void close(boost::system::error_code &ec = boost::system::throws)
        {
            this->service.close(this->implementation, ec);
        }

        void bind(std::string const& endpoint,
            boost::system::error_code &ec = boost::system::throws)
        {
            this->service.bind(this->implementation, endpoint + ".acceptor", ec);
        }

        // synchronous and asynchronous accept
        template <typename Service_>
        void accept(basic_data_window<Service_>& window,
            boost::system::error_code &ec = boost::system::throws)
        {
            return this->service.accept(this->implementation, window, ec);
        }

        template <typename Service_, typename Handler>
        void async_accept(basic_data_window<Service_>& window, Handler handler)
        {
            this->service.async_accept(this->implementation, window, handler);
        }

        // options
        template <typename Opt>
        void set_option(Opt opt, boost::system::error_code &ec =
            boost::system::throws)
        {
            this->service.set_option(this->implementation, opt, ec);
        }
    };

    ///////////////////////////////////////////////////////////////////////////
    namespace detail
    {
        ///////////////////////////////////////////////////////////////////////
        template <typename Service, typename Handler, typename Implementation>
        class accept_operation
          : public boost::enable_shared_from_this<
                accept_operation<Service, Handler, Implementation> >
        {
            typedef boost::shared_ptr<Implementation> implementation_type;

        public:
            accept_operation(implementation_type &impl,
                  boost::asio::io_service &io_service,
                  basic_data_window<Service>& window, Handler handler)
              : impl_(impl),
                io_service_(io_service),
                window_(window),
                handler_(handler)
            {}

            void call() const
            {
                implementation_type impl = impl_.lock();
                if (impl)
                {
                    boost::system::error_code ec;
                    if (!impl->try_accept(window_, ec) && !ec) {
                        // repost this function
                        io_service_.post(boost::bind(
                            &accept_operation::call, this->shared_from_this()));
                    }
                    else {
                        io_service_.post(
                            boost::asio::detail::bind_handler(handler_, ec));
                    }
                }
                else
                {
                    io_service_.post(
                        boost::asio::detail::bind_handler(handler_,
                            boost::asio::error::operation_aborted));
                }
            }

        private:
            boost::weak_ptr<Implementation> impl_;
            boost::asio::io_service &io_service_;
            basic_data_window<Service>& window_;
            Handler handler_;
        };
    }

    ///////////////////////////////////////////////////////////////////////////
    template <typename Implementation>
    class basic_acceptor_service
      : public boost::asio::io_service::service
    {
    public:
        static boost::asio::io_service::id id;

        explicit basic_acceptor_service(boost::asio::io_service &io_service)
          : boost::asio::io_service::service(io_service)
        {}

        ~basic_acceptor_service()
        {}

        typedef boost::shared_ptr<Implementation> implementation_type;

        void construct(implementation_type &impl)
        {
            impl.reset(new Implementation());
        }

        void destroy(implementation_type &impl)
        {
            impl->destroy();
            impl.reset();
        }

        void open(implementation_type &impl, boost::system::error_code &ec)
        {
            impl->open(false, ec);      // create only
            boost::asio::detail::throw_error(ec);
        }

        void close(implementation_type &impl, boost::system::error_code &ec)
        {
            impl->close(ec);
            boost::asio::detail::throw_error(ec);
        }

        void bind(implementation_type &impl, std::string const& endpoint,
            boost::system::error_code &ec)
        {
            impl->bind(endpoint, ec);
            boost::asio::detail::throw_error(ec);
        }

        // synchronous and asynchronous accept
        template <typename Service>
        void accept(implementation_type &impl,
            basic_data_window<Service>& window, boost::system::error_code &ec)
        {
            while (!impl->try_accept(window, ec) && !ec)
                /* just wait for operation to succeed */;
            boost::asio::detail::throw_error(ec);
        }

        template <typename Service, typename Handler>
        void async_accept(implementation_type &impl,
            basic_data_window<Service>& window, Handler handler)
        {
            typedef detail::accept_operation<Service, Handler, Implementation>
                operation_type;

            boost::shared_ptr<operation_type> op(
                boost::make_shared<operation_type>(
                    impl, this->get_io_service(), window, handler));

            this->get_io_service().post(boost::bind(&operation_type::call, op));
        }

        template <typename Opt>
        void set_option(implementation_type &impl, Opt opt,
            boost::system::error_code &ec)
        {
            impl->set_option(opt, ec);
            boost::asio::detail::throw_error(ec);
        }

    private:
        void shutdown_service()
        {}
    };

    template <typename Implementation>
    boost::asio::io_service::id basic_acceptor_service<Implementation>::id;

    ///////////////////////////////////////////////////////////////////////////
    class acceptor_impl
    {
    public:
        acceptor_impl()
          : msg_num_(1),
            executing_operation_(false),
            aborted_(false),
            close_operation_(false),
            manage_lifetime_(false)
        {}

        ~acceptor_impl()
        {
            boost::system::error_code ec;
            close(ec);
        }

        void open(bool open_queue_only, boost::system::error_code &ec)
        {
            if (mq_) {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::already_connected);
            }
            else if (!open_queue_only) {
                using namespace boost::interprocess;
                message_queue::remove(endpoint_.c_str());
                mq_ = boost::make_shared<message_queue>(
                    create_only, endpoint_.c_str(), msg_num_, sizeof(message));
                HPX_SHMEM_RESET_EC(ec);
            }
            else {
                using namespace boost::interprocess;
                mq_ = boost::make_shared<message_queue>(
                    open_only, endpoint_.c_str());
                HPX_SHMEM_RESET_EC(ec);
            }
        }

        void bind(std::string const& endpoint, boost::system::error_code &ec)
        {
            if (mq_) {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::already_connected);
            }
            else {
                endpoint_ = endpoint;
                boost::interprocess::message_queue::remove(endpoint_.c_str());
                HPX_SHMEM_RESET_EC(ec);
            }
        }

        void close(boost::system::error_code &ec)
        {
            if (!mq_) {
                HPX_SHMEM_RESET_EC(ec);
                return;
            }

            close_operation_.store(true);
            BOOST_SCOPE_EXIT(&close_operation_) {
                close_operation_.store(false);
            } BOOST_SCOPE_EXIT_END

//             std::cout << "acceptor: " << endpoint_ << ": close" << std::endl;

            // wait for pending operations to return
            while (executing_operation_.load())
                ;

            if (mq_) {
                mq_.reset();
                boost::interprocess::message_queue::remove(endpoint_.c_str());
                HPX_SHMEM_RESET_EC(ec);
            }
            else {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::not_connected);
            }
        }

        void destroy()
        {
            aborted_.store(true);
            BOOST_SCOPE_EXIT(&aborted_) {
                aborted_.store(false);
            } BOOST_SCOPE_EXIT_END

//             std::cout << "acceptor: " << endpoint_ << ": destroy" << std::endl;

            // cancel operation
            while (executing_operation_.load())
                ;
        }

        template <typename Service>
        bool try_accept(basic_data_window<Service>& window, boost::system::error_code &ec)
        {
            if (close_operation_.load() || !mq_) {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::not_connected);
            }
            else {
                message msg;
                if (!try_receive_command(msg, ec))
                    return false;

                // verify that the received command was 'connect'
                if (!ec) {
                    if (msg.command_ == message::shutdown) {
                        close(ec);
                        HPX_SHMEM_THROWS_IF(ec, boost::asio::error::eof);
                    }
                    else if (msg.command_ != message::connect) {
                        HPX_SHMEM_THROWS_IF(ec, boost::asio::error::not_connected);
                    }
                    else {
                        // establish connection with given data window
                        window.set_option(data_window::manage(manage_lifetime_), ec);
                        if (!ec) {
                            window.bind(msg.data_, ec);
                            if (!ec) window.open(ec);
                        }
                        return true;
                    }
                }
            }
            return false;
        }

        // set options
        void set_option(basic_acceptor_options::msg_num opt,
            boost::system::error_code &ec)
        {
            if (mq_) {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::already_connected);
            }
            else {
                msg_num_ = opt.val_;
                HPX_SHMEM_RESET_EC(ec);
            }
        }

        void set_option(basic_acceptor_options::manage opt,
            boost::system::error_code &ec)
        {
            if (mq_) {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::already_connected);
            }
            else {
                manage_lifetime_ = opt.val_;
                HPX_SHMEM_RESET_EC(ec);
            }
        }

    protected:
        bool try_receive_command(message& msg, boost::system::error_code &ec)
        {
            ++executing_operation_;
            BOOST_SCOPE_EXIT(&executing_operation_) {
                --executing_operation_;
            } BOOST_SCOPE_EXIT_END

            if (close_operation_.load() || !mq_) {
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::not_connected);
                return false;
            }

            if (aborted_.load()) {
                aborted_.store(false);
                HPX_SHMEM_THROWS_IF(ec, boost::asio::error::connection_aborted);
                return false;
            }

            HPX_SHMEM_RESET_EC(ec);

            try {
                boost::interprocess::message_queue::size_type recvd_size;
                unsigned int priority;
                return mq_->try_receive(&msg, sizeof(msg), recvd_size, priority);
            }
            catch (boost::interprocess::interprocess_exception const& e) {
                aborted_.store(false);
                HPX_SHMEM_THROWS_IF(ec, make_error_code(e.get_error_code()));
            }
            return false;
        }

    private:
        std::size_t msg_num_;
        std::string endpoint_;
        boost::shared_ptr<boost::interprocess::message_queue> mq_;
        boost::atomic<boost::uint16_t> executing_operation_;
        boost::atomic<bool> aborted_;
        boost::atomic<bool> close_operation_;
        bool manage_lifetime_;
    };

    ///////////////////////////////////////////////////////////////////////////
    typedef basic_acceptor<
        basic_acceptor_service<acceptor_impl>
    > acceptor;
}}}

#endif

max_stars_repo_name: andreasbuhr/hpx

max_issues_repo_name: andreasbuhr/hpx

max_forks_repo_name: andreasbuhr/hpx


text:
// Boost.Geometry Index
//
// R-tree query iterators
//
// Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
//
// 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)

#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_QUERY_ITERATORS_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_QUERY_ITERATORS_HPP

#include <boost/scoped_ptr.hpp>

//#define BOOST_GEOMETRY_INDEX_DETAIL_QUERY_ITERATORS_USE_MOVE

namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace iterators {

template <typename Value, typename Allocators>
struct end_query_iterator
{
    typedef std::input_iterator_tag iterator_category;
    typedef Value value_type;
    typedef typename Allocators::const_reference reference;
    typedef typename Allocators::difference_type difference_type;
    typedef typename Allocators::const_pointer pointer;

    reference operator*() const
    {
        BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not dereferencable");
        pointer p(0);
        return *p;
    }

    const value_type * operator->() const
    {
        BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not dereferencable");
        const value_type * p = 0;
        return p;
    }

    end_query_iterator & operator++()
    {
        BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not incrementable");
        return *this;
    }

    end_query_iterator operator++(int)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(false, "iterator not incrementable");
        return *this;
    }

    friend bool operator==(end_query_iterator const& /*l*/, end_query_iterator const& /*r*/)
    {
        return true;
    }
};

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators, typename Predicates>
class spatial_query_iterator
{
    typedef visitors::spatial_query_incremental<Value, Options, Translator, Box, Allocators, Predicates> visitor_type;
    typedef typename visitor_type::node_pointer node_pointer;

public:
    typedef std::input_iterator_tag iterator_category;
    typedef Value value_type;
    typedef typename Allocators::const_reference reference;
    typedef typename Allocators::difference_type difference_type;
    typedef typename Allocators::const_pointer pointer;

    inline spatial_query_iterator(Translator const& t, Predicates const& p)
        : m_visitor(t, p)
    {}

    inline spatial_query_iterator(node_pointer root, Translator const& t, Predicates const& p)
        : m_visitor(t, p)
    {
        m_visitor.initialize(root);
    }

    reference operator*() const
    {
        return m_visitor.dereference();
    }

    const value_type * operator->() const
    {
        return boost::addressof(m_visitor.dereference());
    }

    spatial_query_iterator & operator++()
    {
        m_visitor.increment();
        return *this;
    }

    spatial_query_iterator operator++(int)
    {
        spatial_query_iterator temp = *this;
        this->operator++();
        return temp;
    }

    friend bool operator==(spatial_query_iterator const& l, spatial_query_iterator const& r)
    {
        return l.m_visitor == r.m_visitor;
    }

    friend bool operator==(spatial_query_iterator const& l, end_query_iterator<Value, Allocators> const& /*r*/)
    {
        return l.m_visitor.is_end();
    }

    friend bool operator==(end_query_iterator<Value, Allocators> const& /*l*/, spatial_query_iterator const& r)
    {
        return r.m_visitor.is_end();
    }

private:
    visitor_type m_visitor;
};

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators, typename Predicates, unsigned NearestPredicateIndex>
class distance_query_iterator
{
    typedef visitors::distance_query_incremental<Value, Options, Translator, Box, Allocators, Predicates, NearestPredicateIndex> visitor_type;
    typedef typename visitor_type::node_pointer node_pointer;

public:
    typedef std::input_iterator_tag iterator_category;
    typedef Value value_type;
    typedef typename Allocators::const_reference reference;
    typedef typename Allocators::difference_type difference_type;
    typedef typename Allocators::const_pointer pointer;

    inline distance_query_iterator(Translator const& t, Predicates const& p)
        : m_visitor(t, p)
    {}

    inline distance_query_iterator(node_pointer root, Translator const& t, Predicates const& p)
        : m_visitor(t, p)
    {
        m_visitor.initialize(root);
    }

    reference operator*() const
    {
        return m_visitor.dereference();
    }

    const value_type * operator->() const
    {
        return boost::addressof(m_visitor.dereference());
    }

    distance_query_iterator & operator++()
    {
        m_visitor.increment();
        return *this;
    }

    distance_query_iterator operator++(int)
    {
        distance_query_iterator temp = *this;
        this->operator++();
        return temp;
    }

    friend bool operator==(distance_query_iterator const& l, distance_query_iterator const& r)
    {
        return l.m_visitor == r.m_visitor;
    }

    friend bool operator==(distance_query_iterator const& l, end_query_iterator<Value, Allocators> const& /*r*/)
    {
        return l.m_visitor.is_end();
    }

    friend bool operator==(end_query_iterator<Value, Allocators> const& /*l*/, distance_query_iterator const& r)
    {
        return r.m_visitor.is_end();
    }

private:
    visitor_type m_visitor;
};

template <typename L, typename R>
inline bool operator!=(L const& l, R const& r)
{
    return !(l == r);
}

}}}}}} // namespace boost::geometry::index::detail::rtree::iterators

namespace boost { namespace geometry { namespace index { namespace detail { namespace rtree { namespace iterators {

template <typename Value, typename Allocators>
class query_iterator_base
{
public:
    typedef std::input_iterator_tag iterator_category;
    typedef Value value_type;
    typedef typename Allocators::const_reference reference;
    typedef typename Allocators::difference_type difference_type;
    typedef typename Allocators::const_pointer pointer;

    virtual ~query_iterator_base() {}

    virtual query_iterator_base * clone() const = 0;

    virtual bool is_end() const = 0;
    virtual reference dereference() const = 0;
    virtual void increment() = 0;
    virtual bool equals(query_iterator_base const&) const = 0;
};

template <typename Value, typename Allocators, typename Iterator>
class query_iterator_wrapper
    : public query_iterator_base<Value, Allocators>
{
    typedef query_iterator_base<Value, Allocators> base_t;

public:
    typedef std::input_iterator_tag iterator_category;
    typedef Value value_type;
    typedef typename Allocators::const_reference reference;
    typedef typename Allocators::difference_type difference_type;
    typedef typename Allocators::const_pointer pointer;

    explicit query_iterator_wrapper(Iterator const& it) : m_iterator(it) {}

    virtual base_t * clone() const { return new query_iterator_wrapper(m_iterator); }

    virtual bool is_end() const { return m_iterator == end_query_iterator<Value, Allocators>(); }
    virtual reference dereference() const { return *m_iterator; }
    virtual void increment() { ++m_iterator; }
    virtual bool equals(base_t const& r) const
    {
        const query_iterator_wrapper * p = dynamic_cast<const query_iterator_wrapper *>(boost::addressof(r));
        BOOST_GEOMETRY_INDEX_ASSERT(p, "iterators can't be compared");
        return m_iterator == p->m_iterator;
    }

private:
    Iterator m_iterator;
};

template <typename Value, typename Allocators>
class query_iterator
{
    typedef query_iterator_base<Value, Allocators> iterator_base;
    typedef boost::scoped_ptr<iterator_base> iterator_ptr;

public:
    typedef std::input_iterator_tag iterator_category;
    typedef Value value_type;
    typedef typename Allocators::const_reference reference;
    typedef typename Allocators::difference_type difference_type;
    typedef typename Allocators::const_pointer pointer;

    query_iterator() {}

    template <typename It>
    query_iterator(It const& it)
        : m_ptr(static_cast<iterator_base*>(
                    new query_iterator_wrapper<Value, Allocators, It>(it) ))
    {}

    query_iterator(end_query_iterator<Value, Allocators> const& /*it*/)
    {}

    query_iterator(query_iterator const& o)
        : m_ptr(o.m_ptr.get() ? o.m_ptr->clone() : 0)
    {}

#ifndef BOOST_GEOMETRY_INDEX_DETAIL_QUERY_ITERATORS_USE_MOVE
    query_iterator & operator=(query_iterator const& o)
    {
        if ( this != boost::addressof(o) )
        {
            m_ptr.reset(o.m_ptr.get() ? o.m_ptr->clone() : 0);
        }
        return *this;
    }
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
    query_iterator(query_iterator && o)
        : m_ptr(0)
    {
        m_ptr.swap(o.m_ptr);
    }
    query_iterator & operator=(query_iterator && o)
    {
        if ( this != boost::addressof(o) )
        {
            m_ptr.swap(o.m_ptr);
            o.m_ptr.reset();
        }
        return *this;
    }
#endif
#else // !BOOST_GEOMETRY_INDEX_DETAIL_QUERY_ITERATORS_USE_MOVE
private:
    BOOST_COPYABLE_AND_MOVABLE(query_iterator)
public:
    query_iterator & operator=(BOOST_COPY_ASSIGN_REF(query_iterator) o)
    {
        if ( this != boost::addressof(o) )
        {
            m_ptr.reset(o.m_ptr.get() ? o.m_ptr->clone() : 0);
        }
        return *this;
    }
    query_iterator(BOOST_RV_REF(query_iterator) o)
        : m_ptr(0)
    {
        m_ptr.swap(o.m_ptr);
    }
    query_iterator & operator=(BOOST_RV_REF(query_iterator) o)
    {
        if ( this != boost::addressof(o) )
        {
            m_ptr.swap(o.m_ptr);
            o.m_ptr.reset();
        }
        return *this;
    }
#endif // BOOST_GEOMETRY_INDEX_DETAIL_QUERY_ITERATORS_USE_MOVE

    reference operator*() const
    {
        return m_ptr->dereference();
    }

    const value_type * operator->() const
    {
        return boost::addressof(m_ptr->dereference());
    }

    query_iterator & operator++()
    {
        m_ptr->increment();
        return *this;
    }

    query_iterator operator++(int)
    {
        query_iterator temp = *this;
        this->operator++();
        return temp;
    }

    friend bool operator==(query_iterator const& l, query_iterator const& r)
    {
        if ( l.m_ptr.get() )
        {
            if ( r.m_ptr.get() )
                return l.m_ptr->equals(*r.m_ptr);
            else
                return l.m_ptr->is_end();
        }
        else
        {
            if ( r.m_ptr.get() )
                return r.m_ptr->is_end();
            else
                return true;
        }
    }

private:
    iterator_ptr m_ptr;
};

}}}}}} // namespace boost::geometry::index::detail::rtree::iterators

#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_QUERY_ITERATORS_HPP

max_stars_repo_name: multi-os-engine/cinder-natj-binding

max_issues_repo_name: multi-os-engine/cinder-natj-binding

max_forks_repo_name: multi-os-engine/cinder-natj-binding


text:
// ---------------------------------------------------------------------
// pion:  a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2014 Splunk Inc.  (https://github.com/splunk/pion)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//

#ifndef __PION_HTTP_AUTH_HEADER__
#define __PION_HTTP_AUTH_HEADER__

#include <set>
#include <map>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <pion/config.hpp>
#include <pion/error.hpp>
#include <pion/logger.hpp>
#include <pion/hash_map.hpp>
#include <pion/tcp/connection.hpp>
#include <pion/user.hpp>
#include <pion/http/request.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>    // order important, otherwise compiling error under win32

namespace pion {    // begin namespace pion
namespace http {    // begin namespace http

///
/// auth: a base class for handling HTTP Authentication and session management
///
class PION_API auth :
    private boost::noncopyable
{
public:

    /// default constructor
    auth(user_manager_ptr userManager)
        : m_logger(PION_GET_LOGGER("pion.http.auth")),
        m_user_manager(userManager)
    {}

    /// virtual destructor
    virtual ~auth() {}

    /**
     * attempts to validate authentication of a new HTTP request.
     * If request valid, pointer to user identity object (if any) will be preserved in
     * the request and return "true".
     * If request not authenticated, appropriate response is sent over tcp_conn
     * and return "false";
     *
     * @param http_request_ptr the new HTTP request to handle
     * @param tcp_conn the TCP connection that has the new request
     *
     * @return true if request valid and user identity inserted into request
     */
    virtual bool handle_request(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn) = 0;

    /**
     * sets a configuration option
     *
     * @param name the name of the option to change
     * @param value the value of the option
     */
    virtual void set_option(const std::string& name, const std::string& /* value */) {
        BOOST_THROW_EXCEPTION( error::bad_arg() << error::errinfo_arg_name(name) );
    }

    /**
     * adds a resource that requires authentication
     *
     * @param resource the resource name or uri-stem that requires authentication
     */
    void add_restrict(const std::string& resource);

    /**
     * adds a resource that does NOT require authentication
     *
     * @param resource the resource name or uri-stem that does not require authentication
     */
    void add_permit(const std::string& resource);

    /**
     * used to add a new user
     *
     * @ return false if user with such name already exists
     */
    virtual bool add_user(std::string const &username, std::string const &password) {
        return m_user_manager->add_user(username, password);
    }

    /**
     * update password for given user
     *
     * @return false if user with such a name doesn't exist
     */
    virtual bool update_user(std::string const &username, std::string const &password) {
        return m_user_manager->update_user(username, password);
    }

    /**
     * used to remove given user
     *
     * @return false if no user with such username
     */
    virtual bool remove_user(std::string const &username) {
        return m_user_manager->remove_user(username);
    };

    /**
     * Used to locate user object by username
     */
    virtual user_ptr get_user(std::string const &username) {
        return m_user_manager->get_user(username);
    }

protected:

    /// data type for a set of resources to be authenticated
    typedef std::set<std::string>   resource_set_type;

    /// data type used to map authentication credentials to user objects
    typedef std::map<std::string,std::pair<boost::posix_time::ptime,user_ptr> >  user_cache_type;

    /**
     * check if given HTTP request requires authentication
     *
     * @param http_request_ptr the HTTP request to check
     */
    bool need_authentication(http::request_ptr const& http_request_ptr) const;

    /**
     * tries to find a resource in a given collection
     *
     * @param resource_set the collection of resource to look in
     * @param resource the resource to look for
     *
     * @return true if the resource was found
     */
    bool find_resource(const resource_set_type& resource_set,
                      const std::string& resource) const;

    /// sets the logger to be used
    inline void set_logger(logger log_ptr) { m_logger = log_ptr; }

    /// primary logging interface used by this class
    mutable logger          m_logger;

    /// container used to manager user objects
    user_manager_ptr        m_user_manager;

    /// collection of resources that require authentication
    resource_set_type       m_restrict_list;

    /// collection of resources that do NOT require authentication
    resource_set_type       m_white_list;

    /// mutex used to protect access to the resources
    mutable boost::mutex    m_resource_mutex;
};

/// data type for a auth pointer
typedef boost::shared_ptr<auth> auth_ptr;

}   // end namespace http
}   // end namespace pion

#endif


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

/**
 * \file
 * \brief test core camera class
 */

#include <test_common.h>

#include <iostream>
#include <boost/foreach.hpp>
#include <boost/math/constants/constants.hpp>
#include <maptk/core/camera.h>

#include <maptk/core/camera_io.h>

#define TEST_ARGS ()

DECLARE_TEST_MAP();

int
main(int argc, char* argv[])
{
  CHECK_ARGS(1);

  testname_t const testname = argv[1];

  RUN_TEST(testname);
}

IMPLEMENT_TEST(look_at)
{
  using namespace maptk;
  vector_2d pp(300,400);
  camera_intrinsics_d K(1000, pp);
  vector_3d focus(0, 1, -2);
  maptk::camera_d cam(vector_3d(3, -4, 7), rotation_d(), K);
  cam.look_at(focus);

  vector_2d ifocus = cam.project(focus);
  TEST_NEAR("look_at focus projects to origin",
            (ifocus-pp).magnitude(), 0.0, 1e-12);

  vector_2d ifocus_up = cam.project(focus + vector_3d(0,0,2));
  vector_2d tmp = ifocus_up - pp;
  TEST_NEAR("look_at vertical projects vertical",
            tmp.x(), 0.0, 1e-12);
  // "up" in image space is actually negative Y because the
  // Y axis is inverted
  TEST_EQUAL("look_at up projects up", tmp.y() < 0.0, true);
}

IMPLEMENT_TEST(projection)
{
  using namespace maptk;
  vector_2d pp(300,400);
  camera_intrinsics_d K(1000, pp);
  vector_3d focus(0, 1, -2);
  maptk::camera_d cam(vector_3d(3, -4, 7), rotation_d(), K);
  cam.look_at(focus);

  matrix_3x4d P(cam);
  vector_3d test_pt(1,2,3);
  vector_4d test_hpt(test_pt.x(), test_pt.y(), test_pt.z(), 1.0);

  vector_3d proj_hpt = P * test_hpt;
  vector_2d proj_pt(proj_hpt.x()/proj_hpt.z(), proj_hpt.y()/proj_hpt.z());

  TEST_NEAR("camera projection = matrix multiplication",
             (cam.project(test_pt) - proj_pt).magnitude(), 0.0, 1e-12);
}

IMPLEMENT_TEST(interpolation)
{
  using namespace maptk;
  using namespace std;

  double pi = boost::math::constants::pi<double>();
  camera_d a(vector_3d(-1, -1, -1),
             rotation_d(vector_4d(0, 0, 0, 1))),  // no rotation
           b(vector_3d(3, 3, 3),
             rotation_d(-pi / 2, vector_3d(0, 0, 1))),  // rotated around z-axis 90 degrees
           c;
  c = interpolate_camera(a, b, 0.5);

  cerr << "a.rotation: " << a.rotation().axis() << ' '  << a.rotation().angle() << endl;
  cerr << "b.rotation: " << b.rotation().axis() << ' '  << b.rotation().angle() << endl;

  cerr << "c.center  : " << c.center() << endl;
  TEST_NEAR("c.center.x", c.center().x(), 1, 1e-16);
  TEST_NEAR("c.center.y", c.center().y(), 1, 1e-16);
  TEST_NEAR("c.center.z", c.center().z(), 1, 1e-16);

  cerr << "c.rotation (aa): " << c.rotation().axis() << ' ' << c.rotation().angle() << endl;
  cerr << "c.rotation  (q): " << c.rotation() << endl;
  TEST_NEAR("c.rotation.axis.x", c.rotation().axis().x(),  0, 1e-15);
  TEST_NEAR("c.rotation.axis.y", c.rotation().axis().y(),  0, 1e-15);
  TEST_NEAR("c.rotation.axis.z", c.rotation().axis().z(), -1, 1e-15);
  TEST_NEAR("c.rotation.angle" , c.rotation().angle()   , pi / 4, 1e-15);
}

IMPLEMENT_TEST(multiple_interpolations)
{
  using namespace maptk;
  using namespace std;

  double pi = boost::math::constants::pi<double>();
  camera_d a(vector_3d(-1, -1, -1),
             rotation_d(vector_4d(0, 0, 0, 1))),        // no rotation
           b(vector_3d(3, 3, 3),
             rotation_d(-pi / 2, vector_3d(0, 0, 1)));  // rotated around z-axis 90 degrees
  vector<camera_d> cams;

  cams.push_back(a);
  interpolated_cameras(a, b, 3, cams);
  cams.push_back(b);

  cerr << "Vector size: " << cams.size() << endl;
  TEST_EQUAL("vector size", cams.size(), 5);
  BOOST_FOREACH(camera_d cam, cams)
  {
    cerr << "\t" << cam.center() << " :: " << cam.rotation().axis() << " " << cam.rotation().angle() << endl;
  }

  camera_d i1 = cams[1],
           i2 = cams[2],
           i3 = cams[3];
  cerr << "i1 .25 c : " << i1.center() << " :: " << i1.rotation().axis() << ' ' << i1.rotation().angle() << endl;
  cerr << "i2 .25 c : " << i2.center() << " :: " << i2.rotation().axis() << ' ' << i2.rotation().angle() << endl;
  cerr << "i3 .25 c : " << i3.center() << " :: " << i3.rotation().axis() << ' ' << i3.rotation().angle() << endl;

  TEST_NEAR("i1 center.x", i1.center().x(), 0, 1e-15);
  TEST_NEAR("i1 center.y", i1.center().y(), 0, 1e-15);
  TEST_NEAR("i1 center.z", i1.center().z(), 0, 1e-15);
  TEST_NEAR("i1 r.axis.x", i1.rotation().axis().x(), 0, 1e-15);
  TEST_NEAR("i1 r.axis.y", i1.rotation().axis().y(), 0, 1e-15);
  TEST_NEAR("i1 r.axis.z", i1.rotation().axis().z(), -1, 1e-15);
  TEST_NEAR("i1 r.angle",  i1.rotation().angle(), pi / 8, 1e-15);

  TEST_NEAR("i2 center.x", i2.center().x(), 1, 1e-15);
  TEST_NEAR("i2 center.y", i2.center().y(), 1, 1e-15);
  TEST_NEAR("i2 center.z", i2.center().z(), 1, 1e-15);
  TEST_NEAR("i2 r.axis.x", i2.rotation().axis().x(), 0, 1e-15);
  TEST_NEAR("i2 r.axis.y", i2.rotation().axis().y(), 0, 1e-15);
  TEST_NEAR("i2 r.axis.z", i2.rotation().axis().z(), -1, 1e-15);
  TEST_NEAR("i2 r.angle",  i2.rotation().angle(), pi / 4, 1e-15);

  TEST_NEAR("i3 center.x", i3.center().x(), 2, 1e-15);
  TEST_NEAR("i3 center.y", i3.center().y(), 2, 1e-15);
  TEST_NEAR("i3 center.z", i3.center().z(), 2, 1e-15);
  TEST_NEAR("i3 r.axis.x", i3.rotation().axis().x(), 0, 1e-15);
  TEST_NEAR("i3 r.axis.y", i3.rotation().axis().y(), 0, 1e-15);
  TEST_NEAR("i3 r.axis.z", i3.rotation().axis().z(), -1, 1e-15);
  TEST_NEAR("i3 r.angle",  i3.rotation().angle(), 3*pi / 8, 1e-15);
}

// TODO: Full test case for camera interpolation would be to create a full,
// connected ring of cameras looking at a point (or even multiple loops), and
// checking that the rotation angle returned by the getter function of the
// rotation between each cameras is less than pi. It would be even more
// detailed to do this for camera rings along each major axis plane, as well
// as for a stare-point that is not at along the axis of rotation for the
// camera ring.

ext: cxx

max_stars_repo_name: dstoup/maptk

max_issues_repo_name: dstoup/maptk

max_forks_repo_name: dstoup/maptk


text:
// __COPYRIGHT_START__
// Package Name : efscape
// File Name : CommandOpt.hpp
// Copyright (C) 2006-2018 Jon C. Cline
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// __COPYRIGHT_END__
#ifndef EFSCAPE_UTILS_COMMANDOPT_HH
#define EFSCAPE_UTILS_COMMANDOPT_HH

#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <ctype.h>
#include <assert.h>
#include <boost/program_options.hpp>

namespace efscape {

  namespace utils {

    /**
     * class CommandOpt
     *
     * @author Jon C. Cline <clinej@stanfordalumni.org>
     * @version 1.1.0 created:	11 November 1999, revised 10 Jul 2017
     *
     * This class encapsulates the details of processing the command line
     * options.\n\n
     *
     * From the reference below with minor modifications
     * Reference:
     *  - Section 7.8 in Lippman, Stanley and Josee Lajoie. 1999.
     *    C++ Primer - 3rd ed. Addison Wesley. Reading, MA.
     */
    class CommandOpt {

    public:
      CommandOpt();
      virtual ~CommandOpt();

      virtual int parse_options( int argc, char *argv[] );

      std::string out_file() { return mC_out_file; }
      bool   debug_on() { return mb_debug_on; }
      int    files()    { return mC_file_names.size(); }

      std::string& operator[]( int ix ) {
	assert( ix < (int)mC_file_names.size() );
	return mC_file_names[ ix ];
      }

      virtual const char* program_name() = 0;
      virtual const char* program_version() = 0;

      virtual int execute() = 0;

    protected:

      virtual void usage( int exit_value = 0 );

      /** program option descriptions */
      boost::program_options::options_description mC_description;

      /** program option extended descriptions */
      boost::program_options::options_description mC_extended_description;

      /** program variables */
      boost::program_options::variables_map mC_variable_map;

      std::string mC_out_file;
      std::vector<std::string> mC_file_names;

    private:

      bool mb_debug_on;

      //     static const char *const _program_name;
      //     static const char *const _program_version;
    };

  } // namespace utils

} // namespace efscape

#endif	// #ifndef EFSCAPE_UTILS_COMMANDOPT_HH

max_stars_repo_name: clinejc/efscape

max_issues_repo_name: clinejc/efscape

max_forks_repo_name: clinejc/efscape