00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00036
00037
00038 #ifndef _XST_SCALAR_H_INCLUDED_
00039 #define _XST_SCALAR_H_INCLUDED_
00040
00041 namespace cttl_impl {
00042
00043
00056 template< typename ValueT >
00057 struct xst_scalar {
00058
00059
00060 template< typename D > friend struct xst_lambda_wrap;
00061
00062
00063 template< typename D, typename T > friend struct xst_translator;
00064
00066 typedef typename xst_storage_adaptor< ValueT >::value_type value_T;
00067
00075 typedef typename xst_non_scalar_traits< value_T >::value_type unmodified_dereferenced_T;
00076
00078 typedef typename xst_dereference_traits< value_T, unmodified_dereferenced_T >::value_type dereferenced_value_T;
00079
00081 typedef xst_scalar< ValueT > left_T;
00082
00084 typedef xst_scalar< ValueT > right_T;
00085
00086 enum {
00088 const_value_,
00089
00091 depth_ = 1,
00092
00100 capacity_ = xst_dereference_traits< value_T, unmodified_dereferenced_T >::capacity_,
00101
00103 primitive_id_ = primitive_id_scalar
00104 };
00105
00107 typedef xst_scalar< typename xst_storage_adaptor< ValueT >::reference > reference_T;
00108
00110 xst_scalar()
00111 {
00112 }
00113
00115 xst_scalar( ValueT data_ )
00116 :
00117 m_value( data_ )
00118 {
00119 }
00120
00122 xst_scalar( xst_scalar< ValueT > const& other_ )
00123 :
00124 m_value( other_.m_value )
00125 {
00126 }
00127
00129 reference_T make_reference() const
00130 {
00131 return reference_T( const_cast< xst_scalar< ValueT >* >( this )->m_value.value() );
00132 }
00133
00135 template<
00136 int LocationT
00137 >
00138 dereferenced_value_T&
00139 dereferenced_value( xst_lambda_wrap< xst_const_scalar< LocationT > > subscript_ )
00140 {
00141
00142 return xst_dereference_traits< value_T, unmodified_dereferenced_T >::dereference( top( subscript_ ) );
00143 }
00144
00146
00148
00150 left_T& left_lambda()
00151 {
00152 return *this;
00153 }
00154
00156 left_T const& left_lambda() const
00157 {
00158 return *this;
00159 }
00160
00162 right_T& right_lambda()
00163 {
00164 return *this;
00165 }
00166
00168 right_T const& right_lambda() const
00169 {
00170 return *this;
00171 }
00172
00173
00175
00177
00179 template< typename FunctorT >
00180 static void subscript_top_down( FunctorT& functor_ )
00181 {
00182 functor_( const_scalar( 0 ) );
00183 }
00184
00186 template< typename FunctorT >
00187 static void subscript_bottom_up( FunctorT& functor_ )
00188 {
00189 functor_( const_scalar( 0 ) );
00190 }
00191
00193
00195
00197 template< typename FunctorT >
00198 void traverse_bottom_up( FunctorT& functor_ )
00199 {
00200 functor_( *this );
00201 }
00202
00204 template< typename FunctorT >
00205 void traverse_top_down( FunctorT& functor_ )
00206 {
00207 functor_( *this );
00208 }
00209
00211 template< typename FunctorT >
00212 void traverse_bottom_up( FunctorT& functor_ ) const
00213 {
00214 functor_( *this );
00215 }
00216
00218 template< typename FunctorT >
00219 void traverse_top_down( FunctorT& functor_ ) const
00220 {
00221 functor_( *this );
00222 }
00223
00224
00226
00228
00230 template<
00231 int LocationT,
00232 typename InputValueT
00233 >
00234 void
00235 push(
00236 xst_lambda_wrap< xst_const_scalar< LocationT > >,
00237 InputValueT const& data_
00238 )
00239 {
00240 xpush_descend< depth_ - LocationT - 1 >( data_ );
00241 }
00242
00244 template<
00245 int LocationT
00246 >
00247 void
00248 pop(
00249 xst_lambda_wrap< xst_const_scalar< LocationT > >
00250 )
00251
00252 {
00253 xpop_descend< depth_ - LocationT - 1 >();
00254 }
00255
00257 template<
00258 int LocationT
00259 >
00260 value_T const& top(
00261 xst_lambda_wrap< xst_const_scalar< LocationT > >
00262 )
00263 const
00264 {
00265 return xtop_descend< depth_ - LocationT - 1 >();
00266 }
00267
00269 template<
00270 int LocationT
00271 >
00272 value_T& top(
00273 xst_lambda_wrap< xst_const_scalar< LocationT > >
00274 )
00275
00276 {
00277 return xtop_descend< depth_ - LocationT - 1 >();
00278 }
00279
00281 template<
00282 int LocationT
00283 >
00284 size_t
00285 size(
00286 xst_lambda_wrap< xst_const_scalar< LocationT > >
00287 )
00288 const
00289 {
00290 return 1;
00291 }
00292
00294 template<
00295 int LocationT
00296 >
00297 std::stack< value_T > const*
00298 stack_ptr(
00299 xst_lambda_wrap< xst_const_scalar< LocationT > >
00300 )
00301 const
00302 {
00303 assert( !LocationT );
00304 return NULL;
00305 }
00306
00308 template<
00309 int LocationT
00310 >
00311 std::stack< value_T >*
00312 stack_ptr(
00313 xst_lambda_wrap< xst_const_scalar< LocationT > >
00314 )
00315 {
00316 assert( !LocationT );
00317 return NULL;
00318 }
00319
00320 #ifdef CTTL_LAMBDA_REFLECTION
00321
00322 typedef xst_scalar< ValueT > reflection_T;
00323
00325 reflection_T reflection() const
00326 {
00327 return *this;
00328 }
00329 #endif // CTTL_LAMBDA_REFLECTION
00330
00331 private:
00333
00335
00337 xst_storage_adaptor< ValueT > m_value;
00338
00340 template< int LocationT, typename InputValueT >
00341 void xpush_at_location( InputValueT const& data_ )
00342 {
00343 assert( !LocationT );
00344 m_value.value() = data_;
00345 }
00346
00348 template< int LocationT >
00349 void xpop_at_location()
00350 {
00351 assert( !LocationT );
00352 }
00353
00355 template< int LocationT >
00356 value_T const& xtop_at_location() const
00357 {
00358 assert( !LocationT );
00359 CTTL_TRACE_DEPOSIT_TEXT( xst_storage_adaptor< ValueT >::trace_char() );
00360 CTTL_TRACE_DEPOSIT_TEXT( xst_non_scalar_traits< value_T >::identity( m_value.const_value() ) );
00361 CTTL_TRACE_DEPOSIT_TEXT( ' ' );
00362 return m_value.const_value();
00363 }
00364
00366 template< int LocationT, typename InputValueT >
00367 void xpush_descend( InputValueT const& data_ )
00368 {
00369 xpush_at_location< LocationT >( data_ );
00370 }
00371
00373 template< int LocationT >
00374 void xpop_descend()
00375 {
00376 xpop_at_location< LocationT >();
00377 }
00378
00380 template< int LocationT >
00381 value_T const& xtop_descend() const
00382 {
00383 return xtop_at_location< LocationT >();
00384 }
00385
00387
00389
00391 template< typename SubscriptLambdaT, typename FunctorT >
00392 static void xsubscript_top_down_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ )
00393 {
00394 functor_( subscript_ );
00395 }
00396
00398 template< int LocationT, typename FunctorT >
00399 static void xsubscript_top_down_descend( FunctorT& )
00400 {
00401 assert( false );
00402 }
00403
00405 template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00406 static void xsubscript_top_down_subtree_descend( SubscriptLambdaT, FunctorT& )
00407 {
00408 assert( false );
00409 }
00410
00412
00414
00416 template< typename SubscriptLambdaT, typename FunctorT >
00417 static void xsubscript_bottom_up_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ )
00418 {
00419 functor_( subscript_ );
00420 }
00421
00423 template< int LocationT, typename FunctorT >
00424 static void xsubscript_bottom_up_descend( FunctorT& )
00425 {
00426 assert( false );
00427 }
00428
00430 template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00431 static void xsubscript_bottom_up_subtree_descend( SubscriptLambdaT, FunctorT& )
00432 {
00433 assert( false );
00434 }
00435
00437
00439
00441 template< typename SubscriptLambdaT, typename InputValueT >
00442 void xpush_sub_split( SubscriptLambdaT, InputValueT const& )
00443 {
00444 assert( false );
00445 }
00446
00448 template< int LocationT, typename SubscriptLambdaT, typename InputValueT >
00449 void xpush_sub_descend( SubscriptLambdaT, InputValueT const& )
00450 {
00451 assert( false );
00452 }
00453
00455 template< typename SubscriptLambdaT >
00456 void xpop_sub_split( SubscriptLambdaT )
00457 {
00458 assert( false );
00459 }
00460
00462 template< int LocationT, typename SubscriptLambdaT >
00463 void xpop_sub_descend( SubscriptLambdaT )
00464 {
00465 assert( false );
00466 }
00467
00468
00469
00471 template< typename SubscriptLambdaT >
00472 value_T const& xtop_sub_split( SubscriptLambdaT ) const
00473 {
00474 assert( false );
00475 return m_value.const_value();
00476 }
00477
00479 template< int LocationT, typename SubscriptLambdaT >
00480 value_T const& xtop_sub_descend( SubscriptLambdaT ) const
00481 {
00482 assert( false );
00483 return m_value.const_value();
00484 }
00485
00487
00489
00491 template< int LocationT >
00492 value_T& xtop_at_location()
00493 {
00494 assert( !LocationT );
00495 CTTL_TRACE_DEPOSIT_TEXT( "->" );
00496 CTTL_TRACE_DEPOSIT_TEXT( xst_storage_adaptor< ValueT >::trace_char() );
00497 CTTL_TRACE_DEPOSIT_TEXT( xst_non_scalar_traits< value_T >::identity( m_value.const_value() ) );
00498 CTTL_TRACE_DEPOSIT_TEXT( ' ' );
00499 return m_value.value();
00500 }
00501
00503 template< int LocationT >
00504 value_T& xtop_descend()
00505 {
00506 return xtop_at_location< LocationT >();
00507 }
00508
00510 template< typename SubscriptLambdaT >
00511 value_T& xtop_sub_split( SubscriptLambdaT )
00512 {
00513 assert( false );
00514 return m_value.value();
00515 }
00516
00518 template< int LocationT, typename SubscriptLambdaT >
00519 value_T& xtop_sub_descend( SubscriptLambdaT )
00520 {
00521 assert( false );
00522 return m_value.value();
00523 }
00524
00525
00527 template< int LocationT >
00528 size_t xsize_at_location() const
00529 {
00530 assert( !LocationT );
00531 return 1;
00532 }
00533
00535 template< int LocationT >
00536 size_t xsize_descend() const
00537 {
00538 assert( !LocationT );
00539 return 1;
00540 }
00541
00543 template< typename SubscriptLambdaT >
00544 size_t xsize_sub_split( SubscriptLambdaT ) const
00545 {
00546 assert( false );
00547 return 1;
00548 }
00549
00551 template< int LocationT, typename SubscriptLambdaT >
00552 size_t xsize_sub_descend( SubscriptLambdaT ) const
00553 {
00554 assert( false );
00555 return 1;
00556 }
00557
00559 template< int LocationT >
00560 std::stack< value_T > const* xstack_ptr_at_location() const
00561 {
00562 assert( !LocationT );
00563 return NULL;
00564 }
00565
00567 template< int LocationT >
00568 std::stack< value_T > const* xstack_ptr_descend() const
00569 {
00570 assert( !LocationT );
00571 return NULL;
00572 }
00573
00575 template< typename SubscriptLambdaT >
00576 std::stack< value_T > const* xstack_ptr_sub_split( SubscriptLambdaT ) const
00577 {
00578 assert( false );
00579 return NULL;
00580 }
00581
00583 template< int LocationT, typename SubscriptLambdaT >
00584 std::stack< value_T > const* xstack_ptr_sub_descend( SubscriptLambdaT ) const
00585 {
00586 assert( false );
00587 return NULL;
00588 }
00589
00590
00592 template< int LocationT >
00593 std::stack< value_T >* xstack_ptr_at_location()
00594 {
00595 assert( !LocationT );
00596 return NULL;
00597 }
00598
00600 template< int LocationT >
00601 std::stack< value_T >* xstack_ptr_descend()
00602 {
00603 assert( !LocationT );
00604 return NULL;
00605 }
00606
00608 template< typename SubscriptLambdaT >
00609 std::stack< value_T >* xstack_ptr_sub_split( SubscriptLambdaT )
00610 {
00611 assert( false );
00612 return NULL;
00613 }
00614
00616 template< int LocationT, typename SubscriptLambdaT >
00617 std::stack< value_T >* xstack_ptr_sub_descend( SubscriptLambdaT )
00618 {
00619 assert( false );
00620 return NULL;
00621 }
00622
00623 };
00624
00625
00626 }
00627
00628
00629 #endif //_XST_SCALAR_H_INCLUDED_