stlab.adobe.com Adobe Systems Incorporated

sequence_mvc_muldex.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2008 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /******************************************************************************/
00008 
00009 #ifndef ADOBE_SEQUENCE_MVC_MULDEX
00010 #define ADOBE_SEQUENCE_MVC_MULDEX
00011 
00012 /******************************************************************************/
00013 
00014 #include <boost/static_assert.hpp>
00015 
00016 #include <adobe/function_pack.hpp>
00017 #include <adobe/sheet_hooks.hpp>
00018 #include <adobe/selection.hpp>
00019 #include <adobe/sequence_model.hpp>
00020 #include <adobe/zuid.hpp>
00021 
00022 /******************************************************************************/
00023 
00024 namespace adobe {
00025 f
00026 /******************************************************************************/
00217 /******************************************************************************/
00218 #if 0
00219 #pragma mark -
00220 #endif
00221 /******************************************************************************/
00236 template <typename T>
00237 struct sequence_view_multiplexer
00238 {
00239     typedef T                                            value_type;
00240     typedef sequence_model<T>                            sequence_model_type;
00241     typedef typename sequence_model_type::key_type       key_type;
00242     typedef typename sequence_model_type::cow_value_type cow_value_type;
00243     typedef dictionary_t                                 model_type;
00244     typedef boost::function<void (const model_type&)>    proc_type;
00245 
00246     void refresh(key_type key, cow_value_type value)
00247     {
00248         if (proc_m == false)
00249             return;
00250 
00251         dictionary_t command;
00252 
00253         command[static_name_t("command")] = any_regular_t(static_name_t("refresh"));
00254         command[static_name_t("key")] = any_regular_t(key);
00255         command[static_name_t("value")] = any_regular_t(value);
00256 
00257         send(command);
00258     }
00259 
00260     void extend(key_type before, key_type key, cow_value_type value)
00261     {
00262         if (proc_m == false)
00263             return;
00264 
00265         dictionary_t command;
00266 
00267         command[static_name_t("command")] = any_regular_t(static_name_t("extend"));
00268         command[static_name_t("before")] = any_regular_t(before);
00269         command[static_name_t("key")] = any_regular_t(key);
00270         command[static_name_t("value")] = any_regular_t(value);
00271 
00272         send(command);
00273     }
00274 
00275     void extend_set(key_type before, const vector<key_type>& key_set)
00276     {
00277         if (proc_m == false)
00278             return;
00279 
00280         dictionary_t command;
00281 
00282         command[static_name_t("command")] = any_regular_t(static_name_t("extend_set"));
00283         command[static_name_t("before")] = any_regular_t(before);
00284         command[static_name_t("key_set")] = any_regular_t(key_set);
00285 
00286         send(command);
00287     }
00288 
00289     void erase(const vector<key_type>& key_set)
00290     {
00291         if (proc_m == false)
00292             return;
00293 
00294         dictionary_t command;
00295 
00296         command[static_name_t("command")] = any_regular_t(static_name_t("erase"));
00297         command[static_name_t("key_set")] = any_regular_t(key_set);
00298 
00299         send(command);
00300     }
00301 
00302     void clear()
00303     {
00304         if (proc_m == false)
00305             return;
00306 
00307         dictionary_t command;
00308 
00309         command[static_name_t("command")] = any_regular_t(static_name_t("clear"));
00310 
00311         send(command);
00312     }
00313 
00314     void monitor(const proc_type& proc)
00315     { proc_m = proc; }
00316 
00317     void enable(bool) { }
00318 
00319 private:
00320     void send(const adobe::dictionary_t& command)
00321     {
00322         // first we send the command
00323         proc_m(command);
00324 
00325         // then we send an empty dictionary to clear the line
00326         proc_m(dictionary_t());
00327     }
00328 
00329     proc_type proc_m;
00330 };
00331 
00332 /******************************************************************************/
00346 struct sequence_view_demultiplexer_t
00347 {
00348     typedef dictionary_t model_type;
00349 
00358     template <typename T>
00359     explicit sequence_view_demultiplexer_t(T& sequence_view)
00360     {
00361         typedef typename T::key_type key_type;
00362 
00369         funnel_m.register_function(static_name_t("refresh"),
00370                                    boost::function<void (key_type, typename T::cow_value_type)>(boost::bind(&T::refresh, boost::ref(sequence_view), _1, _2)),
00371                                    static_name_t("key"),
00372                                    static_name_t("value"));
00373 
00374         funnel_m.register_function(static_name_t("extend"),
00375                                    boost::function<void (key_type, key_type, typename T::cow_value_type)>(boost::bind(&T::extend, boost::ref(sequence_view), _1, _2, _3)),
00376                                    static_name_t("before"),
00377                                    static_name_t("key"),
00378                                    static_name_t("value"));
00379 
00380         funnel_m.register_function(static_name_t("extend_set"),
00381                                    boost::function<void (key_type, const vector<key_type>&)>(boost::bind(&T::extend_set, boost::ref(sequence_view), _1, _2)),
00382                                    static_name_t("before"),
00383                                    static_name_t("key_set"));
00384 
00385         funnel_m.register_function(static_name_t("erase"),
00386                                    boost::function<void (const vector<key_type>&)>(boost::bind(&T::erase, boost::ref(sequence_view), _1)),
00387                                    static_name_t("key_set"));
00388 
00389         funnel_m.register_named0_function(static_name_t("clear"),
00390                                    boost::function<void ()>(boost::bind(&T::clear, boost::ref(sequence_view))));
00391     }
00392 
00402     void display(const model_type& value)
00403     {
00404         if (value == model_type())
00405             return;
00406 
00407         funnel_m(value);
00408     }
00409 
00410 private:
00411     function_pack_t funnel_m;
00412 };
00413 
00414 /******************************************************************************/
00424 template <typename SequenceView, typename Sheet>
00425 void attach_sequence_view_to_model(assemblage_t& assemblage,
00426                                    Sheet&        model,
00427                                    name_t        cell,
00428                                    SequenceView& sequence_view)
00429 {
00430     // This line asserts that sequence_view does in fact model a SequenceView concept.
00431     boost::function_requires<SequenceViewConcept<SequenceView> >();
00432 
00433     sequence_view_demultiplexer_t* demux(new sequence_view_demultiplexer_t(sequence_view));
00434 
00435     assemblage_cleanup_ptr(assemblage, demux);
00436 
00437     attach_view_to_model(assemblage, model, cell, *demux);
00438 }
00439 
00440 /******************************************************************************/
00450 template <typename SequenceModel, typename Sheet>
00451 void attach_sequence_model_view_to_model(assemblage_t&  assemblage,
00452                                          Sheet&         model,
00453                                          name_t         cell,
00454                                          SequenceModel& sequence_model)
00455 {
00456     typedef typename SequenceModel::value_type                   value_type;
00457     typedef typename poly_sequence_view<value_type>::type poly_sequence_view_type;
00458 
00459     sequence_view_multiplexer<value_type>* mux(new sequence_view_multiplexer<value_type>());
00460 
00461     assemblage_cleanup_ptr(assemblage, mux);
00462 
00463     attach_controller_to_model(assemblage, model, cell, *mux);
00464 
00465     poly_sequence_view_type* poly_sequence_view(new poly_sequence_view_type(boost::ref(*mux)));
00466 
00467     assemblage_cleanup_ptr(assemblage, poly_sequence_view);
00468 
00469     sequence_model.attach_view(*poly_sequence_view);
00470 
00471     assemblage.cleanup(boost::bind(&SequenceModel::detach_view,
00472                                    boost::ref(sequence_model),
00473                                    boost::ref(*poly_sequence_view)));
00474 }
00475 
00476 /******************************************************************************/
00488 template <typename SequenceModel, typename SequenceView, typename Sheet>
00489 void attach_sequence_view_muldex(SequenceModel&       sequence_model,
00490                                  SequenceView&        sequence_view,
00491                                  Sheet&               model,
00492                                  name_t        cell,
00493                                  assemblage_t& assemblage)
00494 {
00495     attach_sequence_view_to_model(assemblage,
00496                                   model,
00497                                   cell,
00498                                   sequence_view);
00499 
00500     attach_sequence_model_view_to_model(assemblage,
00501                                         model,
00502                                         cell,
00503                                         sequence_model);
00504 }
00505 
00506 /******************************************************************************/
00507 #if 0
00508 #pragma mark -
00509 #endif
00510 /******************************************************************************/
00525 template <typename T>
00526 struct sequence_model_multiplexer
00527 {
00528     typedef T                                         value_type;
00529     typedef adobe::sequence_key<T>                    key_type;
00530     typedef dictionary_t                              model_type;
00531     typedef boost::function<void (const model_type&)> proc_type;
00532 
00533     template <typename SequenceController>
00534     sequence_model_multiplexer(SequenceController& controller)
00535     {
00536         BOOST_STATIC_ASSERT((boost::is_same<T, typename sequence_controller_value_type<SequenceController>::type>::value));
00537 
00538         poly_m.reset(new typename poly_sequence_model<T>::type(boost::ref(*this)));
00539 
00540         controller.monitor_sequence(*poly_m);
00541     }
00542 
00543     /*
00544         The following are sequence_controller routines.
00545     */
00546     
00547     void push_back(const value_type& value)
00548     {
00549         if (proc_m == false)
00550             return;
00551 
00552         dictionary_t command;
00553 
00554         command[static_name_t("command")] = any_regular_t(static_name_t("push_back"));
00555         command[static_name_t("value")] = any_regular_t(value);
00556 
00557         send(command);
00558     }
00559 
00560     void set(key_type key, const value_type& value)
00561     {
00562         if (proc_m == false)
00563             return;
00564 
00565         dictionary_t command;
00566 
00567         command[static_name_t("command")] = any_regular_t(static_name_t("set"));
00568         command[static_name_t("key")] = any_regular_t(key);
00569         command[static_name_t("value")] = any_regular_t(value);
00570 
00571         send(command);
00572     }
00573 
00574     void insert(key_type before, const value_type& value)
00575     {
00576         if (proc_m == false)
00577             return;
00578 
00579         dictionary_t command;
00580 
00581         command[static_name_t("command")] = any_regular_t(static_name_t("insert"));
00582         command[static_name_t("before")] = any_regular_t(before);
00583         command[static_name_t("value")] = any_regular_t(value);
00584 
00585         send(command);
00586     }
00587 
00588     void insert_set(key_type before, const vector<value_type>& value_set)
00589     {
00590         if (proc_m == false)
00591             return;
00592 
00593         dictionary_t command;
00594 
00595         command[static_name_t("command")] = any_regular_t(static_name_t("insert_set"));
00596         command[static_name_t("before")] = any_regular_t(before);
00597         command[static_name_t("value_set")] = any_regular_t(value_set);
00598 
00599         send(command);
00600     }
00601 
00602     void erase(const vector<key_type>& key_set)
00603     {
00604         if (proc_m == false)
00605             return;
00606 
00607         dictionary_t command;
00608 
00609         command[static_name_t("command")] = any_regular_t(static_name_t("erase"));
00610         command[static_name_t("key_set")] = any_regular_t(key_set);
00611 
00612         send(command);
00613     }
00614 
00615     void clear()
00616     {
00617         if (proc_m == false)
00618             return;
00619 
00620         dictionary_t command;
00621 
00622         command[static_name_t("command")] = any_regular_t(static_name_t("clear"));
00623 
00624         send(command);
00625     }
00626 
00627     /*
00628         The following are property_model_controller routines.
00629     */
00630     
00631     void monitor(const proc_type& proc)
00632     { proc_m = proc; }
00633 
00634     void enable(bool) { }
00635 
00636 private:
00637     void send(const adobe::dictionary_t& command)
00638     {
00639         // first we send the command
00640         proc_m(command);
00641 
00642         // then we send an empty dictionary to clear the line
00643         proc_m(dictionary_t());
00644     }
00645 
00646     proc_type                                       proc_m;
00647     auto_ptr<typename poly_sequence_model<T>::type> poly_m;
00648 };
00649 
00650 /******************************************************************************/
00664 template <typename T>
00665 struct sequence_model_demultiplexer
00666 {
00667     typedef T                      value_type;
00668     typedef adobe::sequence_key<T> key_type;
00669     typedef dictionary_t           model_type;
00670 
00671     sequence_model_demultiplexer() :
00672         sequence_m(0)
00673     { }
00674 
00683     void display(const model_type& value)
00684     {
00685         if (value == model_type())
00686             return;
00687 
00688         funnel_m(value);
00689     }
00690 
00691     void monitor_sequence(typename poly_sequence_model<T>::type& sequence)
00692     {
00693         sequence_m = &sequence;
00694 
00695         funnel_m.register_function(static_name_t("push_back"),
00696                                    boost::function<void (const value_type&)>(boost::bind(&poly_sequence_model<T>::type::push_back, boost::ref(*sequence_m), _1)),
00697                                    static_name_t("value"));
00698 
00699         funnel_m.register_function(static_name_t("set"),
00700                                    boost::function<void (key_type pos, const value_type&)>(boost::bind(&poly_sequence_model<T>::type::set, boost::ref(*sequence_m), _1, _2)),
00701                                    static_name_t("key"),
00702                                    static_name_t("value"));
00703 
00704         funnel_m.register_function(static_name_t("insert"),
00705                                    boost::function<void (key_type pos, const value_type&)>(boost::bind(&poly_sequence_model<T>::type::insert, boost::ref(*sequence_m), _1, _2)),
00706                                    static_name_t("before"),
00707                                    static_name_t("value"));
00708 
00709         funnel_m.register_function(static_name_t("insert_set"),
00710                                    boost::function<void (key_type pos, const vector<value_type>&)>(boost::bind(&poly_sequence_model<T>::type::insert_set, boost::ref(*sequence_m), _1, _2)),
00711                                    static_name_t("before"),
00712                                    static_name_t("value_set"));
00713 
00714         funnel_m.register_function(static_name_t("erase"),
00715                                    boost::function<void (const vector<key_type>& selection)>(boost::bind(&poly_sequence_model<T>::type::erase, boost::ref(*sequence_m), _1)),
00716                                    static_name_t("key_set"));
00717 
00718         funnel_m.register_named0_function(static_name_t("clear"),
00719                                    boost::function<void ()>(boost::bind(&poly_sequence_model<T>::type::clear, boost::ref(*sequence_m))));
00720     }
00721 
00722 private:
00723     typename poly_sequence_model<T>::type* sequence_m;
00724     function_pack_t                        funnel_m;
00725 };
00726 
00727 /******************************************************************************/
00737 template <typename SequenceController, typename Sheet>
00738 void attach_sequence_controller_to_model(assemblage_t&       assemblage,
00739                                          Sheet&              model,
00740                                          name_t              cell,
00741                                          SequenceController& sequence_controller)
00742 {
00743     // This line asserts that sequence_controller does in fact model a SequenceController concept.
00744     boost::function_requires<SequenceControllerConcept<SequenceController> >();
00745 
00746     typedef typename sequence_controller_value_type<SequenceController>::type value_type;
00747     typedef typename poly_sequence_controller<value_type>::type               poly_sequence_controller_type;
00748 
00749     sequence_model_multiplexer<value_type>* mux(new sequence_model_multiplexer<value_type>(sequence_controller));
00750 
00751     assemblage_cleanup_ptr(assemblage, mux);
00752 
00753     attach_controller_to_model(assemblage, model, cell, *mux);
00754 }
00755 
00756 /******************************************************************************/
00766 template <typename SequenceModel, typename Sheet>
00767 void attach_sequence_model_controller_to_model(assemblage_t&  assemblage,
00768                                                Sheet&         model,
00769                                                name_t         cell,
00770                                                SequenceModel& sequence_model)
00771 {
00772     typedef typename SequenceModel::value_type                  value_type;
00773     typedef typename poly_sequence_controller<value_type>::type poly_sequence_controller_type;
00774 
00775     sequence_model_demultiplexer<value_type>* demux(new sequence_model_demultiplexer<value_type>());
00776 
00777     assemblage_cleanup_ptr(assemblage, demux);
00778 
00779     poly_sequence_controller_type* poly_sequence_controller(new poly_sequence_controller_type(boost::ref(*demux)));
00780 
00781     assemblage_cleanup_ptr(assemblage, poly_sequence_controller);
00782 
00783     sequence_model.attach_controller(*poly_sequence_controller);
00784 
00785     assemblage.cleanup(boost::bind(&SequenceModel::detach_controller,
00786                                    boost::ref(sequence_model),
00787                                    boost::ref(*poly_sequence_controller)));
00788 
00789     attach_view_to_model(assemblage, model, cell, *demux);
00790 }
00791 
00792 /******************************************************************************/
00805 template <typename SequenceModel, typename SequenceController, typename Sheet>
00806 void attach_sequence_controller_muldex(SequenceModel&      sequence_model,
00807                                        SequenceController& sequence_controller,
00808                                        Sheet&              model,
00809                                        name_t              cell,
00810                                        assemblage_t&       assemblage)
00811 {
00812     attach_sequence_controller_to_model(assemblage,
00813                                         model,
00814                                         cell,
00815                                         sequence_controller);
00816 
00817     attach_sequence_model_controller_to_model(assemblage,
00818                                               model,
00819                                               cell,
00820                                               sequence_model);
00821 }
00822 
00823 /******************************************************************************/
00830 template <typename SequenceModel, typename Sheet>
00831 void attach_sequence_model_to_property_model(SequenceModel& sequence_model,
00832                                              Sheet&         model,
00833                                              name_t         view_line_cell,
00834                                              name_t         controller_line_cell,
00835                                              assemblage_t&  assemblage)
00836 {
00837     attach_sequence_model_controller_to_model(assemblage,
00838                                               model,
00839                                               controller_line_cell,
00840                                               sequence_model);
00841 
00842     attach_sequence_model_view_to_model(assemblage,
00843                                         model,
00844                                         view_line_cell,
00845                                         sequence_model);
00846 }
00847 
00848 /******************************************************************************/
00855 template <typename SequenceWidget, typename Sheet>
00856 void attach_sequence_widget_to_property_model(SequenceWidget& sequence_widget,
00857                                               Sheet&          model,
00858                                               name_t          view_line_cell,
00859                                               name_t          controller_line_cell,
00860                                               assemblage_t&   assemblage)
00861 {
00862     attach_sequence_controller_to_model(assemblage,
00863                                         model,
00864                                         controller_line_cell,
00865                                         sequence_widget);
00866 
00867     attach_sequence_view_to_model(assemblage,
00868                                   model,
00869                                   view_line_cell,
00870                                   sequence_widget);
00871 }
00872 
00873 /******************************************************************************/
00874 
00875 } // namespace adobe
00876 
00877 /******************************************************************************/
00878 // ADOBE_SEQUENCE_MVC_MULDEX
00879 #endif
00880 /******************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google