Update procedures
[shapes.git] / source / hottypes.h
blobb54e5a16a867cdb22de9d6aeecfea156db608519
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
6 * any later version.
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
19 #pragma once
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"
34 #include <iostream>
35 #include <fstream>
36 #include <sys/time.h>
39 #define TYPEINFOIMPL_STATE( T ) \
40 const RefCountPtr< const ::Shapes::Lang::Class > & \
41 Kernel::T::getClass( ) const \
42 { \
43 return TypeID; \
44 } \
45 RefCountPtr< const char > \
46 Kernel::T::staticTypeName( ) \
47 { \
48 return TypeID->getPrettyName( ); \
52 namespace Shapes
54 namespace Lang
57 class HotTriple : public Lang::Hot
59 RefCountPtr< const Lang::Value > init_;
60 RefCountPtr< const Lang::Function > update_;
61 RefCountPtr< const Lang::Function > result_;
62 public:
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
71 template< class S >
72 class HotDefault : public Lang::Hot
74 public:
75 HotDefault( ) { }
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
83 size_t sz_;
84 char * state_;
85 public:
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 );
95 namespace Kernel
98 class WarmTriple : public Kernel::State
100 RefCountPtr< const Lang::Value > pile_;
101 RefCountPtr< const Lang::Function > update_;
102 RefCountPtr< const Lang::Function > result_;
103 public:
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 );
110 TYPEINFODECL;
113 class WarmIgnore : public Kernel::State
115 public:
116 WarmIgnore( );
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 );
122 TYPEINFODECL;
125 class WarmOstream : public Kernel::State
127 std::ostream & os_;
128 public:
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 );
135 TYPEINFODECL;
138 class Warm_ostringstream : public Kernel::State
140 std::ostringstream os_;
141 public:
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 );
148 TYPEINFODECL;
151 class WarmGroup2D : public Kernel::State
153 RefCountPtr< const Lang::Group2D > pile_;
154 public:
155 WarmGroup2D( );
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 */
162 void erase( );
163 void remove( Lang::Symbol::KeyType key );
164 TYPEINFODECL;
167 class WarmGroup3D : public Kernel::State
169 RefCountPtr< const Lang::Group3D > pile_;
170 public:
171 WarmGroup3D( );
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 */
178 void erase( );
179 void remove( Lang::Symbol::KeyType key );
180 TYPEINFODECL;
183 class WarmGroupLights : public Kernel::State
185 RefCountPtr< const Lang::LightGroup > pile_;
186 public:
187 WarmGroupLights( );
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 */
194 TYPEINFODECL;
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_;
202 public:
203 WarmZBuf( );
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 );
209 TYPEINFODECL;
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_;
217 public:
218 WarmZSorter( );
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 );
224 TYPEINFODECL;
227 class WarmTimer : public Kernel::State
229 timeval start_;
230 public:
231 WarmTimer( );
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 );
237 TYPEINFODECL;
240 class WarmText : public Kernel::State
242 RefCountPtr< std::list< RefCountPtr< const Lang::TextOperation > > > pile_;
243 public:
244 WarmText( );
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 );
250 TYPEINFODECL;
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_;
260 public:
261 WarmType3Font( );
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 );
267 TYPEINFODECL;
269 private:
270 static void initializeLegalStrechValues( std::set< const char *, charPtrLess > * legalStretchValues );
273 class WarmTime : public Kernel::State
275 public:
276 WarmTime( );
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 );
282 TYPEINFODECL;
285 class WarmRandomDevice : public Kernel::State
287 const char * deviceName_;
288 std::ifstream idev_;
289 std::ofstream odev_;
290 public:
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 );
298 TYPEINFODECL;
301 class WarmRandomState : public Kernel::State
303 char * state_;
304 public:
305 WarmRandomState( char * state );
306 void setState( );
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 );
312 TYPEINFODECL;
315 class WarmColorInterpolator : public Kernel::State
317 public:
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;
324 private:
325 RefCountPtr< KeyContainer > key_;
326 RefCountPtr< RGBContainer > RGBcolor_;
327 RefCountPtr< GrayContainer > graycolor_;
328 RefCountPtr< CMYKContainer > CMYKcolor_;
329 bool hasKey_;
331 ColorType colorType_;
333 public:
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 );
340 TYPEINFODECL;
343 class Warm_vector : public Kernel::State
345 public:
346 /* The data is exposed so that mutator functions get access without messing with friend classes. */
347 std::vector< Kernel::ValueRef > * mem_;
349 Warm_vector( );
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 );
355 TYPEINFODECL;