]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/atom.cc
release: 1.1.28
[lilypond.git] / lily / atom.cc
index 0d71f4e240ae769ea5289d11bbdd5c066a61558a..119f2315ff1490cd61150c68d965d3960a9d4791 100644 (file)
 #include "dimensions.hh"
 #include "lookup.hh"
 #include "main.hh"
+#include "global-ctor.hh"
 
-inline bool
-Atom::check_infinity_b ()const
+Atom::Atom(SCM s)
 {
-  bool ridiculous = false;
-  
-#ifndef NDEBUG
-  /* infinity checks. */
-  for (int a = X_AXIS; a < NO_AXES; a++)
-    {
-      Axis ax = (Axis)a;
-      if (abs (off_[ax]) >= 100 CM)
-       {
-         warning (_f ("ridiculous dimension: %s, %s", axis_name_str (ax),
-                  print_dimen (off_[ax])));
-         
-         if (experimental_features_global_b)
-           assert (false);
-
-         ( (Atom*)this)->off_[ax] = 0.0;
-         ridiculous = true;
-       }
-    }
-#endif
-  return ridiculous;
+  func_ = s;
 }
 
 
-void
-Atom::print () const
+#if 0
+int
+Atom::smob_display (SCM smob, SCM port, scm_print_state*)
 {
-#ifndef NPRINT
-  DOUT << "string: " << str_ << '\n';
-
-  DOUT << "dim:";
-  for (Axis i=X_AXIS; i < NO_AXES; incr (i))
-    DOUT << axis_name_str (i) << " = " << dim_[i].str ();
+  Atom* a =(Atom*) SCM_CDR(smob);
+  String i (a->off_.str ());
+  
+  scm_puts ("#<Atom ", port);
+  scm_puts (i.ch_C(), port);
+  gh_display (a->func_);
+  scm_puts (">", port);
 
-  DOUT << "\noffset: " << off_.str ();
-#endif
+  /* non-zero means success */
+  return 1;
 }
 
-Box
-Atom::extent () const
+
+scm_sizet
+Atom::smob_free (SCM smob)
 {
-  Box b (dim_);
-  b.translate (off_);
-  return b;
+  Atom * a= (Atom*) SCM_CDR(smob);
+  delete a;
+  return sizeof (Atom);
 }
 
-Interval
-Atom::extent (Axis a) const
+SCM
+Atom::smob_mark (SCM smob) 
 {
-  return dim_[a] + off_[a];
+  Atom * a= (Atom*) SCM_CDR(smob);
+  scm_gc_mark (a->func_);
+  return a->font_;
 }
 
+long Atom::smob_tag_;
 
-
-Atom::Atom ()
-  : dim_ (Interval (0,0),Interval (0,0))
+void
+Atom::init_smob ()
 {
-  str_ = "unknown\n";
-  origin_l_ = 0;
-}
+  static scm_smobfuns type_rec;
 
-Atom::Atom (String s, Box b)
-  :  dim_ (b)
-{
-  str_ = s;
-  origin_l_ = 0;  
+  type_rec.mark = smob_mark;
+  type_rec.free = smob_free;
+  type_rec.print = smob_display;
+  type_rec.equalp = 0;
+
+  smob_tag_ = scm_newsmob (&type_rec);
 }
 
 
-String
-Atom::str () const
+SCM
+Atom::make_smob () const
 {
-  return String ("Atom (\'") + str_ + "\', (" + dim_.x ().str () + ", "
-    + dim_.y ().str () + "))";
+  SCM smob;
+  SCM_NEWCELL (smob);
+  SCM_SETCAR (smob, smob_tag_);
+  SCM_SETCDR (smob, this);
+  return smob;
 }
 
-Offset
-Atom::offset () const
+SCM
+Atom::make_atom (SCM outputfunc)
 {
-  check_infinity_b ();
-  return off_;
+  Atom * a= new Atom(outputfunc);
+  return a->make_smob ();
 }
 
-void
-Atom::translate_axis (Real r, Axis a)
+SCM
+Atom::copy_self () const
 {
-  off_[a] += r;
-  check_infinity_b ();
+  return (new Atom (*this))->make_smob ();
 }
 
-void
-Atom::translate (Offset o)
+bool
+Atom::Atom_b (SCM obj)
 {
-  off_ += o;
-  check_infinity_b ();
+  return(SCM_NIMP(obj) && SCM_CAR(obj) == smob_tag_);
 }
 
-bool
-Atom::empty() const
+Atom* 
+Atom::atom_l (SCM a)
 {
-  return (dim_.y().length() == 0);
+  assert (Atom_b (a));
+  return (Atom*) SCM_CDR(a);
 }
+
+
+ADD_GLOBAL_CTOR_WITHNAME(atomsmob, Atom::init_smob);
+#endif
+
+