5 This file is part of LilyPond, the GNU music typesetter.
7 Copyright (C) 2015 David Kastrup <dak@gnu.org>
9 LilyPond is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 LilyPond is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "lily-guile.hh"
25 // Fluid is a wrapper class for cached storage of GUILE fluids.
28 // Fluid parser (Lily::f_parser);
30 // and when you first access `parser' as an SCM value, its value is
31 // fetched from the respective fluid (in this case `%parser', cf
32 // lily/lily-imports.cc) and cached for future accesses.
34 // Since fluids act as implicit function parameters, it can only be
35 // meaningfully employed for variables of automatic
36 // (function/block-local) duration.
38 // Once you create a fluid cache, it should be passed around by
39 // reference in order to keep the performance impact low.
43 SCM const fluid_; // the fluid itself
44 SCM value_; // its cached value, SCM_UNDEFINED if unset
46 Fluid (); // No accessible default constructor
47 Fluid (const Fluid &); // Don't copy
48 // Caching fluids only makes sense if we really treat them as
49 // function parameters, namely only modify them synchronized to
50 // function calls, like when using scm_with_fluid. So no assignment
51 // operator or any other interface to scm_fluid_set_x.
52 Fluid & operator= (const Fluid &);
54 Fluid (SCM fluid) : fluid_ (fluid), value_ (SCM_UNDEFINED)
59 if (SCM_UNBNDP (value_))
60 value_ = scm_fluid_ref (fluid_);