* core/object_groups.hh,
* core/object_links.hh: Share internal data using a tracked
pointer.
---
scribo/ChangeLog | 8 +++
scribo/core/object_groups.hh | 135 ++++++++++++++++++++++++++++++++----------
scribo/core/object_links.hh | 129 +++++++++++++++++++++++++++++++++++-----
3 files changed, 224 insertions(+), 48 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index ee26d66..2c2f0c2 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,11 @@
+2010-03-09 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Share internal data in groups and links structures.
+
+ * core/object_groups.hh,
+ * core/object_links.hh: Share internal data using a tracked
+ pointer.
+
2010-03-02 Guillaume Lazzara <z(a)lrde.epita.fr>
* text/merging.hh (scribo): Update code with lastest Theo's
diff --git a/scribo/core/object_groups.hh b/scribo/core/object_groups.hh
index 6f49bcf..35c5b34 100644
--- a/scribo/core/object_groups.hh
+++ b/scribo/core/object_groups.hh
@@ -30,8 +30,6 @@
/// \file
///
/// \brief Object groups representation.
-///
-/// \fixme Should not inherit from util::array.
# include <mln/util/array.hh>
@@ -44,21 +42,44 @@ namespace scribo
using namespace mln;
+ // Forward declaration.
+ template <typename L> class object_groups;
+
+
+ namespace internal
+ {
+ /// Data structure for \c scribo::object_groups<I>.
+ template <typename L>
+ struct object_groups_data
+ {
+ object_groups_data();
+ object_groups_data(const object_links<L>& links);
+ object_groups_data(const object_links<L>& links, unsigned value);
+
+ mln::util::array<unsigned> comp_to_group_;
+ component_set<L> components_;
+ object_links<L> links_;
+ };
+
+ } // end of namespace scribo::internal
+
+
+
+
/// \brief Object group representation.
//
template <typename L>
class object_groups
- // : public mln::util::array<unsigned>
{
-// typedef mln::util::array<unsigned> super_t;
+ typedef internal::object_groups_data<L> data_t;
public:
object_groups();
- object_groups(const component_set<L>& components);
- object_groups(const component_set<L>& components,
- unsigned value);
+ object_groups(const object_links<L>& links);
+ object_groups(const object_links<L>& links, unsigned value);
- const component_set<L>& component_set_() const;
+ const component_set<L>& components() const;
+ const object_links<L>& links() const;
void init_(const object_links<L>& links);
@@ -69,68 +90,102 @@ namespace scribo
unsigned& operator()(unsigned comp_id);
const unsigned& operator()(unsigned comp_id) const;
- const util::array<unsigned>& comp_to_group() const;
+ const mln::util::array<unsigned>& comp_to_group() const;
private:
- mln::util::array<unsigned> comp_to_group_;
- component_set<L> components_;
+ mln::util::tracked_ptr<data_t> data_;
};
+ template <typename L>
+ std::ostream&
+ operator<<(std::ostream& ostr, const object_groups<L>& groups);
+
+
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+
+ /// Data structure for \c scribo::object_groups<I>.
+ template <typename L>
+ object_groups_data<L>::object_groups_data()
+ {
+ }
+
+
+ template <typename L>
+ object_groups_data<L>::object_groups_data(const object_links<L>&
links)
+ : comp_to_group_(unsigned(links.nelements()) + 1),
+ components_(links.components()), links_(links)
+ {
+ };
+
+
+ template <typename L>
+ object_groups_data<L>::object_groups_data(const object_links<L>&
links,
+ unsigned value)
+ : comp_to_group_(unsigned(links.nelements() + 1), value),
+ components_(links.components()), links_(links)
+ {
+ };
+
+
+ } // end of namespace scribo::internal
+
+
template <typename L>
object_groups<L>::object_groups()
{
}
template <typename L>
- object_groups<L>::object_groups(const component_set<L>& components)
- // : super_t(static_cast<unsigned>(components.nelements()) + 1),
- : comp_to_group_(static_cast<unsigned>(components.nelements()) + 1),
- components_(components)
+ object_groups<L>::object_groups(const object_links<L>& links)
{
-
+ data_ = new data_t(links);
}
template <typename L>
- object_groups<L>::object_groups(const component_set<L>& components,
- unsigned value)
- // : super_t(static_cast<unsigned>(components.nelements()) + 1, value),
- : comp_to_group_(static_cast<unsigned>(components.nelements()) + 1),
- components_(components)
+ object_groups<L>::object_groups(const object_links<L>& links, unsigned
value)
{
-
+ data_ = new data_t(links, value);
}
template <typename L>
const component_set<L>&
- object_groups<L>::component_set_() const
+ object_groups<L>::components() const
{
- return components_;
+ return data_->components_;
}
+ template <typename L>
+ const object_links<L>&
+ object_groups<L>::links() const
+ {
+ return data_->links_;
+ }
template <typename L>
void
object_groups<L>::init_(const object_links<L>& links)
{
- components_ = links.component_set_();
- comp_to_group_.hook_std_vector_() = links.std_vector();
+ data_->comp_to_group_ = links.comp_to_link();
}
template <typename L>
bool
object_groups<L>::is_valid() const
{
- return components_.is_valid() && components_.nelements() == (this->size()
- 1);
+ mln_assertion(data_->components_.nelements() == (nelements() - 1));
+ return data_->links_.is_valid();
}
template <typename L>
unsigned
object_groups<L>::nelements() const
{
- return comp_to_group_.nelements();
+ return data_->comp_to_group_.nelements();
}
@@ -138,7 +193,7 @@ namespace scribo
unsigned&
object_groups<L>::operator()(unsigned comp_id)
{
- return comp_to_group_(comp_id);
+ return data_->comp_to_group_(comp_id);
}
@@ -146,16 +201,32 @@ namespace scribo
const unsigned&
object_groups<L>::operator()(unsigned comp_id) const
{
- return comp_to_group_(comp_id);
+ return data_->comp_to_group_(comp_id);
}
template <typename L>
- const util::array<unsigned>&
+ const mln::util::array<unsigned>&
object_groups<L>::comp_to_group() const
{
- return comp_to_group_;
+ return data_->comp_to_group_;
}
+
+ template <typename L>
+ std::ostream&
+ operator<<(std::ostream& ostr, const object_groups<L>& groups)
+ {
+ ostr << "object_groups[";
+
+ for_all_groups(g, groups)
+ ostr << g << "->" << groups.comp_to_group()[g]
<< ", ";
+
+ ostr << "]";
+
+ return ostr;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/core/object_links.hh b/scribo/core/object_links.hh
index af6a3da..654cb75 100644
--- a/scribo/core/object_links.hh
+++ b/scribo/core/object_links.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -29,10 +30,10 @@
/// \file
///
/// \brief Object links representation.
-///
-/// \fixme Should not inherit from util::array.
+
# include <mln/util/array.hh>
+# include <mln/util/tracked_ptr.hh>
# include <scribo/core/component_set.hh>
@@ -42,58 +43,121 @@ namespace scribo
using namespace mln;
+ // Forward declaration.
+ template <typename L> class object_links;
+
+
+ namespace internal
+ {
+ /// Data structure for \c scribo::object_links<I>.
+ template <typename L>
+ struct object_links_data
+ {
+ object_links_data();
+ object_links_data(const component_set<L>& components, unsigned size);
+ object_links_data(const component_set<L>& components,
+ unsigned size, unsigned value);
+
+ mln::util::array<unsigned> comp_to_link_;
+ component_set<L> components_;
+ };
+
+ } // end of namespace scribo::internal
+
+
+
+
/// \brief Object group representation.
//
template <typename L>
class object_links
- : public mln::util::array<unsigned>
{
- typedef mln::util::array<unsigned> super_t;
+ typedef internal::object_links_data<L> data_t;
public:
object_links();
object_links(const component_set<L>& components);
object_links(const component_set<L>& components, unsigned value);
- const component_set<L>& component_set_() const;
+ const component_set<L>& components() const;
bool is_valid() const;
+ unsigned nelements() const;
+
+ unsigned& operator()(unsigned comp_id);
+ const unsigned& operator()(unsigned comp_id) const;
+
+ const mln::util::array<unsigned>& comp_to_link() const;
+
+
private:
- component_set<L> components_;
+ mln::util::tracked_ptr<data_t> data_;
};
# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+
+ /// Data structure for \c scribo::object_links<I>.
+ template <typename L>
+ object_links_data<L>::object_links_data()
+ {
+ }
+
+
+ template <typename L>
+ object_links_data<L>::object_links_data(const component_set<L>&
components,
+ unsigned size)
+ : comp_to_link_(size), components_(components)
+ {
+ };
+
+
+ template <typename L>
+ object_links_data<L>::object_links_data(const component_set<L>&
components,
+ unsigned size, unsigned value)
+ : comp_to_link_(size, value), components_(components)
+ {
+ };
+
+
+ } // end of namespace scribo::internal
+
+
+
template <typename L>
object_links<L>::object_links()
{
+ data_ = new data_t();
}
+
template <typename L>
object_links<L>::object_links(const component_set<L>& components)
- : super_t(static_cast<unsigned>(components.nelements()) + 1),
- components_(components)
{
-
+ data_ = new data_t(components, unsigned(components.nelements()) + 1);
}
+
template <typename L>
object_links<L>::object_links(const component_set<L>& components,
unsigned value)
- : super_t(static_cast<unsigned>(components.nelements()) + 1, value),
- components_(components)
{
-
+ data_ = new data_t(components, unsigned(components.nelements()) + 1,
+ value);
}
template <typename L>
const component_set<L>&
- object_links<L>::component_set_() const
+ object_links<L>::components() const
{
- return components_;
+ return data_->components_;
}
@@ -101,7 +165,40 @@ namespace scribo
bool
object_links<L>::is_valid() const
{
- return components_.is_valid() && components_.nelements() == (this->size()
- 1);
+ return data_->components_.is_valid()
+ && data_->components_.nelements() == (this->nelements() - 1);
+ }
+
+
+ template <typename L>
+ unsigned
+ object_links<L>::nelements() const
+ {
+ return data_->comp_to_link_.nelements() ;
+ }
+
+
+ template <typename L>
+ unsigned&
+ object_links<L>::operator()(unsigned comp_id)
+ {
+ return data_->comp_to_link_(comp_id);
+ }
+
+
+ template <typename L>
+ const unsigned&
+ object_links<L>::operator()(unsigned comp_id) const
+ {
+ return data_->comp_to_link_(comp_id);
+ }
+
+
+ template <typename L>
+ const mln::util::array<unsigned>&
+ object_links<L>::comp_to_link() const
+ {
+ return data_->comp_to_link_;
}
--
1.5.6.5