* scribo/core/paragraph_set.hh: Make use of this new type.
* scribo/core/tag/paragraph.hh: New.
---
scribo/ChangeLog | 8 +++
scribo/scribo/core/paragraph_set.hh | 49 +++++++++++++++++---
.../core/{def/color_type.hh => tag/paragraph.hh} | 19 +++-----
3 files changed, 57 insertions(+), 19 deletions(-)
copy scribo/scribo/core/{def/color_type.hh => tag/paragraph.hh} (83%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5340656..c1e1ff8 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce paragraph_id_t type.
+
+ * scribo/core/paragraph_set.hh: Make use of this new type.
+
+ * scribo/core/tag/paragraph.hh: New.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Share document structure data.
* scribo/core/document.hh: Here.
diff --git a/scribo/scribo/core/paragraph_set.hh b/scribo/scribo/core/paragraph_set.hh
index 242501d..65e17c6 100644
--- a/scribo/scribo/core/paragraph_set.hh
+++ b/scribo/scribo/core/paragraph_set.hh
@@ -29,15 +29,19 @@
# include <mln/util/array.hh>
# include <mln/make/relabelfun.hh>
# include <mln/value/int_u16.hh>
+# include <mln/core/concept/function.hh>
# include <scribo/core/line_links.hh>
# include <scribo/core/line_set.hh>
# include <scribo/core/paragraph_info.hh>
# include <scribo/core/concept/serializable.hh>
+# include <scribo/core/tag/paragraph.hh>
namespace scribo
{
+ typedef mln::util::object_id<scribo::ParagraphId, unsigned> paragraph_id_t;
+
namespace internal
{
@@ -56,7 +60,6 @@ namespace scribo
} // end of namespace scribo::internal
-
/*! \brief Paragraph container.
Paragraph ids start from 1.
@@ -65,6 +68,8 @@ namespace scribo
template <typename L>
class paragraph_set : public Serializable<paragraph_set<L> >
{
+ typedef internal::paragraph_set_data<L> data_t;
+
public:
paragraph_set();
paragraph_set(internal::paragraph_set_data<L>* data);
@@ -72,15 +77,21 @@ namespace scribo
unsigned nelements() const;
- paragraph_info<L>& operator()(unsigned i);
- const paragraph_info<L>& operator()(unsigned i) const;
+ paragraph_info<L>& operator()(const paragraph_id_t& i);
+ const paragraph_info<L>& operator()(const paragraph_id_t& i) const;
bool is_valid() const;
+ // Massively invalidate paragraphs.
+ template <typename F>
+ void invalidate(const Function_v2b<F>& f);
+
const line_set<L>& lines() const;
const line_links<L>& links() const;
+ paragraph_set<L> duplicate() const;
+
private:
mln::util::tracked_ptr< internal::paragraph_set_data<L> > data_;
};
@@ -161,7 +172,7 @@ namespace scribo
template <typename L>
paragraph_info<L>&
- paragraph_set<L>::operator()(unsigned i)
+ paragraph_set<L>::operator()(const paragraph_id_t& i)
{
mln_precondition(data_ != 0);
return data_->pars_[i];
@@ -169,7 +180,7 @@ namespace scribo
template <typename L>
const paragraph_info<L>&
- paragraph_set<L>::operator()(unsigned i) const
+ paragraph_set<L>::operator()(const paragraph_id_t& i) const
{
mln_precondition(data_ != 0);
return data_->pars_[i];
@@ -183,6 +194,17 @@ namespace scribo
return data_ && !data_->pars_.is_empty();
}
+ template <typename L>
+ template <typename F>
+ void
+ paragraph_set<L>::invalidate(const Function_v2b<F>& f_)
+ {
+ const F& f = exact(f_);
+
+ for_all_paragraphs(p, (*this))
+ if (!f(p))
+ (*this)(p).invalidate();
+ }
template <typename L>
const line_set<L>&
@@ -203,6 +225,19 @@ namespace scribo
template <typename L>
+ inline
+ paragraph_set<L>
+ paragraph_set<L>::duplicate() const
+ {
+ paragraph_set<L> output;
+ output.data_ = new data_t();
+
+ *(output.data_.ptr_) = *(data_.ptr_);
+ return output;
+ }
+
+
+ template <typename L>
bool operator==(const paragraph_set<L>& lhs, const
paragraph_set<L>& rhs)
{
if (! (lhs.lines() == rhs.lines() && lhs.nelements() == rhs.nelements()))
@@ -248,8 +283,8 @@ namespace scribo
{
line_links<L> links = llinks.duplicate();
- for (unsigned i = 1; i < links.nelements(); ++i)
- links(i) = internal::find_root(links, i);
+ for_all_links(l, links)
+ links(l) = internal::find_root(links, l);
unsigned npars;
mln::fun::i2v::array<unsigned>
diff --git a/scribo/scribo/core/def/color_type.hh b/scribo/scribo/core/tag/paragraph.hh
similarity index 83%
copy from scribo/scribo/core/def/color_type.hh
copy to scribo/scribo/core/tag/paragraph.hh
index 7acd334..14dd579 100644
--- a/scribo/scribo/core/def/color_type.hh
+++ b/scribo/scribo/core/tag/paragraph.hh
@@ -23,26 +23,21 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_COLOR_TYPE_HH
-# define SCRIBO_CORE_COLOR_TYPE_HH
+#ifndef SCRIBO_CORE_TAG_PARAGRAPH_HH
+# define SCRIBO_CORE_TAG_PARAGRAPH_HH
/// \file
///
-/// Global type definition for labels.
-
-# include <mln/value/rgb8.hh>
-
+/// \brief Paragraph tags.
namespace scribo
{
- namespace def
- {
+ // Paragraph id tag.
+ struct ParagraphId;
- typedef mln::value::rgb8 color_type;
-
- } // end of namespace scribo::def
} // end of namespace scribo
-#endif // ! SCRIBO_CORE_DEF_HH
+
+#endif // ! SCRIBO_CORE_TAG_PARAGRAPH_HH
--
1.5.6.5