Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* ntg/real/int_u8.hh: Add i/o support.
* ntg/real/integer.hh: Likewise.
* ntg/enum/enum.hh: Likewise.
* ntg/enum/bin.hh: Likewise.
* ntg/core/macros.hh: Likewise.
* ntg/color/rgb_8.hh: Likewise.
* ntg/color/color.hh: Likewise.
color/color.hh | 12 ++++++++++++
color/rgb_8.hh | 32 +++++++++++++++++++++++++++++++-
core/macros.hh | 6 +++++-
enum/bin.hh | 3 ++-
enum/enum.hh | 3 ++-
real/int_u8.hh | 11 +++++++++--
real/integer.hh | 5 +++--
7 files changed, 64 insertions(+), 8 deletions(-)
Index: ntg/real/int_u8.hh
--- ntg/real/int_u8.hh (revision 35)
+++ ntg/real/int_u8.hh (working copy)
@@ -44,7 +44,8 @@
template <>
struct props<cat::integer, int_u8> : public default_props<cat::integer>
{
- enum { ntg_max_val = 255 };
+ enum { max_val = 255 };
+ typedef char io_type;
};
@@ -71,6 +72,12 @@
return *this;
}
+ int_u8& impl_assign(const unsigned char& rhs)
+ {
+ this->value_ = rhs;
+ return *this;
+ }
+
operator unsigned char() const
{
return value_;
@@ -110,7 +117,7 @@
template <>
struct traits < ntg::int_u8 >
{
- typedef char encoding_type;
+ typedef unsigned char encoding_type;
};
} // end of namespace mlc
Index: ntg/real/integer.hh
--- ntg/real/integer.hh (revision 35)
+++ ntg/real/integer.hh (working copy)
@@ -44,7 +44,8 @@
template <>
struct default_props < cat::integer >
{
- enum { ntg_max_val = 0 };
+ enum { max_val = 0 };
+ typedef mlc::no_type io_type;
protected:
default_props() {}
@@ -58,7 +59,7 @@
template <typename V>
exact_type& operator=(const V& rhs)
{
- return this->exact.impl_assign(rhs);
+ return this->exact().impl_assign(rhs);
}
template <typename V>
Index: ntg/enum/enum.hh
--- ntg/enum/enum.hh (revision 35)
+++ ntg/enum/enum.hh (working copy)
@@ -44,6 +44,7 @@
struct default_props < cat::enum_value >
{
enum { max_val = 0 };
+ typedef mlc::no_type io_type;
protected:
default_props() {}
@@ -57,7 +58,7 @@
template <typename V>
exact_type& operator=(const V& rhs)
{
- return this->exact.impl_assign(rhs);
+ return this->exact().impl_assign(rhs);
}
template <typename V>
Index: ntg/enum/bin.hh
--- ntg/enum/bin.hh (revision 35)
+++ ntg/enum/bin.hh (working copy)
@@ -45,7 +45,8 @@
template <>
struct props<cat::enum_value, bin> : public default_props<cat::enum_value>
{
- enum { max_val = 255 };
+ enum { max_val = 1 };
+ typedef unsigned char io_type;
};
struct bin : public enum_value<bin>
Index: ntg/core/macros.hh
--- ntg/core/macros.hh (revision 35)
+++ ntg/core/macros.hh (working copy)
@@ -28,8 +28,12 @@
#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_max_val(T) ntg::props<ntg_category_type(T),T>::max_val
# define ntg_nb_comp(T) ntg::props<ntg_category_type(T),T>::nb_comp
+# define ntg_comp_type(T) typename ntg::props<ntg_category_type(T),T>::comp_type
+
+# define ntg_io_type(T) typename ntg::props<ntg_category_type(T),T>::io_type
+
#endif // ! INTEGRE_CORE_MACROS_HH
Index: ntg/color/rgb_8.hh
--- ntg/color/rgb_8.hh (revision 35)
+++ ntg/color/rgb_8.hh (working copy)
@@ -47,6 +47,7 @@
enum { max_val = 255 };
enum { nb_comp = 3 };
+ typedef char io_type;
typedef unsigned char comp_type;
};
@@ -66,6 +67,12 @@
this->value_[rgb_blue] = 0;
}
+ rgb_8(const unsigned char init[3])
+ {
+ for (unsigned i = 0; i < 3; i++)
+ value_[i] = init[i];
+ }
+
rgb_8(unsigned char red,
unsigned char green,
unsigned char blue)
@@ -104,8 +111,19 @@
this->value_[rgb_blue] != rhs.blue();
}
+ unsigned char& impl_op_sqbr(unsigned int i)
+ {
+ assert(i < 3);
+ return value_[i];
+ }
+ const unsigned char impl_op_sqbr(unsigned int i) const
+ {
+ assert(i < 3);
+ return value_[i];
+ }
+
unsigned char& red()
{
return value_[rgb_red];
@@ -145,13 +163,25 @@
} // end of namespace ntg
+# include <ostream>
+std::ostream& operator<<(std::ostream& ostr, const ntg::rgb_8&
to_print)
+{
+ ostr << "(" << unsigned(to_print[0])
+ << "," << unsigned(to_print[1])
+ << "," << unsigned(to_print[2])
+ << ")";
+ return ostr;
+}
+
+
+
namespace mlc {
template <>
struct traits < ntg::rgb_8 >
{
- typedef unsigned char* encoding_type;
+ typedef ntg::rgb_8 encoding_type;
};
} // end of namespace mlc
Index: ntg/color/color.hh
--- ntg/color/color.hh (revision 35)
+++ ntg/color/color.hh (working copy)
@@ -49,6 +49,7 @@
enum { max_val = 0 };
enum { nb_comp = 0 };
typedef mlc::undefined_type comp_type;
+ typedef mlc::undefined_type io_type;
protected:
@@ -59,6 +60,7 @@
struct color : public mlc::any__best_memory<E>
{
typedef E exact_type;
+ typedef typename props<cat::color, E>::comp_type comp_type;
E& operator=(const exact_type& rhs)
{
@@ -75,6 +77,16 @@
return this->exact().impl_not_eq(rhs);
}
+ comp_type& operator [](const unsigned int &i)
+ {
+ return this->exact().impl_op_sqbr(i);
+ }
+
+ const comp_type operator [](const unsigned int &i) const
+ {
+ return this->exact().impl_op_sqbr(i);
+ }
+
protected:
color() {}
};