https://svn.lrde.epita.fr/svn/oln/trunk/static
ChangeLog | 10 +++++++
stc/Makefile.am | 1
stc/find_exact.hh | 59 +++++++++++++++++++++++++++++++++++++++++++
tests/Makefile.am | 2 +
tests/find_exact.cc | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 143 insertions(+)
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add stc_find_exact.
* stc/find_exact.hh: New.
* tests/find_exact.cc (main): New test.
* stc/Makefile.am (nobase_stc_HEADERS): Add find_exact.hh.
* tests/Makefile.am (check_PROGRAMS): Add find_exact.
(find_exact_SOURCES): New.
Index: tests/find_exact.cc
--- tests/find_exact.cc (révision 0)
+++ tests/find_exact.cc (révision 0)
@@ -0,0 +1,71 @@
+// Copyright (C) 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.
+
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
+
+# include <stc/any.hh>
+# include <stc/find_exact.hh>
+# include <stc/exact.hh>
+
+namespace my
+{
+
+ /// An abstract class.
+ template <typename Exact>
+ struct A : stc::any__simple<Exact>
+ {
+ };
+
+ /// An abstract class, possibly concrete.
+ template <typename Exact = stc::itself>
+ struct B : public A< stc_find_exact(B, Exact) >
+ {
+ };
+
+ /// A concrete class.
+ struct C : public B<C>
+ {
+ };
+
+} // end of namespace my
+
+int
+main()
+{
+ using my::A;
+ using my::B;
+ using my::C;
+
+ mlc::assert_< mlc_is_a_(B<>, A) >::check();
+ mlc::assert_< mlc_is_a_(C, A) >::check();
+ mlc::assert_< mlc_is_a_(C, B) >::check();
+
+ mlc::assert_< mlc_eq(stc::to_exact_< A< B<> > >::ret,
+ B<stc::itself>) >::check();
+ mlc::assert_< mlc_eq(stc::to_exact_< A<C> >::ret, C) >::check();
+}
Index: tests/Makefile.am
--- tests/Makefile.am (révision 497)
+++ tests/Makefile.am (copie de travail)
@@ -11,6 +11,7 @@
any \
entry \
exact \
+ find_exact \
multiple-supers \
super \
vtypes \
@@ -20,6 +21,7 @@
any_SOURCES = any.cc
entry_SOURCES = entry.cc
exact_SOURCES = exact.cc
+find_exact_SOURCES = find_exact.cc
multiple_supers_SOURCES = multiple-supers.cc
super_SOURCES = super.cc
vtypes_SOURCES = vtypes.cc
Index: stc/find_exact.hh
--- stc/find_exact.hh (révision 0)
+++ stc/find_exact.hh (révision 0)
@@ -0,0 +1,59 @@
+// Copyright (C) 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 STATIC_FIND_EXACT_HH
+# define STATIC_FIND_EXACT_HH
+
+# define stc_find_exact(Abstraction, ExactType) \
+ typename stc::find_exact< Abstraction, ExactType >::ret
+
+namespace stc
+{
+
+ /// Special tag to be passed as exact type to make a static abstract
+ /// class ``concrete''.
+ struct itself;
+
+ /// Find the exact type for \a Abstraction whose ``Exact'' template
+ /// parameter is \a exact_type
+ template <template <class> class abstraction, typename exact_type>
+ struct find_exact
+ {
+ typedef exact_type ret;
+ };
+
+ /// Specialization for stc::itself.
+ template <template <class> class abstraction>
+ struct find_exact<abstraction, stc::itself>
+ {
+ typedef abstraction<stc::itself> ret;
+ };
+
+} // end of namespace stc
+
+
+#endif // ! STATIC_FIND_EXACT_HH
Index: stc/Makefile.am
--- stc/Makefile.am (révision 497)
+++ stc/Makefile.am (copie de travail)
@@ -5,6 +5,7 @@
any.hh \
entry.hh \
exact.hh \
+ find_exact.hh \
valist_aggregator.hh \
vtypes.hh \
\