00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #ifndef CEYLAN_GENERIC_VIEW_H_ 00028 #define CEYLAN_GENERIC_VIEW_H_ 00029 00030 00031 #include "CeylanTextDisplayable.h" // for inheritance 00032 #include "CeylanGenericModel.h" // for inheritance 00033 00034 #include <string> 00035 00036 00037 00038 /* 00039 * See the CeylanGenericMVCDefines.h file for detailed design explanations 00040 * about this light-weight generic (template-based) MVC framework. 00041 * 00042 */ 00043 00044 00045 00046 /* 00047 * Here the base view (BaseView) and all necessary templated variations of 00048 * views are defined: 00049 * - a view with one templated model: SingleModelGenericView<Model> 00050 * 00051 * On the contrary of the model counterpart file, no non-templated class is 00052 * implemented, as a view needs to know the actual model class it is linked 00053 * with (whereas the opposite is not true). 00054 * 00055 */ 00056 00057 00058 00059 namespace Ceylan 00060 { 00061 00062 00063 namespace MVC 00064 { 00065 00066 00067 00090 class CEYLAN_DLL BaseView : public TextDisplayable 00091 { 00092 00093 00094 public: 00095 00096 00097 00102 BaseView() ; 00103 00104 00105 00107 virtual ~BaseView() throw() ; 00108 00109 00110 00118 virtual void render() = 0 ; 00119 00120 00121 00133 virtual const std::string toString( 00134 Ceylan::VerbosityLevels level = Ceylan::high ) const ; 00135 00136 00137 00138 00139 private: 00140 00141 00149 BaseView( const BaseView & source ) ; 00150 00151 00159 BaseView & operator = ( const BaseView & source ) ; 00160 00161 00162 00163 } ; 00164 00165 00166 00167 00168 00169 /* 00170 * SingleModelGenericView templated class. 00171 * 00172 */ 00173 00174 00175 00188 template <typename ActualModel> 00189 class SingleModelGenericView: public BaseView 00190 { 00191 00192 00193 public: 00194 00195 00196 00207 explicit SingleModelGenericView( const ActualModel & model ) ; 00208 00209 00210 00215 virtual ~SingleModelGenericView() throw() ; 00216 00217 00218 00230 virtual const std::string toString( 00231 Ceylan::VerbosityLevels level = Ceylan::high ) const ; 00232 00233 00234 00235 protected: 00236 00237 00239 const ActualModel * _model ; 00240 00241 00242 00243 private: 00244 00245 00253 SingleModelGenericView( const SingleModelGenericView & source ); 00254 00255 00263 SingleModelGenericView & operator = ( 00264 const SingleModelGenericView & source ) ; 00265 00266 } ; 00267 00268 00269 00270 00271 // Implementation of the SingleModelGenericView templated class. 00272 00273 00274 template <typename ActualModel> 00275 SingleModelGenericView<ActualModel>::SingleModelGenericView( 00276 const ActualModel & model ) : 00277 _model( & model ) 00278 { 00279 00280 _model->addView( *this ) ; 00281 00282 } 00283 00284 00285 00286 template <typename ActualModel> 00287 SingleModelGenericView<ActualModel>::~SingleModelGenericView() throw() 00288 { 00289 00290 // Nothing to do, model not owned. 00291 00292 } 00293 00294 00295 00296 template <typename ActualModel> 00297 const std::string SingleModelGenericView<ActualModel>::toString( 00298 Ceylan::VerbosityLevels level ) const 00299 { 00300 00301 return "Single-model generic view associated to " 00302 + this->_model->ActualModel::toString( Ceylan::low ) ; 00303 00304 } 00305 00306 00307 } 00308 00309 00310 } 00311 00312 00313 00314 #endif // CEYLAN_GENERIC_VIEW_H_ 00315