gui/auxiliary/iterator/policy_visit.hpp

Go to the documentation of this file.
00001 /* $Id: policy_visit.hpp 52869 2012-02-03 20:18:33Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2011 - 2012 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef GUI_WIDGETS_AUXILIARY_ITERATOR_POLICY_VISIT_HPP_INCLUDED
00017 #define GUI_WIDGETS_AUXILIARY_ITERATOR_POLICY_VISIT_HPP_INCLUDED
00018 
00019 #include "gui/auxiliary/iterator/walker.hpp"
00020 
00021 #include <cstring>
00022 
00023 namespace gui2 {
00024 
00025 namespace iterator {
00026 
00027 namespace policy {
00028 
00029 namespace visit {
00030 
00031 /**
00032  * This policy skips the current level.
00033  */
00034 class tskip
00035 {
00036 public:
00037 
00038     /**
00039      * Acts like @ref twalker_::next for the level where the policy is used.
00040      */
00041     twalker_::tstate next(twalker_&) { return twalker_::fail; }
00042 
00043     /**
00044      * Acts like @ref twalker_::at_end for the level where the policy is used.
00045      */
00046     bool at_end(const twalker_&) const { return true; }
00047 
00048     /**
00049      * Acts like @ref twalker_::get for the level where the policy is used.
00050      */
00051     gui2::twidget* get(twalker_&) { return NULL; }
00052 };
00053 
00054 /**
00055  * This policy tries to visit the current level.
00056  *
00057  * @tparam level                  The level to visit.
00058  */
00059 template<twalker_::tlevel level>
00060 class tvisit
00061 {
00062 public:
00063 
00064     /**
00065      * Acts like @ref twalker_::next for the level where the policy is used.
00066      */
00067     twalker_::tstate next(twalker_& visitor)
00068     {
00069         return visitor.next(level);
00070     }
00071 
00072     /**
00073      * Acts like @ref twalker_::at_end for the level where the policy is used.
00074      */
00075     bool at_end(const twalker_& visitor) const
00076     {
00077         return visitor.at_end(level);
00078     }
00079 
00080     /**
00081      * Acts like @ref twalker_::get for the level where the policy is used.
00082      */
00083     gui2::twidget* get(twalker_& visitor)
00084     {
00085         return visitor.get(level);
00086     }
00087 };
00088 
00089 } // namespace visit
00090 
00091 /**
00092  * Helper class to select to visit or skip a level.
00093  *
00094  * @tparam level                  The level to determine the policy for.
00095  */
00096 template<bool, twalker_::tlevel level>
00097 class tvisit
00098 {
00099 };
00100 
00101 /** Specialized to select the @ref visit::tskip policy. */
00102 template<twalker_::tlevel level>
00103 class tvisit<false, level>
00104     : public visit::tskip
00105 {
00106 };
00107 
00108 /** Specialized to select the @ref visit::tvisit policy. */
00109 template<twalker_::tlevel level>
00110 class tvisit<true, level>
00111     : public visit::tvisit<level>
00112 {
00113 };
00114 
00115 } // namespace policy
00116 
00117 } // namespace iterator
00118 
00119 } // namespace gui2
00120 
00121 #endif
00122 
00123 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:54 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs