-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
URL:
https://svn.lrde.epita.fr/svn/oln/trunk/static
ChangeLog:
2007-06-15 Thomas Moulard <thomas.moulard(a)lrde.epita.fr>
Add logger morpher and fix transform morpher.
* samples/mini-std/cpp2/Makefile: New.
* samples/mini-std/cpp2/mini-std.cc: Here.
Makefile | 7 ++
mini-std.cc | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 133 insertions(+), 16 deletions(-)
Index: trunk/static/samples/mini-std/cpp2/mini-std.cc
===================================================================
- --- trunk/static/samples/mini-std/cpp2/mini-std.cc (revision 979)
+++ trunk/static/samples/mini-std/cpp2/mini-std.cc (revision 980)
@@ -535,35 +535,35 @@
template <typename Exact>
struct case_<switch_iterator_kind, Exact, 1> :
- - public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t), forwardIterator)
>
+ public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t)::primitiveIterator_t,
forwardIterator) >
{
typedef ForwardContainer<Exact> ret;
};
template <typename Exact>
struct case_<switch_iterator_kind, Exact, 2> :
- - public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t), backwardIterator)
>
+ public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t)::primitiveIterator_t,
backwardIterator) >
{
typedef BiDirContainer<Exact> ret;
};
template <typename Exact>
struct case_<switch_iterator_kind, Exact, 3> :
- - public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t)::primitiveIterator_t,
biDirIterator) > // ::primitiveIterator_t
+ public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t)::primitiveIterator_t,
biDirIterator) >
{
typedef BiDirContainer<Exact> ret;
};
template <typename Exact>
struct case_<switch_iterator_kind, Exact, 4> :
- - public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t),
randomAccessibleIterator) >
+ public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t)::primitiveIterator_t,
randomAccessibleIterator) >
{
typedef RandomAccessibleContainer<Exact> ret;
};
template <typename Exact>
struct case_<switch_iterator_kind, Exact, 5> :
- - public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t), associativeIterator)
>
+ public mlc::where_ < mlc_is_a(stc_find_type(Exact, iter_t)::primitiveIterator_t,
associativeIterator) >
{
typedef AssociativeContainer<Exact> ret;
};
@@ -1076,20 +1076,18 @@
return deleg_;
}
- - delegatee& get_deleg() const
+ delegatee get_deleg() const
{
return deleg_;
}
- - //FIXME
current& operator++()
{
deleg_++;
return *exact(this);
}
- - //FIXME
current operator++(int)
{
current ret = *exact(this);
@@ -1097,7 +1095,7 @@
return ret;
}
protected:
- - delegatee& deleg_;
+ delegatee deleg_;
Functor trans_;
};
@@ -1159,8 +1157,6 @@
stc_using(value_t);
stc_using(iter_t);
- - //typedef std::unary_function<value_t&,value_t> transform_t;
- -
transform_morpher(delegatee& d, Functor trans) :
container_morpher_<current>(),
deleg_ (d),
@@ -1185,9 +1181,9 @@
iter_t impl_end()
{
- - // iter_t it(deleg_.end(), trans_);
- - // it.get_deleg().to_end();
- - return iter_t(deleg_.end(), trans_);
+ iter_t it(deleg_.end(), trans_);
+ it.get_deleg().to_end();
+ return it;
}
protected:
@@ -1195,6 +1191,85 @@
Functor trans_;
};
+ // logger morpher
+#define LOGGER(name) NAME##_logger_morpher
+#define LOGGER_STREAM std::cerr
+#define LOGGER_BEGIN(NAME) \
+ template <typename Container> \
+ struct NAME##_logger_morpher; \
+ \
+ template <typename Container> \
+ struct super_trait_<NAME##_logger_morpher<Container> >
\
+ { \
+ typedef container_morpher_<Container> ret; \
+ }; \
+ \
+ template <typename Container> \
+ struct vtypes<NAME##_logger_morpher<Container> >
\
+ { \
+ typedef Container delegatee; \
+ }; \
+ \
+ template <typename Container> \
+ struct NAME##_logger_morpher : \
+ public container_morpher_<NAME##_logger_morpher<Container> >
\
+ { \
+ typedef NAME##_logger_morpher<Container> current; \
+ typedef container_morpher_<current> super; \
+ \
+ stc_using(delegatee); \
+ stc_using(iter_t); \
+ \
+ NAME##_logger_morpher(delegatee& d) : \
+ container_morpher_<current>(), \
+ deleg_ (d) \
+ { \
+ } \
+ \
+ delegatee& get_deleg() \
+ { \
+ return deleg_; \
+ } \
+ \
+ delegatee& get_deleg() const \
+ { \
+ return deleg_; \
+ }
+
+#define LOGMETHOD(MESSAGE, RETURNTYPE, NAME) \
+ \
+ RETURNTYPE NAME() \
+ { \
+ LOGGER_STREAM << __FILE__ << ":" << __LINE__ <<
":" \
+ << MESSAGE << std::endl;
\
+ return deleg_.NAME(); \
+ }
+
+#define LOGMETHODVOID(MESSAGE, RETURNTYPE, NAME) \
+ \
+ RETURNTYPE NAME() \
+ { \
+ LOGGER_STREAM << __FILE__ << ":" << __LINE__ <<
":" \
+ << MESSAGE << std::endl;
\
+ deleg_.NAME(); \
+ }
+
+#define LOGMETHODARG(MESSAGE, RETURNTYPE, NAME, ARGTYPE, ARGNAME) \
+ \
+ RETURNTYPE NAME(ARGTYPE) \
+ { \
+ LOGGER_STREAM << __FILE__ << ":" << __LINE__ <<
":" \
+ << MESSAGE << std::endl;
\
+ return deleg_.NAME(ARGNAME); \
+ }
+
+
+#define LOGGER_END() \
+ \
+ protected: \
+ delegatee& deleg_; \
+ };
+
} // End of namespace mstd.
@@ -1224,6 +1299,15 @@
{
}
+// Create logger class.
+namespace mstd
+{
+ LOGGER_BEGIN(begin)
+ LOGMETHOD("Begin has been triggered.", iter_t, begin)
+ LOGMETHOD("End has been triggered.", iter_t, end)
+ LOGGER_END()
+};
+
int main()
{
// List
@@ -1295,8 +1379,15 @@
// Dummy<int> a;
// test(a);
- - // Morphers
+ // *** Morphers ***
typedef mstd::transform_morpher<mstd::list<int>, transform > morpher_t;
+ typedef mstd::begin_logger_morpher<mstd::list<int> > logger_t;
+
+ typedef mstd::transform_morpher<logger_t, transform > translog_t;
+
+
+ // Transform
+ {
morpher_t tm(l, transform());
typedef mstd::transform_morpher_iterator<mstd::list<int>::iter_t,
transform> itmorpher_t;
@@ -1319,6 +1410,25 @@
TEST(*it);
TEST(*im);
}
- - tm.clear();
TEST(tm.size());
}
+
+ // Logger
+ {
+ logger_t lm(l);
+
+ logger_t::iter_t im = lm.begin();
+ for (; im != lm.end(); ++im)
+ TEST(*im);
+ TEST(*im);
+ }
+
+ // Transform + Log
+ {
+ logger_t lm(l);
+ translog_t tlm(lm, transform());
+
+ translog_t::iter_t im = tlm.begin();
+ TEST(*im);
+ }
+}
Index: trunk/static/samples/mini-std/cpp2/Makefile
===================================================================
- --- trunk/static/samples/mini-std/cpp2/Makefile (revision 0)
+++ trunk/static/samples/mini-std/cpp2/Makefile (revision 980)
@@ -0,0 +1,7 @@
+CPPFLAGS = -I../../../../olena/oln -I../../../../metalic
+
+.PHONY: all
+
+all: mini-std
+
+mini-std: mini-std.cc
\ No newline at end of file
- --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFGcmNd8QvmnUS5oeMRAtrKAKDGo424ympOK/fS7Tsw+WYI9yq6zQCfYER3
E3bqGThYOBu00+Og85t+jqw=
=1OpT
-----END PGP SIGNATURE-----