Commit 65f043b1 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

2006-08-31 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>

	Add dpoint, oln traits, and operators on point/dpoint.
	
	* oln/core/type.hh: New.
	* oln/core/traits_id.hh: New.
	* oln/core/abstract/dpoint.hh: New.
	* oln/core/abstract/dpoint_nd.hh: New.
	* oln/core/traits.hh: New.
	* oln/core/2d/dpoint2d.hh: New.
	* oln/core/abstract/point.hh (point): Add inheritance to
	oln::type.
	(operators): New.
	* oln/core/abstract/point_nd.hh (point_): New meta-function.
	(impl_eq): Rename as...
	(impl_equal): ...this.
	(coord): Rename as...
	(coord_t): ...this.
	(impl_less): New.
	(impl_plus_equal, impl_plus): New.
	(impl_minus_equal, impl_minus, impl_minus): New.
	(vec): New.
	(case_): New specializations.
	(point_nd): New ctor.
	* oln/core/2d/point2d.hh: Update forward declarations.
	(point_, dpoint_): New specializations.
	(point2d): New ctor.
	(coord): Rename as...
	(coord_t): ...this.



git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@511 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent b560a9fe
2006-08-31 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Add dpoint, oln traits, and operators on point/dpoint.
* oln/core/type.hh: New.
* oln/core/traits_id.hh: New.
* oln/core/abstract/dpoint.hh: New.
* oln/core/abstract/dpoint_nd.hh: New.
* oln/core/traits.hh: New.
* oln/core/2d/dpoint2d.hh: New.
* oln/core/abstract/point.hh (point): Add inheritance to
oln::type.
(operators): New.
* oln/core/abstract/point_nd.hh (point_): New meta-function.
(impl_eq): Rename as...
(impl_equal): ...this.
(coord): Rename as...
(coord_t): ...this.
(impl_less): New.
(impl_plus_equal, impl_plus): New.
(impl_minus_equal, impl_minus, impl_minus): New.
(vec): New.
(case_): New specializations.
(point_nd): New ctor.
* oln/core/2d/point2d.hh: Update forward declarations.
(point_, dpoint_): New specializations.
(point2d): New ctor.
(coord): Rename as...
(coord_t): ...this.
2006-08-30 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Start point hierarchy.
* oln/core/typedefs.hh (oln_type_of): New macro.
(dim_type): New typedef decl.
* oln/core/abstract/point.hh: New.
......
// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLENA_CORE_2D_DPOINT2D_HH
# define OLENA_CORE_2D_DPOINT2D_HH
# include <mlc/int.hh>
# include <oln/core/2d/point2d.hh>
# include <oln/core/abstract/dpoint_nd.hh>
namespace oln
{
// /// Super type.
// template<typename C>
// struct set_super_type< dpoint2d_<C> >
// {
// typedef abstract::dpoint< dpoint2d_<C> > ret;
// };
/// Virtual types associated to oln::abstract::image.
template <typename C>
struct vtypes_< dpoint2d_<C> >
{
typedef grid2d grid_type;
typedef point2d point_type;
typedef C coord_type;
typedef mlc::uint_<2> dim_type;
};
/// General 2D dpoint class.
template <typename C>
class dpoint2d_ : public abstract::dpoint_nd< dpoint2d_<C> > // FIXME: stc_get_super_(dpoint2d_<C>)
{
typedef dpoint2d_<C> self_t;
typedef abstract::dpoint_nd<self_t> super_t; // FIXME: stc_get_super(self)
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_;
public:
/// Ctor.
dpoint2d_()
{
}
/// Ctor.
dpoint2d_(const xtd::vec<2,coord_t>& v) :
super_t(v)
{
}
coord_t row() const { return v_[0]; }
coord_t& row() { return v_[0]; }
coord_t col() const { return v_[1]; }
coord_t& col() { return v_[1]; }
};
} // end of namespace oln
#endif // ! OLENA_CORE_2D_DPOINT2D_HH
......@@ -28,6 +28,8 @@
#ifndef OLENA_CORE_2D_POINT2D_HH
# define OLENA_CORE_2D_POINT2D_HH
# include <string>
# include <mlc/int.hh>
# include <oln/core/abstract/point_nd.hh>
......@@ -35,18 +37,34 @@
namespace oln
{
// Forward declarations.
/// \{
/// Forward declarations.
template <typename C> class point2d_;
class dpoint2d;
template <typename C> class dpoint2d_;
class grid2d;
/// \}
/// \{
/// Classical 2D point classes.
typedef point2d_<int> point2d;
typedef point2d_<float> point2df;
/// \}
/// \{
/// Classical 2D point classes.
typedef dpoint2d_<int> dpoint2d;
typedef dpoint2d_<float> dpoint2df;
/// \}
// /// Super type.
// template<typename C>
// struct set_super_type< point2d_<C> >
// {
// typedef abstract::point< point2d_<C> > ret;
// };
/// \{
/// Specializations of functions point and dpoint : (n,coord) -> type for n = 2.
template <typename C> struct point_ <2, C> { typedef point2d_<C> ret; };
template <typename C> struct dpoint_ <2, C> { typedef dpoint2d_<C> ret; };
/// \}
/// Virtual types associated to oln::abstract::image.
......@@ -64,27 +82,36 @@ namespace oln
template <typename C>
class point2d_ : public abstract::point_nd< point2d_<C> > // FIXME: stc_get_super_(point2d_<C>)
{
typedef point2d_<C> self;
typedef abstract::point_nd<self> super; // FIXME: stc_get_super(self)
typedef oln_type_of(self, coord) coord;
typedef point2d_<C> self_t;
typedef abstract::point_nd<self_t> super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super::v_;
using super_t::v_;
public:
const coord row() const { return v_[0]; }
coord& row() { return v_[0]; }
/// Ctor.
point2d_()
{
}
const coord col() const { return v_[1]; }
coord& col() { return v_[1]; }
};
/// Ctor.
point2d_(const xtd::vec<2,coord_t>& v) :
super_t(v)
{
}
coord_t row() const { return v_[0]; }
coord_t& row() { return v_[0]; }
/// Classical 2D point class.
typedef point2d_<int> point2d;
coord_t col() const { return v_[1]; }
coord_t& col() { return v_[1]; }
};
} // end of namespace oln
# include <oln/core/2d/dpoint2d.hh>
#endif // ! OLENA_CORE_2D_POINT2D_HH
// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and
// Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLENA_CORE_ABSTRACT_DPOINT_HH
# define OLENA_CORE_ABSTRACT_DPOINT_HH
# include <mlc/assert.hh>
# include <mlc/cmp.hh>
# include <stc/any.hh>
# include <stc/vtypes.hh>
# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
namespace oln
{
/// Function "dpoint_ : (n, coord) -> dpoint type".
template <unsigned n, typename C>
struct dpoint_
{
typedef mlc::undefined ret;
};
namespace abstract
{
/// Abstract dpoint class.
template <typename E>
class dpoint : public stc::any__simple<E>,
public oln::type
{
public:
bool operator==(const abstract::dpoint<E>& rhs) const
{
return this->exact().impl_eq(rhs.exact());
}
bool operator!=(const abstract::dpoint<E>& rhs) const { return not (*this == rhs); }
bool operator<(const abstract::dpoint<E>& rhs) const
{
return this->exact().impl_less(rhs.exact());
}
bool operator> (const abstract::dpoint<E>& rhs) const { return rhs < *this; }
bool operator>=(const abstract::dpoint<E>& rhs) const { return not (*this < rhs); }
bool operator<=(const abstract::dpoint<E>& rhs) const { return not (rhs < *this); }
protected:
dpoint()
{}
~dpoint() {
mlc::assert_defined_< oln_type_of(E, grid) >::check();
mlc::assert_defined_< oln_type_of(E, point) >::check();
mlc::assert_defined_< oln_type_of(E, coord) >::check();
mlc::assert_defined_< oln_type_of(E, dim) >::check();
}
};
} // end of namespace oln::abstract
} // end of namespace oln
#endif // ! OLENA_CORE_ABSTRACT_DPOINT_HH
// Copyright (C) 2001, 2002, 2003, 2004, 2006 EPITA Research and
// Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLENA_CORE_ABSTRACT_DPOINT_ND_HH
# define OLENA_CORE_ABSTRACT_DPOINT_ND_HH
# include <mlc/value.hh>
# include <xtd/vec.hh>
# include <oln/core/abstract/dpoint.hh>
namespace oln
{
namespace abstract
{
template <typename E>
class dpoint_nd : public abstract::dpoint<E>
{
typedef dpoint_nd<E> self_t;
typedef oln_type_of(E, dim) dim;
typedef oln_type_of(E, coord) coord_t;
public:
enum { n = mlc_value(dim) };
bool impl_equal(const self_t& rhs) const
{
return v_ == rhs.v_;
}
coord_t operator[](unsigned i) const
{
assert(i < n);
return v_[i];
}
coord_t& operator[](unsigned i)
{
assert(i < n);
return v_[i];
}
const xtd::vec<n,coord_t>& vec() const
{
return v_;
}
protected:
/// Ctor.
dpoint_nd()
{}
/// Ctor.
dpoint_nd(const xtd::vec<n,coord_t>& v) :
v_(v)
{}
xtd::vec<n,coord_t> v_;
};
} // end of namespace oln::abstract
} // end of namespace oln
#endif // ! OLENA_CORE_ABSTRACT_DPOINT_ND_HH
......@@ -34,28 +34,264 @@
# include <stc/any.hh>
# include <stc/vtypes.hh>
# include <stc/exact.hh>
# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
# include <oln/core/abstract/dpoint.hh>
# include <oln/core/traits_id.hh>
namespace oln {
namespace ERROR
{
struct OPERANDS_ARE_NOT_COMPATIBLE;
} // end of namespace oln::ERROR
namespace abstract {
/// Abstract point class.
template <typename E>
class point : public stc::any__simple<E>
class point : public stc::any__simple<E>,
public oln::type
{
typedef E exact_t;
typedef oln_type_of(E, dpoint) dpoint_t;
public:
bool operator==(const abstract::point<E>& rhs) const
/// \{
/// Operator ==.
bool operator==(const exact_t& rhs) const
{
return this->exact().impl_equal(rhs);
}
template <typename P>
bool operator==(const abstract::point<P>& rhs) const
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(P, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return this->exact().impl_equal(rhs.exact());
}
/// \}
/// \{
/// Operator !=.
bool operator!=(const exact_t& rhs) const
{
return not (*this == rhs);
}
template <typename P>
bool operator!=(const abstract::point<P>& rhs) const
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(P, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return not (*this == rhs);
}
/// \}
/// \{
/// Operator <.
bool operator<(const exact_t& rhs) const
{
return this->exact().impl_less(rhs);
}
template <typename P>
bool operator<(const abstract::point<P>& rhs) const
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(P, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return this->exact().impl_less(rhs.exact());
}
/// \}
/// \{
/// Operator >.
bool operator>(const exact_t& rhs) const
{
return rhs < *this;
}
template <typename P>
bool operator>(const abstract::point<P>& rhs) const
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(P, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return rhs < *this;
}
/// \}
/// \{
/// Operator >=.
bool operator>=(const exact_t& rhs) const
{
return not (*this < rhs);
}
template <typename P>
bool operator>=(const abstract::point<P>& rhs) const
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(P, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return not (*this < rhs);
}
/// \}
/// \{
/// Operator <=.
bool operator<=(const exact_t& rhs) const
{
return this->exact().impl_eq(rhs.exact());
return not (rhs < *this);
}
template <typename P>
bool operator<=(const abstract::point<P>& rhs) const
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(P, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return not (rhs < *this);
}
/// \}
/// \{
/// Operator +=.
exact_t& operator+=(const dpoint_t& rhs)
{
return this->exact().impl_plus_equal(rhs);
}
template <typename D>
exact_t& operator+=(const abstract::dpoint<D>& rhs)
{
mlc::assert_equal_< oln_type_of(E, grid),
oln_type_of(D, grid),
oln::ERROR::OPERANDS_ARE_NOT_COMPATIBLE >::check();
return this->exact().impl_plus_equal(rhs.exact());
}
/// \}
/// \{
/// Operator +.
exact_t operator+(const dpoint_t& rhs) const
{
return this->exact().impl_plus(rhs);
}
template <typename D>
xtd_op_plus_trait(E,D) operator+(const abstract::dpoint<D>& rhs)