stlab.adobe.com Adobe Systems Incorporated

widget_factory_registry.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_WIDGET_FACTORY_REGISTRY_HPP
00010 #define ADOBE_WIDGET_FACTORY_REGISTRY_HPP
00011 
00012 /*************************************************************************************************/
00013 
00014 #include <adobe/dictionary.hpp>
00015 #include <adobe/name.hpp>
00016 #include <adobe/layout_attributes.hpp>
00017 
00018 #include <boost/function.hpp>
00019 #include <boost/tuple/tuple.hpp>
00020 
00021 #include <map>
00022 
00023 /*************************************************************************************************/
00024 
00025 namespace adobe {
00026 
00027 /*************************************************************************************************/
00028 
00029 struct widget_node_t;
00030 struct factory_token_t;
00031 
00032 /*************************************************************************************************/
00033 
00034 class widget_factory_t
00035 {
00036 public:
00037     typedef boost::function<widget_node_t(const dictionary_t&     parameters,
00038                                           const widget_node_t&    parent,
00039                                           const factory_token_t&  token,
00040                                           const widget_factory_t& factory)> widget_factory_method_t;
00041     typedef boost::tuple<widget_factory_method_t,
00042                          bool,
00043                          layout_attributes_t> data_type;
00044     typedef name_t                            key_type;
00045     typedef std::map<key_type, data_type>     map_type;
00046     typedef map_type::value_type              value_type;
00047 
00048     void reg(name_t           name,
00049              const data_type& data)
00050     {  map_m[name] = data; }
00051 
00052     void reg(name_t                     name,
00053              widget_factory_method_t    method,
00054              bool                       is_container = false,
00055              const layout_attributes_t& layout_attributes = layout_attributes_t())
00056     {  map_m[name] = data_type(method, is_container, layout_attributes); }
00057 
00058     bool is_reg(name_t name) const
00059     { return find(name, nothrow()) == map_m.end(); }
00060 
00061     void unreg(name_t name)
00062     { map_m.erase(find(name, noconst())); }
00063 
00064     const widget_factory_method_t& method(name_t name) const
00065     { return find(name)->second.get<0>(); }
00066 
00067     bool is_container(name_t name) const
00068     { return find(name)->second.get<1>(); }
00069 
00070     const layout_attributes_t& layout_attributes(name_t name) const
00071     { return find(name)->second.get<2>(); }
00072 
00076     map_type::const_iterator find(name_t name) const
00077     { return find(name, noconst()); }
00078 
00079 private:
00080     struct nothrow { };
00081     struct noconst { };
00082 
00083     map_type::iterator find(name_t name, nothrow) const
00084     { return const_cast<map_type&>(map_m).find(name); }
00085 
00089     map_type::iterator find(name_t name, noconst) const;
00090 
00091     map_type map_m;
00092 };
00093 
00094 /*************************************************************************************************/
00095 
00096 } // namespace adobe
00097 
00098 /*************************************************************************************************/
00099 
00100 #endif
00101 
00102 /*************************************************************************************************/

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