00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00033
00034
00035 #ifndef _XST_SCALAR_H_INCLUDED_
00036 #define _XST_SCALAR_H_INCLUDED_
00037
00038 namespace cttl_impl {
00039
00040
00053 template< typename ValueT >
00054 struct xst_scalar {
00055
00056
00057 template< typename D > friend struct xst_lambda_wrap;
00058
00059
00060 template< typename D, typename T > friend struct xst_translator;
00061
00063 typedef typename xst_storage_adaptor< ValueT >::value_type value_T;
00064
00072 typedef typename xst_non_scalar_traits< value_T >::value_type unmodified_dereferenced_T;
00073
00075 typedef typename xst_dereference_traits< value_T, unmodified_dereferenced_T >::value_type dereferenced_value_T;
00076
00078 typedef xst_scalar< ValueT > left_T;
00079
00081 typedef xst_scalar< ValueT > right_T;
00082
00083 enum {
00085 const_value_,
00086
00088 depth_ = 1,
00089
00097 capacity_ = xst_dereference_traits< value_T, unmodified_dereferenced_T >::capacity_,
00098
00100 primitive_id_ = primitive_id_scalar
00101 };
00102
00104 typedef xst_scalar< typename xst_storage_adaptor< ValueT >::reference > reference_T;
00105
00107 xst_scalar()
00108 {
00109 }
00110
00112 xst_scalar( ValueT data_ )
00113 :
00114 m_value( data_ )
00115 {
00116 }
00117
00119 xst_scalar( xst_scalar< ValueT > const& other_ )
00120 :
00121 m_value( other_.m_value )
00122 {
00123 }
00124
00126 reference_T make_reference() const
00127 {
00128 return reference_T( const_cast< xst_scalar< ValueT >* >( this )->m_value.value() );
00129 }
00130
00132 template<
00133 int LocationT
00134 >
00135 dereferenced_value_T&
00136 dereferenced_value( xst_lambda_wrap< xst_const_scalar< LocationT > > subscript_ )
00137 {
00138
00139 return xst_dereference_traits< value_T, unmodified_dereferenced_T >::dereference( top( subscript_ ) );
00140 }
00141
00143
00145
00147 left_T& left_lambda()
00148 {
00149 return *this;
00150 }
00151
00153 left_T const& left_lambda() const
00154 {
00155 return *this;
00156 }
00157
00159 right_T& right_lambda()
00160 {
00161 return *this;
00162 }
00163
00165 right_T const& right_lambda() const
00166 {
00167 return *this;
00168 }
00169
00170
00172
00174
00176 template< typename FunctorT >
00177 static void subscript_top_down( FunctorT& functor_ )
00178 {
00179 functor_( const_scalar( 0 ) );
00180 }
00181
00183 template< typename FunctorT >
00184 static void subscript_bottom_up( FunctorT& functor_ )
00185 {
00186 functor_( const_scalar( 0 ) );
00187 }
00188
00190
00192
00194 template< typename FunctorT >
00195 void traverse_bottom_up( FunctorT& functor_ )
00196 {
00197 functor_( *this );
00198 }
00199
00201 template< typename FunctorT >
00202 void traverse_top_down( FunctorT& functor_ )
00203 {
00204 functor_( *this );
00205 }
00206
00208 template< typename FunctorT >
00209 void traverse_bottom_up( FunctorT& functor_ ) const
00210 {
00211 functor_( *this );
00212 }
00213
00215 template< typename FunctorT >
00216 void traverse_top_down( FunctorT& functor_ ) const
00217 {
00218 functor_( *this );
00219 }
00220
00221
00223
00225
00227 template<
00228 int LocationT,
00229 typename InputValueT
00230 >
00231 void
00232 push(
00233 xst_lambda_wrap< xst_const_scalar< LocationT > >,
00234 InputValueT const& data_
00235 )
00236 {
00237 xpush_descend< depth_ - LocationT - 1 >( data_ );
00238 }
00239
00241 template<
00242 int LocationT
00243 >
00244 void
00245 pop(
00246 xst_lambda_wrap< xst_const_scalar< LocationT > >
00247 )
00248
00249 {
00250 xpop_descend< depth_ - LocationT - 1 >();
00251 }
00252
00254 template<
00255 int LocationT
00256 >
00257 value_T const& top(
00258 xst_lambda_wrap< xst_const_scalar< LocationT > >
00259 )
00260 const
00261 {
00262 return xtop_descend< depth_ - LocationT - 1 >();
00263 }
00264
00266 template<
00267 int LocationT
00268 >
00269 value_T& top(
00270 xst_lambda_wrap< xst_const_scalar< LocationT > >
00271 )
00272
00273 {
00274 return xtop_descend< depth_ - LocationT - 1 >();
00275 }
00276
00278 template<
00279 int LocationT
00280 >
00281 size_t
00282 size(
00283 xst_lambda_wrap< xst_const_scalar< LocationT > >
00284 )
00285 const
00286 {
00287 return 1;
00288 }
00289
00291 template<
00292 int LocationT
00293 >
00294 std::stack< value_T > const*
00295 stack_ptr(
00296 xst_lambda_wrap< xst_const_scalar< LocationT > >
00297 )
00298 const
00299 {
00300 assert( !LocationT );
00301 return NULL;
00302 }
00303
00305 template<
00306 int LocationT
00307 >
00308 std::stack< value_T >*
00309 stack_ptr(
00310 xst_lambda_wrap< xst_const_scalar< LocationT > >
00311 )
00312 {
00313 assert( !LocationT );
00314 return NULL;
00315 }
00316
00317 #ifdef CTTL_LAMBDA_REFLECTION
00318
00319 typedef xst_scalar< ValueT > reflection_T;
00320
00322 reflection_T reflection() const
00323 {
00324 return *this;
00325 }
00326 #endif // CTTL_LAMBDA_REFLECTION
00327
00328 private:
00330
00332
00334 xst_storage_adaptor< ValueT > m_value;
00335
00337 template< int LocationT, typename InputValueT >
00338 void xpush_at_location( InputValueT const& data_ )
00339 {
00340 assert( !LocationT );
00341 m_value.value() = data_;
00342 }
00343
00345 template< int LocationT >
00346 void xpop_at_location()
00347 {
00348 assert( !LocationT );
00349 }
00350
00352 template< int LocationT >
00353 value_T const& xtop_at_location() const
00354 {
00355 assert( !LocationT );
00356 CTTL_TRACE_DEPOSIT_TEXT( xst_storage_adaptor< ValueT >::trace_char() );
00357 CTTL_TRACE_DEPOSIT_TEXT( xst_non_scalar_traits< value_T >::identity( m_value.const_value() ) );
00358 CTTL_TRACE_DEPOSIT_TEXT( ' ' );
00359 return m_value.const_value();
00360 }
00361
00363 template< int LocationT, typename InputValueT >
00364 void xpush_descend( InputValueT const& data_ )
00365 {
00366 xpush_at_location< LocationT >( data_ );
00367 }
00368
00370 template< int LocationT >
00371 void xpop_descend()
00372 {
00373 xpop_at_location< LocationT >();
00374 }
00375
00377 template< int LocationT >
00378 value_T const& xtop_descend() const
00379 {
00380 return xtop_at_location< LocationT >();
00381 }
00382
00384
00386
00388 template< typename SubscriptLambdaT, typename FunctorT >
00389 static void xsubscript_top_down_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ )
00390 {
00391 functor_( subscript_ );
00392 }
00393
00395 template< int LocationT, typename FunctorT >
00396 static void xsubscript_top_down_descend( FunctorT& )
00397 {
00398 assert( false );
00399 }
00400
00402 template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00403 static void xsubscript_top_down_subtree_descend( SubscriptLambdaT, FunctorT& )
00404 {
00405 assert( false );
00406 }
00407
00409
00411
00413 template< typename SubscriptLambdaT, typename FunctorT >
00414 static void xsubscript_bottom_up_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ )
00415 {
00416 functor_( subscript_ );
00417 }
00418
00420 template< int LocationT, typename FunctorT >
00421 static void xsubscript_bottom_up_descend( FunctorT& )
00422 {
00423 assert( false );
00424 }
00425
00427 template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00428 static void xsubscript_bottom_up_subtree_descend( SubscriptLambdaT, FunctorT& )
00429 {
00430 assert( false );
00431 }
00432
00434
00436
00438 template< typename SubscriptLambdaT, typename InputValueT >
00439 void xpush_sub_split( SubscriptLambdaT, InputValueT const& )
00440 {
00441 assert( false );
00442 }
00443
00445 template< int LocationT, typename SubscriptLambdaT, typename InputValueT >
00446 void xpush_sub_descend( SubscriptLambdaT, InputValueT const& )
00447 {
00448 assert( false );
00449 }
00450
00452 template< typename SubscriptLambdaT >
00453 void xpop_sub_split( SubscriptLambdaT )
00454 {
00455 assert( false );
00456 }
00457
00459 template< int LocationT, typename SubscriptLambdaT >
00460 void xpop_sub_descend( SubscriptLambdaT )
00461 {
00462 assert( false );
00463 }
00464
00465
00466
00468 template< typename SubscriptLambdaT >
00469 value_T const& xtop_sub_split( SubscriptLambdaT ) const
00470 {
00471 assert( false );
00472 return m_value.const_value();
00473 }
00474
00476 template< int LocationT, typename SubscriptLambdaT >
00477 value_T const& xtop_sub_descend( SubscriptLambdaT ) const
00478 {
00479 assert( false );
00480 return m_value.const_value();
00481 }
00482
00484
00486
00488 template< int LocationT >
00489 value_T& xtop_at_location()
00490 {
00491 assert( !LocationT );
00492 CTTL_TRACE_DEPOSIT_TEXT( "->" );
00493 CTTL_TRACE_DEPOSIT_TEXT( xst_storage_adaptor< ValueT >::trace_char() );
00494 CTTL_TRACE_DEPOSIT_TEXT( xst_non_scalar_traits< value_T >::identity( m_value.const_value() ) );
00495 CTTL_TRACE_DEPOSIT_TEXT( ' ' );
00496 return m_value.value();
00497 }
00498
00500 template< int LocationT >
00501 value_T& xtop_descend()
00502 {
00503 return xtop_at_location< LocationT >();
00504 }
00505
00507 template< typename SubscriptLambdaT >
00508 value_T& xtop_sub_split( SubscriptLambdaT )
00509 {
00510 assert( false );
00511 return m_value.value();
00512 }
00513
00515 template< int LocationT, typename SubscriptLambdaT >
00516 value_T& xtop_sub_descend( SubscriptLambdaT )
00517 {
00518 assert( false );
00519 return m_value.value();
00520 }
00521
00522
00524 template< int LocationT >
00525 size_t xsize_at_location() const
00526 {
00527 assert( !LocationT );
00528 return 1;
00529 }
00530
00532 template< int LocationT >
00533 size_t xsize_descend() const
00534 {
00535 assert( !LocationT );
00536 return 1;
00537 }
00538
00540 template< typename SubscriptLambdaT >
00541 size_t xsize_sub_split( SubscriptLambdaT ) const
00542 {
00543 assert( false );
00544 return 1;
00545 }
00546
00548 template< int LocationT, typename SubscriptLambdaT >
00549 size_t xsize_sub_descend( SubscriptLambdaT ) const
00550 {
00551 assert( false );
00552 return 1;
00553 }
00554
00556 template< int LocationT >
00557 std::stack< value_T > const* xstack_ptr_at_location() const
00558 {
00559 assert( !LocationT );
00560 return NULL;
00561 }
00562
00564 template< int LocationT >
00565 std::stack< value_T > const* xstack_ptr_descend() const
00566 {
00567 assert( !LocationT );
00568 return NULL;
00569 }
00570
00572 template< typename SubscriptLambdaT >
00573 std::stack< value_T > const* xstack_ptr_sub_split( SubscriptLambdaT ) const
00574 {
00575 assert( false );
00576 return NULL;
00577 }
00578
00580 template< int LocationT, typename SubscriptLambdaT >
00581 std::stack< value_T > const* xstack_ptr_sub_descend( SubscriptLambdaT ) const
00582 {
00583 assert( false );
00584 return NULL;
00585 }
00586
00587
00589 template< int LocationT >
00590 std::stack< value_T >* xstack_ptr_at_location()
00591 {
00592 assert( !LocationT );
00593 return NULL;
00594 }
00595
00597 template< int LocationT >
00598 std::stack< value_T >* xstack_ptr_descend()
00599 {
00600 assert( !LocationT );
00601 return NULL;
00602 }
00603
00605 template< typename SubscriptLambdaT >
00606 std::stack< value_T >* xstack_ptr_sub_split( SubscriptLambdaT )
00607 {
00608 assert( false );
00609 return NULL;
00610 }
00611
00613 template< int LocationT, typename SubscriptLambdaT >
00614 std::stack< value_T >* xstack_ptr_sub_descend( SubscriptLambdaT )
00615 {
00616 assert( false );
00617 return NULL;
00618 }
00619
00620 };
00621
00622
00623 }
00624
00625
00626 #endif //_XST_SCALAR_H_INCLUDED_