IWORKStyleStack.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libetonyek project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef IWORKSTYLESTACK_H_INCLUDED
00011 #define IWORKSTYLESTACK_H_INCLUDED
00012 
00013 #include <deque>
00014 
00015 #include <boost/any.hpp>
00016 
00017 #include "IWORKStyle.h"
00018 
00019 namespace libetonyek
00020 {
00021 
00034 class IWORKStyleStack
00035 {
00041   typedef std::deque<IWORKStylePtr_t> Stack_t;
00042 
00043 public:
00046   IWORKStyleStack();
00047 
00048   ~IWORKStyleStack();
00049 
00054   void push();
00055 
00060   void push(const IWORKStylePtr_t &style);
00061 
00064   void pop();
00065 
00066   void set(const IWORKStylePtr_t &style);
00067 
00068   template<class Property>
00069   bool has(const bool lookInParent = true) const
00070   {
00071     for (Stack_t::const_iterator it = m_stack.begin(); m_stack.end() != it; ++it)
00072     {
00073       if (*it)
00074       {
00075         if ((*it)->getPropertyMap().has<Property>(lookInParent))
00076           return true;
00077         else if ((*it)->getPropertyMap().clears<Property>(lookInParent))
00078           break;
00079       }
00080     }
00081     return false;
00082   }
00083 
00084   template<class Property>
00085   const typename IWORKPropertyInfo<Property>::ValueType &get(const bool lookInParent = true) const
00086   {
00087     for (Stack_t::const_iterator it = m_stack.begin(); m_stack.end() != it; ++it)
00088     {
00089       if (*it)
00090       {
00091         if ((*it)->getPropertyMap().has<Property>(lookInParent))
00092           return (*it)->getPropertyMap().get<Property>(lookInParent);
00093         else if ((*it)->getPropertyMap().clears<Property>(lookInParent))
00094           break;
00095       }
00096     }
00097     throw IWORKPropertyMap::NotFoundException();
00098   }
00099 
00100 private:
00101   Stack_t m_stack;
00102 };
00103 
00104 }
00105 
00106 #endif // IWORKSTYLESTACK_H_INCLUDED
00107 
00108 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */