URL:
https://svn.lrde.epita.fr/svn/scool/branches/scool-ng
ChangeLog:
2009-05-12 Warren Seine <soow(a)lrde.epita.fr>
mini-std: Multiple improvements in design (compiling).
* mini-std.hh: Update.
Removed old properties.
Added iterator properties.
Added iterator_base code sharing class.
Added check in constructors (instanciating concepts is evil!).
Removed get_stdcontainer function (not in the STL reference).
Fixed "wrong template number" errors.
Implemented empty constructors.
* scoop.hh: New.
Moved stc definition to scoop.hh.
---
mini-std.hh | 234 ++++++++++++++++++++++++------------------------------------
scoop.hh | 62 +++++++++++++++
2 files changed, 156 insertions(+), 140 deletions(-)
Index: branches/scool-ng/examples/mini-std/c++/scoop.hh
===================================================================
--- branches/scool-ng/examples/mini-std/c++/scoop.hh (revision 0)
+++ branches/scool-ng/examples/mini-std/c++/scoop.hh (revision 152)
@@ -0,0 +1,62 @@
+// Copyright (C) 2009 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.
+
+/* \file examples/mini-std/c++/scoop.hh
+ \brief SCOOP 1.5 definitions. */
+
+#ifndef SCOOP_HH
+# define SCOOP_HH
+
+namespace stc
+{
+ // Fwd decl.
+ template <typename E> struct Object;
+
+ // Object category flag type.
+ template <>
+ struct Object<void>
+ {
+ };
+
+ /*! \brief Base class for almost every class.
+ *
+ * The parameter \a E is the exact type.
+ */
+ template <typename E>
+ struct Object
+ {
+ typedef E exact_t;
+ typedef Object<void> category; // Default.
+ protected:
+ Object() {}
+ };
+
+ typedef char true_;
+ typedef struct { char _[2]; } false_;
+}
+
+#endif
Index: branches/scool-ng/examples/mini-std/c++/mini-std.hh
===================================================================
--- branches/scool-ng/examples/mini-std/c++/mini-std.hh (revision 151)
+++ branches/scool-ng/examples/mini-std/c++/mini-std.hh (revision 152)
@@ -31,43 +31,13 @@
#include <list>
#include <iostream>
+#include "scoop.hh"
namespace mstd
{
- // Fwd decl.
- template <typename E> struct Object;
+ using namespace stc;
- // Object category flag type.
- template <>
- struct Object<void>
- {
- // typedef Unknown<void> super; // LOL !?
- };
-
-
- /*! \brief Base class for almost every class defined in Milena.
- *
- * The parameter \a E is the exact type.
- */
- template <typename E>
- struct Object
- {
- typedef E exact_t;
- typedef Object<void> category; // Default.
- protected:
- Object() {}
- };
-} // End of namespace mstd
-
-
-namespace mstd
-{
- namespace internal
- {
- typedef char yes_;
- struct no_ { char dummy[2]; };
-
- } // End of namespace internal
+ namespace internal {}
} // End of namespace mstd
@@ -87,7 +57,7 @@
typedef Object<void> super;
};
- // Container category flag type.
+ // Iterator category flag type.
template <>
struct Iterator<void>
{
@@ -107,6 +77,18 @@
// Undefined property tag
struct undef { std::string name() const { return "undef"; } };
+ namespace iterator
+ {
+ struct access
+ {
+ struct any
+ { protected: any() {} };
+
+ struct bidirectional : any
+ { std::string name() const { return "access::bidirectional"; } };
+ };
+ }
+
namespace container
{
struct category
@@ -161,15 +143,9 @@
template <typename T>
struct undefined_container_ // See: mln/trait/images.hh:134
{
- // misc
typedef undef category;
typedef undef speed;
typedef undef size;
-
- // data (I::value)
- // typedef undef kind;
- // typedef undef nature;
- // typedef undef quant;
};
@@ -180,10 +156,8 @@
template <typename T>
- struct default_container_ : undefined_container_<T>
+ struct default_container_ : container_<T>
{
- public:
- typedef trait::container::speed::fast speed;
};
@@ -200,7 +174,7 @@
template <typename T>
- struct default_iterator_ : undefined_iterator_<T>
+ struct default_iterator_ : iterator_<T>
{
};
}
@@ -223,15 +197,22 @@
struct Iterator :
public Object<E>
{
+ typedef Iterator<void> category;
+
/*
+ // provided by internal::container_base:
+
bool is_valid() const;
void invalidate();
void start();
void next_();
*/
+ protected:
Iterator()
{
+ // See: mln/core/concept/image.hh:199
+
bool (E::*m1)() const = & E::is_valid;
m1 = 0;
void (E::*m2)() = & E::invalidate;
@@ -255,21 +236,7 @@
return *this;
}
- // value_t operator*()
- // {
- // return *(exact(this));
- // }
-
- // bool operator==(const Exact& it)
- // {
- // return exact(this) == it;
- // }
-
- // bool operator!=(const Exact& it)
- // {
- // return exact(this) == it;
- // }
-
+ public:
/*! \brief Go to the next element.
*
* \warning This is a final method; iterator classes should not
@@ -283,10 +250,19 @@
assert(exact(this)->is_valid());
exact(this)->next_();
}
+ };
+ namespace internal
+ {
+ template <typename T, typename E>
+ struct iterator_base :
+ public Iterator<E>
+ {
+ typedef T value_t;
protected:
- Iterator();
+ iterator_base();
};
+ }
// ----------- //
@@ -321,11 +297,8 @@
typedef stdcontainer_t;
size_t size() const;
-
bool empty() const;
-
void clear();
-
stdcontainer_t& get_stdcontainer();
@@ -339,12 +312,12 @@
{
// See: mln/core/concept/image.hh:199
- // FIXME: Add new checks like above
-
- // size_t (E::*m1)() const = & E::size;
- // m1 = 0;
-
- // provided by internal::container_base:
+ size_t (E::*m1)() const = & E::size;
+ m1 = 0;
+ bool (E::*m2)() const = & E::empty;
+ m2 = 0;
+ void (E::*m3)() = & E::clear;
+ m3 = 0;
typedef typename E::value_t value_t;
}
@@ -358,8 +331,8 @@
struct container_base :
public Container<E>
{
+ typedef T value_t;
typedef std::size_t size_t;
- typedef typename mstd::trait::container_<E>::stdcontainer_t stdcontainer_t;
size_t size() const
{
@@ -376,15 +349,10 @@
exact(this)->clear();
}
- stdcontainer_t& get_stdcontainer()
- {
- return exact(this)->get_stdcontainer();
- }
-
protected:
/// Constructor without argument.
- container_base();
+ container_base() {}
};
@@ -415,19 +383,34 @@
// ForwardContainer. //
// ------------------ //
- template <typename E>
- struct ForwardContainer : public Container<E>
+ namespace internal
{
- typedef Container<E> super;
+ template <typename T, typename E>
+ struct bidirectional_iterator_base :
+ public iterator_base<T, E>
+ {
+ protected:
+ bidirectional_iterator_base();
+ };
+ }
- typedef typename mstd::trait::container_<E>::iter_t iter_t;
+ namespace internal
+ {
+ template <typename T, typename E>
+ struct forward_container_base :
+ public container_base<T, E>
+ {
+ typedef typename E::iter_t iter_t;
iter_t begin()
{
return exact(this)->begin();
}
- };
+ protected:
+ forward_container_base();
+ };
+ }
// ---------------- //
// BiDirContainer. //
@@ -459,80 +442,63 @@
namespace mstd
{
// ------------------ //
- // Forward_Iterator. //
+ // List iterator. //
// ------------------ //
// Forward declarations.
- template <typename T, typename E>
- struct Forward_Iterator;
+ template <typename T>
+ struct list_iterator;
namespace trait
{
- template <typename E>
- struct iterator_< Forward_Iterator<E> > :
- public default_iterator_< Forward_Iterator<E> >
+ template <typename T>
+ struct iterator_< list_iterator<T> > :
+ public default_iterator_< list_iterator<T> >
{
- typedef T container_t;
-
- typedef typename container_t::value_t value_t;
+ typedef iterator::access::bidirectional access;
};
}
- template <typename T, typename E>
- struct Forward_Iterator :
- public Iterator< Forward_Iterator<T> >
- {
- typedef mstd::trait::iterator_<E>::container_t container_t;
-
- Forward_Iterator(container_t& c) :
- c_ (c),
- iter_ (c.get_stdcontainer().begin())
+ template <typename T>
+ struct list_iterator :
+ // FIXME: Add internal::bidirectional_iterator_primary
+ public internal::bidirectional_iterator_base< T, list_iterator<T> >
{
- }
+ typedef T value_t;
+ typedef list_iterator<T> self_t;
value_t& operator*()
{
return *iter_;
}
- Forward_Iterator<T, E>& operator++()
+ self_t& operator++()
{
iter_++;
return *exact(this);
}
- Forward_Iterator<T, E> operator++(int)
+ self_t operator++(int)
{
- current ret = *exact(this);
+ self_t ret = *exact(this);
++iter_;
return ret;
}
- void to_begin()
- {
- iter_ = c_.get_stdcontainer().begin();
- }
-
- void to_end()
- {
- iter_ = c_.get_stdcontainer().end();
- }
-
- bool operator==(const Forward_Iterator<T, E>& it)
+ bool operator==(const self_t& it)
{
return this->iter_ == it.iter_;
}
- bool operator!=(const Forward_Iterator<T, E>& it)
+ bool operator!=(const self_t& it)
{
return this->iter_ != it.iter_;
}
protected:
- container_t& c_;
- iter_t iter_;
+ typename std::list<T>::iterator iter_;
};
@@ -549,21 +515,13 @@
{
template <typename T>
struct container_< list<T> > :
- public default_container_< T, list<T> >
+ public default_container_< list<T> >
{
- // misc
typedef trait::container::category::primary category;
- // typedef mlc::true_ is_isfrontinsertion;
- // typedef mlc::true_ is_isbackinsertion;
-
- // typedef mlc::true_ is_mutable;
-
- typedef T value_t;
-
- typedef bi_dir_iterator< list<T> > iter_t;
-
- typedef std::list<T> stdcontainer_t;
+ typedef stc::true_ is_reversible_container;
+ typedef stc::true_ is_front_insertion_sequence;
+ typedef stc::true_ is_back_insertion_sequence;
};
}
@@ -574,9 +532,12 @@
{
public:
typedef T value_t;
+ typedef list_iterator<T> iter_t;
/// Constructor without argument.
- list();
+ list()
+ {
+ }
size_t size() const
{
@@ -593,11 +554,6 @@
list_.clear();
}
- stdcontainer_t& get_stdcontainer()
- {
- return list_;
- }
-
void push_front(value_t& v)
{
list_.push_front(v);
@@ -620,14 +576,12 @@
iter_t begin()
{
- return iter_t(*this);
+ return list_.begin();
}
iter_t end()
{
- iter_t it(*this);
- it.to_end();
- return it;
+ return list_.end();
}
value_t& front()
@@ -641,7 +595,7 @@
}
protected:
- stdcontainer_t list_;
+ std::list<T> list_;
};
// ---------- //
--
:: Warren Seine // SooW ::
:: warren.seine @
gmail.com ::
:: EPITA CSI 2010 ::