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 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 Hot
: public Lang::NoOperatorOverloadValue
62 virtual Kernel::State
* newState( ) const = 0;
67 class HotTriple
: public Lang::Hot
69 RefCountPtr
< const Lang::Value
> init_
;
70 RefCountPtr
< const Lang::Function
> update_
;
71 RefCountPtr
< const Lang::Function
> result_
;
73 HotTriple( const RefCountPtr
< const Lang::Value
> & init
, RefCountPtr
< const Lang::Function
> update
, RefCountPtr
< const Lang::Function
> result
);
74 virtual ~HotTriple( );
75 virtual Kernel::State
* newState( ) const;
76 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
79 /* 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
82 class HotDefault
: public Lang::Hot
86 virtual ~HotDefault( ) { }
87 virtual Kernel::State
* newState( ) const { return new S
; }
88 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ }
91 class HotRandomSeed
: public Lang::Hot
96 HotRandomSeed( size_t sz
, Kernel::WarmRandomDevice
* dev
);
97 HotRandomSeed( size_t sz
, unsigned long seed
);
98 virtual ~HotRandomSeed( );
99 virtual Kernel::State
* newState( ) const;
100 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
108 class WarmTriple
: public Kernel::State
110 RefCountPtr
< const Lang::Value
> pile_
;
111 RefCountPtr
< const Lang::Function
> update_
;
112 RefCountPtr
< const Lang::Function
> result_
;
114 WarmTriple( const RefCountPtr
< const Lang::Value
> & pile
, RefCountPtr
< const Lang::Function
> update
, RefCountPtr
< const Lang::Function
> result
);
115 virtual ~WarmTriple( );
116 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
117 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
118 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
119 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
123 class WarmIgnore
: public Kernel::State
127 virtual ~WarmIgnore( );
128 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
129 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
130 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
131 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
135 class WarmOstream
: public Kernel::State
139 WarmOstream( std::ostream
& os
);
140 virtual ~WarmOstream( );
141 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
142 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
143 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
144 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
148 class Warm_ostringstream
: public Kernel::State
150 std::ostringstream os_
;
152 Warm_ostringstream( );
153 virtual ~Warm_ostringstream( );
154 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
155 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
156 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
157 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
161 class WarmGroup2D
: public Kernel::State
163 RefCountPtr
< const Lang::Group2D
> pile_
;
166 virtual ~WarmGroup2D( );
167 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
168 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
169 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
170 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
171 RefCountPtr
< const Lang::Group2D
> getPile( ){ return pile_
; } /* For special use with arrowheads and instances of user classes */
173 void remove( Lang::Symbol::KeyType key
);
177 class WarmGroup3D
: public Kernel::State
179 RefCountPtr
< const Lang::Group3D
> pile_
;
182 virtual ~WarmGroup3D( );
183 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
184 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
185 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
186 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
187 RefCountPtr
< const Lang::Group3D
> getPile( ){ return pile_
; } /* For special use with arrowheads and instances of user classes */
189 void remove( Lang::Symbol::KeyType key
);
193 class WarmGroupLights
: public Kernel::State
195 RefCountPtr
< const Lang::LightGroup
> pile_
;
198 virtual ~WarmGroupLights( );
199 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
200 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
201 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
202 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
203 RefCountPtr
< const Lang::LightGroup
> getPile( ){ return pile_
; } /* For special use with arrowheads and instances of user classes */
207 class WarmZBuf
: public Kernel::State
209 RefCountPtr
< std::list
< RefCountPtr
< Computation::PaintedPolygon3D
> > > pile_
;
210 RefCountPtr
< std::list
< RefCountPtr
< Computation::StrokedLine3D
> > > strokePile_
;
211 RefCountPtr
< std::list
< RefCountPtr
< const Lang::LightSource
> > > lightPile_
;
214 virtual ~WarmZBuf( );
215 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
216 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
217 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
218 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
222 class WarmZSorter
: public Kernel::State
224 RefCountPtr
< std::list
< RefCountPtr
< Computation::PaintedPolygon3D
> > > pile_
;
225 RefCountPtr
< std::list
< RefCountPtr
< Computation::StrokedLine3D
> > > strokePile_
;
226 RefCountPtr
< std::list
< RefCountPtr
< const Lang::LightSource
> > > lightPile_
;
229 virtual ~WarmZSorter( );
230 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
231 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
232 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
233 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
237 class WarmTimer
: public Kernel::State
242 virtual ~WarmTimer( );
243 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
244 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
245 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
246 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
250 class WarmText
: public Kernel::State
252 RefCountPtr
< std::list
< RefCountPtr
< const Lang::TextOperation
> > > pile_
;
255 virtual ~WarmText( );
256 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
257 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
258 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
259 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
263 class WarmType3Font
: public Kernel::State
265 std::list
< RefCountPtr
< const Lang::KernedText
> > kernings_
;
266 std::list
< RefCountPtr
< const Lang::Type3Glyph
> > glyphs_
;
267 RefCountPtr
< FontMetrics::AFM
> metrics_
;
268 FontMetrics::SingleByte_WritingDirectionMetrics
* horizontalMetrics_typed_
;
269 Concrete::Length size_
;
272 virtual ~WarmType3Font( );
273 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
274 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
275 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
276 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
280 static void initializeLegalStrechValues( std::set
< const char *, charPtrLess
> * legalStretchValues
);
283 class WarmTime
: public Kernel::State
287 virtual ~WarmTime( );
288 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
289 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
290 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
291 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
295 class WarmRandomDevice
: public Kernel::State
297 const char * deviceName_
;
301 WarmRandomDevice( const char * deviceName
);
302 virtual ~WarmRandomDevice( );
303 void read( char * dst
, size_t sz
);
304 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
305 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
306 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
307 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
311 class WarmRandomState
: public Kernel::State
315 WarmRandomState( char * state
);
317 virtual ~WarmRandomState( );
318 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
319 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
320 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
321 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
325 class WarmColorInterpolator
: public Kernel::State
328 typedef Lang::ColorInterpolator::KeyContainer KeyContainer
;
329 typedef Lang::ColorInterpolator::RGBContainer RGBContainer
;
330 typedef Lang::ColorInterpolator::GrayContainer GrayContainer
;
331 typedef Lang::ColorInterpolator::CMYKContainer CMYKContainer
;
332 typedef Lang::ColorInterpolator::ColorType ColorType
;
335 RefCountPtr
< KeyContainer
> key_
;
336 RefCountPtr
< RGBContainer
> RGBcolor_
;
337 RefCountPtr
< GrayContainer
> graycolor_
;
338 RefCountPtr
< CMYKContainer
> CMYKcolor_
;
341 ColorType colorType_
;
344 WarmColorInterpolator( );
345 virtual ~WarmColorInterpolator( );
346 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
347 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
348 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
349 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
353 class Warm_vector
: public Kernel::State
356 /* The data is exposed so that mutator functions get access without messing with friend classes. */
357 std::vector
< Kernel::ValueRef
> * mem_
;
360 virtual ~Warm_vector( );
361 virtual void tackOnImpl( Kernel::EvalState
* evalState
, const RefCountPtr
< const Lang::Value
> & piece
, const Ast::SourceLocation
& callLoc
);
362 virtual void peekImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
363 virtual void freezeImpl( Kernel::EvalState
* evalState
, const Ast::SourceLocation
& callLoc
);
364 virtual void gcMark( Kernel::GCMarkedSet
& marked
);