AutoChoice.h

00001 
00012 #ifndef _AutoChoice_h
00013 #define _AutoChoice_h
00014 
00015 // SYSTEM INCLUDES
00016 //
00017 
00018 // PROJECT INCLUDES
00019 //
00020 
00021 // LOCAL INCLUDES
00022 //
00023 #include "../Method.h"
00024 #include "../LineSearch.h"
00025 
00026 // FORWARD REFERENCES
00027 //
00028 
00029 // TODO: poprawić nazwę,
00030 template<class T>
00031 class AutoChoice
00032     : public wxChoice
00033 {
00034 public:
00035 // LIFECYCLE
00036 
00039     AutoChoice()
00040         : wxChoice()
00041     {
00042     }// AutoChoice
00043 
00046     AutoChoice(wxWindow             *pParent,
00047                wxWindowID           id,
00048                const ProblemBase*   pProblem = NULL,
00049                const wxPoint&       pos = wxDefaultPosition,
00050                const wxSize&        size = wxDefaultSize,
00051                long                 style = 0,
00052                const wxString&      name = wxT(""))
00053         : wxChoice(pParent, id, pos, size, 0, NULL, style, wxDefaultValidator,
00054                 name)
00055     {
00056         FillIn(pProblem);
00057     }// AutoChoice
00058 
00061     ~AutoChoice()
00062     {
00063     }// ~AutoChoice
00064 
00065 // OPERATORS
00066 
00067 // OPERATIONS
00068 
00072     bool        Create(wxWindow          *pParent,
00073                        wxWindowID        id,
00074                        const wxPoint&    pos,
00075                        const wxSize&     size,
00076                        long              style,
00077                        const wxString&   name)
00078     {
00079         bool result;
00080 
00081         result = wxChoice::Create(pParent, id, pos, size, 0, NULL,
00082                 wxDefaultValidator, name);
00083 
00084         if (result) FillIn(NULL);
00085 
00086         return result;
00087     }
00088 
00089 
00092     T*          GetSelected() const
00093     {
00094         T* p_selected_item
00095             = static_cast<T*>(GetClientData(GetSelection()));
00096 
00097         return p_selected_item;
00098     }// GetSelected
00099 
00100 //    std::auto_ptr<T> CreateSelected() const
00101 //    {
00102 //        return GetSelected()->Clone();
00103 //    }// CreateSelected
00104 
00109     bool        Reset(const ProblemBase* pProblem);
00110 
00111 // INQUIRY
00112 
00113 protected:
00114 
00115 private:
00116 
00120     void FillIn(const ProblemBase* pProblem);
00121 
00127     bool CanHandle(const Method* pMethod, const ProblemBase* pProblem) const;
00128 };
00129 
00130 // IMPLEMENTATION
00131 
00132 
00133 template<class T>
00134 void
00135 AutoChoice<T>::FillIn(const ProblemBase* pProblem)
00136 {
00137     const vector<Method*> container = Method::Methods();
00138     typename vector<Method*>::const_iterator i;
00139 
00140     Clear();
00141 
00142     for (i = container.begin(); i != container.end(); ++i)
00143     {
00144         if ((dynamic_cast<T*>(*i) != NULL) &&
00145                 (pProblem == NULL || CanHandle(*i, pProblem)))
00146         {
00147             Append((*i)->Name(), static_cast<void *>(*i));
00148         }
00149     }
00150     SetSelection(0);
00151 }// FillIn
00152 
00153 
00154 template<class T>
00155 bool
00156 AutoChoice<T>::Reset(const ProblemBase* pProblem)
00157 {
00158     const T* p_old_selection = GetSelected();
00159 
00160     FillIn(pProblem);
00161 
00162     if (CanHandle(p_old_selection, pProblem))
00163     {   // Stara metoda może poradzić sobie z nowym problemem - zostawiamy
00164         assert(GetCount() > 0);
00165 
00166         // Znajdz p_old_selection
00167         int i = 0;
00168         while (GetClientData(i) != p_old_selection) ++i;
00169 
00170         SetSelection(i);
00171 
00172         return false;
00173     }
00174     else return true;
00175 }// Reset
00176 
00177 #endif

Wygenerowano Fri Sep 29 21:04:48 2006 dla EduOptim2 programem  doxygen 1.4.6