Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / elementarytypes.h
blob8084c20ee4eb37f2b3952df544499b6aea453c3d
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_Concrete_decls.h"
25 #include "ptrowner.h"
26 #include "refcount.h"
27 #include "pdfstructure.h"
28 #include "shapesvalue.h"
29 #include "charptrless.h"
30 #include "elementarylength.h"
31 #include "consts.h"
33 #include <list>
34 #include <iostream>
35 #include <stack>
36 #include <set>
39 namespace Shapes
42 namespace Concrete
44 class SplineTime
46 Concrete::Time t_;
47 bool isPast_;
48 public:
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; }
60 namespace Lang
63 class Void : public Lang::Value
65 public:
66 Void( );
67 virtual void show( std::ostream & os ) const;
68 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
69 TYPEINFODECL;
70 virtual Kernel::QuickTypeID getTypeID( ) const { return Kernel::TYPEID_NoOperatorOverloadValue; };
73 class Symbol : public Lang::Value
75 public:
76 typedef int KeyType;
77 private:
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;
83 KeyType key_;
84 public:
85 Symbol( );
86 Symbol( int key );
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 );
99 TYPEINFODECL;
100 virtual void show( std::ostream & os ) const;
101 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
102 DISPATCHDECL;
105 class Float : public Lang::Value
107 public:
108 double val_;
109 Float( double val ) : val_( val ) { };
110 TYPEINFODECL;
111 virtual void show( std::ostream & os ) const;
112 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
113 DISPATCHDECL;
116 class Integer : public Lang::Value
118 public:
119 typedef int ValueType;
120 ValueType val_;
121 Integer( ValueType val ) : val_( val ) { };
122 TYPEINFODECL;
123 virtual void show( std::ostream & os ) const;
124 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
125 DISPATCHDECL;
128 class Length : public Lang::Value
130 bool isOffset_;
131 Concrete::Length val_;
132 public:
133 Length( const Lang::Length & orig ) : isOffset_( orig.isOffset_ ), val_( orig.val_ ) { };
134 // If the following is not explicit, there is a risk that
135 // operator <<
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;
145 TYPEINFODECL;
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 );
149 DISPATCHDECL;
152 class Boolean : public Lang::Value
154 public:
155 bool val_;
156 Boolean( bool val ) : val_( val ) { };
157 TYPEINFODECL;
158 virtual void show( std::ostream & os ) const;
159 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
160 DISPATCHDECL;
163 class String : public Lang::Value
165 public:
166 RefCountPtr< const char > val_;
167 size_t bytecount_;
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;
172 virtual ~String( );
173 TYPEINFODECL;
174 virtual void show( std::ostream & os ) const;
175 virtual void gcMark( Kernel::GCMarkedSet & marked ){ };
176 DISPATCHDECL;
179 class Continuation : public Lang::NoOperatorOverloadValue
181 public:
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( );
186 TYPEINFODECL;
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_;
200 public:
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( );
208 TYPEINFODECL;
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
218 public:
219 double x_;
220 double y_;
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;
224 TYPEINFODECL;
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 ){ };
228 DISPATCHDECL;
231 class FloatTriple : public Lang::Value
233 public:
234 double x_;
235 double y_;
236 double z_;
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;
240 TYPEINFODECL;
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 ){ };
244 DISPATCHDECL;
247 inline
248 Lang::FloatTriple
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
258 public:
259 Lang::Length x_;
260 Lang::Length y_;
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;
268 TYPEINFODECL;
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 );
272 DISPATCHDECL;
275 class CornerCoords2D : public Lang::Coords2D
277 public:
278 double a_;
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;
285 TYPEINFODECL;
286 DISPATCHDECL;
289 class Coords3D : public Lang::Geometric3D
291 public:
292 Lang::Length x_;
293 Lang::Length y_;
294 Lang::Length z_;
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;
303 TYPEINFODECL;
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 );
307 DISPATCHDECL;