-/*
- dimension-cache.cc -- implement Dimension_cache
-
- source file of the GNU LilyPond music typesetter
-
- (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
- */
-
-#include "dimension-cache.hh"
-#include "parray.hh"
-
-Dimension_cache::Dimension_cache (Dimension_cache const &d)
-{
- init();
- callback_l_ = d.callback_l_;
- empty_b_ = d.empty_b_;
- offset_ = d.offset_; //let's hope others will copy the refpoint appropriately.
-}
-
-Dimension_cache::Dimension_cache ()
-{
- init();
-}
-
-void
-Dimension_cache::init()
-{
- callback_l_ =0;
- offset_ =0.0;
- elt_l_ = 0;
- dim_.set_empty ();
- parent_l_ =0;
- valid_b_ = false;
- empty_b_ = false;
-}
+/*
+ dimension-cache.cc -- implement Dimension_cache
+ source file of the GNU LilyPond music typesetter
-void
-Dimension_cache::invalidate ()
-{
- valid_b_ = false;
- invalidate_dependencies ();
-}
+ (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
+*/
-void
-Dimension_cache::invalidate_dependencies ()
-{
- for (int i=0; i < dependencies_l_arr_.size (); i++)
- {
- Dimension_cache * g = dependencies_l_arr_[i];
- if (g->valid_b_)
- {
- g->invalidate ();
- }
- }
-}
-
-void
-Dimension_cache::set_offset (Real x)
-{
- invalidate_dependencies ();
- offset_ = x;
-}
-
-void
-Dimension_cache::translate (Real x)
-{
- invalidate_dependencies ();
- offset_ += x;
-}
+#include "dimension-cache.hh"
-Real
-Dimension_cache::absolute_coordinate () const
-{
- Real r = offset_;
- for (Dimension_cache * c = parent_l_;
- c; c = c->parent_l_)
- r += c->offset_;
- return r;
-}
+#include "warn.hh"
+#include "grob.hh"
-/*
- what *should* these functions *do* anyway.
- */
-Real
-Dimension_cache::relative_coordinate (Dimension_cache *d) const
+Dimension_cache::Dimension_cache (Dimension_cache const &d)
{
- Real r =0.0;
- if (d == this) // UGH
- return 0.0;
-
- for (Dimension_cache* c = parent_l_;
- c != d;
- c = c->parent_l_)
- r += c->offset_;
- return r;
+ init ();
+ offset_ = d.offset_ ? new Real (*d.offset_) : 0;
+ parent_ = d.parent_;
+ extent_ = d.extent_ ? new Interval (*d.extent_) : 0;
}
-Dimension_cache *
-Dimension_cache::common_group (Dimension_cache const* s) const
+Dimension_cache::Dimension_cache ()
{
- Link_array<Dimension_cache const> my_groups;
- for (Dimension_cache const *c = this;
- c ; c = c->parent_l_)
- my_groups.push (c);
-
-
- Dimension_cache const *common=0;
-
- for (Dimension_cache const * d = s;
- !common && d;
- d = d->parent_l_)
- common = my_groups.find_l (d);
-
- return (Dimension_cache*)common;
+ init ();
}
-
-
-void
-Dimension_cache::set_empty (bool b)
-{
- if (empty_b_ != b)
- {
- empty_b_ = b;
- if (!empty_b_)
- invalidate ();
- }
-}
-
void
-Dimension_cache::set_dim (Interval v)
+Dimension_cache::init ()
{
- dim_ = v;
- valid_b_ = true;
+ offset_ = 0;
+ extent_ = 0;
+ parent_ = 0;
}
-
-Interval
-Dimension_cache::get_dim () const
+Dimension_cache::~Dimension_cache ()
{
- Interval r;
- if (empty_b_)
- {
- r.set_empty ();
- return r;
- }
-
- if (!valid_b_)
- {
- Dimension_cache *nc = ((Dimension_cache*)this);
- nc->dim_= (*callback_l_ ) (nc);
- nc->valid_b_ = true;
- }
-
- r=dim_;
- if (!r.empty_b()) // float exception on DEC Alpha
- r += offset_;
-
- return r;
+ clear ();
}
void
-Dimension_cache::set_callback (Dim_cache_callback c)
-{
- callback_l_ =c;
-}
-
-Real
-Dimension_cache::offset () const
+Dimension_cache::clear ()
{
- return offset_;
+ delete extent_;
+ delete offset_;
+ extent_ = 0;
+ offset_ = 0;
}