Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / hottypes.h
bloba76e4eb6a0b3a1030dea695c51209795c9e9c2da
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 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 Hot : public Lang::NoOperatorOverloadValue
59 public:
60 Hot( );
61 virtual ~Hot( );
62 virtual Kernel::State * newState( ) const = 0;
63 TYPEINFODECL;
67 class HotTriple : public Lang::Hot
69 RefCountPtr< const Lang::Value > init_;
70 RefCountPtr< const Lang::Function > update_;
71 RefCountPtr< const Lang::Function > result_;
72 public:
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
81 template< class S >
82 class HotDefault : public Lang::Hot
84 public:
85 HotDefault( ) { }
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
93 size_t sz_;
94 char * state_;
95 public:
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 );
105 namespace Kernel
108 class WarmTriple : public Kernel::State
110 RefCountPtr< const Lang::Value > pile_;
111 RefCountPtr< const Lang::Function > update_;
112 RefCountPtr< const Lang::Function > result_;
113 public:
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 );
120 TYPEINFODECL;
123 class WarmIgnore : public Kernel::State
125 public:
126 WarmIgnore( );
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 );
132 TYPEINFODECL;
135 class WarmOstream : public Kernel::State
137 std::ostream & os_;
138 public:
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 );
145 TYPEINFODECL;
148 class Warm_ostringstream : public Kernel::State
150 std::ostringstream os_;
151 public:
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 );
158 TYPEINFODECL;
161 class WarmGroup2D : public Kernel::State
163 RefCountPtr< const Lang::Group2D > pile_;
164 public:
165 WarmGroup2D( );
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 */
172 void erase( );
173 void remove( Lang::Symbol::KeyType key );
174 TYPEINFODECL;
177 class WarmGroup3D : public Kernel::State
179 RefCountPtr< const Lang::Group3D > pile_;
180 public:
181 WarmGroup3D( );
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 */
188 void erase( );
189 void remove( Lang::Symbol::KeyType key );
190 TYPEINFODECL;
193 class WarmGroupLights : public Kernel::State
195 RefCountPtr< const Lang::LightGroup > pile_;
196 public:
197 WarmGroupLights( );
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 */
204 TYPEINFODECL;
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_;
212 public:
213 WarmZBuf( );
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 );
219 TYPEINFODECL;
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_;
227 public:
228 WarmZSorter( );
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 );
234 TYPEINFODECL;
237 class WarmTimer : public Kernel::State
239 timeval start_;
240 public:
241 WarmTimer( );
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 );
247 TYPEINFODECL;
250 class WarmText : public Kernel::State
252 RefCountPtr< std::list< RefCountPtr< const Lang::TextOperation > > > pile_;
253 public:
254 WarmText( );
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 );
260 TYPEINFODECL;
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::BaseFont > metrics_;
268 Concrete::Length size_;
269 public:
270 WarmType3Font( );
271 virtual ~WarmType3Font( );
272 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
273 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
274 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
275 virtual void gcMark( Kernel::GCMarkedSet & marked );
276 TYPEINFODECL;
278 private:
279 static void initializeLegalStrechValues( std::set< const char *, charPtrLess > * legalStretchValues );
282 class WarmTime : public Kernel::State
284 public:
285 WarmTime( );
286 virtual ~WarmTime( );
287 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
288 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
289 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
290 virtual void gcMark( Kernel::GCMarkedSet & marked );
291 TYPEINFODECL;
294 class WarmRandomDevice : public Kernel::State
296 const char * deviceName_;
297 std::ifstream idev_;
298 std::ofstream odev_;
299 public:
300 WarmRandomDevice( const char * deviceName );
301 virtual ~WarmRandomDevice( );
302 void read( char * dst, size_t sz );
303 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
304 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
305 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
306 virtual void gcMark( Kernel::GCMarkedSet & marked );
307 TYPEINFODECL;
310 class WarmRandomState : public Kernel::State
312 char * state_;
313 public:
314 WarmRandomState( char * state );
315 void setState( );
316 virtual ~WarmRandomState( );
317 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
318 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
319 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
320 virtual void gcMark( Kernel::GCMarkedSet & marked );
321 TYPEINFODECL;
324 class WarmColorInterpolator : public Kernel::State
326 public:
327 typedef Lang::ColorInterpolator::KeyContainer KeyContainer;
328 typedef Lang::ColorInterpolator::RGBContainer RGBContainer;
329 typedef Lang::ColorInterpolator::GrayContainer GrayContainer;
330 typedef Lang::ColorInterpolator::CMYKContainer CMYKContainer;
331 typedef Lang::ColorInterpolator::ColorType ColorType;
333 private:
334 RefCountPtr< KeyContainer > key_;
335 RefCountPtr< RGBContainer > RGBcolor_;
336 RefCountPtr< GrayContainer > graycolor_;
337 RefCountPtr< CMYKContainer > CMYKcolor_;
338 bool hasKey_;
340 ColorType colorType_;
342 public:
343 WarmColorInterpolator( );
344 virtual ~WarmColorInterpolator( );
345 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
346 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
347 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
348 virtual void gcMark( Kernel::GCMarkedSet & marked );
349 TYPEINFODECL;