Index: ChangeLog from Damien Thivolle damien@lrde.epita.fr
* ntg/real/int_u8.hh: Comply with new properties and categories. * ntg/real/bin.hh: Move to... * ntg/real/integer.hh: New. Integer types abstraction. * ntg/makefile.src: Notify new files. * ntg/enum: New. * ntg/enum/enum.hh: New. Enumeration types abstraction. * ntg/enum/bin.hh: ...here. Comply with new properties and categories. * ntg/core: New. * ntg/core/props.hh: New. Integre properties. * ntg/core/macros.hh: New. Integre macros. * ntg/core/cats.hh: New. Integre categories. * ntg/color/rgb_8.hh: Comply with new properties and categories. * ntg/color/color.hh: New. Color types abstraction.
color/color.hh | 85 ++++++++++++++++++++++++++++++++++++++++++++ color/rgb_8.hh | 33 +++++++++++++---- core/cats.hh | 77 ++++++++++++++++++++++++++++++++++++++++ core/macros.hh | 35 ++++++++++++++++++ core/props.hh | 77 ++++++++++++++++++++++++++++++++++++++++ enum/bin.hh | 59 ++++++++++++++++++++++++++---- enum/enum.hh | 90 +++++++++++++++++++++++++++++++++++++++++++++++ makefile.src | 10 ++++- real/bin.hh | 107 -------------------------------------------------------- real/int_u8.hh | 27 ++++++++++---- real/integer.hh | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 555 insertions(+), 133 deletions(-)
Index: ntg/real/int_u8.hh --- ntg/real/int_u8.hh (revision 34) +++ ntg/real/int_u8.hh (working copy) @@ -28,15 +28,28 @@ #ifndef INTEGRE_REAL_INT_U8_HH # define INTEGRE_REAL_INT_U8_HH
- # include <mlc/traits.hh>
+# include <ntg/core/cats.hh> +# include <ntg/core/props.hh> +# include <ntg/real/integer.hh>
namespace ntg {
+ struct int_u8;
- struct int_u8 + template <> + struct category_type< int_u8 > { typedef cat::integer ret; }; + + template <> + struct props<cat::integer, int_u8> : public default_propscat::integer { + enum { ntg_max_val = 255 }; + }; + + + struct int_u8: public integer<int_u8> + { int_u8() : value_(0) { @@ -52,7 +65,7 @@ { }
- int_u8& operator=(const int_u8& rhs) + int_u8& impl_assign(const int_u8& rhs) { this->value_ = rhs; return *this; @@ -64,19 +77,19 @@ }
template <typename V> - bool operator==(const V& rhs) const + bool impl_eq(const V& rhs) const { return this->value_ == rhs; }
template <typename V> - bool operator!=(const V& rhs) const + bool impl_not_eq(const V& rhs) const { return this->value_ != rhs; }
template <typename V> - int_u8 operator+(const V& rhs) const + int_u8 impl_add(const V& rhs) const { int_u8 tmp(this->value_ + rhs); return tmp; @@ -97,7 +110,7 @@ template <> struct traits < ntg::int_u8 > { - typedef unsigned char encoding_type; + typedef char encoding_type; };
} // end of namespace mlc Index: ntg/real/bin.hh --- ntg/real/bin.hh (revision 34) +++ ntg/real/bin.hh (working copy) @@ -1,107 +0,0 @@ -// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_REAL_BIN_HH -# define INTEGRE_REAL_BIN_HH - - -# include <mlc/traits.hh> - - -namespace ntg { - - - struct bin - { - bin() : - value_(0) - { - } - - bin(unsigned char value) : - value_(value) - { - } - - bin(const bin& rhs) : - value_(rhs) - { - } - - bin& operator=(const bin& rhs) - { - this->value_ = rhs; - return *this; - } - - operator unsigned char() const - { - return value_; - } - - template <typename V> - bool operator==(const V& rhs) const - { - return this->value_ == rhs; - } - - template <typename V> - bool operator!=(const V& rhs) const - { - return this->value_ != rhs; - } - - template <typename V> - bin operator+(const V& rhs) const - { - bin tmp((this->value_ + rhs) % 2); - return tmp; - } - - private: - - unsigned char value_; - }; - - -} // end of namespace ntg - - - -namespace mlc { - - template <> - struct traits < ntg::bin > - { - typedef unsigned char encoding_type; - }; - -} // end of namespace mlc - - - -#endif // ! INTEGRE_REAL_BIN_HH Index: ntg/real/integer.hh --- ntg/real/integer.hh (revision 0) +++ ntg/real/integer.hh (revision 0) @@ -0,0 +1,88 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_REAL_INTEGER_HH +# define INTEGRE_REAL_INTEGER_HH + +# include <mlc/any.hh> +# include <mlc/types.hh> + +# include <ntg/core/cats.hh> +# include <ntg/core/props.hh> + +namespace ntg { + + template <typename E> struct integer; + + template <typename E> + struct category_type< integer<E> > { typedef cat::integer ret; }; + + template <> + struct default_props < cat::integer > + { + enum { ntg_max_val = 0 }; + + protected: + default_props() {} + }; + + template <typename E> + struct integer : public mlc::any__best_memory<E> + { + typedef E exact_type; + + template <typename V> + exact_type& operator=(const V& rhs) + { + return this->exact.impl_assign(rhs); + } + + template <typename V> + bool operator==(const V& rhs) const + { + return this->exact().impl_eq(rhs); + } + + template <typename V> + bool operator!=(const V& rhs) const + { + return this->exact().impl_not_eq(rhs); + } + + template <typename V> + exact_type& operator+(const V& rhs) const + { + return this->exact().impl_add(rhs); + } + + protected : + integer() {} + }; + +} + +#endif // ! INTEGRE_REAL_INTEGER_HH Index: ntg/makefile.src --- ntg/makefile.src (revision 34) +++ ntg/makefile.src (working copy) @@ -5,7 +5,13 @@
NTG_DEP = \ color/rgb_8.hh \ + color/color.hh \ config/system.hh \ config/math.hh \ - real/bin.hh \ - real/int_u8.hh + core/cats.hh \ + core/macros.hh \ + core/props.hh \ + enum/bin.hh \ + enum/enum.hh \ + real/int_u8.hh \ + real/integer.hh Index: ntg/enum/enum.hh --- ntg/enum/enum.hh (revision 0) +++ ntg/enum/enum.hh (revision 0) @@ -0,0 +1,90 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_ENUM_ENUM_HH +# define INTEGRE_ENUM_ENUM_HH + +# include <mlc/any.hh> + +# include <ntg/core/cats.hh> +# include <ntg/core/props.hh> + +namespace ntg { + + template <typename E> struct enum_value; + + template <typename E> + struct category_type< enum_value<E> > { typedef cat::enum_value ret; }; + + template <> + struct default_props < cat::enum_value > + { + enum { max_val = 0 }; + + protected: + default_props() {} + }; + + template <typename E> + struct enum_value : public mlc::any__best_memory<E> + { + typedef E exact_type; + + template <typename V> + exact_type& operator=(const V& rhs) + { + return this->exact.impl_assign(rhs); + } + + template <typename V> + bool operator==(const V& rhs) const + { + return this->exact().impl_eq(rhs); + } + + template <typename V> + bool operator!=(const V& rhs) const + { + return this->exact().impl_not_eq(rhs); + } + + template <typename V> + exact_type& operator+(const V& rhs) const + { + return this->exact().impl_add(rhs); + } + + protected: + enum_value() {} + }; + +} // end of namespace ntg + + + + +#endif // ! INTEGRE_ENUM_ENUM_HH Index: ntg/enum/bin.hh --- ntg/enum/bin.hh (revision 0) +++ ntg/enum/bin.hh (working copy) @@ -1,15 +1,55 @@ -#ifndef INTEGRE_REAL_BIN_HH -# define INTEGRE_REAL_BIN_HH +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_ENUM_BIN_HH +# define INTEGRE_ENUM_BIN_HH
# include <mlc/traits.hh>
+# include <ntg/core/props.hh> +# include <ntg/core/cats.hh> +# include <ntg/enum/enum.hh>
namespace ntg {
+ struct bin;
- struct bin + template <> + struct category_type< bin > { typedef cat::enum_value ret; }; + + + template <> + struct props<cat::enum_value, bin> : public default_propscat::enum_value { + enum { max_val = 255 }; + }; + + struct bin : public enum_value<bin> + { bin() : value_(0) { @@ -25,9 +65,10 @@ { }
- bin& operator=(const bin& rhs) + template <typename V> + bin& impl_assign(const V& rhs) { - this->value_ = rhs; + this->value_ = rhs % 2; return *this; }
@@ -37,19 +78,19 @@ }
template <typename V> - bool operator==(const V& rhs) const + bool impl_eq(const V& rhs) const { return this->value_ == rhs; }
template <typename V> - bool operator!=(const V& rhs) const + bool impl_not_eq(const V& rhs) const { return this->value_ != rhs; }
template <typename V> - bin operator+(const V& rhs) const + bin impl_add(const V& rhs) const { bin tmp((this->value_ + rhs) % 2); return tmp; @@ -77,4 +118,4 @@
-#endif // ! INTEGRE_REAL_BIN_HH +#endif // ! INTEGRE_ENUM_BIN_HH Index: ntg/core/props.hh --- ntg/core/props.hh (revision 0) +++ ntg/core/props.hh (revision 0) @@ -0,0 +1,77 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_CORE_PROPS_HH +# define INTEGRE_CORE_PROPS_HH + +# include <mlc/types.hh> + +# include <ntg/core/cats.hh> + +/*! \namespace ntg +** \brief ntg namespace. +*/ +namespace ntg { + + + /*! \class default_props + ** + ** \brief Class that defines properties by default, so properties are + ** undefined. // FIXME: this doc should be modified... + ** + ** Practically all typedefs of default_props are thus set to + ** mlc::undefined_type. + ** + ** When props<E> is specialized, the programmer should derive that + ** specialization from another props<E'> or from default_props. + ** That ensures that an undefined property is set to mlc::undefined_type. + ** + ** \see props<E> + */ + template < typename category > + struct default_props; + + + /*! \class props<E> + ** + ** Declaration of the trait class for properties. + ** Parameter E is the targeted type. FIXME: rewrite doc. + */ + template <typename category, typename type> + struct props : public default_props <category> + {}; + + template <typename category, typename type> + struct props <category, const type> : public props <category, type> + {}; + + + +} // end of namespace ntg + + +#endif // ndef INTEGRE_CORE_PROPS_HH Index: ntg/core/macros.hh --- ntg/core/macros.hh (revision 0) +++ ntg/core/macros.hh (revision 0) @@ -0,0 +1,35 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_CORE_MACROS_HH +# define INTEGRE_CORE_MACROS_HH + +# define ntg_max_val(T) ntg::props<ntg_category_type(T),T>::ntg_max_val + +# define ntg_nb_comp(T) ntg::props<ntg_category_type(T),T>::nb_comp + +#endif // ! INTEGRE_CORE_MACROS_HH Index: ntg/core/cats.hh --- ntg/core/cats.hh (revision 0) +++ ntg/core/cats.hh (revision 0) @@ -0,0 +1,77 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_CORE_CATS_HH +# define INTEGRE_CORE_CATS_HH + +# include <mlc/types.hh> + + +/*! \macro FIXME:doc +*/ + +# define ntg_category_type(T) typename ntg::category_type<T>::ret + + + +/*! \namespace ntg +** \brief ntg namespace. +*/ +namespace ntg { + + + /*! \class category_type<T> + ** + ** FIXME: doc + ** + */ + template <typename T> + struct category_type + { + typedef mlc::undefined_type ret; + }; + + + /*! \namespace ntg::cat + ** \brief ntg::cat namespace. + */ + namespace cat { + + struct color; + struct enum_value; + struct integer; + // FIXME:... + + } // end of namespace ntg::cat + + +} // end of namespace ntg + + + + +#endif // ! INTEGRE_CORE_CATS_HH Index: ntg/color/rgb_8.hh --- ntg/color/rgb_8.hh (revision 34) +++ ntg/color/rgb_8.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory +// Copyright (C) 2005 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 @@ -28,20 +28,36 @@ #ifndef INTEGRE_COLOR_RGB_8_HH # define INTEGRE_COLOR_RGB_8_HH
- # include <mlc/traits.hh>
+# include <ntg/core/props.hh> +# include <ntg/color/color.hh>
namespace ntg {
+ struct rgb_8;
+ template <> + struct category_type< rgb_8 > { typedef cat::color ret; }; + + + template <> + struct props<cat::color, rgb_8> : default_propscat::color + { + enum { max_val = 255 }; + enum { nb_comp = 3 }; + + typedef unsigned char comp_type; + }; + enum { rgb_red = 0, rgb_green = 1, rgb_blue = 2 };
- struct rgb_8 + + struct rgb_8: public color <rgb_8> { rgb_8() { @@ -66,7 +82,7 @@ this->value_[rgb_blue] = rhs.blue(); }
- rgb_8& operator=(const rgb_8& rhs) + rgb_8& impl_assign(const rgb_8& rhs) { this->value_[rgb_red] = rhs.red(); this->value_[rgb_green] = rhs.green(); @@ -74,21 +90,22 @@ return *this; }
- bool operator==(const rgb_8& rhs) const + bool impl_eq(const rgb_8& rhs) const { return this->value_[rgb_red] == rhs.red() && this->value_[rgb_green] == rhs.green() && this->value_[rgb_blue] == rhs.blue(); }
- template <typename V> - bool operator!=(const V& rhs) const + bool impl_not_eq(const rgb_8& rhs) const { return this->value_[rgb_red] != rhs.red() || this->value_[rgb_green] != rhs.green() || this->value_[rgb_blue] != rhs.blue(); }
+ + unsigned char& red() { return value_[rgb_red]; @@ -141,4 +158,4 @@
-#endif // ! INTEGRE_COLOR_RGB_8_HH +#endif // ! NTG_COLOR_RGB_8_HH Index: ntg/color/color.hh --- ntg/color/color.hh (revision 0) +++ ntg/color/color.hh (revision 0) @@ -0,0 +1,85 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 INTEGRE_COLOR_COLOR_HH +# define INTEGRE_COLOR_COLOR_HH + +# include <mlc/any.hh> +# include <mlc/types.hh> + +# include <ntg/core/cats.hh> +# include <ntg/core/props.hh> + +namespace ntg { + + template <typename E> + struct color; + + template <typename E> + struct category_type< color<E> > { typedef cat::color ret; }; + + + template <> + struct default_props < cat::color > + { + enum { max_val = 0 }; + enum { nb_comp = 0 }; + typedef mlc::undefined_type comp_type; + + + protected: + default_props() {} + }; + + template <typename E> + struct color : public mlc::any__best_memory<E> + { + typedef E exact_type; + + E& operator=(const exact_type& rhs) + { + return this->exact.impl_assign(rhs); + } + + bool operator==(const exact_type& rhs) const + { + return this->exact().impl_eq(rhs); + } + + bool operator!=(const exact_type& rhs) const + { + return this->exact().impl_not_eq(rhs); + } + + protected: + color() {} + }; + +} // end of namespace ntg + + +#endif // ! INTEGRE_COLOR_COLOR_HH