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 #include "CeylanModel.h" 00028 00029 #include "CeylanLogPlug.h" // for LogPlug 00030 #include "CeylanOperators.h" // for Ceylan::toString 00031 00032 #include "CeylanView.h" // for Ceylan::View 00033 #include "CeylanController.h" // for Ceylan::Controller 00034 00035 #ifdef CEYLAN_USES_CONFIG_H 00036 #include "CeylanConfig.h" // for CEYLAN_DEBUG_EVENTS 00037 #endif // CEYLAN_USES_CONFIG_H 00038 00039 00040 #include <list> 00041 00042 00043 using std::string ; 00044 using std::list ; 00045 00046 00047 using namespace Ceylan ; 00048 using namespace Ceylan::Log ; 00049 00050 00051 00052 00053 MVCEvent::MVCEvent( EventSource & source ) : 00054 Event( source ) 00055 { 00056 00057 } 00058 00059 00060 MVCEvent::~MVCEvent() throw() 00061 { 00062 00063 } 00064 00065 00066 00067 00068 Model::Model() : 00069 CallableEventSource(), 00070 CallerEventListener() 00071 { 00072 00073 } 00074 00075 00076 00077 Model::~Model() throw() 00078 { 00079 00080 #if CEYLAN_DEBUG_EVENTS 00081 LogPlug::debug( "Deleting Model " + toString() ) ; 00082 #endif // CEYLAN_DEBUG_EVENTS 00083 00084 unsubscribeFromAllControllers() ; 00085 00086 // removeAllViews would be useless. 00087 00088 } 00089 00090 00091 00092 void Model::addView( View & newView ) 00093 { 00094 00095 // Model will send events to views: 00096 add( newView ) ; 00097 00098 } 00099 00100 00101 00102 void Model::removeView( View & view ) 00103 { 00104 00105 remove( view ) ; 00106 00107 } 00108 00109 00110 00111 void Model::removeAllViews() 00112 { 00113 00114 removeAllListeners() ; 00115 00116 } 00117 00118 00119 00120 void Model::subscribeToController( Controller & newController ) 00121 { 00122 00123 // Model will listen to controller: 00124 subscribeTo( newController ) ; 00125 00126 } 00127 00128 00129 00130 void Model::unsubscribeFromController( Controller & controller ) 00131 { 00132 00133 unsubscribeFrom( controller ) ; 00134 00135 } 00136 00137 00138 00139 void Model::unsubscribeFromAllControllers() 00140 { 00141 00142 unsubscribeFromAllSources() ; 00143 00144 } 00145 00146 00147 00148 const string Model::toString( Ceylan::VerbosityLevels level ) const 00149 { 00150 00151 string result ; 00152 00153 if ( _sources.empty() ) 00154 result = "MVC Model currently not subscribed to any controller, " ; 00155 else 00156 result = "MVC Model having currently subscribed to " 00157 + Ceylan::toString( 00158 static_cast<Ceylan::Uint32>( _sources.size() ) ) 00159 + " controller(s), " ; 00160 00161 if ( _listeners.empty() ) 00162 result += "and having no registered view" ; 00163 else 00164 result += "and having " 00165 + Ceylan::toString( 00166 static_cast<Ceylan::Uint32>( _listeners.size() ) ) 00167 + " registered view(s)" ; 00168 00169 return result ; 00170 00171 } 00172 00173 00174 00175 void Model::notifyAllViews( const MVCEvent & newMVCEvent ) 00176 { 00177 00178 notifyAllListeners( newMVCEvent ) ; 00179 00180 } 00181