00001 #ifndef s11n_net_s11n_1_1_FUNCTIONAL_HPP_INCLUDED
00002 #define s11n_net_s11n_1_1_FUNCTIONAL_HPP_INCLUDED 1
00003
00004
00005
00006
00007 #include <s11n.net/s11n/tags.hpp>
00008 #include <s11n.net/s11n/traits.hpp>
00009 #include <s11n.net/s11n/serialize.hpp>
00010
00011 namespace s11n {
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 template <typename T>
00025 struct reference_base_f
00026 {
00027 typedef T type;
00028 type & value;
00029 explicit reference_base_f( type & _ref ) : value(_ref)
00030 {}
00031
00032
00033
00034
00035 inline operator T() const
00036 {
00037 return this->value;
00038 }
00039
00040
00041
00042
00043
00044 inline type & operator()() const
00045 {
00046 return this->value;
00047 }
00048
00049 };
00050
00051
00052
00053
00054
00055
00056
00057 template <typename T>
00058 struct reference_f : reference_base_f<T>
00059 {
00060 typedef typename reference_base_f<T>::type type;
00061 explicit reference_f( type & _ref ) : reference_base_f<T>(_ref)
00062 {}
00063
00064 template <typename X>
00065 inline const reference_f & operator=( const X & val ) const
00066 {
00067 this->value = val;
00068 return *this;
00069 }
00070 };
00071
00072
00073
00074
00075
00076
00077
00078 template <typename T>
00079 struct reference_f<T const> : reference_base_f<T const>
00080 {
00081 typedef typename reference_base_f<T const>::type type;
00082 explicit reference_f( type & _ref ) : reference_base_f<T const>(_ref)
00083 {}
00084 };
00085
00086
00087
00088
00089 template <typename T>
00090 struct reference_f<T *> : reference_base_f<T>
00091 {
00092
00093 typedef typename reference_base_f<T>::type type;
00094 explicit reference_f( type * _ref ) : reference_base_f<T>(*_ref)
00095 {}
00096 };
00097
00098
00099
00100
00101 template <typename T>
00102 struct reference_f<T const *> : reference_base_f<T const>
00103 {
00104
00105 typedef typename reference_base_f<T const>::type type;
00106 explicit reference_f( type * _ref ) : reference_base_f<T const>(*_ref)
00107 {}
00108 };
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 template <typename T>
00133 struct pointer_base_f
00134 {
00135
00136 typedef T type;
00137 type * value;
00138 explicit pointer_base_f( type * _ref ) : value(_ref)
00139 {}
00140 explicit pointer_base_f( type & _ref ) : value(&_ref)
00141 {}
00142
00143
00144
00145
00146 inline type * operator()() const
00147 {
00148 return this->value;
00149 }
00150
00151
00152 inline type * get() const
00153 {
00154 return this->value;
00155 }
00156
00157 inline type * operator->() const
00158 {
00159 return this->value;
00160 }
00161
00162 inline bool empty() const
00163 {
00164 return 0 != this->value;
00165 }
00166 };
00167
00168
00169
00170
00171
00172 template <typename T>
00173 struct pointer_f : pointer_base_f<T>
00174 {
00175 typedef typename pointer_base_f<T>::type type;
00176 explicit pointer_f( type & _ref ) : pointer_base_f<T>(&_ref)
00177 {}
00178 explicit pointer_f( type * _ref ) : pointer_base_f<T>(_ref)
00179 {}
00180 };
00181
00182
00183
00184
00185
00186 template <typename T>
00187 struct pointer_f<T const> : pointer_base_f<T const>
00188 {
00189 typedef typename pointer_base_f<T const>::type type;
00190 explicit pointer_f( type & _ref ) : pointer_base_f<T const>(&_ref)
00191 {}
00192 explicit pointer_f( type * _ref ) : pointer_base_f<T const>(_ref)
00193 {}
00194
00195 };
00196
00197
00198
00199
00200
00201 template <typename T>
00202 struct pointer_f<T *> : pointer_base_f<T>
00203 {
00204 typedef typename pointer_base_f<T>::type type;
00205 explicit pointer_f( type * _ref ) : pointer_base_f<T>(_ref)
00206 {}
00207 explicit pointer_f( type & _ref ) : pointer_base_f<T>(&_ref)
00208 {}
00209 };
00210
00211
00212
00213
00214
00215 template <typename T>
00216 struct pointer_f<T const *> : pointer_base_f<T const>
00217 {
00218 typedef typename pointer_base_f<T const>::type type;
00219 explicit pointer_f( type * _ref ) : pointer_base_f<T const>(_ref)
00220 {}
00221 explicit pointer_f( type & _ref ) : pointer_base_f<T const>(&_ref)
00222 {}
00223 };
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 template <typename T>
00257 struct value_f
00258 {
00259 typedef T type;
00260 type value;
00261 value_f( type const & _ref ) : value(_ref)
00262 {}
00263
00264
00265 inline operator T() const
00266 {
00267 return this->value;
00268 }
00269
00270
00271 inline type operator()() const
00272 {
00273 return this->value;
00274 }
00275 };
00276
00277
00278 template <typename T>
00279 struct value_f<T const> : value_f<T> {};
00280
00281
00282 template <typename T>
00283 struct value_f<T &> : value_f<T> {};
00284
00285
00286 template <typename T>
00287 struct value_f<T const &> : value_f<T> {};
00288
00289
00290
00291 template <typename T>
00292 inline value_f<T> val( const T & v )
00293 {
00294 return value_f<T>(v);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 struct serialize_binary_f : serialize_binary_f_tag
00306 {
00307 template <typename NT, typename ST>
00308 inline bool operator()( NT & dest, const ST & src ) const
00309 {
00310 return serialize<NT,ST>( dest, src );
00311 }
00312 };
00313
00314
00315
00316
00317
00318
00319
00320 struct deserialize_binary_f : deserialize_binary_f_tag
00321 {
00322 template <typename NT, typename ST>
00323 inline bool operator()( const NT & src, ST & dest ) const
00324 {
00325 return deserialize<NT,ST>( src, dest );
00326 }
00327 };
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 template <typename NodeType,typename SerializableT, typename BinaryFunctorT = serialize_binary_f>
00341 struct serialize_nullary_f : serialize_nullary_f_tag
00342 {
00343 reference_f<NodeType> node;
00344 reference_f<SerializableT const> serializable;
00345 BinaryFunctorT functor;
00346
00347
00348
00349
00350 serialize_nullary_f( NodeType & n, SerializableT const & s )
00351 : node(n), serializable(s), functor()
00352 {
00353 }
00354
00355
00356
00357
00358
00359
00360
00361 serialize_nullary_f( NodeType & n, SerializableT const & s, BinaryFunctorT const & f )
00362 : node(n), serializable(s), functor(f)
00363 {
00364 }
00365
00366 inline bool operator()() const
00367 {
00368 return this->functor( this->node(), this->serializable() );
00369 }
00370 };
00371
00372
00373
00374
00375 template <typename NodeType,typename SerializableT, typename BinaryFunctorT>
00376 inline serialize_nullary_f<NodeType,SerializableT,BinaryFunctorT>
00377 ser_nullary_f( NodeType & n, SerializableT const & s, BinaryFunctorT const & f )
00378 {
00379 return serialize_nullary_f<NodeType,SerializableT,BinaryFunctorT>( n, s, f );
00380 }
00381
00382
00383
00384
00385 template <typename NodeType,typename SerializableT>
00386 inline serialize_nullary_f<NodeType,SerializableT>
00387 ser_nullary_f( NodeType & n, SerializableT const & s )
00388 {
00389 return serialize_nullary_f<NodeType,SerializableT>( n, s );
00390 }
00391
00392
00393
00394
00395
00396
00397
00398 template <typename NodeType, typename BinaryFunctorT = serialize_binary_f>
00399 struct node_to_serialize_unary_f : serialize_unary_serializable_f_tag
00400 {
00401
00402 reference_f<NodeType> node;
00403 BinaryFunctorT functor;
00404 node_to_serialize_unary_f( NodeType & n ) : node(n), functor() {}
00405 node_to_serialize_unary_f( NodeType & n, BinaryFunctorT const & f ) : node(n), functor(f) {}
00406
00407 template <typename SerT>
00408 inline bool operator()( const SerT & src ) const
00409 {
00410 return this->functor( this->node(), src );
00411 }
00412 };
00413
00414
00415
00416
00417 template <typename NodeType, typename BinaryFunctorT>
00418 node_to_serialize_unary_f<NodeType,BinaryFunctorT>
00419 node_to_ser_unary_f( NodeType & n, BinaryFunctorT f )
00420 {
00421 return node_to_serialize_unary_f<NodeType,BinaryFunctorT>(n,f);
00422 }
00423
00424
00425
00426
00427 template <typename NodeType>
00428 node_to_serialize_unary_f<NodeType>
00429 node_to_ser_unary_f( NodeType & n )
00430 {
00431 return node_to_serialize_unary_f<NodeType>(n);
00432 }
00433
00434
00435
00436
00437
00438
00439
00440
00441 template <typename NodeType, typename BinaryFunctorT = deserialize_binary_f>
00442 struct node_to_deserialize_unary_f : deserialize_unary_serializable_f_tag
00443 {
00444
00445 reference_f<NodeType const> node;
00446 BinaryFunctorT functor;
00447 node_to_deserialize_unary_f( NodeType const & n ) : node(n), functor() {}
00448 node_to_deserialize_unary_f( NodeType const & n, BinaryFunctorT const & f ) : node(n), functor(f) {}
00449 template <typename SerT>
00450 inline bool operator()( SerT & dest ) const
00451 {
00452 return this->functor( this->node(), dest );
00453 }
00454 };
00455
00456
00457
00458
00459 template <typename NodeType, typename BinaryFunctorT>
00460 node_to_deserialize_unary_f<NodeType,BinaryFunctorT>
00461 node_to_deser_unary_f( NodeType const & n, BinaryFunctorT const & f )
00462 {
00463 return node_to_deserialize_unary_f<NodeType,BinaryFunctorT>(n,f);
00464 }
00465
00466
00467
00468
00469 template <typename NodeType>
00470 inline node_to_deserialize_unary_f<NodeType>
00471 node_to_deser_unary_f( NodeType const & n )
00472 {
00473 return node_to_deserialize_unary_f<NodeType>(n);
00474 }
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 template <typename SerT, typename BinaryFunctorT = serialize_binary_f>
00486 struct serializable_to_serialize_unary_f : serialize_unary_node_f_tag
00487 {
00488 typedef SerT type;
00489 reference_f<SerT const> serializable;
00490 BinaryFunctorT functor;
00491 serializable_to_serialize_unary_f( SerT const & n ) : serializable(n), functor() {}
00492 serializable_to_serialize_unary_f( SerT const & n, BinaryFunctorT const & f ) : serializable(n), functor(f) {}
00493
00494 template <typename NodeT>
00495 inline bool operator()( NodeT & dest ) const
00496 {
00497 return this->functor( dest, this->serializable() );
00498 }
00499 };
00500
00501
00502
00503
00504 template <typename SerT, typename BinaryFunctorT>
00505 inline serializable_to_serialize_unary_f<SerT,BinaryFunctorT>
00506 ser_to_ser_unary_f( SerT const & s, BinaryFunctorT const & f )
00507 {
00508 return serializable_to_serialize_unary_f<SerT,BinaryFunctorT>( s, f );
00509 }
00510
00511
00512
00513
00514 template <typename SerT>
00515 inline serializable_to_serialize_unary_f<SerT>
00516 ser_to_ser_unary_f( SerT const & s)
00517 {
00518 return serializable_to_serialize_unary_f<SerT>( s );
00519 }
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 template <typename SerT, typename BinaryFunctorT = deserialize_binary_f>
00531 struct serializable_to_deserialize_unary_f : deserialize_unary_node_f_tag
00532 {
00533 typedef SerT type;
00534 reference_f<SerT> serializable;
00535 BinaryFunctorT functor;
00536 serializable_to_deserialize_unary_f( SerT & n ) : serializable(n), functor() {}
00537 serializable_to_deserialize_unary_f( SerT & n, BinaryFunctorT const & f ) : serializable(n), functor(f) {}
00538
00539 template <typename NodeT>
00540 inline bool operator()( NodeT const & src ) const
00541 {
00542 return this->functor( src, this->serializable() );
00543 }
00544 };
00545
00546
00547
00548
00549 template <typename SerT, typename BinaryFunctorT>
00550 inline serializable_to_deserialize_unary_f<SerT,BinaryFunctorT>
00551 ser_to_deser_unary_f( SerT & s, BinaryFunctorT const & f )
00552 {
00553 return serializable_to_deserialize_unary_f<SerT,BinaryFunctorT>( s, f );
00554 }
00555
00556
00557
00558
00559 template <typename SerT>
00560 inline serializable_to_deserialize_unary_f<SerT>
00561 ser_to_deser_unary_f( SerT const & s)
00562 {
00563 return serializable_to_deserialize_unary_f<SerT>( s );
00564 }
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 template <typename NodeType,typename DeserializableT, typename BinaryFunctorT = deserialize_binary_f>
00583 struct deserialize_nullary_f : deserialize_nullary_f_tag
00584 {
00585 reference_f<NodeType const> node;
00586 reference_f<DeserializableT> serializable;
00587 BinaryFunctorT functor;
00588 deserialize_nullary_f( NodeType const & n, DeserializableT & s )
00589 : node(n), serializable(s), functor()
00590 {
00591 }
00592
00593 deserialize_nullary_f( NodeType const & n, DeserializableT & s, BinaryFunctorT const & f )
00594 : node(n), serializable(s), functor(f)
00595 {
00596 }
00597
00598
00599
00600
00601 inline bool operator()() const
00602 {
00603 return this->functor( this->node(), this->serializable() );
00604 }
00605 };
00606
00607
00608
00609
00610 template <typename NodeType,typename DeserializableT, typename BinaryFunctorT>
00611 inline deserialize_nullary_f<NodeType,DeserializableT,BinaryFunctorT>
00612 deser_nullary_f( NodeType const & n, DeserializableT & s, BinaryFunctorT const & f )
00613 {
00614 return deserialize_nullary_f<NodeType,DeserializableT,BinaryFunctorT>( n, s, f );
00615 }
00616
00617
00618
00619
00620 template <typename NodeType,typename DeserializableT>
00621 inline deserialize_nullary_f<NodeType,DeserializableT>
00622 deser_nullary_f( NodeType const & n, DeserializableT & s )
00623 {
00624 return deserialize_nullary_f<NodeType,DeserializableT>( n, s );
00625 }
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639 template <typename SerializableT, typename BinaryFunctorT = serialize_binary_f>
00640 struct serializable_f : serialize_unary_node_f_tag
00641 {
00642 typedef SerializableT const type;
00643 reference_f<type> reference;
00644 BinaryFunctorT functor;
00645
00646
00647
00648
00649 explicit serializable_f( type & _ref ) : reference(_ref), functor()
00650 {
00651 }
00652
00653 serializable_f( type & _ref, BinaryFunctorT f ) : reference(_ref), functor(f)
00654 {
00655 }
00656
00657
00658
00659
00660
00661
00662
00663 template <typename NodeType>
00664 inline bool operator()( NodeType & dest ) const
00665 {
00666 return this->functor( dest, this->reference() );
00667 }
00668
00669
00670 inline type & operator()() const
00671 {
00672 return this->reference();
00673 }
00674 };
00675
00676
00677
00678
00679
00680
00681
00682
00683 template <typename SerializableT>
00684 inline serializable_f<SerializableT>
00685 ser_f( SerializableT const & ref )
00686 {
00687 return serializable_f<SerializableT>( ref );
00688 }
00689
00690
00691
00692
00693
00694
00695
00696
00697 template <typename SerializableT,typename BinaryFunctorT>
00698 inline serializable_f<SerializableT,BinaryFunctorT>
00699 ser_f( SerializableT const & ref, BinaryFunctorT f )
00700 {
00701 return serializable_f<SerializableT,BinaryFunctorT>( ref, f );
00702 }
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715 template <typename DeserializableT, typename BinaryFunctorT = deserialize_binary_f>
00716 struct deserializable_f : deserialize_unary_node_f_tag
00717 {
00718
00719 typedef DeserializableT type;
00720 reference_f<type> reference;
00721 BinaryFunctorT functor;
00722
00723
00724
00725
00726 explicit deserializable_f( type & _ref ) : reference(_ref),functor()
00727 {
00728 }
00729
00730 deserializable_f( type & _ref, BinaryFunctorT f ) : reference(_ref),functor(f)
00731 {
00732 }
00733
00734
00735
00736
00737
00738
00739 template <typename NodeType>
00740 inline bool operator()( const NodeType & src ) const
00741 {
00742 return this->functor( src, this->reference() );
00743 }
00744
00745
00746 inline type & operator()() const
00747 {
00748 return this->reference();
00749 }
00750 };
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760 template <typename DeserializableT>
00761 inline deserializable_f<DeserializableT>
00762 deser_f( DeserializableT & ref )
00763 {
00764 return deserializable_f<DeserializableT>( ref );
00765 }
00766
00767
00768
00769
00770
00771
00772
00773
00774 template <typename DeserializableT,typename BinaryFunctorT>
00775 inline deserializable_f<DeserializableT,BinaryFunctorT>
00776 deser_f( DeserializableT & ref, BinaryFunctorT f )
00777 {
00778 return deserializable_f<DeserializableT,BinaryFunctorT>( ref, f );
00779 }
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816 template <typename SerializableType, typename OutIterator, typename BinaryFunctorT = deserialize_binary_f>
00817 struct deserialize_to_output_iter_f
00818 {
00819
00820 typedef OutIterator type;
00821 type iterator;
00822 BinaryFunctorT functor;
00823 typedef SerializableType serializable_type;
00824
00825
00826
00827
00828
00829
00830 explicit deserialize_to_output_iter_f( type target ) : iterator(target), functor()
00831 {}
00832
00833
00834
00835
00836
00837 deserialize_to_output_iter_f( type target, BinaryFunctorT f ) : iterator(target), functor(f)
00838 {}
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853 template <typename NodeType>
00854 bool operator()( NodeType * const & src )
00855 {
00856 if( src )
00857 {
00858 #if 0
00859
00860 std::string c = node_traits<NodeType>::class_name(*src);
00861 cleanup_ptr<serializable_type> dest( s11n::cl::classload<serializable_type>( c ) );
00862
00863
00864 if( ! dest.get() )
00865 {
00866 return false;
00867 }
00868 if( this->functor( *src, *dest ) )
00869 {
00870 *(iterator++) = *dest;
00871 return true;
00872 }
00873 #else
00874 serializable_type dest;
00875 if( this->functor( *src, dest ) )
00876 {
00877 *(iterator++) = dest;
00878 return true;
00879 }
00880 #endif
00881 }
00882 return false;
00883 }
00884 };
00885
00886
00887
00888
00889
00890
00891 template <typename SerializableType,typename OutIterator, typename BinaryFunctorT>
00892 inline deserialize_to_output_iter_f<SerializableType,OutIterator,BinaryFunctorT>
00893 deser_to_outiter_f( OutIterator target, BinaryFunctorT f )
00894 {
00895 return deserialize_to_output_iter_f<SerializableType,OutIterator,BinaryFunctorT>( target, f );
00896 }
00897
00898
00899
00900
00901
00902
00903 template <typename SerializableType, typename OutIterator>
00904 inline deserialize_to_output_iter_f<SerializableType,OutIterator>
00905 deser_to_outiter_f( OutIterator target )
00906 {
00907 return deserialize_to_output_iter_f<SerializableType,OutIterator>( target );
00908 }
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919 template <typename BinaryFunctorT = serialize_binary_f>
00920 struct serialize_to_subnode_f : serialize_binary_f_tag
00921 {
00922
00923 std::string name;
00924 BinaryFunctorT functor;
00925
00926
00927
00928
00929 serialize_to_subnode_f( const std::string & subnodename, BinaryFunctorT f )
00930 : name(subnodename),functor(f)
00931 {
00932 }
00933
00934
00935
00936 explicit serialize_to_subnode_f( const std::string & subnodename )
00937 : name(subnodename),functor()
00938 {
00939 }
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950 template <typename NodeType, typename SerializableT>
00951 inline bool operator()( NodeType & dest, SerializableT const & src ) const
00952 {
00953 typedef node_traits<NodeType> NTR;
00954 Detail::auto_ptr<NodeType> nap( NTR::create( this->name ) );
00955 return this->functor( *nap, src )
00956 ? (NTR::children(dest).push_back( nap.release() ),true)
00957 : false;
00958 }
00959
00960 };
00961
00962
00963
00964
00965
00966
00967
00968
00969 inline serialize_to_subnode_f<>
00970 ser_to_subnode_f( const std::string & subnodename )
00971 {
00972 return serialize_to_subnode_f<>( subnodename );
00973 }
00974
00975
00976
00977
00978
00979
00980 template <typename BinaryFunctorT>
00981 inline serialize_to_subnode_f<BinaryFunctorT>
00982 ser_to_subnode_f( const std::string & subnodename, BinaryFunctorT f )
00983 {
00984 return serialize_to_subnode_f<BinaryFunctorT>( subnodename, f );
00985 }
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997 template <typename NodeType, typename BinaryFunctorT = serialize_binary_f>
00998 struct serialize_to_subnode_unary_f : serialize_unary_serializable_f_tag
00999 {
01000
01001 reference_f<NodeType> node;
01002 std::string name;
01003 BinaryFunctorT functor;
01004
01005
01006
01007 serialize_to_subnode_unary_f( NodeType & parent, const std::string & subnodename )
01008 : node(parent), name(subnodename),functor()
01009 {
01010 }
01011
01012
01013
01014 serialize_to_subnode_unary_f( NodeType & parent, const std::string & subnodename, BinaryFunctorT f )
01015 : node(parent), name(subnodename),functor(f)
01016 {
01017 }
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029 template <typename SerializableT>
01030 bool operator()( SerializableT const & src ) const
01031 {
01032 typedef node_traits<NodeType> NTR;
01033 Detail::auto_ptr<NodeType> nap( NTR::create( this->name ) );
01034 if( this->functor( *nap, src ) )
01035 {
01036 NTR::children(this->node()).push_back( nap.release() );
01037 }
01038 return 0 == nap.get();
01039 }
01040 };
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 template <typename NodeType>
01057 inline serialize_to_subnode_unary_f<NodeType>
01058 ser_to_subnode_unary_f( NodeType & parent, const std::string & subnodename )
01059 {
01060 return serialize_to_subnode_unary_f<NodeType>( parent, subnodename );
01061 }
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077 template <typename NodeType, typename BinaryFunctorT>
01078 inline serialize_to_subnode_unary_f<NodeType,BinaryFunctorT>
01079 ser_to_subnode_unary_f( NodeType & parent, const std::string & subnodename, BinaryFunctorT f )
01080 {
01081 return serialize_to_subnode_unary_f<NodeType,BinaryFunctorT>( parent, subnodename, f );
01082 }
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095 template <typename BinaryFunctorT = deserialize_binary_f>
01096 struct deserialize_from_subnode_f : deserialize_binary_f_tag
01097 {
01098
01099 std::string name;
01100 BinaryFunctorT functor;
01101 deserialize_from_subnode_f( const std::string & subnodename )
01102 : name(subnodename),functor()
01103 {
01104 }
01105
01106 deserialize_from_subnode_f( const std::string & subnodename, BinaryFunctorT f )
01107 : name(subnodename),functor(f)
01108 {
01109 }
01110
01111
01112
01113
01114
01115
01116 template <typename NodeType, typename SerializableT>
01117 inline bool operator()( NodeType const & src, SerializableT & dest ) const
01118 {
01119 const NodeType * ch = ::s11n::find_child_by_name( src, this->name );
01120 return ch
01121 ? this->functor( *ch, dest )
01122 : false;
01123 }
01124 };
01125
01126
01127
01128
01129
01130
01131
01132 inline deserialize_from_subnode_f<>
01133 deser_from_subnode_f( const std::string & subnodename )
01134 {
01135 return deserialize_from_subnode_f<>( subnodename );
01136 }
01137
01138
01139
01140
01141
01142 template <typename BinaryFunctorT>
01143 inline deserialize_from_subnode_f<BinaryFunctorT>
01144 deser_from_subnode_f( const std::string & subnodename, BinaryFunctorT f )
01145 {
01146 return deserialize_from_subnode_f<BinaryFunctorT>( subnodename, f );
01147 }
01148
01149
01150
01151
01152
01153
01154
01155
01156 template <typename NodeType, typename BinaryFunctorT = deserialize_binary_f>
01157 struct deserialize_from_subnode_unary_f : deserialize_unary_serializable_f_tag
01158 {
01159
01160 reference_f<NodeType const> node;
01161 std::string name;
01162 BinaryFunctorT functor;
01163 deserialize_from_subnode_unary_f( const NodeType & parent, const std::string & subnodename )
01164 : node(parent), name(subnodename),functor()
01165 {
01166 }
01167
01168 deserialize_from_subnode_unary_f( const NodeType & parent, const std::string & subnodename, BinaryFunctorT f )
01169 : node(parent), name(subnodename),functor(f)
01170 {
01171 }
01172
01173
01174
01175
01176
01177
01178 template <typename SerializableT>
01179 inline bool operator()( SerializableT & dest ) const
01180 {
01181 const NodeType * ch = ::s11n::find_child_by_name( this->node(), this->name );
01182 return ch
01183 ? this->functor( *ch, dest )
01184 : false;
01185 }
01186 };
01187
01188
01189
01190
01191
01192
01193
01194 template <typename NodeType>
01195 inline deserialize_from_subnode_unary_f<NodeType>
01196 deser_from_subnode_unary_f( const NodeType & parent, const std::string & subnodename )
01197 {
01198 return deserialize_from_subnode_unary_f<NodeType>( parent, subnodename );
01199 }
01200
01201
01202
01203
01204
01205 template <typename NodeType, typename BinaryFunctorT>
01206 inline deserialize_from_subnode_unary_f<NodeType,BinaryFunctorT>
01207 deser_from_subnode_unary_f( const NodeType & parent, const std::string & subnodename, BinaryFunctorT f )
01208 {
01209 return deserialize_from_subnode_unary_f<NodeType,BinaryFunctorT>( parent, subnodename, f );
01210 }
01211
01212
01213
01214
01215
01216
01217
01218
01219 struct logical_and_binary_f
01220 {
01221 template <typename F1, typename F2>
01222 inline bool operator()( F1 const & f1, F2 const & f2 ) const
01223 {
01224 return f1() && f2();
01225 }
01226 };
01227
01228
01229
01230
01231
01232 template <typename F1>
01233 struct logical_and_unary_f
01234 {
01235 F1 functor;
01236 logical_and_unary_f( F1 const & f ) : functor(f)
01237 {}
01238 template <typename F2>
01239 inline bool operator()( F2 const & f2 ) const
01240 {
01241 return this->functor() && f2();
01242 }
01243 };
01244
01245
01246
01247
01248
01249 template <typename F1, typename F2>
01250 struct logical_and_nullary_f
01251 {
01252 F1 functor1;
01253 F2 functor2;
01254 logical_and_nullary_f( F1 const & f1, F2 const & f2 ) : functor1(f1), functor2(f2)
01255 {}
01256 inline bool operator()() const
01257 {
01258 return this->functor1() && this->functor2();
01259 }
01260 };
01261
01262
01263
01264
01265
01266 template <typename F1, typename F2>
01267 inline logical_and_nullary_f<F1,F2>
01268 logical_and( F1 const & f1, F2 const & f2 )
01269 {
01270 return logical_and_nullary_f<F1,F2>(f1,f2);
01271 }
01272
01273
01274
01275
01276 template <typename F1>
01277 inline logical_and_unary_f<F1>
01278 logical_and( F1 const & f1 )
01279 {
01280 return logical_and_unary_f<F1>(f1);
01281 }
01282
01283
01284
01285
01286 inline logical_and_binary_f
01287 logical_and()
01288 {
01289 return logical_and_binary_f();
01290 }
01291
01292
01293
01294
01295 }
01296
01297
01298 #endif // s11n_net_s11n_1_1_FUNCTIONAL_HPP_INCLUDED