1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008, 2010, 2013 Henrik Tidefelt
21 #include "Shapes_Ast_decls.h"
22 #include "Shapes_Kernel_decls.h"
23 #include "Shapes_Lang_decls.h"
24 #include "FontMetrics_decls.h"
25 #include "SimplePDF_decls.h"
27 #include "shapesvalue.h"
28 #include "functiontypes.h"
29 #include "drawabletypes.h"
30 #include "lighttypes.h"
31 #include "fonttypes.h"
32 #include "charptrless.h"
39 #define TYPEINFOIMPL_STATE( T ) \
40 const RefCountPtr< const ::Shapes::Lang::Class > & \
41 Kernel::T::getClass( ) const \
45 RefCountPtr< const char > \
46 Kernel::T::staticTypeName( ) \
48 return TypeID->getPrettyName( ); \
57 class HotTriple
: public Lang::Hot
59 RefCountPtr
< const Lang::Value
> init_
;
60 RefCountPtr
< const Lang::Function
> update_
;
61 RefCountPtr
< const Lang::Function
> result_
;
63 HotTriple( const RefCountPtr
< const Lang::Value
> & init
, RefCountPtr
< const Lang::Function
> update
, RefCountPtr
< const Lang::Function
> result
);
64 virtual ~HotTriple( );
65 virtual Kernel::State
* newState( ) const;
66 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
69 /* This template can be used to create hot types such as 2D and 3D, where the warm value can be created using a default constructor
72 class HotDefault
: public Lang::Hot
76 virtual ~HotDefault( ) { }
77 virtual Kernel::State
* newState( ) const { return new S
; }
78 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ }
81 class HotRandomSeed
: public Lang::Hot
86 HotRandomSeed( size_t sz
, Kernel::WarmRandomDevice
* dev
);
87 HotRandomSeed( size_t sz
, unsigned long seed
);
88 virtual ~HotRandomSeed( );
89 virtual Kernel::State
* newState( ) const;
90 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
98 class WarmTriple
: public Kernel::State
100 RefCountPtr
< const Lang::Value
> pile_
;
101 RefCountPtr
< const Lang::Function
> update_
;
102 RefCountPtr
< const Lang::Function
> result_
;
104 WarmTriple( const RefCountPtr
< const Lang::Value
> & pile
, RefCountPtr
< const Lang::Function
> update
, RefCountPtr
< const Lang::Function
> result
);
105 virtual ~WarmTriple( );
106 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
107 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
108 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
109 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
113 class WarmIgnore
: public Kernel::State
117 virtual ~WarmIgnore( );
118 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
119 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
120 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
121 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
125 class WarmOstream
: public Kernel::State
129 WarmOstream( std::ostream
& os
);
130 virtual ~WarmOstream( );
131 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
132 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
133 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
134 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
138 class Warm_ostringstream
: public Kernel::State
140 std::ostringstream os_
;
142 Warm_ostringstream( );
143 virtual ~Warm_ostringstream( );
144 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
145 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
146 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
147 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
151 class WarmGroup2D
: public Kernel::State
153 RefCountPtr
< const Lang::Group2D
> pile_
;
156 virtual ~WarmGroup2D( );
157 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
158 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
159 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
160 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
161 RefCountPtr
< const Lang::Group2D
> getPile( ){ return pile_
; } /* For special use with arrowheads and instances of user classes */
163 void remove( Lang::Symbol::KeyType key
);
167 class WarmGroup3D
: public Kernel::State
169 RefCountPtr
< const Lang::Group3D
> pile_
;
172 virtual ~WarmGroup3D( );
173 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
174 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
175 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
176 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
177 RefCountPtr
< const Lang::Group3D
> getPile( ){ return pile_
; } /* For special use with arrowheads and instances of user classes */
179 void remove( Lang::Symbol::KeyType key
);
183 class WarmGroupLights
: public Kernel::State
185 RefCountPtr
< const Lang::LightGroup
> pile_
;
188 virtual ~WarmGroupLights( );
189 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
190 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
191 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
192 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
193 RefCountPtr
< const Lang::LightGroup
> getPile( ){ return pile_
; } /* For special use with arrowheads and instances of user classes */
197 class WarmZBuf
: public Kernel::State
199 RefCountPtr
< std::list
< RefCountPtr
< Computation::PaintedPolygon3D
> > > pile_
;
200 RefCountPtr
< std::list
< RefCountPtr
< Computation::StrokedLine3D
> > > strokePile_
;
201 RefCountPtr
< std::list
< RefCountPtr
< const Lang::LightSource
> > > lightPile_
;
204 virtual ~WarmZBuf( );
205 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
206 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
207 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
208 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
212 class WarmZSorter
: public Kernel::State
214 RefCountPtr
< std::list
< RefCountPtr
< Computation::PaintedPolygon3D
> > > pile_
;
215 RefCountPtr
< std::list
< RefCountPtr
< Computation::StrokedLine3D
> > > strokePile_
;
216 RefCountPtr
< std::list
< RefCountPtr
< const Lang::LightSource
> > > lightPile_
;
219 virtual ~WarmZSorter( );
220 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
221 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
222 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
223 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
227 class WarmTimer
: public Kernel::State
232 virtual ~WarmTimer( );
233 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
234 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
235 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
236 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
240 class WarmText
: public Kernel::State
242 RefCountPtr
< std::list
< RefCountPtr
< const Lang::TextOperation
> > > pile_
;
245 virtual ~WarmText( );
246 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
247 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
248 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
249 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
253 class WarmType3Font
: public Kernel::State
255 std::list
< RefCountPtr
< const Lang::KernedText
> > kernings_
;
256 std::list
< RefCountPtr
< const Lang::Type3Glyph
> > glyphs_
;
257 RefCountPtr
< FontMetrics::AFM
> metrics_
;
258 FontMetrics::SingleByte_WritingDirectionMetrics
* horizontalMetrics_typed_
;
259 Concrete::Length size_
;
262 virtual ~WarmType3Font( );
263 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
264 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
265 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
266 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
270 static void initializeLegalStrechValues( std::set
< const char *, charPtrLess
> * legalStretchValues
);
273 class WarmTime
: public Kernel::State
277 virtual ~WarmTime( );
278 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
279 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
280 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
281 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
285 class WarmRandomDevice
: public Kernel::State
287 const char * deviceName_
;
291 WarmRandomDevice( const char * deviceName
);
292 virtual ~WarmRandomDevice( );
293 void read( char * dst
, size_t sz
);
294 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
295 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
296 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
297 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
301 class WarmRandomState
: public Kernel::State
305 WarmRandomState( char * state
);
307 virtual ~WarmRandomState( );
308 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
309 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
310 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
311 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
315 class WarmColorInterpolator
: public Kernel::State
318 typedef Lang::ColorInterpolator::KeyContainer KeyContainer
;
319 typedef Lang::ColorInterpolator::RGBContainer RGBContainer
;
320 typedef Lang::ColorInterpolator::GrayContainer GrayContainer
;
321 typedef Lang::ColorInterpolator::CMYKContainer CMYKContainer
;
322 typedef Lang::ColorInterpolator::ColorType ColorType
;
325 RefCountPtr
< KeyContainer
> key_
;
326 RefCountPtr
< RGBContainer
> RGBcolor_
;
327 RefCountPtr
< GrayContainer
> graycolor_
;
328 RefCountPtr
< CMYKContainer
> CMYKcolor_
;
331 ColorType colorType_
;
334 WarmColorInterpolator( );
335 virtual ~WarmColorInterpolator( );
336 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
337 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
338 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
339 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
343 class Warm_vector
: public Kernel::State
346 /* The data is exposed so that mutator functions get access without messing with friend classes. */
347 std::vector
< Kernel::ValueRef
> * mem_
;
350 virtual ~Warm_vector( );
351 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
352 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
353 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
354 virtual void gcMark( Kernel::GCMarkedSet
& marked
);