Doc: Update namespace of extensions
[shapes.git] / source / hottypes.h
blob6dd8876200fd888592b74f43279dcbeecac4a65f
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 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::AFM > metrics_;
268 FontMetrics::SingleByte_WritingDirectionMetrics * horizontalMetrics_typed_;
269 Concrete::Length size_;
270 public:
271 WarmType3Font( );
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 );
277 TYPEINFODECL;
279 private:
280 static void initializeLegalStrechValues( std::set< const char *, charPtrLess > * legalStretchValues );
283 class WarmTime : public Kernel::State
285 public:
286 WarmTime( );
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 );
292 TYPEINFODECL;
295 class WarmRandomDevice : public Kernel::State
297 const char * deviceName_;
298 std::ifstream idev_;
299 std::ofstream odev_;
300 public:
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 );
308 TYPEINFODECL;
311 class WarmRandomState : public Kernel::State
313 char * state_;
314 public:
315 WarmRandomState( char * state );
316 void setState( );
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 );
322 TYPEINFODECL;
325 class WarmColorInterpolator : public Kernel::State
327 public:
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;
334 private:
335 RefCountPtr< KeyContainer > key_;
336 RefCountPtr< RGBContainer > RGBcolor_;
337 RefCountPtr< GrayContainer > graycolor_;
338 RefCountPtr< CMYKContainer > CMYKcolor_;
339 bool hasKey_;
341 ColorType colorType_;
343 public:
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 );
350 TYPEINFODECL;
353 class Warm_vector : public Kernel::State
355 public:
356 /* The data is exposed so that mutator functions get access without messing with friend classes. */
357 std::vector< Kernel::ValueRef > * mem_;
359 Warm_vector( );
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 );
365 TYPEINFODECL;