stlab.adobe.com Adobe Systems Incorporated

behavior.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 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_DEFERRED_PROC_SYSTEM_HPP
00010 #define ADOBE_DEFERRED_PROC_SYSTEM_HPP
00011 
00012 /****************************************************************************************************/
00013 
00014 #include <adobe/memory.hpp>
00015 #include <adobe/name.hpp>
00016 
00017 #include <boost/function.hpp>
00018 
00019 #include <cassert>
00020 #include <list>
00021 #include <vector>
00022 
00023 /****************************************************************************************************/
00024 
00025 namespace adobe {
00026 
00027 /****************************************************************************************************/
00028 
00029 typedef boost::function<void ()> verb_t;
00030 
00031 class behavior_t
00032 {
00033 public:
00034     typedef std::list<verb_t>     verb_set_t;
00035     typedef std::list<behavior_t> behavior_set_t;
00036 
00037     typedef verb_set_t::iterator     verb_token_t;
00038     typedef behavior_set_t::iterator behavior_token_t;
00039 
00040     explicit behavior_t(bool single_execution);
00041 
00042     // Executes the behavior
00043     void operator () ();
00044 
00045     behavior_token_t insert_behavior(bool single_execution);
00046     verb_token_t     insert(const verb_t&);
00047     void             reset(verb_token_t, const verb_t&);
00048     void             disconnect(verb_token_t token);
00049     void             disconnect(behavior_token_t token);
00050 
00051     bool        empty() const
00052         { return order_set_m.empty(); }
00053 
00054     std::size_t size() const
00055         { return order_set_m.size(); }
00056 
00057 private:
00058     enum order_t
00059     {
00060         order_verb_k = 0,
00061         order_behavior_k = 1
00062     };
00063 
00064     typedef std::vector<order_t> order_set_t;
00065 
00066     void erase_from_order(order_t type, std::size_t index);
00067 
00068     bool           single_execution_m;
00069     verb_set_t     verb_set_m;
00070     behavior_set_t behavior_set_m;
00071     order_set_t    order_set_m;
00072 };
00073 
00074 /****************************************************************************************************/
00075 
00076 behavior_t& general_deferred_proc_queue();
00077 
00078 /****************************************************************************************************/
00079 
00080 } // namespace adobe
00081 
00082 /****************************************************************************************************/
00083 
00084 #endif
00085 
00086 /****************************************************************************************************/

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