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, 2013, 2014 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"
32 #include "charconverters.h"
50 SplineTime( const SplineTime
& orig
) : t_( orig
.t_
), isPast_( orig
.isPast_
) { };
51 SplineTime( Concrete::Time t
) : t_( t
), isPast_( false ) { }
52 SplineTime( Concrete::Time t
, bool isPast
) : t_( t
), isPast_( isPast
) { }
54 const Concrete::Time
& t( ) const { return t_
; }
55 const bool & isPast( ) const { return isPast_
; }
57 SplineTime
& operator ++ ( ) { t_
+= UNIT_TIME
; return *this; }
64 class Symbol
: public Lang::Value
69 typedef std::map
< const char *, int, charPtrLess
> NameTableType
;
70 typedef std::map
< int, RefCountPtr
< const char > > ReverseTableType
;
71 static NameTableType nameTable
;
72 static ReverseTableType reverseTable
;
73 static KeyType nextUnique
;
78 Symbol( const char * name
);
80 bool operator == ( const Symbol
& other
) const;
81 bool operator != ( const Symbol
& other
) const;
82 bool operator < ( const Symbol
& other
) const;
83 bool operator > ( const Symbol
& other
) const;
84 bool operator <= ( const Symbol
& other
) const;
85 bool operator >= ( const Symbol
& other
) const;
86 bool isUnique( ) const;
87 KeyType
getKey( ) const { return key_
; }
88 RefCountPtr
< const char > name( ) const;
89 static RefCountPtr
< const char > nameFromKey( KeyType key
);
91 virtual void show( std::ostream
& os
) const;
92 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
96 class Float
: public Lang::Value
99 typedef double ValueType
;
101 Float( ValueType val
) : val_( val
) { };
103 virtual void show( std::ostream
& os
) const;
104 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
108 class Integer
: public Lang::Value
111 typedef int ValueType
;
112 typedef unsigned int ValueType_unsigned
;
114 Integer( ValueType val
) : val_( val
) { };
115 bool operator == ( const Integer
& other
) const;
116 bool operator != ( const Integer
& other
) const;
117 bool operator < ( const Integer
& other
) const;
118 bool operator > ( const Integer
& other
) const;
119 bool operator <= ( const Integer
& other
) const;
120 bool operator >= ( const Integer
& other
) const;
122 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
123 virtual void show( std::ostream
& os
) const;
124 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
128 class Length
: public Lang::Value
131 typedef Concrete::Length ValueType
;
136 Length( const Lang::Length
& orig
) : isOffset_( orig
.isOffset_
), val_( orig
.val_
) { };
137 /* If the following is not explicit, there is a risk that
139 * gets applied to output a Concrete::Length via Lang::Length, which is typically not what we want.
141 explicit Length( ValueType val
) : isOffset_( false ), val_( val
) { };
142 Length( bool isOffset
, ValueType val
) : isOffset_( isOffset
), val_( val
) { };
143 Concrete::Length
get( Concrete::Length baseLength
) const;
144 Concrete::Length
get( ) const;
145 double getScalar( Concrete::Length baseLength
) const;
146 double getScalar( ) const;
147 Lang::Length
operator + ( const Lang::Length
& term
) const;
148 Lang::Length
operator - ( const Lang::Length
& term
) const;
150 virtual void show( std::ostream
& os
) const;
151 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
152 friend std::ostream
& operator << ( std::ostream
& os
, const Lang::Length
& self
);
156 class Boolean
: public Lang::Value
160 Boolean( bool val
) : val_( val
) { };
162 virtual void show( std::ostream
& os
) const;
163 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
167 class Character
: public Lang::Value
170 typedef Kernel::UnicodeCodePoint ValueType
;
172 Character( ValueType val
) : val_( val
) { };
173 Character( ValueType::value_type code
) : val_( code
) { };
174 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
176 virtual void show( std::ostream
& os
) const;
177 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
181 class String
: public Lang::Value
184 RefCountPtr
< const char > val_
;
186 String( RefCountPtr
< const char > val
) : val_( val
), bytecount_( strlen( val
.getPtr( ) ) ) { };
187 String( RefCountPtr
< const char > val
, size_t bytecount
) : val_( val
), bytecount_( bytecount
) { };
188 String( const char * val
, bool duplicate
) : val_( duplicate
? strdup( val
) : val
), bytecount_( strlen( val
) ) { };
189 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
192 virtual void show( std::ostream
& os
) const;
193 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
194 size_t UTF8count( ) const;
198 class Continuation
: public Lang::NoOperatorOverloadValue
201 Kernel::ContRef cont_
;
202 Continuation( const Kernel::ContRef
& cont
);
203 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
204 virtual ~Continuation( );
206 virtual void show( std::ostream
& os
) const;
207 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
210 class Exception
: public Lang::NoOperatorOverloadValue
212 const Ast::SourceLocation
& loc_
;
213 RefCountPtr
< const Lang::Symbol
> kind_
;
214 RefCountPtr
< const Lang::String
> source_
;
215 RefCountPtr
< const Lang::Value
> details_
;
216 RefCountPtr
< const char > message_
;
217 Kernel::ContRef cont_
;
218 Interaction::ExitCode exitCode_
;
220 /* First constructor allows source location to be set directly, second takes the location from the continuation.
222 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
);
223 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
);
225 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
226 virtual ~Exception( );
228 const Ast::SourceLocation
& loc( ) const { return loc_
; }
229 const Kernel::ContRef
& cont( ) const { return cont_
; }
230 virtual void show( std::ostream
& os
) const;
231 virtual void gcMark( Kernel::GCMarkedSet
& marked
);
232 Interaction::ExitCode
exitCode( ) const { return exitCode_
; }
235 class FloatPair
: public Lang::Value
240 FloatPair( double x
, double y
) : x_( x
), y_( y
) { };
241 FloatPair( const Concrete::UnitFloatPair
& orig
);
242 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
244 virtual RefCountPtr
< const Lang::FloatPair
> transformed( const Lang::Transform2D
& tf
) const;
245 virtual void show( std::ostream
& os
) const;
246 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
250 class FloatTriple
: public Lang::Value
256 FloatTriple( double x
, double y
, double z
) : x_( x
), y_( y
), z_( z
) { };
257 FloatTriple( const Concrete::UnitFloatTriple
& orig
);
258 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
260 virtual RefCountPtr
< const Lang::FloatTriple
> transformed( const Lang::Transform3D
& tf
) const;
261 virtual void show( std::ostream
& os
) const;
262 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
268 cross( const Lang::FloatTriple
& a
, const Lang::FloatTriple
& b
)
270 return Lang::FloatTriple( a
.y_
* b
.z_
- a
.z_
* b
.y_
,
271 a
.z_
* b
.x_
- a
.x_
* b
.z_
,
272 a
.x_
* b
.y_
- a
.y_
* b
.x_
);
275 class Coords2D
: public Lang::Geometric2D
280 Coords2D( const Lang::Coords2D
& orig
);
281 Coords2D( const Lang::Length
& x
, const Lang::Length
& y
);
282 Coords2D( const Concrete::Length
& x
, const Concrete::Length
& y
);
283 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
284 Coords2D
* transformedPtr( const Lang::Transform2D
& tf
) const;
285 virtual RefCountPtr
< const Lang::Geometric2D
> transformed( const Lang::Transform2D
& tf
, const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
286 virtual RefCountPtr
< const Lang::Geometric3D
> to3D( const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
288 virtual void show( std::ostream
& os
) const;
289 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
290 friend std::ostream
& operator << ( std::ostream
& os
, const Lang::Coords2D
& self
);
294 class CornerCoords2D
: public Lang::Coords2D
298 CornerCoords2D( const Lang::Length
& x
, const Lang::Length
& y
, double a
);
299 CornerCoords2D( const Concrete::Length
& x
, const Concrete::Length
& y
, double a
);
300 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
301 CornerCoords2D
* transformedPtr( const Lang::Transform2D
& tf
) const;
302 virtual RefCountPtr
< const Lang::Geometric2D
> transformed( const Lang::Transform2D
& tf
, const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
303 virtual RefCountPtr
< const Lang::Geometric3D
> to3D( const RefCountPtr
< const Lang::Geometric2D
> & self
) const;
308 class Coords3D
: public Lang::Geometric3D
314 Coords3D( const Coords3D
& orig
);
315 Coords3D( const Lang::Length
& x
, const Lang::Length
& y
, const Lang::Length
& z
);
316 Coords3D( const Concrete::Length
& x
, const Concrete::Length
& y
, const Concrete::Length
& z
);
317 virtual Kernel::VariableHandle
getField( const char * fieldID
, const RefCountPtr
< const Lang::Value
> & selfRef
) const;
318 Coords3D
* transformedPtr( const Lang::Transform3D
& tf
) const;
319 virtual RefCountPtr
< const Lang::Geometric3D
> transformed( const Lang::Transform3D
& tf
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const;
320 RefCountPtr
< const Lang::Coords2D
> make2D( Concrete::Length eyez
) const;
321 virtual RefCountPtr
< const Lang::Geometric2D
> to2D( const Kernel::PassedDyn
& dyn
, const RefCountPtr
< const Lang::Geometric3D
> & self
) const;
323 virtual void show( std::ostream
& os
) const;
324 virtual void gcMark( Kernel::GCMarkedSet
& marked
){ };
325 friend std::ostream
& operator << ( std::ostream
& os
, const Lang::Coords3D
& self
);