EventIterators.h

00001 /*
00002  * This source file is part of libRocket, the HTML/CSS Interface Middleware
00003  *
00004  * For the latest information, see http://www.librocket.com
00005  *
00006  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  */
00027 
00028 #ifndef ROCKETCOREEVENTITERATORS_H
00029 #define ROCKETCOREEVENTITERATORS_H
00030 
00031 #include <Rocket/Core/ElementReference.h>
00032 #include <Rocket/Core/Element.h>
00033 
00034 namespace Rocket {
00035 namespace Core {
00036 
00043 class RKTEventFunctor
00044 {
00045 public:
00046         RKTEventFunctor(const String& event, const Dictionary& parameters, bool interruptible)
00047         {
00048                 this->event = event;
00049                 this->parameters = &parameters;
00050                 this->interruptible = interruptible;
00051         }
00052 
00053         void operator()(ElementReference& element)
00054         {
00055                 element->DispatchEvent(event, *parameters, interruptible);
00056         }
00057 
00058 private:
00059         String event;
00060         const Dictionary* parameters;
00061         bool interruptible;
00062 };
00063 
00070 class PseudoClassFunctor
00071 {
00072         public:
00073                 PseudoClassFunctor(const String& pseudo_class, bool set) : pseudo_class(pseudo_class)
00074                 {
00075                         this->set = set;
00076                 }
00077 
00078                 void operator()(ElementReference& element)
00079                 {
00080                         element->SetPseudoClass(pseudo_class, set);
00081                 }
00082 
00083         private:
00084                 String pseudo_class;
00085                 bool set;
00086 };
00087 
00093 template<typename T>
00094 class RKTOutputIterator : public std::iterator< std::output_iterator_tag, void, void, void, void >
00095 {
00096 public:
00097         RKTOutputIterator(T& _elements) : elements(_elements)
00098         {
00099         }
00100 
00101         RKTOutputIterator &operator=(const typename T::value_type &v) 
00102         {
00103                 // Store the given item
00104                 elements.push_back(v);
00105                 return *this;
00106         }
00107         
00108         RKTOutputIterator &operator *()
00109         { 
00110                 // Always return the same object
00111                 return *this; 
00112         }
00113 
00114         RKTOutputIterator &operator ++()
00115         {
00116                 // Always return the same object
00117                 return *this;
00118         }
00119         
00120         RKTOutputIterator operator ++(int)
00121         {
00122                 // Always return the same object
00123                 return *this;
00124         }
00125 private:
00126         T& elements;
00127 };
00128 
00129 }
00130 }
00131 
00132 #endif