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 Henrik Tidefelt
21 #include "Shapes_Ast_decls.h"
22 #include "Shapes_Kernel_decls.h"
23 #include "Shapes_Concrete_decls.h"
27 #include "pdfstructure.h"
28 #include "shapesvalue.h"
29 #include "charptrless.h"
30 #include "elementarylength.h"
49 SplineTime( const SplineTime
& orig
) : t_( orig
.t_
), isPast_( orig
.isPast_
) { };
50 SplineTime( Concrete::Time t
) : t_( t
), isPast_( false ) { }
51 SplineTime( Concrete::Time t
, bool isPast
) : t_( t
), isPast_( isPast
) { }
53 const Concrete::Time
& t( ) const { return t_
; }
54 const bool & isPast( ) const { return isPast_
; }
56 SplineTime
& operator ++ ( ) { t_
+= UNIT_TIME
; return *this; }
63 class Void
: public Lang::Value
67 virtual void show( std::ostream
& os
) const;
68 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
70 virtual Kernel::QuickTypeID
getTypeID( ) const { return Kernel::TYPEID_NoOperatorOverloadValue
; };
73 class Symbol
: public Lang::Value
78 typedef std::map
< const char *, int, charPtrLess
> NameTableType
;
79 typedef std::map
< int, RefCountPtr
< const char > > ReverseTableType
;
80 static NameTableType nameTable
;
81 static ReverseTableType reverseTable
;
82 static KeyType nextUnique
;
87 Symbol( const char * name
);
89 bool operator == ( const Symbol
& other
) const;
90 bool operator != ( const Symbol
& other
) const;
91 bool operator < ( const Symbol
& other
) const;
92 bool operator > ( const Symbol
& other
) const;
93 bool operator <= ( const Symbol
& other
) const;
94 bool operator >= ( const Symbol
& other
) const;
95 bool isUnique( ) const;
96 KeyType
getKey( ) const { return key_
; }
97 RefCountPtr
< const char > name( ) const;
98 static RefCountPtr
< const char > nameFromKey( KeyType key
);
100 virtual void show( std::ostream
& os
) const;
101 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
105 class Float
: public Lang::Value
109 Float( double val
) : val_( val
) { };
111 virtual void show( std::ostream
& os
) const;
112 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
116 class Integer
: public Lang::Value
119 typedef int ValueType
;
121 Integer( ValueType val
) : val_( val
) { };
123 virtual void show( std::ostream
& os
) const;
124 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
128 class Length
: public Lang::Value
131 Concrete::Length val_
;
133 Length( const Lang::Length
& orig
) : isOffset_( orig
.isOffset_
), val_( orig
.val_
) { };
134 // If the following is not explicit, there is a risk that
136 // gets applied to output a Concrete::Length via Lang::Length, which is typically not what we want.
137 explicit Length( Concrete::Length val
) : isOffset_( false ), val_( val
) { };
138 Length( bool isOffset
, Concrete::Length val
) : isOffset_( isOffset
), val_( val
) { };
139 Concrete::Length
get( Concrete::Length baseLength
) const;
140 Concrete::Length
get( ) const;
141 double getScalar( Concrete::Length baseLength
) const;
142 double getScalar( ) const;
143 Lang::Length
operator + ( const Lang::Length
& term
) const;
144 Lang::Length
operator - ( const Lang::Length
& term
) const;
146 virtual void show( std::ostream
& os
) const;
147 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
148 friend std::ostream
& operator << ( std::ostream
& os
, const Lang::Length
& self
);
152 class Boolean
: public Lang::Value
156 Boolean( bool val
) : val_( val
) { };
158 virtual void show( std::ostream
& os
) const;
159 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
163 class String
: public Lang::Value
166 RefCountPtr
< const char > val_
;
168 String( RefCountPtr
< const char > val
) : val_( val
), bytecount_( strlen( val
.getPtr( ) ) ) { };
169 String( RefCountPtr
< const char > val
, size_t bytecount
) : val_( val
), bytecount_( bytecount
) { };
170 String( const char * val
, bool duplicate
) : val_( duplicate
? strdup( val
) : val
), bytecount_( strlen( val
) ) { };
171 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
174 virtual void show( std::ostream
& os
) const;
175 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
179 class Continuation
: public Lang::NoOperatorOverloadValue
182 Kernel::ContRef cont_
;
183 Continuation( const Kernel::ContRef
& cont
);
184 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
185 virtual ~Continuation( );
187 virtual void show( std::ostream
& os
) const;
188 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
191 class Exception
: public Lang::NoOperatorOverloadValue
193 Ast::SourceLocation loc_
;
194 RefCountPtr
< const Lang::Symbol
> kind_
;
195 RefCountPtr
< const Lang::String
> source_
;
196 RefCountPtr
< const Lang::Value
> details_
;
197 RefCountPtr
< const char > message_
;
198 Kernel::ContRef cont_
;
199 Interaction::ExitCode exitCode_
;
201 /* First constructor allows source location to be set directly, second takes the location from the continuation.
203 Exception( const Ast::SourceLocation
& loc
, const RefCountPtr
< const Lang::Symbol
> & kind
, const RefCountPtr
< const Lang::String
> & source
, const RefCountPtr
< const Lang::Value
> & details
, const RefCountPtr
< const char > & message
, const Kernel::ContRef
& cont
, Interaction::ExitCode exitCode
);
204 Exception( const RefCountPtr
< const Lang::Symbol
> & kind
, const RefCountPtr
< const Lang::String
> & source
, const RefCountPtr
< const Lang::Value
> & details
, const RefCountPtr
< const char > & message
, const Kernel::ContRef
& cont
, Interaction::ExitCode exitCode
);
206 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
207 virtual ~Exception( );
209 const Ast::SourceLocation
& loc( ) const { return loc_
; }
210 const Kernel::ContRef
& cont( ) const { return cont_
; }
211 virtual void show( std::ostream
& os
) const;
212 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
213 Interaction::ExitCode
exitCode( ) const { return exitCode_
; }
216 class FloatPair
: public Lang::Value
221 FloatPair( double x
, double y
) : x_( x
), y_( y
) { };
222 FloatPair( const Concrete::UnitFloatPair
& orig
);
223 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
225 virtual RefCountPtr
< const Lang::FloatPair
> transformed( const Lang::Transform2D
& tf
) const;
226 virtual void show( std::ostream
& os
) const;
227 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
231 class FloatTriple
: public Lang::Value
237 FloatTriple( double x
, double y
, double z
) : x_( x
), y_( y
), z_( z
) { };
238 FloatTriple( const Concrete::UnitFloatTriple
& orig
);
239 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
241 virtual RefCountPtr
< const Lang::FloatTriple
> transformed( const Lang::Transform3D
& tf
) const;
242 virtual void show( std::ostream
& os
) const;
243 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
249 cross( const Lang::FloatTriple
& a
, const Lang::FloatTriple
& b
)
251 return Lang::FloatTriple( a
.y_
* b
.z_
- a
.z_
* b
.y_
,
252 a
.z_
* b
.x_
- a
.x_
* b
.z_
,
253 a
.x_
* b
.y_
- a
.y_
* b
.x_
);
256 class Coords2D
: public Lang::Geometric2D
261 Coords2D( const Lang::Coords2D
& orig
);
262 Coords2D( const Lang::Length
& x
, const Lang::Length
& y
);
263 Coords2D( const Concrete::Length
& x
, const Concrete::Length
& y
);
264 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
265 Coords2D
* transformedPtr( const Lang::Transform2D
& tf
) const;
266 virtual RefCountPtr
< const Lang::Geometric2D
> transformed( const Lang::Transform2D
& tf
, const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
267 virtual RefCountPtr
< const Lang::Geometric3D
> to3D( const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
269 virtual void show( std::ostream
& os
) const;
270 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
271 friend std::ostream
& operator << ( std::ostream
& os
, const Lang::Coords2D
& self
);
275 class CornerCoords2D
: public Lang::Coords2D
279 CornerCoords2D( const Lang::Length
& x
, const Lang::Length
& y
, double a
);
280 CornerCoords2D( const Concrete::Length
& x
, const Concrete::Length
& y
, double a
);
281 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
282 CornerCoords2D
* transformedPtr( const Lang::Transform2D
& tf
) const;
283 virtual RefCountPtr
< const Lang::Geometric2D
> transformed( const Lang::Transform2D
& tf
, const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
284 virtual RefCountPtr
< const Lang::Geometric3D
> to3D( const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
289 class Coords3D
: public Lang::Geometric3D
295 Coords3D( const Coords3D
& orig
);
296 Coords3D( const Lang::Length
& x
, const Lang::Length
& y
, const Lang::Length
& z
);
297 Coords3D( const Concrete::Length
& x
, const Concrete::Length
& y
, const Concrete::Length
& z
);
298 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
299 Coords3D
* transformedPtr( const Lang::Transform3D
& tf
) const;
300 virtual RefCountPtr
< const Lang::Geometric3D
> transformed( const Lang::Transform3D
& tf
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const;
301 RefCountPtr
< const Lang::Coords2D
> make2D( Concrete::Length eyez
) const;
302 virtual RefCountPtr
< const Lang::Geometric2D
> to2D( const Kernel::PassedDyn
& dyn
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const;
304 virtual void show( std::ostream
& os
) const;
305 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
306 friend std::ostream
& operator << ( std::ostream
& os
, const Lang::Coords3D
& self
);