This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Creating environments/frames ?



Hi all,

I am trying to integrate GUILE into LilyPond, and I have questions.
Please forgive, I am a newbie: I have never really used Scheme.

I want to integrate scheme frames into C++ classes, in the following
manner: there are classes Paper and Graphical_object (with concrete
derivations Beam and Stem), that currently basically look like

	class Paper {
		List<Graphical_object* > objects_;

		remove_object (Graphical_object *);
	};

	class Graphical_object {
		Paper *paper_;

		substitute_object_ptr (Graphical_object *old, Graphical_object*new);
	};

	class Beam : public Graphical_object { 
		Array<Stem *> stems_;
		int direction_

		void set_direction  () {
			[stuff]
			direction_ = stems_[j]->direction_
		}
	}

	class Stem : public Graphical_object { 
		int direction_;

	}

Each graphical object is contained in Paper, and has a pointer that
points back to the Paper object.  Objects can be removed from the
system generically: one can  call 

	Paper::remove_object (stem_pointer),

and that would cause stem_pointer to be removed from Paper::objects_,
but also any references to stem_pointer from Beam::stems_ will
disappear automagically, for instance by calling

	Graphical_object::substitute_object_ptr (stem_pointer, NULL);

for all Graphical_objects


* Now I want to make each Graphical_object into a namespace (a frame,
is that the right word?), such that the parent namespace of any
Graphical_object is the Paper object.  Of course Paper will also
contain a namespace, so I would get


	class Paper {
		List<Graphical_object* > objects_;
		SCM global_env_;
	};


	class Graphical_object {
		Paper *paper_;
		SCM local_env_;
	};

The general idea is to move data members of Stem and Beam to variables
in the namespaces local_env_.



PROBLEM: how would I initialise global_env_ and local_env_?

* I want to remove any pointers of Graphical_object that point to
fellow Graphical_objects, and encapsulate them in SCMs, in other
words, I want to replace code that looks like this

	class Beam : Graphical_object { 
		Array<Stem *> stems_;
		int direction_

		void set_direction  () {
			[stuff]
			direction_ = stems_[j]->direction_
		}
	}

	class Stem : Graphical_object { 
		int direction_;

	}


With code that somehow looks like this

		(define (beam-set-direction)
			(set! direction_
				(access-member (list-ref j stems_) 'direction_))

		)


The key point is that I want the access by Beam to members of Stem to
be routed through the C++ code, so that I can remove (in this example)
a Stem object in a generic way easily, by a C++ call in
Paper::remove_object()


PROBLEM 

How do I do this?   




* Finally, I want to make changes to the existing source
incrementally, gradually moving from C++

	pointer->member_

to

	(access-member object-ptr 'member)


and not by completely redesigning the class Hierarchy.  Might this
preclude making Graphical_objects into smobs?



-- 



Han-Wen Nienhuys, hanwen@cs.uu.nl ** GNU LilyPond - The Music Typesetter 
      http://www.cs.uu.nl/people/hanwen/lilypond/index.html