]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dimension-cache.cc
Web-ja: update introduction
[lilypond.git] / lily / dimension-cache.cc
index f7757ee82039a8224bf093ec0dbfb7d4f786497a..33294db5e62cd37c9a3253554b083f94f6b023de 100644 (file)
-/*   
-  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"
-#include "score-element.hh"
+/*
+  This file is part of LilyPond, the GNU music typesetter.
 
+  Copyright (C) 1998--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
-Dimension_cache::Dimension_cache (Dimension_cache const &d)
-{
-  init();
-  callback_l_ = d.callback_l_;
-  basic_offset_ = d.basic_offset_;
-  extra_offset_ = d.extra_offset_;
-  off_valid_b_ = d.off_valid_b_;
-  off_callbacks_ = d.off_callbacks_;
-  parent_l_ = d.parent_l_;  
-}
-
-Dimension_cache::Dimension_cache ()
-{
-  init();
-}
-
-void
-Dimension_cache::init()
-{
-  callback_l_ =0;
-  basic_offset_ =0.0;
-  extra_offset_ =0.0;
-  
-  elt_l_ = 0;
-  dim_.set_empty ();
-  parent_l_ =0;
-  valid_b_ = false;
-  off_valid_b_ = false;
-}
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
 
+  LilyPond 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.
 
-void
-Dimension_cache::translate (Real x)
-{
-  extra_offset_ += x;
-}
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
-Real
-Dimension_cache::relative_coordinate (Dimension_cache *refp) const
-{
-  if (refp == this)
-    return 0.0;
+#include "dimension-cache.hh"
 
-  /*
-    We catch PARENT_L_ == nil case with this, but we crash if we did
-    not ask for the absolute coordinate (ie. REFP == nil.)
-    
-   */
-  if (refp == parent_l_)
-    return get_offset ();
-  else
-    return get_offset () + parent_l_->relative_coordinate (refp);
-}
+#include "warn.hh"
+#include "grob.hh"
 
-Axis
-Dimension_cache::axis () const
+Dimension_cache::Dimension_cache (Dimension_cache const &d)
 {
-  if (elt_l_-> dim_cache_[X_AXIS] == this)
-    return X_AXIS;
-  else
-    return Y_AXIS;
+  init ();
+  offset_ = d.offset_ ? new Real (*d.offset_) : 0;
+  parent_ = d.parent_;
+  extent_ = d.extent_ ? new Interval (*d.extent_) : 0;
 }
 
-Real
-Dimension_cache::get_offset () const
+Dimension_cache &
+Dimension_cache::operator = (Dimension_cache const &d)
 {
-  Dimension_cache *me = (Dimension_cache*) this;
-  while (off_callbacks_.size ())
-    {
-      Offset_cache_callback c = me->off_callbacks_[0];
-      me->off_callbacks_.del (0);
-      me->basic_offset_ += (*c) (me);
-    }
-  return basic_offset_ + extra_offset_;
+  clear ();
+  offset_ = d.offset_ ? new Real (*d.offset_) : 0;
+  parent_ = d.parent_;
+  extent_ = d.extent_ ? new Interval (*d.extent_) : 0;
+  return *this;
 }
 
-Dimension_cache *
-Dimension_cache::common_refpoint (Dimension_cache const* s) const
+Dimension_cache::Dimension_cache ()
 {
-  Link_array<Dimension_cache> my_groups;
-  for (Dimension_cache const *c = this; c ; c = c->parent_l_)
-    my_groups.push ((Dimension_cache*)c);
-  
-  Dimension_cache const *common=0;
-  
-  for (Dimension_cache const * d = s; !common && d; d = d->parent_l_)
-    common = (Dimension_cache const*)my_groups.find_l (d);
-
-  return (Dimension_cache*) common;
+  init ();
 }
 
-Interval
-Dimension_cache::point_dimension_callback (Dimension_cache const* )
+void
+Dimension_cache::init ()
 {
-  return Interval (0,0);
+  offset_ = 0;
+  extent_ = 0;
+  parent_ = 0;
 }
 
-Interval
-Dimension_cache::get_dim () const
+Dimension_cache::~Dimension_cache ()
 {
-  Interval r;
-  Dimension_cache *nc = ((Dimension_cache*)this);
-  if (!callback_l_)
-    {
-      nc->dim_.set_empty ();
-    }
-  else if (!valid_b_)
-    {
-      nc->dim_= (*callback_l_ ) (nc);
-      nc->valid_b_ = true;
-    }
-
-  r=dim_;
-  return r;
+  clear ();
 }
 
 void
-Dimension_cache::set_callback (Dim_cache_callback c)
+Dimension_cache::clear ()
 {
-  callback_l_ =c;
+  delete extent_;
+  delete offset_;
+  extent_ = 0;
+  offset_ = 0;
 }
-
-